mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Merge pull request #5826 from Bnyro/master
feat: show confirm modal before deleting channel group
This commit is contained in:
commit
809f18f046
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user