mirror of
https://github.com/pendragonnn/PalmGuard-App-Thesis.git
synced 2025-08-13 10:52:22 +00:00
feat: [history] add delete history feature
This commit is contained in:
@ -47,15 +47,19 @@ class HistoryDiagnoseAdapter : ListAdapter<HistoryDiagnose, HistoryDiagnoseAdapt
|
||||
dateResultDiagnosis.text = date
|
||||
val confidenceFloat = historyDiagnose.confidence.toFloatOrNull() ?: 0f
|
||||
binding.confidenceResultDiagnosis.text = "Confidence: %.1f%%".format(confidenceFloat)
|
||||
delete.setOnClickListener {
|
||||
onItemClickCallback.onDeleteClicked(historyDiagnose)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface OnItemClickCallback {
|
||||
fun onItemClicked(data: HistoryDiagnose)
|
||||
fun onDeleteClicked(data: HistoryDiagnose)
|
||||
}
|
||||
|
||||
fun setOnItemClickCallback(onItemClickCallback: OnItemClickCallback) {
|
||||
this.onItemClickCallback = onItemClickCallback
|
||||
fun setOnItemClickCallback(callback: OnItemClickCallback) {
|
||||
this.onItemClickCallback = callback
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.example.palmguardapp.ui.detection
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
@ -51,6 +52,20 @@ class DetectionFragment : Fragment(R.layout.fragment_detection) {
|
||||
override fun onItemClicked(data: HistoryDiagnose) {
|
||||
navigateToDiagnoseDetail(data)
|
||||
}
|
||||
|
||||
fun onDeleteClicked(data: HistoryDiagnose) {
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setTitle("Hapus Riwayat")
|
||||
.setMessage("Apakah kamu yakin ingin menghapus riwayat ini?")
|
||||
.setPositiveButton("Hapus") { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
viewModel.deleteHistory(data)
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Batal", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,10 @@ import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class DetectionViewModel (private val historyDiagnoseRepository: HistoryDiagnoseRepository) : ViewModel() {
|
||||
class DetectionViewModel(private val historyDiagnoseRepository: HistoryDiagnoseRepository) : ViewModel() {
|
||||
|
||||
private val _detectionList = MutableSharedFlow<List<HistoryDiagnose>>()
|
||||
val detectionList : Flow<List<HistoryDiagnose>> = _detectionList.asSharedFlow()
|
||||
val detectionList: Flow<List<HistoryDiagnose>> = _detectionList.asSharedFlow()
|
||||
|
||||
init {
|
||||
getDetectionList()
|
||||
@ -25,4 +25,12 @@ class DetectionViewModel (private val historyDiagnoseRepository: HistoryDiagnose
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteHistory(historyDiagnose: HistoryDiagnose) {
|
||||
viewModelScope.launch {
|
||||
historyDiagnoseRepository.delete(historyDiagnose)
|
||||
// Refresh the list after deletion
|
||||
getDetectionList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
app/src/main/res/drawable/baseline_delete_24.xml
Normal file
5
app/src/main/res/drawable/baseline_delete_24.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#F18282" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
|
||||
|
||||
</vector>
|
@ -84,5 +84,17 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:contentDescription="TODO"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/baseline_delete_24"
|
||||
app:layout_constraintEnd_toStartOf="@id/img_arrow2"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
Reference in New Issue
Block a user