diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt index cb264437b..5e06be5d8 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt @@ -18,6 +18,12 @@ package com.infomaniak.swisstransfer.ui.screen.main.settings +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import android.provider.Settings import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -39,6 +45,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment 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.ui.components.TwoPaneScaffold @@ -60,13 +67,24 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewTablet fun SettingsScreenWrapper( windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo(), ) { + val context = LocalContext.current + val aboutURL = stringResource(R.string.urlAbout) + val userReportURL = stringResource(R.string.urlUserReportAndroid) TwoPaneScaffold( windowAdaptiveInfo, listPane = { SettingsScreen( onItemClick = { item -> - // Navigate to the detail pane with the passed item - navigateTo(ListDetailPaneScaffoldRole.Detail, item) + when (item) { + NOTIFICATIONS -> openAppNotificationSettings(context) + DISCOVER_INFOMANIAK -> openUrl(context, aboutURL) + SHARE_IDEAS -> openUrl(context, userReportURL) + GIVE_FEEDBACK -> goToPlayStore(context) + else -> { + // Navigate to the detail pane with the passed item + navigateTo(ListDetailPaneScaffoldRole.Detail, item) + } + } }, getSelectedSetting = { currentDestination?.content }, ) @@ -79,19 +97,56 @@ fun SettingsScreenWrapper( when (destination) { THEME -> SettingsThemeScreen() - NOTIFICATIONS -> {} VALIDITY_PERIOD -> SettingsValidityPeriodScreen() - DOWNLOAD_LIMIT -> {} - EMAIL_LANGUAGE -> {} - DISCOVER_INFOMANIAK -> {} - SHARE_IDEAS -> {} - GIVE_FEEDBACK -> {} + DOWNLOAD_LIMIT -> Unit + EMAIL_LANGUAGE -> Unit + NOTIFICATIONS, + DISCOVER_INFOMANIAK, + SHARE_IDEAS, + GIVE_FEEDBACK -> Unit null -> NoSelectionEmptyState() } } ) } +private fun openUrl(context: Context, url: String) { + context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) +} + +private fun goToPlayStore(context: Context) { + try { + context.startActivity( + Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${context.packageName}")) + ) + } catch (_: ActivityNotFoundException) { + context.startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse("https://play.google.com/store/apps/details?id=${context.packageName}") + ) + ) + } +} + +fun openAppNotificationSettings(context: Context) { + val packageName = context.packageName + val appUid = context.applicationInfo.uid + 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", appUid) + } + } + }.also { context.startActivity(it) } +} + @Composable private fun SettingsScreen(onItemClick: (SettingsOptionScreens) -> Unit, getSelectedSetting: () -> SettingsOptionScreens?) { val selectedSetting = getSelectedSetting() diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index ac60d4a6c..99b6685b6 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -58,5 +58,7 @@ Dateien durchsuchen Foto- und Videogalerie Herunterladen von + https://www.infomaniak.com/de/about + https://feedback.userreport.com/9abc7665-a78e-4fd2-aa41-a47a8b867fcd/#ideas/popular Version diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 34e6995eb..892c96312 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -58,5 +58,7 @@ Examinar archivos Galería de fotos y vídeos Descargar desde + https://www.infomaniak.com/es/about + https://feedback.userreport.com/1c462a20-7559-415e-a6e0-4b624dc38877/#ideas/popular Versión diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 137275e24..fdb9f01ed 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -58,5 +58,7 @@ Parcourir les fichiers Galerie photos et vidéos Télécharger à partir de + https://www.infomaniak.com/fr/a-propos + https://feedback.userreport.com/1c462a20-7559-415e-a6e0-4b624dc38877/#ideas/popular Version diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 68f434995..1dcdc54d5 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -58,5 +58,7 @@ Sfogliare i file Galleria di foto e video Scarica da + https://www.infomaniak.com/it/about + https://feedback.userreport.com/c85aa792-0f76-4923-8fe2-fae976cac9c2/#ideas/popular Versione diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc365e084..9292bcec9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -61,5 +61,7 @@ Browse files Photo and video gallery Upload from + https://www.infomaniak.com/en/about + https://feedback.userreport.com/f12466ad-db5b-4f5c-b24c-a54b0a5117ca/#ideas/popular Version