diff --git a/app/src/main/java/com/infomaniak/swisstransfer/extensions/ContextExt.kt b/app/src/main/java/com/infomaniak/swisstransfer/extensions/ContextExt.kt deleted file mode 100644 index a215c142e..000000000 --- a/app/src/main/java/com/infomaniak/swisstransfer/extensions/ContextExt.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Infomaniak SwissTransfer - Android - * Copyright (C) 2024 Infomaniak Network SA - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.infomaniak.swisstransfer.extensions - -import android.content.ActivityNotFoundException -import android.content.Context -import android.content.Intent -import android.net.Uri -import android.os.Build -import android.provider.Settings - -fun Context.openUrl(url: String) { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) -} - -fun Context.goToPlayStore() { - try { - startActivity( - Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${packageName}")) - ) - } catch (_: ActivityNotFoundException) { - startActivity( - Intent( - Intent.ACTION_VIEW, - Uri.parse("https://play.google.com/store/apps/details?id=${packageName}") - ) - ) - } -} - -fun Context.openAppNotificationSettings() { - Intent().apply { - when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> { - action = Settings.ACTION_APP_NOTIFICATION_SETTINGS - putExtra(Settings.EXTRA_APP_PACKAGE, packageName) - } - else -> { - action = "Settings.ACTION_APP_NOTIFICATION_SETTINGS" - putExtra("app_package", packageName) - putExtra("app_uid", applicationInfo.uid) - } - } - }.also { startActivity(it) } -} diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt index 6c27c6aef..1f15a2367 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt @@ -38,14 +38,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import com.infomaniak.swisstransfer.R -import com.infomaniak.swisstransfer.extensions.goToPlayStore -import com.infomaniak.swisstransfer.extensions.openAppNotificationSettings -import com.infomaniak.swisstransfer.extensions.openUrl import com.infomaniak.swisstransfer.ui.components.TwoPaneScaffold import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsOptionScreens.* import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewMobile -import com.infomaniak.swisstransfer.ui.utils.PreviewTablet +import com.infomaniak.swisstransfer.ui.utils.* @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/ContextExt.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/ContextExt.kt index c30aa7321..1acd32cb9 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/ContextExt.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/ContextExt.kt @@ -19,12 +19,51 @@ package com.infomaniak.swisstransfer.ui.utils import android.app.Activity +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent +import android.net.Uri +import android.os.Build import android.os.Bundle +import android.provider.Settings import kotlin.reflect.KClass fun Context.launchActivity(kClass: KClass, options: Bundle? = null) { startActivity(Intent(this, kClass.java), options) } + +fun Context.openUrl(url: String) { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) +} + +fun Context.goToPlayStore() { + try { + startActivity( + Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${packageName}")) + ) + } catch (_: ActivityNotFoundException) { + startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse("https://play.google.com/store/apps/details?id=${packageName}") + ) + ) + } +} + +fun Context.openAppNotificationSettings() { + Intent().apply { + when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> { + action = Settings.ACTION_APP_NOTIFICATION_SETTINGS + putExtra(Settings.EXTRA_APP_PACKAGE, packageName) + } + else -> { + action = "Settings.ACTION_APP_NOTIFICATION_SETTINGS" + putExtra("app_package", packageName) + putExtra("app_uid", applicationInfo.uid) + } + } + }.also(::startActivity) +}