Skip to content

Commit

Permalink
Add privacy policy section on settings screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AfigAliyev committed Oct 21, 2022
1 parent a9a9131 commit 2fdd2a3
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
package com.maximillianleonov.cinemax.core.domain.repository

interface SettingsRepository {
val privacyPolicyUrl: String
val version: String
}
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions core/core-ui/src/main/res/drawable/ic_shield.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group>
<clip-path
android:pathData="M0,0h24v24h-24z" />
<path
android:fillColor="#ffffff"
android:pathData="M21.616,2.854L12.202,0.03C12.07,-0.01 11.93,-0.01 11.798,0.03L2.384,2.854C2.086,2.943 1.883,3.217 1.883,3.527V13.883C1.883,15.23 2.428,16.608 3.503,17.981C4.325,19.029 5.461,20.081 6.881,21.109C9.266,22.835 11.614,23.894 11.713,23.939C11.804,23.979 11.902,24 12,24C12.098,24 12.196,23.98 12.287,23.939C12.386,23.894 14.734,22.835 17.119,21.109C18.539,20.081 19.675,19.029 20.497,17.981C21.572,16.608 22.117,15.23 22.117,13.883V3.527C22.117,3.217 21.913,2.943 21.616,2.854Z" />
</group>
</vector>
1 change: 1 addition & 0 deletions core/core-ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="settings">Settings</string>

<string name="about">About</string>
<string name="privacy_policy">Privacy Policy</string>
<string name="version">Version</string>

<string name="back">Back</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +32,7 @@ import javax.inject.Inject

@HiltViewModel
class SettingsViewModel @Inject constructor(
private val getSettingsPrivacyPolicyUrlUseCase: GetSettingsPrivacyPolicyUrlUseCase,
private val getSettingsVersionUseCase: GetSettingsVersionUseCase
) : ViewModel(), EventHandler<SettingsEvent> {
private val _uiState = MutableStateFlow(getInitialUiState())
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,28 +32,29 @@ 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

@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)
Expand All @@ -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()
}
}
}
Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.maximillianleonov.cinemax.feature.settings.model

import android.content.Intent
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes

Expand All @@ -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
}

0 comments on commit 2fdd2a3

Please sign in to comment.