Skip to content

Commit

Permalink
Merge pull request #6133 from Bnyro/master
Browse files Browse the repository at this point in the history
fix: notification bell shown even though notifications disabled
  • Loading branch information
Bnyro committed Jun 14, 2024
2 parents 8e7999c + cf4363d commit c91d397
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit c91d397

Please sign in to comment.