Merge pull request #5826 from Bnyro/master

feat: show confirm modal before deleting channel group
This commit is contained in:
Bnyro 2024-03-28 15:56:16 +01:00 committed by GitHub
commit 809f18f046
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,15 +1,18 @@
package com.github.libretube.ui.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.databinding.SubscriptionGroupRowBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.SubscriptionGroup
import com.github.libretube.ui.models.EditChannelGroupsModel
import com.github.libretube.ui.sheets.EditChannelGroupSheet
import com.github.libretube.ui.viewholders.SubscriptionGroupsViewHolder
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -36,13 +39,7 @@ class SubscriptionGroupsAdapter(
groupName.text = subscriptionGroup.name
deleteGroup.setOnClickListener {
CoroutineScope(Dispatchers.IO).launch {
DatabaseHolder.Database.subscriptionGroupsDao()
.deleteGroup(subscriptionGroup.name)
groups.removeAt(position)
viewModel.groups.postValue(groups)
}
showDeleteDialog(root.context, position)
}
editGroup.setOnClickListener {
@ -51,4 +48,21 @@ class SubscriptionGroupsAdapter(
}
}
}
private fun showDeleteDialog(context: Context, position: Int) {
MaterialAlertDialogBuilder(context)
.setTitle(R.string.delete)
.setMessage(R.string.irreversible)
.setPositiveButton(R.string.okay) { _, _ ->
CoroutineScope(Dispatchers.IO).launch {
DatabaseHolder.Database.subscriptionGroupsDao()
.deleteGroup(groups[position].name)
groups.removeAt(position)
viewModel.groups.postValue(groups)
}
}
.setNegativeButton(R.string.cancel, null)
.show()
}
}