diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt index c4e5a126..0ab68f83 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt @@ -51,6 +51,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.dialog import androidx.navigation.navArgument import androidx.navigation.navDeepLink +import androidx.navigation.navOptions import androidx.navigation.navigation import com.bobbyesp.library.SpotDL import com.bobbyesp.spowlo.App @@ -452,7 +453,9 @@ fun InitialEntry( onBackPressed, downloaderViewModel, navController - ) { id -> navController.navigate(Route.PLAYLIST_PAGE + "/" + "playlist" + "/" + id) } + ) { id -> navController.navigate(Route.PLAYLIST_PAGE + "/" + "playlist" + "/" + id, navOptions = navOptions { + launchSingleTop = true + }) } // } } diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt index 653a27de..bf63d34c 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt @@ -2,6 +2,7 @@ package com.bobbyesp.spowlo.ui.pages.downloader import android.Manifest import android.os.Build +import android.util.Log import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.FastOutSlowInEasing @@ -91,6 +92,7 @@ import com.bobbyesp.spowlo.ui.pages.settings.about.LocalAsset import com.bobbyesp.spowlo.ui.theme.harmonizeWith import com.bobbyesp.spowlo.utils.CONFIGURE import com.bobbyesp.spowlo.utils.DEBUG +import com.bobbyesp.spowlo.utils.NOTIFICATION import com.bobbyesp.spowlo.utils.PreferencesUtil import com.bobbyesp.spowlo.utils.PreferencesUtil.getBoolean import com.bobbyesp.spowlo.utils.ToastUtil @@ -124,6 +126,30 @@ fun DownloaderPage( } } + val notificationsPermission = rememberPermissionState( + permission = Manifest.permission.ACCESS_NOTIFICATION_POLICY + ) { b: Boolean -> + Log.d("DownloaderPage", "notificationsPermission: $b") + if (b) { + PreferencesUtil.updateValue(NOTIFICATION, true) + } else { + PreferencesUtil.updateValue(NOTIFICATION, false) + ToastUtil.makeToast(R.string.permission_denied) + } + } + + val modernNotificationPermission = rememberPermissionState( + permission = Manifest.permission.POST_NOTIFICATIONS + ) { b: Boolean -> + Log.d("DownloaderPage", "modernNotificationPermission: $b") + if (b) { + PreferencesUtil.updateValue(NOTIFICATION, true) + } else { + PreferencesUtil.updateValue(NOTIFICATION, false) + ToastUtil.makeToast(R.string.permission_denied) + } + } + //STATE FLOWS val viewState by downloaderViewModel.viewStateFlow.collectAsStateWithLifecycle() val downloaderState by Downloader.downloaderState.collectAsStateWithLifecycle() @@ -146,6 +172,20 @@ fun DownloaderPage( if (CONFIGURE.getBoolean()) navigateToDownloaderSheet() else checkPermissionOrDownload() keyboardController?.hide() + if(NOTIFICATION.getBoolean()){ + when(Build.VERSION.SDK_INT){ + in 23..31 -> { + if(notificationsPermission.status != PermissionStatus.Granted){ + notificationsPermission.launchPermissionRequest() + } + } + in 32..Int.MAX_VALUE -> { + if(modernNotificationPermission.status != PermissionStatus.Granted){ + modernNotificationPermission.launchPermissionRequest() + } + } + } + } } val songCardClicked = { diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderViewModel.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderViewModel.kt index 747c3f70..83a249cc 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderViewModel.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderViewModel.kt @@ -68,6 +68,7 @@ class DownloaderViewModel @Inject constructor() : ViewModel() { } fun startDownloadSong(skipInfoFetch: Boolean = false) { + val url = viewStateFlow.value.url Downloader.clearErrorState() if (!Downloader.isDownloaderAvailable()) @@ -76,6 +77,7 @@ class DownloaderViewModel @Inject constructor() : ViewModel() { showErrorMessage(R.string.url_empty) return } + //request notification permission Downloader.getInfoAndDownload(url, skipInfoFetch = skipInfoFetch) }