From 064fe52b842d1024bb118982079020462569e80c Mon Sep 17 00:00:00 2001
From: Maximillian Leonov <91663102+MaximillianLeonov@users.noreply.github.com>
Date: Fri, 21 Oct 2022 16:00:19 +0400
Subject: [PATCH] Add privacy policy section on settings screen (#199)
---
.../data/repository/SettingsRepositoryImpl.kt | 1 +
.../source/SettingsDatabaseDataSource.kt | 2 ++
.../cinemax/core/database/util/Constants.kt | 5 ++++
.../domain/repository/SettingsRepository.kt | 1 +
.../GetSettingsPrivacyPolicyUrlUseCase.kt | 24 +++++++++++++++
.../src/main/res/drawable/ic_shield.xml | 29 +++++++++++++++++++
core/core-ui/src/main/res/values/strings.xml | 1 +
.../feature/settings/SettingsViewModel.kt | 10 +++++++
.../feature/settings/components/Settings.kt | 20 ++++++-------
.../feature/settings/model/Settings.kt | 7 +++++
10 files changed, 90 insertions(+), 10 deletions(-)
create mode 100644 core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/usecase/GetSettingsPrivacyPolicyUrlUseCase.kt
create mode 100644 core/core-ui/src/main/res/drawable/ic_shield.xml
diff --git a/core/core-data/src/main/kotlin/com/maximillianleonov/cinemax/core/data/repository/SettingsRepositoryImpl.kt b/core/core-data/src/main/kotlin/com/maximillianleonov/cinemax/core/data/repository/SettingsRepositoryImpl.kt
index f85373d2..1f0a90fc 100644
--- a/core/core-data/src/main/kotlin/com/maximillianleonov/cinemax/core/data/repository/SettingsRepositoryImpl.kt
+++ b/core/core-data/src/main/kotlin/com/maximillianleonov/cinemax/core/data/repository/SettingsRepositoryImpl.kt
@@ -23,5 +23,6 @@ import javax.inject.Inject
class SettingsRepositoryImpl @Inject constructor(
databaseDataSource: SettingsDatabaseDataSource
) : SettingsRepository {
+ override val privacyPolicyUrl = databaseDataSource.privacyPolicyUrl
override val version = databaseDataSource.version
}
diff --git a/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/source/SettingsDatabaseDataSource.kt b/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/source/SettingsDatabaseDataSource.kt
index 354a8e2d..b882dbb4 100644
--- a/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/source/SettingsDatabaseDataSource.kt
+++ b/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/source/SettingsDatabaseDataSource.kt
@@ -17,8 +17,10 @@
package com.maximillianleonov.cinemax.core.database.source
import com.maximillianleonov.cinemax.core.database.util.CinemaxVersionProvider
+import com.maximillianleonov.cinemax.core.database.util.Constants
import javax.inject.Inject
class SettingsDatabaseDataSource @Inject constructor(versionProvider: CinemaxVersionProvider) {
+ val privacyPolicyUrl = Constants.Urls.PRIVACY_POLICY_URL
val version = versionProvider.version
}
diff --git a/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/util/Constants.kt b/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/util/Constants.kt
index c56c4576..a0ca36b1 100644
--- a/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/util/Constants.kt
+++ b/core/core-database/src/main/kotlin/com/maximillianleonov/cinemax/core/database/util/Constants.kt
@@ -88,4 +88,9 @@ internal object Constants {
internal const val PREV_PAGE = "prev_page"
internal const val NEXT_PAGE = "next_page"
}
+
+ internal object Urls {
+ private const val CINEMAX_PAGE_URL = "https://maximillianleonov.github.io/Cinemax"
+ internal const val PRIVACY_POLICY_URL = "$CINEMAX_PAGE_URL/privacy-policy.html"
+ }
}
diff --git a/core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/repository/SettingsRepository.kt b/core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/repository/SettingsRepository.kt
index cf9ca314..06880218 100644
--- a/core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/repository/SettingsRepository.kt
+++ b/core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/repository/SettingsRepository.kt
@@ -17,5 +17,6 @@
package com.maximillianleonov.cinemax.core.domain.repository
interface SettingsRepository {
+ val privacyPolicyUrl: String
val version: String
}
diff --git a/core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/usecase/GetSettingsPrivacyPolicyUrlUseCase.kt b/core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/usecase/GetSettingsPrivacyPolicyUrlUseCase.kt
new file mode 100644
index 00000000..34ef5a24
--- /dev/null
+++ b/core/core-domain/src/main/kotlin/com/maximillianleonov/cinemax/core/domain/usecase/GetSettingsPrivacyPolicyUrlUseCase.kt
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2022 Maximillian Leonov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.maximillianleonov.cinemax.core.domain.usecase
+
+import com.maximillianleonov.cinemax.core.domain.repository.SettingsRepository
+import javax.inject.Inject
+
+class GetSettingsPrivacyPolicyUrlUseCase @Inject constructor(private val repository: SettingsRepository) {
+ operator fun invoke() = repository.privacyPolicyUrl
+}
diff --git a/core/core-ui/src/main/res/drawable/ic_shield.xml b/core/core-ui/src/main/res/drawable/ic_shield.xml
new file mode 100644
index 00000000..8615d241
--- /dev/null
+++ b/core/core-ui/src/main/res/drawable/ic_shield.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
diff --git a/core/core-ui/src/main/res/values/strings.xml b/core/core-ui/src/main/res/values/strings.xml
index 992e55e9..9cebe266 100644
--- a/core/core-ui/src/main/res/values/strings.xml
+++ b/core/core-ui/src/main/res/values/strings.xml
@@ -21,6 +21,7 @@
Settings
About
+ Privacy Policy
Version
Back
diff --git a/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/SettingsViewModel.kt b/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/SettingsViewModel.kt
index 67b05ccb..9c6e923b 100644
--- a/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/SettingsViewModel.kt
+++ b/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/SettingsViewModel.kt
@@ -16,7 +16,10 @@
package com.maximillianleonov.cinemax.feature.settings
+import android.content.Intent
+import androidx.core.net.toUri
import androidx.lifecycle.ViewModel
+import com.maximillianleonov.cinemax.core.domain.usecase.GetSettingsPrivacyPolicyUrlUseCase
import com.maximillianleonov.cinemax.core.domain.usecase.GetSettingsVersionUseCase
import com.maximillianleonov.cinemax.core.ui.R
import com.maximillianleonov.cinemax.core.ui.common.EventHandler
@@ -29,6 +32,7 @@ import javax.inject.Inject
@HiltViewModel
class SettingsViewModel @Inject constructor(
+ private val getSettingsPrivacyPolicyUrlUseCase: GetSettingsPrivacyPolicyUrlUseCase,
private val getSettingsVersionUseCase: GetSettingsVersionUseCase
) : ViewModel(), EventHandler {
private val _uiState = MutableStateFlow(getInitialUiState())
@@ -37,9 +41,15 @@ class SettingsViewModel @Inject constructor(
override fun onEvent(event: SettingsEvent) = Unit
private fun getInitialUiState(): SettingsUiState {
+ val privacyPolicyUrl = getSettingsPrivacyPolicyUrlUseCase().toUri()
val version = getSettingsVersionUseCase()
val aboutSettings = listOf(
+ Settings.IntentAction(
+ iconResourceId = R.drawable.ic_shield,
+ titleResourceId = R.string.privacy_policy,
+ intent = Intent(Intent.ACTION_VIEW, privacyPolicyUrl)
+ ),
Settings.Info(
iconResourceId = R.drawable.ic_info,
titleResourceId = R.string.version,
diff --git a/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/components/Settings.kt b/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/components/Settings.kt
index b422e066..4b3c6688 100644
--- a/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/components/Settings.kt
+++ b/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/components/Settings.kt
@@ -16,6 +16,7 @@
package com.maximillianleonov.cinemax.feature.settings.components
+import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.background
@@ -31,12 +32,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.maximillianleonov.cinemax.core.designsystem.component.CinemaxCenteredBox
import com.maximillianleonov.cinemax.core.designsystem.component.CinemaxIcon
-import com.maximillianleonov.cinemax.core.designsystem.component.CinemaxIconButton
import com.maximillianleonov.cinemax.core.designsystem.theme.CinemaxTheme
import com.maximillianleonov.cinemax.core.ui.R
import com.maximillianleonov.cinemax.feature.settings.model.Settings
@@ -44,15 +45,16 @@ import com.maximillianleonov.cinemax.feature.settings.model.Settings
@Composable
internal fun SettingsItem(
settings: Settings,
- modifier: Modifier = Modifier
+ modifier: Modifier = Modifier,
+ context: Context = LocalContext.current
) {
Row(
modifier = modifier
.then(
- if (settings is Settings.Action) {
- Modifier.clickable(onClick = settings.onClick)
- } else {
- Modifier
+ when (settings) {
+ is Settings.Action -> Modifier.clickable(onClick = settings.onClick)
+ is Settings.IntentAction -> Modifier.clickable { context.startActivity(settings.intent) }
+ is Settings.Info -> Modifier
}
)
.padding(CinemaxTheme.spacing.medium)
@@ -72,7 +74,7 @@ internal fun SettingsItem(
}
when (settings) {
is Settings.Info -> ValueText(value = settings.value)
- is Settings.Action -> ForwardButton(onClick = settings.onClick)
+ is Settings.Action, is Settings.IntentAction -> ForwardButton()
}
}
}
@@ -128,15 +130,13 @@ private fun ValueText(
@Composable
private fun ForwardButton(
- onClick: () -> Unit,
modifier: Modifier = Modifier,
color: Color = CinemaxTheme.colors.accent
) {
- CinemaxIconButton(
+ CinemaxIcon(
modifier = modifier.size(IconShapeSize),
iconResourceId = R.drawable.ic_arrow_forward,
contentDescription = stringResource(id = R.string.forward),
- onClick = onClick,
tint = color
)
}
diff --git a/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/model/Settings.kt b/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/model/Settings.kt
index f7755933..50bee027 100644
--- a/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/model/Settings.kt
+++ b/features/feature-settings/src/main/kotlin/com/maximillianleonov/cinemax/feature/settings/model/Settings.kt
@@ -16,6 +16,7 @@
package com.maximillianleonov.cinemax.feature.settings.model
+import android.content.Intent
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
@@ -37,4 +38,10 @@ sealed interface Settings {
@StringRes override val titleResourceId: Int,
val onClick: () -> Unit
) : Settings
+
+ data class IntentAction(
+ @DrawableRes override val iconResourceId: Int,
+ @StringRes override val titleResourceId: Int,
+ val intent: Intent
+ ) : Settings
}