From 881e1bae3bde800f19d0b4c5d3ca71d73387a911 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 28 Mar 2024 15:55:57 +0100 Subject: [PATCH] feat: show confirm modal before deleting channel group --- .../ui/adapters/SubscriptionGroupsAdapter.kt | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupsAdapter.kt index 3bb35b38e..4740a327b 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupsAdapter.kt @@ -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() + } }