Fix some UI subscription groups issues

This commit is contained in:
Bnyro 2023-03-28 18:08:50 +02:00
parent a4088189bf
commit caea47d0ed
4 changed files with 18 additions and 11 deletions

View File

@ -33,12 +33,13 @@ class SubscriptionGroupsAdapter(
holder.binding.apply { holder.binding.apply {
groupName.text = subscriptionGroup.name groupName.text = subscriptionGroup.name
deleteGroup.setOnClickListener { deleteGroup.setOnClickListener {
groups.remove(subscriptionGroup) groups.removeAt(position)
runBlocking(Dispatchers.IO) { runBlocking(Dispatchers.IO) {
DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup( DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup(
subscriptionGroup.name subscriptionGroup.name
) )
} }
onGroupsChanged(groups)
notifyItemRemoved(position) notifyItemRemoved(position)
notifyItemRangeChanged(position, itemCount) notifyItemRangeChanged(position, itemCount)
} }
@ -48,7 +49,7 @@ class SubscriptionGroupsAdapter(
runBlocking(Dispatchers.IO) { runBlocking(Dispatchers.IO) {
// delete the old one as it might have a different name // delete the old one as it might have a different name
DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup( DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup(
subscriptionGroup.name groupName.text.toString()
) )
DatabaseHolder.Database.subscriptionGroupsDao().createGroup(it) DatabaseHolder.Database.subscriptionGroupsDao().createGroup(it)
} }

View File

@ -17,11 +17,11 @@ import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.JsonPrimitive
class BackupDialog( class BackupDialog(
private val createBackupFile: (BackupFile) -> Unit, private val createBackupFile: (BackupFile) -> Unit
) : DialogFragment() { ) : DialogFragment() {
sealed class BackupOption( sealed class BackupOption(
@StringRes val name: Int, @StringRes val name: Int,
val onSelected: suspend (BackupFile) -> Unit, val onSelected: suspend (BackupFile) -> Unit
) { ) {
object WatchHistory : BackupOption(R.string.watch_history, onSelected = { object WatchHistory : BackupOption(R.string.watch_history, onSelected = {
it.watchHistory = Database.watchHistoryDao().getAll() it.watchHistory = Database.watchHistoryDao().getAll()
@ -78,7 +78,7 @@ class BackupDialog(
BackupOption.PlaylistBookmarks, BackupOption.PlaylistBookmarks,
BackupOption.LocalPlaylists, BackupOption.LocalPlaylists,
BackupOption.SubscriptionGroups, BackupOption.SubscriptionGroups,
BackupOption.Preferences, BackupOption.Preferences
) )
val backupItems = backupOptions.map { context?.getString(it.name)!! }.toTypedArray() val backupItems = backupOptions.map { context?.getString(it.name)!! }.toTypedArray()

View File

@ -1,5 +1,6 @@
package com.github.libretube.ui.fragments package com.github.libretube.ui.fragments
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -162,19 +163,19 @@ class SubscriptionsFragment : Fragment() {
} }
} }
@SuppressLint("InflateParams")
private suspend fun initChannelGroups() { private suspend fun initChannelGroups() {
channelGroups = DatabaseHolder.Database.subscriptionGroupsDao().getAll() channelGroups = DatabaseHolder.Database.subscriptionGroupsDao().getAll()
binding.chipAll.isSelected = true binding.chipAll.isChecked = true
binding.channelGroups.children.forEach { view -> binding.channelGroups.removeAllViews()
if (view.id != R.id.chip_all) binding.channelGroups.removeView(view)
}
binding.channelGroups.addView(binding.chipAll)
channelGroups.forEach { group -> 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() id = View.generateViewId()
isCheckable = true isCheckable = true
isClickable = true
text = group.name text = group.name
} }

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />