Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Matomo & Sentry opt-out related screens #90

Merged
merged 9 commits into from
Nov 4, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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.ui.screen.main.settings

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
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.res.stringResource
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.SwissTransferTopAppBar
import com.infomaniak.swisstransfer.ui.components.TopAppBarButton
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.illus.matomo.Matomo
import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun SettingsDataManagementMatomoScreen(navigateBack: (() -> Unit)?) {

// TODO: Use real value from Realm, and save it to Realm / anywhere else too.
var isMatomoAuthorized by rememberSaveable { mutableStateOf(true) }

SmallWindowTopAppBarScaffold(
smallWindowTopAppBar = {
SwissTransferTopAppBar(
titleRes = R.string.matomo,
navigationMenu = TopAppBarButton.backButton(navigateBack ?: {}),
)
},
) {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Image(
imageVector = AppIllus.Matomo.image(),
contentDescription = null,
modifier = Modifier.padding(Margin.Medium),
)
Text(
text = stringResource(R.string.settingsMatomoDescription),
style = SwissTransferTheme.typography.bodyRegular,
color = SwissTransferTheme.colors.primaryTextColor,
modifier = Modifier.padding(Margin.Medium),
)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(Margin.Medium),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = stringResource(R.string.settingsAuthorizeTracking),
style = SwissTransferTheme.typography.bodyRegular,
color = SwissTransferTheme.colors.primaryTextColor,
)
Spacer(Modifier.weight(1.0f))
Switch(
checked = isMatomoAuthorized,
onCheckedChange = { isMatomoAuthorized = it },
)
}
}
}
}

@PreviewAllWindows
@Composable
private fun Preview() {
SwissTransferTheme {
Surface {
SettingsDataManagementMatomoScreen {}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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.ui.screen.main.settings

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.SharpRippleButton
import com.infomaniak.swisstransfer.ui.components.SwissTransferTopAppBar
import com.infomaniak.swisstransfer.ui.components.TopAppBarButton
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.icons.matomo.Matomo
import com.infomaniak.swisstransfer.ui.images.icons.sentry.Sentry
import com.infomaniak.swisstransfer.ui.images.illus.dataProtection.DataProtection
import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsOptionScreens.*
import com.infomaniak.swisstransfer.ui.screen.main.settings.components.EndIconType.CHEVRON
import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingItem
import com.infomaniak.swisstransfer.ui.theme.Dimens
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun SettingsDataManagementScreen(
navigateBack: (() -> Unit)?,
onItemClick: (SettingsOptionScreens) -> Unit,
) {
SmallWindowTopAppBarScaffold(
smallWindowTopAppBar = {
SwissTransferTopAppBar(
titleRes = R.string.settingsOptionDataManagement,
navigationMenu = TopAppBarButton.backButton(navigateBack ?: {}),
)
},
) {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Image(
imageVector = AppIllus.DataProtection.image(),
contentDescription = null,
modifier = Modifier.padding(Margin.Medium),
)
Text(
text = stringResource(R.string.settingsDataManagementDescription),
style = SwissTransferTheme.typography.bodyRegular,
color = SwissTransferTheme.colors.primaryTextColor,
modifier = Modifier.padding(Margin.Medium),
)
SharpRippleButton(
modifier = Modifier.fillMaxWidth(),
onClick = { onItemClick(DATA_MANAGEMENT_SOURCE_CODE) },
) {
Text(
text = stringResource(R.string.settingsDataManagementSourceCode),
style = SwissTransferTheme.typography.bodyMedium,
color = SwissTransferTheme.materialColors.primary,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = Dimens.SettingHorizontalMargin, vertical = Dimens.SettingVerticalMargin),
)
}
SettingItem(
titleRes = R.string.matomo,
isSelected = { false },
icon = AppIcons.Matomo.image(),
endIcon = CHEVRON,
shouldTintIcon = false,
onClick = { onItemClick(DATA_MANAGEMENT_MATOMO) },
)
SettingItem(
titleRes = R.string.sentry,
isSelected = { false },
icon = AppIcons.Sentry.image(),
endIcon = CHEVRON,
shouldTintIcon = false,
onClick = { onItemClick(DATA_MANAGEMENT_SENTRY) },
)
}
}
}

@PreviewAllWindows
@Composable
private fun Preview() {
SwissTransferTheme {
Surface {
SettingsDataManagementScreen({}, {})
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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.ui.screen.main.settings

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
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.res.stringResource
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.SwissTransferTopAppBar
import com.infomaniak.swisstransfer.ui.components.TopAppBarButton
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.illus.sentry.Sentry
import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun SettingsDataManagementSentryScreen(navigateBack: (() -> Unit)?) {

// TODO: Use real value from Realm, and save it to Realm / anywhere else too.
var isSentryAuthorized by rememberSaveable { mutableStateOf(true) }

SmallWindowTopAppBarScaffold(
smallWindowTopAppBar = {
SwissTransferTopAppBar(
titleRes = R.string.sentry,
navigationMenu = TopAppBarButton.backButton(navigateBack ?: {}),
)
},
) {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Image(
imageVector = AppIllus.Sentry.image(),
contentDescription = null,
modifier = Modifier.padding(Margin.Medium),
)
Text(
text = stringResource(R.string.settingsSentryDescription),
style = SwissTransferTheme.typography.bodyRegular,
color = SwissTransferTheme.colors.primaryTextColor,
modifier = Modifier.padding(Margin.Medium),
)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(Margin.Medium),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = stringResource(R.string.settingsAuthorizeTracking),
style = SwissTransferTheme.typography.bodyRegular,
color = SwissTransferTheme.colors.primaryTextColor,
)
Spacer(Modifier.weight(1.0f))
Switch(
checked = isSentryAuthorized,
onCheckedChange = { isSentryAuthorized = it },
)
}
}
}
}

@PreviewAllWindows
@Composable
private fun Preview() {
SwissTransferTheme {
Surface {
SettingsDataManagementSentryScreen {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ fun SettingsScreen(
description = BuildConfig.VERSION_NAME,
onClick = null,
)
SettingDivider()

SettingTitle(R.string.settingsCategoryDataManagement)
SettingItem(
titleRes = R.string.settingsOptionDataManagement,
isSelected = { selectedSetting == DATA_MANAGEMENT },
endIcon = CHEVRON,
onClick = { onItemClick(DATA_MANAGEMENT) },
)
}
}
}
Expand Down Expand Up @@ -182,6 +191,7 @@ enum class SettingsOptionScreens {
THEME, NOTIFICATIONS,
VALIDITY_PERIOD, DOWNLOAD_LIMIT, EMAIL_LANGUAGE,
DISCOVER_INFOMANIAK, SHARE_IDEAS, GIVE_FEEDBACK,
DATA_MANAGEMENT, DATA_MANAGEMENT_SOURCE_CODE, DATA_MANAGEMENT_MATOMO, DATA_MANAGEMENT_SENTRY,
}

@PreviewAllWindows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,17 @@ private fun DetailPane(
emailLanguage: GetSetCallbacks<EmailLanguage>,
) {
var lastSelectedScreen by rememberSaveable { mutableStateOf<SettingsOptionScreens?>(null) }
val context = LocalContext.current

val destination = navigator.currentDestination?.content ?: lastSelectedScreen
navigator.currentDestination?.content?.let { lastSelectedScreen = it }

val navigateBackCallback: () -> Unit = { navigator.navigateBack() }
val navigateBack: (() -> Unit)? = if (navigator.canNavigateBack()) navigateBackCallback else null

// TODO: Update this URL when we know what we want.
val sourceCodeURL = stringResource(R.string.urlSourceCode)

when (destination) {
THEME -> SettingsThemeScreen(
theme = theme.get(),
Expand All @@ -151,10 +155,24 @@ private fun DetailPane(
navigateBack = navigateBack,
onEmailLanguageChange = { emailLanguage.set(it) },
)
DATA_MANAGEMENT -> SettingsDataManagementScreen(
navigateBack = navigateBack,
onItemClick = { item ->
if (item == DATA_MANAGEMENT_SOURCE_CODE) {
context.openUrl(sourceCodeURL)
} else {
// Navigate to the detail pane with the passed item
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, item)
}
},
)
DATA_MANAGEMENT_MATOMO -> SettingsDataManagementMatomoScreen(navigateBack)
DATA_MANAGEMENT_SENTRY -> SettingsDataManagementSentryScreen(navigateBack)
NOTIFICATIONS,
DISCOVER_INFOMANIAK,
SHARE_IDEAS,
GIVE_FEEDBACK -> Unit
GIVE_FEEDBACK,
DATA_MANAGEMENT_SOURCE_CODE -> Unit
null -> NoSelectionEmptyState()
}
}
Expand Down
Loading
Loading