mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Fix some minor subscription group issues
This commit is contained in:
parent
a2117bd74b
commit
4402bf1baf
@ -4,7 +4,6 @@ import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.github.libretube.db.obj.SubscriptionGroup
|
||||
|
||||
@Dao()
|
||||
@ -15,9 +14,6 @@ interface SubscriptionGroupsDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun createGroup(subscriptionGroup: SubscriptionGroup)
|
||||
|
||||
@Update
|
||||
suspend fun updateGroup(subscriptionGroup: SubscriptionGroup)
|
||||
|
||||
@Query("DELETE FROM subscriptionGroups WHERE name = :name")
|
||||
suspend fun deleteGroup(name: String)
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.db.obj.SubscriptionGroup
|
||||
import com.github.libretube.ui.dialogs.EditChannelGroupDialog
|
||||
import com.github.libretube.ui.viewholders.SubscriptionGroupsViewHolder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class SubscriptionGroupsAdapter(
|
||||
@ -33,7 +34,7 @@ class SubscriptionGroupsAdapter(
|
||||
groupName.text = subscriptionGroup.name
|
||||
deleteGroup.setOnClickListener {
|
||||
groups.remove(subscriptionGroup)
|
||||
runBlocking {
|
||||
runBlocking(Dispatchers.IO) {
|
||||
DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup(
|
||||
subscriptionGroup.name
|
||||
)
|
||||
@ -44,8 +45,12 @@ class SubscriptionGroupsAdapter(
|
||||
editGroup.setOnClickListener {
|
||||
EditChannelGroupDialog(subscriptionGroup) {
|
||||
groups[position] = it
|
||||
runBlocking {
|
||||
DatabaseHolder.Database.subscriptionGroupsDao().updateGroup(it)
|
||||
runBlocking(Dispatchers.IO) {
|
||||
// delete the old one as it might have a different name
|
||||
DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup(
|
||||
subscriptionGroup.name
|
||||
)
|
||||
DatabaseHolder.Database.subscriptionGroupsDao().createGroup(it)
|
||||
}
|
||||
notifyItemChanged(position)
|
||||
onGroupsChanged(groups)
|
||||
|
@ -10,6 +10,7 @@ import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.db.obj.SubscriptionGroup
|
||||
import com.github.libretube.ui.adapters.SubscriptionGroupsAdapter
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class ChannelGroupsDialog(
|
||||
@ -33,7 +34,7 @@ class ChannelGroupsDialog(
|
||||
.setPositiveButton(R.string.okay, null)
|
||||
.setNeutralButton(R.string.new_group) { _, _ ->
|
||||
EditChannelGroupDialog(SubscriptionGroup("", mutableListOf())) {
|
||||
runBlocking {
|
||||
runBlocking(Dispatchers.IO) {
|
||||
DatabaseHolder.Database.subscriptionGroupsDao().createGroup(it)
|
||||
}
|
||||
groups.add(it)
|
||||
|
@ -166,25 +166,26 @@ class SubscriptionsFragment : Fragment() {
|
||||
channelGroups = DatabaseHolder.Database.subscriptionGroupsDao().getAll()
|
||||
|
||||
binding.chipAll.isSelected = true
|
||||
binding.channelGroups.children.forEachIndexed { index, view ->
|
||||
if (index != 0) binding.channelGroups.removeView(view)
|
||||
binding.channelGroups.children.forEach { view ->
|
||||
if (view.id != R.id.chip_all) binding.channelGroups.removeView(view)
|
||||
}
|
||||
|
||||
channelGroups.forEachIndexed { index, group ->
|
||||
channelGroups.forEach { group ->
|
||||
val chip = Chip(context, null, R.style.ElevatedFilterChip).apply {
|
||||
id = View.generateViewId()
|
||||
isCheckable = true
|
||||
isClickable = true
|
||||
text = group.name
|
||||
setOnClickListener {
|
||||
selectedFilterGroup = index + 1 // since the first one is "All"
|
||||
showFeed()
|
||||
}
|
||||
}
|
||||
|
||||
binding.channelGroups.addView(chip)
|
||||
}
|
||||
|
||||
binding.channelGroups.setOnCheckedStateChangeListener { group, checkedIds ->
|
||||
selectedFilterGroup = group.children.indexOfFirst { it.id == checkedIds.first() }
|
||||
showFeed()
|
||||
}
|
||||
|
||||
binding.editGroups.setOnClickListener {
|
||||
ChannelGroupsDialog(channelGroups.toMutableList()) {
|
||||
lifecycleScope.launch { initChannelGroups() }
|
||||
@ -203,7 +204,8 @@ class SubscriptionsFragment : Fragment() {
|
||||
true
|
||||
} else {
|
||||
val channelId = streamItem.uploaderUrl.orEmpty().toID()
|
||||
channelGroups.getOrNull(selectedFilterGroup + 1)?.channels?.contains(channelId) != false
|
||||
val group = channelGroups.getOrNull(selectedFilterGroup - 1)
|
||||
group?.channels?.contains(channelId) != false
|
||||
}
|
||||
}
|
||||
.filter {
|
||||
@ -216,7 +218,11 @@ class SubscriptionsFragment : Fragment() {
|
||||
}
|
||||
}.let { streams ->
|
||||
runBlocking {
|
||||
if (!PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) {
|
||||
if (!PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.HIDE_WATCHED_FROM_FEED,
|
||||
false
|
||||
)
|
||||
) {
|
||||
streams
|
||||
} else {
|
||||
removeWatchVideosFromFeed(streams)
|
||||
|
@ -8,6 +8,7 @@
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:hint="@string/group_name"
|
||||
app:startIconDrawable="@drawable/ic_edit">
|
||||
|
@ -460,6 +460,7 @@
|
||||
<string name="new_group">New</string>
|
||||
<string name="group_name">Group name</string>
|
||||
<string name="edit_group">Edit group</string>
|
||||
<string name="group_already_exists">Group already exists!</string>
|
||||
|
||||
<!-- Notification channel strings -->
|
||||
<string name="download_channel_name">Download Service</string>
|
||||
|
Loading…
Reference in New Issue
Block a user