Skip to content

Commit

Permalink
Add url in strings and handle external action
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Aug 22, 2024
1 parent e9648b6 commit 23d089e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<SettingsOptionScreens>(
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 },
)
Expand All @@ -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()
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 @@ -57,5 +57,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 23d089e

Please sign in to comment.