Skip to content

Commit

Permalink
Merge pull request #35 from Infomaniak/settings-links
Browse files Browse the repository at this point in the history
Implement external settings links
  • Loading branch information
tevincent authored Aug 26, 2024
2 parents 30eaa6d + 0a3052e commit 1b675a7
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ 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
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.*
Expand All @@ -62,36 +67,56 @@ fun SettingsScreenWrapper(
) {
TwoPaneScaffold<SettingsOptionScreens>(
windowAdaptiveInfo,
listPane = {
SettingsScreen(
onItemClick = { item ->
listPane = { ListPane(this) },
detailPane = { DetailPane(this) }
)
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
private fun ListPane(navigator: ThreePaneScaffoldNavigator<SettingsOptionScreens>) {
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<SettingsOptionScreens?>(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()
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, item)
}
}
}
},
getSelectedSetting = { navigator.currentDestination?.content },
)
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
private fun DetailPane(navigator: ThreePaneScaffoldNavigator<SettingsOptionScreens>) {
var lastSelectedScreen by rememberSaveable { mutableStateOf<SettingsOptionScreens?>(null) }

val destination = navigator.currentDestination?.content ?: lastSelectedScreen
navigator.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()
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
<string name="transferUploadSourceChoiceFiles">Dateien durchsuchen</string>
<string name="transferUploadSourceChoiceGallery">Foto- und Videogalerie</string>
<string name="transferUploadSourceChoiceTitle">Herunterladen von</string>
<string name="urlAbout">https://www.infomaniak.com/de/about</string>
<string name="urlUserReportAndroid">https://feedback.userreport.com/9abc7665-a78e-4fd2-aa41-a47a8b867fcd/#ideas/popular</string>
<string name="version">Version</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
<string name="transferUploadSourceChoiceFiles">Examinar archivos</string>
<string name="transferUploadSourceChoiceGallery">Galería de fotos y vídeos</string>
<string name="transferUploadSourceChoiceTitle">Descargar desde</string>
<string name="urlAbout">https://www.infomaniak.com/es/about</string>
<string name="urlUserReportAndroid">https://feedback.userreport.com/1c462a20-7559-415e-a6e0-4b624dc38877/#ideas/popular</string>
<string name="version">Versión</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
<string name="transferUploadSourceChoiceFiles">Parcourir les fichiers</string>
<string name="transferUploadSourceChoiceGallery">Galerie photos et vidéos</string>
<string name="transferUploadSourceChoiceTitle">Télécharger à partir de</string>
<string name="urlAbout">https://www.infomaniak.com/fr/a-propos</string>
<string name="urlUserReportAndroid">https://feedback.userreport.com/1c462a20-7559-415e-a6e0-4b624dc38877/#ideas/popular</string>
<string name="version">Version</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
<string name="transferUploadSourceChoiceFiles">Sfogliare i file</string>
<string name="transferUploadSourceChoiceGallery">Galleria di foto e video</string>
<string name="transferUploadSourceChoiceTitle">Scarica da</string>
<string name="urlAbout">https://www.infomaniak.com/it/about</string>
<string name="urlUserReportAndroid">https://feedback.userreport.com/c85aa792-0f76-4923-8fe2-fae976cac9c2/#ideas/popular</string>
<string name="version">Versione</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@
<string name="transferUploadSourceChoiceFiles">Browse files</string>
<string name="transferUploadSourceChoiceGallery">Photo and video gallery</string>
<string name="transferUploadSourceChoiceTitle">Upload from</string>
<string name="urlAbout">https://www.infomaniak.com/en/about</string>
<string name="urlUserReportAndroid">https://feedback.userreport.com/f12466ad-db5b-4f5c-b24c-a54b0a5117ca/#ideas/popular</string>
<string name="version">Version</string>
</resources>

0 comments on commit 1b675a7

Please sign in to comment.