diff --git a/features/preferences/impl/build.gradle.kts b/features/preferences/impl/build.gradle.kts index 51a3fcdf6b..0e53ef6716 100644 --- a/features/preferences/impl/build.gradle.kts +++ b/features/preferences/impl/build.gradle.kts @@ -49,6 +49,7 @@ dependencies { implementation(libs.datetime) implementation(libs.accompanist.placeholder) implementation(libs.coil.compose) + implementation(libs.androidx.browser) api(projects.features.preferences.api) ksp(libs.showkase.processor) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutNode.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutNode.kt index 0cd19d8e14..000a397cfe 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutNode.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutNode.kt @@ -16,15 +16,19 @@ package io.element.android.features.preferences.impl.about +import android.app.Activity import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import com.bumble.appyx.core.modality.BuildContext import com.bumble.appyx.core.node.Node import com.bumble.appyx.core.plugin.Plugin import dagger.assisted.Assisted import dagger.assisted.AssistedInject import io.element.android.anvilannotations.ContributesNode +import io.element.android.libraries.androidutils.browser.openUrlInChromeCustomTab import io.element.android.libraries.di.SessionScope +import io.element.android.libraries.theme.ElementTheme @ContributesNode(SessionScope::class) class AboutNode @AssistedInject constructor( @@ -33,12 +37,25 @@ class AboutNode @AssistedInject constructor( private val presenter: AboutPresenter, ) : Node(buildContext, plugins = plugins) { + private fun onElementLegalClicked( + activity: Activity, + darkTheme: Boolean, + elementLegal: ElementLegal, + ) { + activity.openUrlInChromeCustomTab(null, darkTheme, elementLegal.url) + } + @Composable override fun View(modifier: Modifier) { + val activity = LocalContext.current as Activity + val isDark = ElementTheme.isLightTheme.not() val state = presenter.present() AboutView( state = state, onBackPressed = ::navigateUp, + onElementLegalClicked = { elementLegal -> + onElementLegalClicked(activity, isDark, elementLegal) + }, modifier = modifier ) } diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutPresenter.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutPresenter.kt index 708e7c9abc..ce2439d8a6 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutPresenter.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutPresenter.kt @@ -32,6 +32,7 @@ class AboutPresenter @Inject constructor() : Presenter { } return AboutState( + elementLegals = getAllLegals(), eventSink = ::handleEvents ) } diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutState.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutState.kt index 0af95e5502..5a1a123b11 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutState.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutState.kt @@ -19,5 +19,6 @@ package io.element.android.features.preferences.impl.about // TODO add your ui models. Remove the eventSink if you don't have events. // Do not use default value, so no member get forgotten in the presenters. data class AboutState( + val elementLegals: List, val eventSink: (AboutEvents) -> Unit ) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutStateProvider.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutStateProvider.kt index aeb8dd9aa3..6f195b71d7 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutStateProvider.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutStateProvider.kt @@ -26,5 +26,6 @@ open class AboutStateProvider : PreviewParameterProvider { } fun aAboutState() = AboutState( + elementLegals = getAllLegals(), eventSink = {} ) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutView.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutView.kt index 3736c33bfa..b7c2663b72 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutView.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/AboutView.kt @@ -30,6 +30,7 @@ import io.element.android.libraries.ui.strings.CommonStrings @Composable fun AboutView( state: AboutState, + onElementLegalClicked: (ElementLegal) -> Unit, onBackPressed: () -> Unit, modifier: Modifier = Modifier, ) { @@ -38,9 +39,12 @@ fun AboutView( onBackPressed = onBackPressed, title = stringResource(id = CommonStrings.common_about) ) { - PreferenceText(title = stringResource(id = CommonStrings.common_copyright)) - PreferenceText(title = stringResource(id = CommonStrings.common_acceptable_use_policy)) - PreferenceText(title = stringResource(id = CommonStrings.common_privacy_policy)) + state.elementLegals.forEach { elementLegal -> + PreferenceText( + title = stringResource(id = elementLegal.titleRes), + onClick = { onElementLegalClicked(elementLegal) } + ) + } } } @@ -58,6 +62,7 @@ fun AboutViewDarkPreview(@PreviewParameter(AboutStateProvider::class) state: Abo private fun ContentToPreview(state: AboutState) { AboutView( state = state, + onElementLegalClicked = {}, onBackPressed = {}, ) } diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/ElementLegal.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/ElementLegal.kt new file mode 100644 index 0000000000..81af611716 --- /dev/null +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/about/ElementLegal.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * 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 io.element.android.features.preferences.impl.about + +import androidx.annotation.StringRes +import io.element.android.libraries.ui.strings.CommonStrings + +private const val CopyrightUrl = "https://element.io/copyright" +private const val UsePolicyUrl = "https://element.io/acceptable-use-policy-terms" +private const val PrivacyUrl = "https://element.io/privacy" + +sealed class ElementLegal( + @StringRes val titleRes: Int, + val url: String, +) { + object Copyright : ElementLegal(CommonStrings.common_copyright, CopyrightUrl) + object AcceptableUsePolicy : ElementLegal(CommonStrings.common_acceptable_use_policy, UsePolicyUrl) + object PrivacyPolicy : ElementLegal(CommonStrings.common_privacy_policy, PrivacyUrl) +} + +fun getAllLegals(): List { + return listOf( + ElementLegal.Copyright, + ElementLegal.AcceptableUsePolicy, + ElementLegal.PrivacyPolicy, + ) +}