Legals: Move the 2 copyrights items to the new legal screen

This commit is contained in:
Benoit Marty 2021-12-08 22:46:25 +01:00 committed by Benoit Marty
parent a8c921ef03
commit 5823777755
7 changed files with 57 additions and 36 deletions

View file

@ -24,6 +24,7 @@ import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.onClick import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
@EpoxyModelClass(layout = R.layout.item_discovery_policy) @EpoxyModelClass(layout = R.layout.item_discovery_policy)
abstract class DiscoveryPolicyItem : EpoxyModelWithHolder<DiscoveryPolicyItem.Holder>() { abstract class DiscoveryPolicyItem : EpoxyModelWithHolder<DiscoveryPolicyItem.Holder>() {
@ -40,7 +41,7 @@ abstract class DiscoveryPolicyItem : EpoxyModelWithHolder<DiscoveryPolicyItem.Ho
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.title.text = name holder.title.text = name
holder.url.text = url holder.url.setTextOrHide(url)
holder.view.onClick(clickListener) holder.view.onClick(clickListener)
} }

View file

@ -44,8 +44,6 @@ class VectorPreferences @Inject constructor(private val context: Context) {
const val SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY = "SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY" const val SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY = "SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY"
const val SETTINGS_DISCOVERY_PREFERENCE_KEY = "SETTINGS_DISCOVERY_PREFERENCE_KEY" const val SETTINGS_DISCOVERY_PREFERENCE_KEY = "SETTINGS_DISCOVERY_PREFERENCE_KEY"
const val SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY"
const val SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY"
const val SETTINGS_CLEAR_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_CACHE_PREFERENCE_KEY" const val SETTINGS_CLEAR_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_CACHE_PREFERENCE_KEY"
const val SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY" const val SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY"
const val SETTINGS_USER_SETTINGS_PREFERENCE_KEY = "SETTINGS_USER_SETTINGS_PREFERENCE_KEY" const val SETTINGS_USER_SETTINGS_PREFERENCE_KEY = "SETTINGS_USER_SETTINGS_PREFERENCE_KEY"

View file

@ -20,12 +20,9 @@ import androidx.preference.Preference
import im.vector.app.BuildConfig import im.vector.app.BuildConfig
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.preference.VectorPreference import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.utils.FirstThrottler
import im.vector.app.core.utils.copyToClipboard import im.vector.app.core.utils.copyToClipboard
import im.vector.app.core.utils.displayInWebView
import im.vector.app.core.utils.openAppSettingsPage import im.vector.app.core.utils.openAppSettingsPage
import im.vector.app.features.version.VersionProvider import im.vector.app.features.version.VersionProvider
import im.vector.app.openOssLicensesMenuActivity
import org.matrix.android.sdk.api.Matrix import org.matrix.android.sdk.api.Matrix
import javax.inject.Inject import javax.inject.Inject
@ -36,8 +33,6 @@ class VectorSettingsHelpAboutFragment @Inject constructor(
override var titleRes = R.string.preference_root_help_about override var titleRes = R.string.preference_root_help_about
override val preferenceXmlRes = R.xml.vector_settings_help_about override val preferenceXmlRes = R.xml.vector_settings_help_about
private val firstThrottler = FirstThrottler(1000)
override fun bindPref() { override fun bindPref() {
// preference to start the App info screen, to facilitate App permissions access // preference to start the App info screen, to facilitate App permissions access
findPreference<VectorPreference>(APP_INFO_LINK_PREFERENCE_KEY)!! findPreference<VectorPreference>(APP_INFO_LINK_PREFERENCE_KEY)!!
@ -75,23 +70,6 @@ class VectorSettingsHelpAboutFragment @Inject constructor(
// olm version // olm version
findPreference<VectorPreference>(VectorPreferences.SETTINGS_OLM_VERSION_PREFERENCE_KEY)!! findPreference<VectorPreference>(VectorPreferences.SETTINGS_OLM_VERSION_PREFERENCE_KEY)!!
.summary = session.cryptoService().getCryptoVersion(requireContext(), false) .summary = session.cryptoService().getCryptoVersion(requireContext(), false)
// third party notice
findPreference<VectorPreference>(VectorPreferences.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY)!!
.onPreferenceClickListener = Preference.OnPreferenceClickListener {
if (firstThrottler.canHandle() is FirstThrottler.CanHandlerResult.Yes) {
activity?.displayInWebView(VectorSettingsUrls.THIRD_PARTY_LICENSES)
}
false
}
// Note: preference is not visible on F-Droid build
findPreference<VectorPreference>(VectorPreferences.SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY)!!
.onPreferenceClickListener = Preference.OnPreferenceClickListener {
// See https://developers.google.com/android/guides/opensource
openOssLicensesMenuActivity(requireActivity())
false
}
} }
companion object { companion object {

View file

@ -15,6 +15,7 @@
*/ */
package im.vector.app.features.settings.legals package im.vector.app.features.settings.legals
import android.content.res.Resources
import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.epoxy.TypedEpoxyController
import com.airbnb.mvrx.Async import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Fail
@ -35,6 +36,7 @@ import javax.inject.Inject
class LegalsController @Inject constructor( class LegalsController @Inject constructor(
private val stringProvider: StringProvider, private val stringProvider: StringProvider,
private val resources: Resources,
private val elementLegals: ElementLegals, private val elementLegals: ElementLegals,
private val errorFormatter: ErrorFormatter private val errorFormatter: ErrorFormatter
) : TypedEpoxyController<LegalsState>() { ) : TypedEpoxyController<LegalsState>() {
@ -45,6 +47,7 @@ class LegalsController @Inject constructor(
buildAppSection() buildAppSection()
buildHomeserverSection(data) buildHomeserverSection(data)
buildIdentityServerSection(data) buildIdentityServerSection(data)
buildThirdPartyNotices()
} }
private fun buildAppSection() { private fun buildAppSection() {
@ -118,8 +121,32 @@ class LegalsController @Inject constructor(
} }
} }
private fun buildThirdPartyNotices() {
val host = this
settingsSectionTitleItem {
id("appTitle")
titleResId(R.string.legals_third_party_notices)
}
discoveryPolicyItem {
id("elcp1")
name(host.stringProvider.getString(R.string.settings_third_party_notices))
clickListener { host.listener?.openThirdPartyNotice() }
}
// Only on Gplay
if (resources.getBoolean(R.bool.isGplay)) {
discoveryPolicyItem {
id("elcp2")
name(host.stringProvider.getString(R.string.settings_other_third_party_notices))
clickListener { host.listener?.openThirdPartyNoticeGplay() }
}
}
}
interface Listener { interface Listener {
fun onTapRetry() fun onTapRetry()
fun openPolicy(policy: ServerPolicy) fun openPolicy(policy: ServerPolicy)
fun openThirdPartyNotice()
fun openThirdPartyNoticeGplay()
} }
} }

View file

@ -27,9 +27,13 @@ import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.FirstThrottler
import im.vector.app.core.utils.displayInWebView
import im.vector.app.core.utils.openUrlInChromeCustomTab import im.vector.app.core.utils.openUrlInChromeCustomTab
import im.vector.app.databinding.FragmentGenericRecyclerBinding import im.vector.app.databinding.FragmentGenericRecyclerBinding
import im.vector.app.features.discovery.ServerPolicy import im.vector.app.features.discovery.ServerPolicy
import im.vector.app.features.settings.VectorSettingsUrls
import im.vector.app.openOssLicensesMenuActivity
import javax.inject.Inject import javax.inject.Inject
class LegalsFragment @Inject constructor( class LegalsFragment @Inject constructor(
@ -42,6 +46,7 @@ class LegalsFragment @Inject constructor(
} }
private val viewModel by fragmentViewModel(LegalsViewModel::class) private val viewModel by fragmentViewModel(LegalsViewModel::class)
private val firstThrottler = FirstThrottler(1000)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -79,6 +84,27 @@ class LegalsFragment @Inject constructor(
} }
override fun openPolicy(policy: ServerPolicy) { override fun openPolicy(policy: ServerPolicy) {
openUrlInChromeCustomTab(requireContext(), null, policy.url) openUrl(policy.url)
}
override fun openThirdPartyNotice() {
openUrl(VectorSettingsUrls.THIRD_PARTY_LICENSES)
}
private fun openUrl(url: String) {
if (firstThrottler.canHandle() is FirstThrottler.CanHandlerResult.Yes) {
if (url.startsWith("file://")) {
activity?.displayInWebView(url)
} else {
openUrlInChromeCustomTab(requireContext(), null, url)
}
}
}
override fun openThirdPartyNoticeGplay() {
if (firstThrottler.canHandle() is FirstThrottler.CanHandlerResult.Yes) {
// See https://developers.google.com/android/guides/opensource
openOssLicensesMenuActivity(requireActivity())
}
} }
} }

View file

@ -1400,6 +1400,7 @@
<string name="template_legals_application_title">${app_name} policy</string> <string name="template_legals_application_title">${app_name} policy</string>
<string name="legals_home_server_title">Your homeserver policy</string> <string name="legals_home_server_title">Your homeserver policy</string>
<string name="legals_identity_server_title">Your identity server policy</string> <string name="legals_identity_server_title">Your identity server policy</string>
<string name="legals_third_party_notices">Third party libraries</string>
<string name="legals_no_policy_provided">This server does not provide any policy.</string> <string name="legals_no_policy_provided">This server does not provide any policy.</string>
<string name="disabled_integration_dialog_title">Integrations are disabled</string> <string name="disabled_integration_dialog_title">Integrations are disabled</string>

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<im.vector.app.core.preference.VectorPreference <im.vector.app.core.preference.VectorPreference
@ -23,13 +22,4 @@
android:title="@string/settings_olm_version" android:title="@string/settings_olm_version"
tools:summary="7.8.9" /> tools:summary="7.8.9" />
<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY"
android:title="@string/settings_third_party_notices" />
<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY"
android:title="@string/settings_other_third_party_notices"
app:isPreferenceVisible="@bool/isGplay" />
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>