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 ec4422129..03c1c402f 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 @@ -33,12 +33,13 @@ class SubscriptionGroupsAdapter( holder.binding.apply { groupName.text = subscriptionGroup.name deleteGroup.setOnClickListener { - groups.remove(subscriptionGroup) + groups.removeAt(position) runBlocking(Dispatchers.IO) { DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup( subscriptionGroup.name ) } + onGroupsChanged(groups) notifyItemRemoved(position) notifyItemRangeChanged(position, itemCount) } @@ -48,7 +49,7 @@ class SubscriptionGroupsAdapter( runBlocking(Dispatchers.IO) { // delete the old one as it might have a different name DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup( - subscriptionGroup.name + groupName.text.toString() ) DatabaseHolder.Database.subscriptionGroupsDao().createGroup(it) } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt index d5626bcb3..f57e4383c 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt @@ -17,11 +17,11 @@ import kotlinx.serialization.json.JsonNull import kotlinx.serialization.json.JsonPrimitive class BackupDialog( - private val createBackupFile: (BackupFile) -> Unit, + private val createBackupFile: (BackupFile) -> Unit ) : DialogFragment() { sealed class BackupOption( @StringRes val name: Int, - val onSelected: suspend (BackupFile) -> Unit, + val onSelected: suspend (BackupFile) -> Unit ) { object WatchHistory : BackupOption(R.string.watch_history, onSelected = { it.watchHistory = Database.watchHistoryDao().getAll() @@ -78,7 +78,7 @@ class BackupDialog( BackupOption.PlaylistBookmarks, BackupOption.LocalPlaylists, BackupOption.SubscriptionGroups, - BackupOption.Preferences, + BackupOption.Preferences ) val backupItems = backupOptions.map { context?.getString(it.name)!! }.toTypedArray() diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index 3db87c0ca..48b29fb46 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -1,5 +1,6 @@ package com.github.libretube.ui.fragments +import android.annotation.SuppressLint import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -162,19 +163,19 @@ class SubscriptionsFragment : Fragment() { } } + @SuppressLint("InflateParams") private suspend fun initChannelGroups() { channelGroups = DatabaseHolder.Database.subscriptionGroupsDao().getAll() - binding.chipAll.isSelected = true - binding.channelGroups.children.forEach { view -> - if (view.id != R.id.chip_all) binding.channelGroups.removeView(view) - } + binding.chipAll.isChecked = true + binding.channelGroups.removeAllViews() + binding.channelGroups.addView(binding.chipAll) channelGroups.forEach { group -> - val chip = Chip(context, null, R.style.ElevatedFilterChip).apply { + val chip = layoutInflater.inflate(R.layout.filter_chip, null) as Chip + chip.apply { id = View.generateViewId() isCheckable = true - isClickable = true text = group.name } diff --git a/app/src/main/res/layout/filter_chip.xml b/app/src/main/res/layout/filter_chip.xml new file mode 100644 index 000000000..0f287ddcb --- /dev/null +++ b/app/src/main/res/layout/filter_chip.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file