From cf4363d703aee213b9f002e1982ca7212c7d327a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 14 Jun 2024 18:50:38 +0200 Subject: [PATCH] fix: notification bell shown even though notifications disabled --- .../ui/extensions/SetupNotificationBell.kt | 7 +++++-- .../ui/extensions/SetupSubscriptionButton.kt | 20 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetupNotificationBell.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetupNotificationBell.kt index c293235d2..5271543d5 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetupNotificationBell.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetupNotificationBell.kt @@ -13,11 +13,14 @@ fun MaterialButton.setupNotificationBell(channelId: String) { } var isIgnorable = PreferenceHelper.isChannelNotificationIgnorable(channelId) - setIconResource(if (isIgnorable) R.drawable.ic_bell else R.drawable.ic_notification) + setIconResource(iconResource(isIgnorable)) setOnClickListener { isIgnorable = !isIgnorable PreferenceHelper.toggleIgnorableNotificationChannel(channelId) - setIconResource(if (isIgnorable) R.drawable.ic_bell else R.drawable.ic_notification) + setIconResource(iconResource(isIgnorable)) } } + +private fun iconResource(isIgnorable: Boolean) = + if (isIgnorable) R.drawable.ic_bell else R.drawable.ic_notification \ No newline at end of file diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt index f602afaae..2e060a1d6 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt @@ -5,11 +5,12 @@ import androidx.core.view.isGone import androidx.core.view.isVisible import com.github.libretube.R import com.github.libretube.api.SubscriptionHelper +import com.github.libretube.constants.PreferenceKeys +import com.github.libretube.helpers.PreferenceHelper import com.google.android.material.button.MaterialButton import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext fun TextView.setupSubscriptionButton( @@ -38,19 +39,26 @@ fun TextView.setupSubscriptionButton( } notificationBell?.setupNotificationBell(channelId) - this.setOnClickListener { + + setOnClickListener { if (subscribed == true) { SubscriptionHelper.handleUnsubscribe(context, channelId, channelName) { - this.text = context.getString(R.string.subscribe) + text = context.getString(R.string.subscribe) notificationBell?.isGone = true + subscribed = false onIsSubscribedChange(false) } } else { - runBlocking { - SubscriptionHelper.subscribe(channelId) + CoroutineScope(Dispatchers.Main).launch { + withContext(Dispatchers.IO) { + SubscriptionHelper.subscribe(channelId) + } + text = context.getString(R.string.unsubscribe) - notificationBell?.isVisible = true + notificationBell?.isVisible = PreferenceHelper + .getBoolean(PreferenceKeys.NOTIFICATION_ENABLED, true) + subscribed = true onIsSubscribedChange(true) }