This repository was archived by the owner on Aug 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Privacy Settings #114
Merged
Merged
Privacy Settings #114
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e68e67e
Create new PrivacySettings bottom sheet
AdamGrzybkowski 07a0435
Add privacy setting to the GravatarScreen
AdamGrzybkowski ee7e26c
Add privacy setting to the ProfileScreen
AdamGrzybkowski ec33532
Add privacy setting to the ShareScreen
AdamGrzybkowski 759a838
Generate new screenshot test
AdamGrzybkowski 80d6b3d
Add PrivacySettingsStorage
AdamGrzybkowski a87f179
Add screen shot test for PrivacySettings component
AdamGrzybkowski 38e7f8d
Enable/Disable crash reporting based on privacy settings storage
AdamGrzybkowski 06f32ac
Temporary commit with crash report
AdamGrzybkowski 232a71e
Revert "Temporary commit with crash report"
AdamGrzybkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+109 KB
...ts.privacySetting.PrivacySettingsBottomSheetTest.privacySettingsAllDisabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+107 KB
...nts.privacySetting.PrivacySettingsBottomSheetTest.privacySettingsAllEnabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.88 KB
(100%)
....home.components.topbar.components.AboutAppDialogTest.aboutAppDialogVisible.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
.../gravatar/app/homeUi/presentation/home/components/privacySetting/PrivacySettingUiState.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.gravatar.app.homeUi.presentation.home.components.privacySetting | ||
|
|
||
| import com.gravatar.app.usercomponent.domain.model.PrivacySettings | ||
|
|
||
| internal data class PrivacySettingUiState( | ||
| val privacySettings: PrivacySettings = PrivacySettings( | ||
| analyticsEnabled = true, | ||
| crashReportingEnabled = true | ||
| ) | ||
| ) |
224 changes: 224 additions & 0 deletions
224
...atar/app/homeUi/presentation/home/components/privacySetting/PrivacySettingsBottomSheet.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| @file:OptIn(ExperimentalMaterial3Api::class) | ||
|
|
||
| package com.gravatar.app.homeUi.presentation.home.components.privacySetting | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import androidx.annotation.DrawableRes | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.ColumnScope | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.WindowInsets | ||
| import androidx.compose.foundation.layout.WindowInsetsSides | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.only | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.safeContent | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.rememberScrollState | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.foundation.verticalScroll | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.filled.Close | ||
| import androidx.compose.material3.CenterAlignedTopAppBar | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.IconButton | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.ModalBottomSheet | ||
| import androidx.compose.material3.Surface | ||
| import androidx.compose.material3.Switch | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TopAppBarDefaults | ||
| import androidx.compose.material3.rememberModalBottomSheetState | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.platform.LocalDensity | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.core.net.toUri | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import com.gravatar.app.design.theme.GravatarAppTheme | ||
| import com.gravatar.app.homeUi.R | ||
| import org.koin.androidx.compose.koinViewModel | ||
|
|
||
| private const val PRIVACY_POLICY_URL = "https://automattic.com/privacy/" | ||
|
|
||
| @Composable | ||
| internal fun PrivacySettingsBottomSheet( | ||
| onDismissRequest: () -> Unit | ||
| ) { | ||
| val topPadding = with(LocalDensity.current) { | ||
| WindowInsets.safeContent.only(WindowInsetsSides.Top).getTop(LocalDensity.current).toDp() | ||
| } | ||
| val viewModel: PrivacySettingsViewModel = koinViewModel() | ||
| val uiState by viewModel.uiState.collectAsStateWithLifecycle() | ||
|
|
||
| ModalBottomSheet( | ||
| onDismissRequest = onDismissRequest, | ||
| sheetState = rememberModalBottomSheetState( | ||
| skipPartiallyExpanded = true | ||
| ), | ||
| containerColor = MaterialTheme.colorScheme.surfaceVariant, | ||
| modifier = Modifier.padding(top = topPadding), | ||
| dragHandle = { | ||
| Surface( | ||
| modifier = Modifier.padding(vertical = 8.dp), | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| shape = MaterialTheme.shapes.extraLarge | ||
| ) { | ||
| Box(Modifier.size(width = 32.dp, height = 4.dp)) | ||
| } | ||
| } | ||
| ) { | ||
| PrivacySettings( | ||
| uiState = uiState, | ||
| onEvent = viewModel::onEvent, | ||
| onDismissRequest = onDismissRequest, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| internal fun PrivacySettings( | ||
| uiState: PrivacySettingUiState, | ||
| onEvent: (PrivacySettingsEvent) -> Unit, | ||
| onDismissRequest: () -> Unit, | ||
| ) { | ||
| val context = LocalContext.current | ||
| Column( | ||
| modifier = Modifier | ||
| .background(MaterialTheme.colorScheme.surfaceVariant) | ||
| .fillMaxWidth(), | ||
| ) { | ||
| CenterAlignedTopAppBar( | ||
| title = { | ||
| Text(text = stringResource(R.string.privacy_settings_top_bar_title)) | ||
| }, | ||
| navigationIcon = { | ||
| IconButton( | ||
| onClick = onDismissRequest | ||
| ) { | ||
| Icon( | ||
| imageVector = Icons.Default.Close, | ||
| contentDescription = stringResource(R.string.close_button) | ||
| ) | ||
| } | ||
| }, | ||
| colors = TopAppBarDefaults.topAppBarColors( | ||
| containerColor = MaterialTheme.colorScheme.surfaceVariant | ||
| ), | ||
| windowInsets = WindowInsets(0.dp, 0.dp, 0.dp, 0.dp), | ||
| ) | ||
| Column( | ||
| verticalArrangement = Arrangement.spacedBy(26.dp), | ||
| modifier = Modifier | ||
| .verticalScroll(rememberScrollState()) | ||
| .padding(bottom = 16.dp, top = 8.dp, start = 16.dp, end = 16.dp) | ||
| ) { | ||
| PrivacySettingsCard( | ||
| settingTitle = stringResource(R.string.privacy_settings_share_analytics_data_tittle), | ||
| settingIcon = R.drawable.ic_analytics_tracking, | ||
| settingDescription = stringResource(R.string.privacy_settings_share_analytics_data_description), | ||
| checked = uiState.privacySettings.analyticsEnabled, | ||
| onCheckedChange = { onEvent(PrivacySettingsEvent.OnAnalyticsEnabledChanged(it)) }, | ||
| extraContent = { | ||
| Text( | ||
| text = stringResource(R.string.privacy_settings_privacy_policy), | ||
| color = MaterialTheme.colorScheme.primary, | ||
| modifier = Modifier | ||
| .padding(top = 16.dp) | ||
| .clickable { | ||
| context.openPrivacyPolicy() | ||
| } | ||
| ) | ||
| }, | ||
| modifier = Modifier.fillMaxWidth() | ||
| ) | ||
| PrivacySettingsCard( | ||
| settingTitle = stringResource(R.string.privacy_settings_share_crash_reports_title), | ||
| settingIcon = R.drawable.ic_crashlytics, | ||
| settingDescription = stringResource(R.string.privacy_settings_share_crash_reports_description), | ||
| checked = uiState.privacySettings.crashReportingEnabled, | ||
| onCheckedChange = { onEvent(PrivacySettingsEvent.OnCrashReportingEnabledChanged(it)) }, | ||
| modifier = Modifier.fillMaxWidth() | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun Context.openPrivacyPolicy() { | ||
| val intent = Intent(Intent.ACTION_VIEW, PRIVACY_POLICY_URL.toUri()) | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PrivacySettingsCard( | ||
| settingTitle: String, | ||
| @DrawableRes settingIcon: Int, | ||
| settingDescription: String, | ||
| checked: Boolean, | ||
| onCheckedChange: (Boolean) -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| extraContent: @Composable ColumnScope.() -> Unit = {}, | ||
| ) { | ||
| val shape = RoundedCornerShape(12.dp) | ||
| Column( | ||
| modifier = modifier | ||
| .background(MaterialTheme.colorScheme.surface, shape) | ||
| .padding(16.dp) | ||
| ) { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| modifier = Modifier.fillMaxWidth() | ||
| ) { | ||
| Icon( | ||
| painter = painterResource(settingIcon), | ||
| contentDescription = null, | ||
| tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f) | ||
| ) | ||
| Spacer(modifier = Modifier.width(8.dp)) | ||
| Text( | ||
| text = settingTitle, | ||
| style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.SemiBold), | ||
| modifier = Modifier.weight(1f) | ||
| ) | ||
| Switch( | ||
| checked = checked, | ||
| onCheckedChange = onCheckedChange, | ||
| ) | ||
| } | ||
| HorizontalDivider(thickness = 1.dp) | ||
| Text( | ||
| text = settingDescription, | ||
| style = MaterialTheme.typography.bodyLarge, | ||
| modifier = Modifier.padding(top = 16.dp) | ||
| ) | ||
| extraContent() | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| internal fun PrivacySettingsPreview() { | ||
| GravatarAppTheme { | ||
| PrivacySettings( | ||
| uiState = PrivacySettingUiState(), | ||
| onEvent = {}, | ||
| onDismissRequest = {} | ||
| ) | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
...m/gravatar/app/homeUi/presentation/home/components/privacySetting/PrivacySettingsEvent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.gravatar.app.homeUi.presentation.home.components.privacySetting | ||
|
|
||
| internal sealed class PrivacySettingsEvent { | ||
| data class OnAnalyticsEnabledChanged(val enabled: Boolean) : PrivacySettingsEvent() | ||
| data class OnCrashReportingEnabledChanged(val enabled: Boolean) : PrivacySettingsEvent() | ||
| } |
58 changes: 58 additions & 0 deletions
58
...avatar/app/homeUi/presentation/home/components/privacySetting/PrivacySettingsViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.gravatar.app.homeUi.presentation.home.components.privacySetting | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.gravatar.app.usercomponent.domain.model.PrivacySettings | ||
| import com.gravatar.app.usercomponent.domain.usecase.GetPrivacySettings | ||
| import com.gravatar.app.usercomponent.domain.usecase.UpdatePrivacySettings | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.launchIn | ||
| import kotlinx.coroutines.flow.onEach | ||
| import kotlinx.coroutines.flow.update | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| internal class PrivacySettingsViewModel( | ||
| private val getPrivacySettings: GetPrivacySettings, | ||
| private val updatePrivacySettings: UpdatePrivacySettings, | ||
| ) : ViewModel() { | ||
|
|
||
| private val _uiState = MutableStateFlow(PrivacySettingUiState()) | ||
| val uiState: StateFlow<PrivacySettingUiState> = _uiState.asStateFlow() | ||
|
|
||
| init { | ||
| collectPrivacySettings() | ||
| } | ||
|
|
||
| fun onEvent(event: PrivacySettingsEvent) { | ||
| when (event) { | ||
| is PrivacySettingsEvent.OnAnalyticsEnabledChanged -> { | ||
| val newSettings = _uiState.value.privacySettings.copy(analyticsEnabled = event.enabled) | ||
| updateSettings(newSettings) | ||
| } | ||
|
|
||
| is PrivacySettingsEvent.OnCrashReportingEnabledChanged -> { | ||
| val newSettings = _uiState.value.privacySettings.copy(crashReportingEnabled = event.enabled) | ||
| updateSettings(newSettings) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun collectPrivacySettings() { | ||
| getPrivacySettings() | ||
| .onEach { settings -> | ||
| _uiState.update { current -> | ||
| current.copy(privacySettings = settings) | ||
| } | ||
| } | ||
| .launchIn(viewModelScope) | ||
| } | ||
|
|
||
| private fun updateSettings(newSettings: PrivacySettings) { | ||
| _uiState.update { it.copy(privacySettings = newSettings) } | ||
| viewModelScope.launch { | ||
| updatePrivacySettings(newSettings) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️