From 58fe08c59f336eca73cf74c7eca67414eeeb91e9 Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Wed, 21 Aug 2024 16:30:17 +0200 Subject: [PATCH] Add url in strings and handle external action --- .../swisstransfer/extensions/ContextExt.kt | 61 ++++++++++++++ .../ui/screen/main/settings/SettingsScreen.kt | 81 +++++++++++++------ app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-it/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 7 files changed, 126 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/com/infomaniak/swisstransfer/extensions/ContextExt.kt diff --git a/app/src/main/java/com/infomaniak/swisstransfer/extensions/ContextExt.kt b/app/src/main/java/com/infomaniak/swisstransfer/extensions/ContextExt.kt new file mode 100644 index 000000000..a215c142e --- /dev/null +++ b/app/src/main/java/com/infomaniak/swisstransfer/extensions/ContextExt.kt @@ -0,0 +1,61 @@ +/* + * 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/SettingsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt index cb264437b..6c7a254ae 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 @@ -32,6 +32,7 @@ import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi import androidx.compose.material3.adaptive.WindowAdaptiveInfo import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole +import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldNavigator import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -39,8 +40,12 @@ 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.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.icons.AppIcons import com.infomaniak.swisstransfer.ui.icons.app.* @@ -62,36 +67,56 @@ fun SettingsScreenWrapper( ) { TwoPaneScaffold( windowAdaptiveInfo, - listPane = { - SettingsScreen( - onItemClick = { item -> + listPane = { ListPane(this) }, + detailPane = { DetailPane(this) } + ) +} + +@OptIn(ExperimentalMaterial3AdaptiveApi::class) +@Composable +private fun ListPane(threePaneScaffoldNavigator: ThreePaneScaffoldNavigator) { + val context = LocalContext.current + val aboutURL = stringResource(R.string.urlAbout) + val userReportURL = stringResource(R.string.urlUserReportAndroid) + + SettingsScreen( + onItemClick = { item -> + when (item) { + NOTIFICATIONS -> context.openAppNotificationSettings() + DISCOVER_INFOMANIAK -> context.openUrl(aboutURL) + SHARE_IDEAS -> context.openUrl(userReportURL) + GIVE_FEEDBACK -> context.goToPlayStore() + else -> { // Navigate to the detail pane with the passed item - navigateTo(ListDetailPaneScaffoldRole.Detail, item) - }, - getSelectedSetting = { currentDestination?.content }, - ) - }, - detailPane = { - var lastSelectedScreen by rememberSaveable { mutableStateOf(null) } - - val destination = currentDestination?.content ?: lastSelectedScreen - currentDestination?.content?.let { lastSelectedScreen = it } - - when (destination) { - THEME -> SettingsThemeScreen() - NOTIFICATIONS -> {} - VALIDITY_PERIOD -> SettingsValidityPeriodScreen() - DOWNLOAD_LIMIT -> {} - EMAIL_LANGUAGE -> {} - DISCOVER_INFOMANIAK -> {} - SHARE_IDEAS -> {} - GIVE_FEEDBACK -> {} - null -> NoSelectionEmptyState() + threePaneScaffoldNavigator.navigateTo(ListDetailPaneScaffoldRole.Detail, item) + } } - } + }, + getSelectedSetting = { threePaneScaffoldNavigator.currentDestination?.content }, ) } +@OptIn(ExperimentalMaterial3AdaptiveApi::class) +@Composable +private fun DetailPane(threePaneScaffoldNavigator: ThreePaneScaffoldNavigator) { + var lastSelectedScreen by rememberSaveable { mutableStateOf(null) } + + val destination = threePaneScaffoldNavigator.currentDestination?.content ?: lastSelectedScreen + threePaneScaffoldNavigator.currentDestination?.content?.let { lastSelectedScreen = it } + + when (destination) { + THEME -> SettingsThemeScreen() + VALIDITY_PERIOD -> SettingsValidityPeriodScreen() + DOWNLOAD_LIMIT -> Unit + EMAIL_LANGUAGE -> Unit + NOTIFICATIONS, + DISCOVER_INFOMANIAK, + SHARE_IDEAS, + GIVE_FEEDBACK -> Unit + null -> NoSelectionEmptyState() + } +} + @Composable private fun SettingsScreen(onItemClick: (SettingsOptionScreens) -> Unit, getSelectedSetting: () -> SettingsOptionScreens?) { val selectedSetting = getSelectedSetting() @@ -161,7 +186,11 @@ private fun SettingsScreen(onItemClick: (SettingsOptionScreens) -> Unit, getSele SettingDivider() SettingTitle(R.string.settingsCategoryAbout) - SettingItem(R.string.settingsOptionDiscoverInfomaniak, { selectedSetting == DISCOVER_INFOMANIAK }, endIcon = OPEN_OUTSIDE) { + SettingItem( + R.string.settingsOptionDiscoverInfomaniak, + { selectedSetting == DISCOVER_INFOMANIAK }, + endIcon = OPEN_OUTSIDE + ) { onItemClick(DISCOVER_INFOMANIAK) } SettingItem(R.string.settingsOptionShareIdeas, { selectedSetting == SHARE_IDEAS }, endIcon = OPEN_OUTSIDE) { 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