Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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