Open legals URL

This commit is contained in:
Benoit Marty 2023-06-30 16:13:33 +02:00 committed by Benoit Marty
parent 03bb351657
commit 97c4d783d6
7 changed files with 70 additions and 3 deletions

View file

@ -49,6 +49,7 @@ dependencies {
implementation(libs.datetime) implementation(libs.datetime)
implementation(libs.accompanist.placeholder) implementation(libs.accompanist.placeholder)
implementation(libs.coil.compose) implementation(libs.coil.compose)
implementation(libs.androidx.browser)
api(projects.features.preferences.api) api(projects.features.preferences.api)
ksp(libs.showkase.processor) ksp(libs.showkase.processor)

View file

@ -16,15 +16,19 @@
package io.element.android.features.preferences.impl.about package io.element.android.features.preferences.impl.about
import android.app.Activity
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.bumble.appyx.core.modality.BuildContext import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin import com.bumble.appyx.core.plugin.Plugin
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import io.element.android.anvilannotations.ContributesNode 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.di.SessionScope
import io.element.android.libraries.theme.ElementTheme
@ContributesNode(SessionScope::class) @ContributesNode(SessionScope::class)
class AboutNode @AssistedInject constructor( class AboutNode @AssistedInject constructor(
@ -33,12 +37,25 @@ class AboutNode @AssistedInject constructor(
private val presenter: AboutPresenter, private val presenter: AboutPresenter,
) : Node(buildContext, plugins = plugins) { ) : Node(buildContext, plugins = plugins) {
private fun onElementLegalClicked(
activity: Activity,
darkTheme: Boolean,
elementLegal: ElementLegal,
) {
activity.openUrlInChromeCustomTab(null, darkTheme, elementLegal.url)
}
@Composable @Composable
override fun View(modifier: Modifier) { override fun View(modifier: Modifier) {
val activity = LocalContext.current as Activity
val isDark = ElementTheme.isLightTheme.not()
val state = presenter.present() val state = presenter.present()
AboutView( AboutView(
state = state, state = state,
onBackPressed = ::navigateUp, onBackPressed = ::navigateUp,
onElementLegalClicked = { elementLegal ->
onElementLegalClicked(activity, isDark, elementLegal)
},
modifier = modifier modifier = modifier
) )
} }

View file

@ -32,6 +32,7 @@ class AboutPresenter @Inject constructor() : Presenter<AboutState> {
} }
return AboutState( return AboutState(
elementLegals = getAllLegals(),
eventSink = ::handleEvents eventSink = ::handleEvents
) )
} }

View file

@ -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. // 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. // Do not use default value, so no member get forgotten in the presenters.
data class AboutState( data class AboutState(
val elementLegals: List<ElementLegal>,
val eventSink: (AboutEvents) -> Unit val eventSink: (AboutEvents) -> Unit
) )

View file

@ -26,5 +26,6 @@ open class AboutStateProvider : PreviewParameterProvider<AboutState> {
} }
fun aAboutState() = AboutState( fun aAboutState() = AboutState(
elementLegals = getAllLegals(),
eventSink = {} eventSink = {}
) )

View file

@ -30,6 +30,7 @@ import io.element.android.libraries.ui.strings.CommonStrings
@Composable @Composable
fun AboutView( fun AboutView(
state: AboutState, state: AboutState,
onElementLegalClicked: (ElementLegal) -> Unit,
onBackPressed: () -> Unit, onBackPressed: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
@ -38,9 +39,12 @@ fun AboutView(
onBackPressed = onBackPressed, onBackPressed = onBackPressed,
title = stringResource(id = CommonStrings.common_about) title = stringResource(id = CommonStrings.common_about)
) { ) {
PreferenceText(title = stringResource(id = CommonStrings.common_copyright)) state.elementLegals.forEach { elementLegal ->
PreferenceText(title = stringResource(id = CommonStrings.common_acceptable_use_policy)) PreferenceText(
PreferenceText(title = stringResource(id = CommonStrings.common_privacy_policy)) title = stringResource(id = elementLegal.titleRes),
onClick = { onElementLegalClicked(elementLegal) }
)
}
} }
} }
@ -58,6 +62,7 @@ fun AboutViewDarkPreview(@PreviewParameter(AboutStateProvider::class) state: Abo
private fun ContentToPreview(state: AboutState) { private fun ContentToPreview(state: AboutState) {
AboutView( AboutView(
state = state, state = state,
onElementLegalClicked = {},
onBackPressed = {}, onBackPressed = {},
) )
} }

View file

@ -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<ElementLegal> {
return listOf(
ElementLegal.Copyright,
ElementLegal.AcceptableUsePolicy,
ElementLegal.PrivacyPolicy,
)
}