-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#101
- Loading branch information
Showing
18 changed files
with
457 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...com/healthc/app/presentation/detection/object_detection/adapter/ObjectDetectionAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.healthc.app.presentation.detection.object_detection.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.healthc.app.databinding.ItemObjectDetectionBinding | ||
import com.healthc.data.model.local.detection.ObjectDetectionResult | ||
|
||
class ObjectDetectionAdapter( | ||
private val classes: List<String>, | ||
private val onClick: (String) -> Unit, | ||
): ListAdapter<ObjectDetectionResult, ObjectDetectionAdapter.ObjectDetectionViewHolder>(diffCallback) { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ObjectDetectionViewHolder { | ||
return ObjectDetectionViewHolder( | ||
ItemObjectDetectionBinding.inflate( | ||
LayoutInflater.from(parent.context), parent, false | ||
) | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ObjectDetectionViewHolder, position: Int) { | ||
holder.bind(currentList[position]) | ||
} | ||
|
||
inner class ObjectDetectionViewHolder( | ||
private val binding: ItemObjectDetectionBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(objectDetectionResult: ObjectDetectionResult) { | ||
val detectedObject = classes[objectDetectionResult.classIndex] | ||
binding.tvODItemObject.text = detectedObject | ||
|
||
val score = objectDetectionResult.score * 100 | ||
binding.tvODItemScore.text = "${String.format("%.2f", score)}%" | ||
|
||
binding.cdODItem.setOnClickListener { | ||
onClick(detectedObject) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
val diffCallback = object : DiffUtil.ItemCallback<ObjectDetectionResult>() { | ||
override fun areItemsTheSame(oldItem: ObjectDetectionResult, newItem: ObjectDetectionResult): Boolean { | ||
return oldItem == newItem | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: ObjectDetectionResult, newItem: ObjectDetectionResult): Boolean { | ||
return oldItem == newItem | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.