From 0941b612476cd93611f7e8de66dccff33b7ad815 Mon Sep 17 00:00:00 2001 From: michaelbel Date: Wed, 25 Dec 2024 12:45:33 +0300 Subject: [PATCH] Update project --- .../ic_splash_screen_branding_image.xml | 12 +++-- .../build.gradle.kts | 0 .../inject/FlavorServiceKtorModule.jvm.kt | 0 .../ui/compose/NotificationBottomSheet.kt | 35 +++---------- .../org/michaelbel/movies/ui/ktx/IntentKtx.kt | 52 +++++++++++++++++++ desktopApp/build.gradle.kts | 2 +- feature/main-impl/build.gradle.kts | 2 +- settings.gradle.kts | 2 +- 8 files changed, 69 insertions(+), 36 deletions(-) rename core/platform-services/{inject-desktop => inject-jvm}/build.gradle.kts (100%) rename core/platform-services/{inject-desktop => inject-jvm}/src/commonMain/kotlin/org/michaelbel/movies/platform/inject/FlavorServiceKtorModule.jvm.kt (100%) diff --git a/androidApp/src/main/res/drawable/ic_splash_screen_branding_image.xml b/androidApp/src/main/res/drawable/ic_splash_screen_branding_image.xml index 5b77406bd..064a8baee 100644 --- a/androidApp/src/main/res/drawable/ic_splash_screen_branding_image.xml +++ b/androidApp/src/main/res/drawable/ic_splash_screen_branding_image.xml @@ -1,11 +1,13 @@ + xmlns:tools="http://schemas.android.com/tools" + android:width="180dp" + android:height="64dp" + android:viewportWidth="180" + android:viewportHeight="64"> + android:pathData="M75.97,41.01C74.67,41.91 73.45,42.36 72.31,42.36C71.17,42.36 70.36,42.09 69.88,41.55C69.42,41.01 69.19,40.3 69.19,39.42C69.19,38.54 69.66,36.28 70.6,32.64C71.54,28.98 72.01,26.71 72.01,25.83C72.01,24.73 71.62,24.18 70.84,24.18C70.06,24.18 69,24.76 67.66,25.92C67.62,26.08 67.29,27.3 66.67,29.58C65.31,34.58 64.58,38.61 64.48,41.67C63.7,41.97 62.29,42.12 60.25,42.12H59.86C59.86,40.88 60.39,38.02 61.45,33.54C62.51,29.06 63.04,26.45 63.04,25.71C63.04,24.69 62.63,24.18 61.81,24.18C60.93,24.18 59.78,24.8 58.36,26.04C58.36,30.12 57.64,33.94 56.2,37.5C55.52,39.18 54.63,40.55 53.53,41.61C52.45,42.65 51.33,43.17 50.17,43.17C49.03,43.17 48.13,42.82 47.47,42.12C46.83,41.44 46.51,40.49 46.51,39.27C46.51,38.03 46.95,36.58 47.83,34.92C48.71,33.24 49.64,31.81 50.62,30.63C51.62,29.43 52.64,28.35 53.68,27.39C53.68,25.55 53.46,24.44 53.02,24.06C52.8,23.88 52.48,23.79 52.06,23.79C51.66,23.79 51.06,23.97 50.26,24.33C49.48,24.69 48.73,25.18 48.01,25.8L47.26,24.75C47.96,23.89 49.01,23.06 50.41,22.26C51.81,21.46 53.05,21.06 54.13,21.06C55.23,21.06 56.09,21.35 56.71,21.93C57.35,22.49 57.8,23.21 58.06,24.09C60.82,21.83 63,20.7 64.6,20.7C65.4,20.7 66.08,20.95 66.64,21.45C67.22,21.95 67.59,22.7 67.75,23.7C70.11,21.7 72.08,20.7 73.66,20.7C74.54,20.7 75.28,21.05 75.88,21.75C76.5,22.45 76.81,23.4 76.81,24.6C76.81,25.78 76.32,28.17 75.34,31.77C74.36,35.37 73.87,37.65 73.87,38.61C73.87,39.55 74.17,40.02 74.77,40.02C74.97,40.02 75.22,39.97 75.52,39.87L75.97,41.01ZM49.6,40.32C50.4,40.32 51.19,39.33 51.97,37.35C52.77,35.35 53.31,32.85 53.59,29.85C52.31,31.17 51.16,32.74 50.14,34.56C49.12,36.36 48.61,37.77 48.61,38.79C48.61,39.81 48.94,40.32 49.6,40.32ZM82.8,42.36C81.42,42.36 80.34,41.88 79.56,40.92C78.78,39.94 78.39,38.58 78.39,36.84C78.39,34.62 78.98,32.71 80.16,31.11C81.36,29.51 83.01,28.71 85.11,28.71L86.19,28.77C86.53,28.59 86.91,28.5 87.33,28.5C88.91,28.5 89.7,29.99 89.7,32.97C90.52,32.93 91.35,32.82 92.19,32.64L92.67,32.52L92.85,33.69C92.19,33.97 91.3,34.22 90.18,34.44L89.58,34.56C89.2,36.66 88.43,38.49 87.27,40.05C86.11,41.59 84.62,42.36 82.8,42.36ZM84.42,39.78C85.26,39.78 86.01,39.24 86.67,38.16C87.35,37.08 87.82,35.94 88.08,34.74C85.94,34.74 84.87,33.94 84.87,32.34C84.87,31.7 85,31.1 85.26,30.54L85.41,30.24C85.33,30.2 85.23,30.18 85.11,30.18C84.99,30.18 84.9,30.2 84.84,30.24C84.34,30.56 83.87,31.31 83.43,32.49C82.99,33.67 82.77,35.02 82.77,36.54C82.77,38.7 83.32,39.78 84.42,39.78ZM93.93,28.71C94.81,28.71 95.46,28.89 95.88,29.25C96.32,29.61 96.54,30.35 96.54,31.47C96.54,32.07 96.36,33.3 96,35.16C95.64,37 95.46,38.12 95.46,38.52C95.46,39.32 95.62,39.72 95.94,39.72C96.7,39.72 97.53,39.16 98.43,38.04C99.35,36.9 99.83,35.95 99.87,35.19L97.83,32.91C97.91,32.05 98.12,31.27 98.46,30.57C98.8,29.87 99.12,29.38 99.42,29.1L99.84,28.71C100.7,28.71 101.35,28.94 101.79,29.4C102.23,29.86 102.45,30.4 102.45,31.02C102.45,32.6 102.06,34.27 101.28,36.03C100.5,37.79 99.46,39.29 98.16,40.53C96.86,41.75 95.54,42.36 94.2,42.36C93.36,42.36 92.71,42.1 92.25,41.58C91.81,41.06 91.59,40.38 91.59,39.54C91.59,38.68 91.65,37.53 91.77,36.09C91.91,34.65 91.98,33.22 91.98,31.8C91.98,31.48 91.86,31.1 91.62,30.66C91.4,30.22 91.17,29.87 90.93,29.61L91.02,29.25C92.1,28.89 93.07,28.71 93.93,28.71ZM109.04,30.57C109.04,31.41 108.77,32.86 108.23,34.92C107.69,36.96 107.42,38.3 107.42,38.94C107.42,39.56 107.51,39.87 107.69,39.87C107.81,39.87 108.27,39.68 109.07,39.3L109.43,39.12L109.94,40.17C109.76,40.33 109.52,40.53 109.22,40.77C108.92,41.01 108.36,41.34 107.54,41.76C106.72,42.16 105.96,42.36 105.26,42.36C104.56,42.36 104.01,42.15 103.61,41.73C103.21,41.29 103.01,40.71 103.01,39.99C103.01,39.25 103.26,37.95 103.76,36.09C104.26,34.21 104.51,32.99 104.51,32.43C104.51,31.59 104.25,30.8 103.73,30.06L103.46,29.7L103.49,29.31C104.55,29.01 106.27,28.86 108.65,28.86C108.91,29.16 109.04,29.73 109.04,30.57ZM105.62,25.59C105.22,25.19 105.02,24.66 105.02,24C105.02,23.34 105.29,22.76 105.83,22.26C106.39,21.76 107.03,21.51 107.75,21.51C108.47,21.51 109.03,21.71 109.43,22.11C109.83,22.51 110.03,23.04 110.03,23.7C110.03,24.34 109.74,24.91 109.16,25.41C108.6,25.91 107.97,26.16 107.27,26.16C106.57,26.16 106.02,25.97 105.62,25.59ZM110.88,36.81C110.88,34.31 111.63,32.34 113.13,30.9C114.65,29.44 116.37,28.71 118.29,28.71C119.47,28.71 120.44,29 121.2,29.58C121.96,30.16 122.34,30.94 122.34,31.92C122.34,32.88 122.09,33.69 121.59,34.35C121.11,35.01 120.52,35.52 119.82,35.88C118.4,36.58 117.1,37.02 115.92,37.2L115.2,37.29C115.34,39.17 116.11,40.11 117.51,40.11C117.99,40.11 118.5,39.99 119.04,39.75C119.58,39.51 120,39.27 120.3,39.03L120.75,38.67L121.47,39.63C121.31,39.85 120.99,40.14 120.51,40.5C120.03,40.86 119.58,41.16 119.16,41.4C118,42.04 116.73,42.36 115.35,42.36C113.97,42.36 112.88,41.87 112.08,40.89C111.28,39.91 110.88,38.55 110.88,36.81ZM115.17,35.82C116.19,35.64 117,35.21 117.6,34.53C118.2,33.85 118.5,32.97 118.5,31.89C118.5,30.81 118.18,30.27 117.54,30.27C116.78,30.27 116.19,30.92 115.77,32.22C115.37,33.5 115.17,34.7 115.17,35.82ZM132.55,38.07C132.55,39.33 131.99,40.36 130.87,41.16C129.77,41.96 128.51,42.36 127.09,42.36C125.67,42.36 124.54,42.06 123.7,41.46C122.88,40.86 122.47,40.33 122.47,39.87C122.47,39.59 122.82,39.14 123.52,38.52C124.22,37.88 124.81,37.49 125.29,37.35C126.29,38.09 127.11,39.26 127.75,40.86C128.49,40.8 128.86,40.45 128.86,39.81C128.86,38.89 128.05,37.59 126.43,35.91C124.81,34.21 124,32.86 124,31.86C124,30.86 124.45,30.09 125.35,29.55C126.25,28.99 127.33,28.71 128.59,28.71C129.87,28.71 130.83,28.94 131.47,29.4C132.11,29.84 132.43,30.45 132.43,31.23C132.43,31.99 131.82,33.05 130.6,34.41C130.74,34.55 130.92,34.74 131.14,34.98C131.36,35.2 131.65,35.63 132.01,36.27C132.37,36.91 132.55,37.51 132.55,38.07ZM129.67,33.36C130.51,32.64 130.93,31.93 130.93,31.23C130.93,30.53 130.45,30.18 129.49,30.18C129.03,30.18 128.65,30.28 128.35,30.48C128.05,30.66 127.9,30.87 127.9,31.11C127.9,31.55 128.34,32.17 129.22,32.97L129.67,33.36Z" + tools:ignore="VectorPath" /> \ No newline at end of file diff --git a/core/platform-services/inject-desktop/build.gradle.kts b/core/platform-services/inject-jvm/build.gradle.kts similarity index 100% rename from core/platform-services/inject-desktop/build.gradle.kts rename to core/platform-services/inject-jvm/build.gradle.kts diff --git a/core/platform-services/inject-desktop/src/commonMain/kotlin/org/michaelbel/movies/platform/inject/FlavorServiceKtorModule.jvm.kt b/core/platform-services/inject-jvm/src/commonMain/kotlin/org/michaelbel/movies/platform/inject/FlavorServiceKtorModule.jvm.kt similarity index 100% rename from core/platform-services/inject-desktop/src/commonMain/kotlin/org/michaelbel/movies/platform/inject/FlavorServiceKtorModule.jvm.kt rename to core/platform-services/inject-jvm/src/commonMain/kotlin/org/michaelbel/movies/platform/inject/FlavorServiceKtorModule.jvm.kt diff --git a/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/compose/NotificationBottomSheet.kt b/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/compose/NotificationBottomSheet.kt index b433540ef..b40e6f552 100644 --- a/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/compose/NotificationBottomSheet.kt +++ b/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/compose/NotificationBottomSheet.kt @@ -2,11 +2,7 @@ package org.michaelbel.movies.ui.compose -import android.Manifest -import android.app.Activity import android.os.Build -import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.animation.core.LinearEasing import androidx.compose.animation.core.RepeatMode import androidx.compose.animation.core.animateFloat @@ -36,7 +32,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.TransformOrigin import androidx.compose.ui.graphics.graphicsLayer -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -44,7 +39,8 @@ import org.jetbrains.compose.ui.tooling.preview.Preview import org.michaelbel.movies.ui.R import org.michaelbel.movies.ui.accessibility.MoviesContentDescription import org.michaelbel.movies.ui.icons.MoviesIcons -import org.michaelbel.movies.ui.ktx.appNotificationSettingsIntent +import org.michaelbel.movies.ui.ktx.rememberNavigateToAppSettings +import org.michaelbel.movies.ui.ktx.rememberRequestNotificationPermission import org.michaelbel.movies.ui.theme.MoviesTheme @Composable @@ -52,22 +48,9 @@ fun NotificationBottomSheet( onDismissRequest: () -> Unit, modifier: Modifier = Modifier ) { - val context = LocalContext.current - val activityContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {} - - val permissionContract = rememberLauncherForActivityResult( - ActivityResultContracts.RequestPermission() - ) { granted -> - val shouldRequest = (context as Activity).shouldShowRequestPermissionRationale( - Manifest.permission.POST_NOTIFICATIONS - ) - if (!granted && !shouldRequest) { - activityContract.launch(context.appNotificationSettingsIntent) - } - } - + val requestNotificationPermission = rememberRequestNotificationPermission() + val navigateToAppSettings = rememberNavigateToAppSettings() val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) - val value by rememberInfiniteTransition(label = "") .animateFloat( initialValue = 15F, @@ -107,7 +90,7 @@ fun NotificationBottomSheet( modifier = Modifier.graphicsLayer( transformOrigin = TransformOrigin( pivotFractionX = 0.5F, - pivotFractionY = 0.0F, + pivotFractionY = 0.0F ), rotationZ = value ), @@ -133,12 +116,8 @@ fun NotificationBottomSheet( onClick = { onDismissRequest() when { - Build.VERSION.SDK_INT >= 33 -> { - permissionContract.launch(Manifest.permission.POST_NOTIFICATIONS) - } - else -> { - activityContract.launch(context.appNotificationSettingsIntent) - } + Build.VERSION.SDK_INT >= 33 -> requestNotificationPermission() + else -> navigateToAppSettings() } }, colors = ButtonDefaults.buttonColors( diff --git a/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/ktx/IntentKtx.kt b/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/ktx/IntentKtx.kt index 3cb717d20..4693bc876 100644 --- a/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/ktx/IntentKtx.kt +++ b/core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/ktx/IntentKtx.kt @@ -1,12 +1,19 @@ package org.michaelbel.movies.ui.ktx +import android.Manifest +import android.app.Activity import android.content.Intent +import android.content.pm.PackageManager import android.os.Build import android.provider.Settings import android.speech.RecognizerIntent import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalContext +import androidx.core.content.ContextCompat +import androidx.core.net.toUri @Composable fun rememberSpeechRecognitionLauncher(onInputText: (String) -> Unit): () -> Unit { @@ -41,4 +48,49 @@ fun rememberConnectivityClickHandler(): () -> Unit { } else { return {} } +} + +@Composable +fun rememberNavigateToAppSettings(): () -> Unit { + val context = LocalContext.current + val appSettingsContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {} + val intent = Intent( + Settings.ACTION_APPLICATION_DETAILS_SETTINGS, + "package:${context.packageName}".toUri() + ).apply { + addCategory(Intent.CATEGORY_DEFAULT) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + return remember { { appSettingsContract.launch(intent) } } +} + +@Composable +fun rememberRequestNotificationPermission( + onGranted: () -> Unit = {} +): () -> Unit { + if (Build.VERSION.SDK_INT >= 33) { + val context = LocalContext.current + val navigateToAppSettings = rememberNavigateToAppSettings() + val cameraPermissionContract = rememberLauncherForActivityResult( + ActivityResultContracts.RequestPermission() + ) { granted -> + val shouldRequest = (context as Activity).shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS) + when { + granted -> onGranted() + !granted && !shouldRequest -> navigateToAppSettings() + } + } + return remember { + { + when { + ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED -> { + cameraPermissionContract.launch(Manifest.permission.POST_NOTIFICATIONS) + } + else -> onGranted() + } + } + } + } else { + return {} + } } \ No newline at end of file diff --git a/desktopApp/build.gradle.kts b/desktopApp/build.gradle.kts index 6609db84a..cd7dce3c9 100755 --- a/desktopApp/build.gradle.kts +++ b/desktopApp/build.gradle.kts @@ -11,7 +11,7 @@ kotlin { sourceSets { jvmMain.dependencies { - implementation(projects.core.platformServices.injectDesktop) + implementation(projects.core.platformServices.injectJvm) implementation(projects.feature.mainImpl) } } diff --git a/feature/main-impl/build.gradle.kts b/feature/main-impl/build.gradle.kts index a361fc5f1..d0b3bf5df 100644 --- a/feature/main-impl/build.gradle.kts +++ b/feature/main-impl/build.gradle.kts @@ -25,7 +25,7 @@ kotlin { api(projects.feature.debug) } jvmMain.dependencies { - implementation(projects.core.platformServices.injectDesktop) + implementation(projects.core.platformServices.injectJvm) } iosMain.dependencies { implementation(projects.core.platformServices.injectIos) diff --git a/settings.gradle.kts b/settings.gradle.kts index 946683d18..832ecf3b3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -39,7 +39,7 @@ include( ":core:platform-services:hms", ":core:platform-services:foss", ":core:platform-services:inject-android", - ":core:platform-services:inject-macos", + ":core:platform-services:inject-jvm", ":core:platform-services:inject-ios", ":core:platform-services:inject-web", ":core:platform-services:interactor",