diff --git a/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt b/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt index a2f90c0d3..e38c10074 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt @@ -7,13 +7,13 @@ package org.schabi.newpipe.settings import android.content.Context import android.content.Intent -import io.reactivex.rxjava3.schedulers.Schedulers import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.map import kotlinx.coroutines.reactive.asFlow -import kotlinx.coroutines.rx3.await +import kotlinx.coroutines.withContext import net.newpipe.app.model.ChannelNotification import net.newpipe.app.platform.NotificationHost import org.schabi.newpipe.App @@ -75,9 +75,12 @@ class ComposeNotificationHost(private val context: Context) : NotificationHost { override suspend fun setChannelNotificationsEnabled(channel: ChannelNotification, enabled: Boolean) { val mode = if (enabled) NotificationMode.ENABLED else NotificationMode.DISABLED try { - subscriptionManager.updateNotificationMode(channel.serviceId, channel.url, mode) - .subscribeOn(Schedulers.io()) - .await() + withContext(Dispatchers.IO) { + val subscriptionTable = subscriptionManager.subscriptionTable() + val subscription = subscriptionTable.getSubscription(channel.id) + subscription.notificationMode = mode + subscriptionTable.update(subscription) + } } catch (cancellation: CancellationException) { throw cancellation } catch (error: Exception) { diff --git a/shared/src/commonMain/composeResources/values/strings.xml b/shared/src/commonMain/composeResources/values/strings.xml index 22aa6f40d..353e29844 100644 --- a/shared/src/commonMain/composeResources/values/strings.xml +++ b/shared/src/commonMain/composeResources/values/strings.xml @@ -327,6 +327,7 @@ Channels Notifications are disabled Toggle all + Select the channels for which you want to receive notifications about new streams Crop thumbnail to 1:1 aspect ratio diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/ChannelNotificationSettingsScreen.kt b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/ChannelNotificationSettingsScreen.kt index efb9d4159..cbf50d9b2 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/ChannelNotificationSettingsScreen.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/ChannelNotificationSettingsScreen.kt @@ -17,6 +17,7 @@ import androidx.compose.material3.Checkbox import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.ListItem +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -26,6 +27,7 @@ import androidx.compose.ui.semantics.Role import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.tooling.preview.PreviewWrapper +import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import net.newpipe.app.composable.TopAppBar import net.newpipe.app.model.ChannelNotification @@ -33,6 +35,7 @@ import net.newpipe.app.navigation.Navigator import net.newpipe.app.preview.ThemePreviewProvider import net.newpipe.app.viewmodel.settings.ChannelNotificationSettingsViewModel import newpipe.shared.generated.resources.Res +import newpipe.shared.generated.resources.channel_notifications_description import newpipe.shared.generated.resources.channels import newpipe.shared.generated.resources.ic_checklist import newpipe.shared.generated.resources.toggle_all @@ -42,6 +45,7 @@ import org.koin.compose.koinInject import org.koin.compose.viewmodel.koinViewModel private const val CHANNEL_NAME_MAX_LINES = 2 +private const val DESCRIPTION_KEY = "description" @Composable fun ChannelNotificationSettingsScreen( @@ -87,6 +91,15 @@ fun ChannelNotificationSettingsScreenContent( .padding(top = paddingValues.calculateTopPadding()), contentPadding = WindowInsets.navigationBars.asPaddingValues() ) { + item(key = DESCRIPTION_KEY) { + Text( + text = stringResource(Res.string.channel_notifications_description), + modifier = Modifier.padding(16.dp), + color = MaterialTheme.colorScheme.onSurfaceVariant, + style = MaterialTheme.typography.bodyMedium + ) + } + items(items = channels, key = { channel -> channel.id }) { channel -> ListItem( modifier = Modifier.toggleable(