From 5823777755c0849562b3c93aa3d978911aa747b6 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 8 Dec 2021 22:46:25 +0100 Subject: [PATCH] Legals: Move the 2 copyrights items to the new legal screen --- .../features/discovery/DiscoveryPolicyItem.kt | 3 +- .../features/settings/VectorPreferences.kt | 2 -- .../VectorSettingsHelpAboutFragment.kt | 22 --------------- .../settings/legals/LegalsController.kt | 27 ++++++++++++++++++ .../settings/legals/LegalsFragment.kt | 28 ++++++++++++++++++- vector/src/main/res/values/strings.xml | 1 + .../res/xml/vector_settings_help_about.xml | 10 ------- 7 files changed, 57 insertions(+), 36 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoveryPolicyItem.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoveryPolicyItem.kt index c97a2286ae..4df4146d2f 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoveryPolicyItem.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoveryPolicyItem.kt @@ -24,6 +24,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.onClick +import im.vector.app.core.extensions.setTextOrHide @EpoxyModelClass(layout = R.layout.item_discovery_policy) abstract class DiscoveryPolicyItem : EpoxyModelWithHolder() { @@ -40,7 +41,7 @@ abstract class DiscoveryPolicyItem : EpoxyModelWithHolder(APP_INFO_LINK_PREFERENCE_KEY)!! @@ -75,23 +70,6 @@ class VectorSettingsHelpAboutFragment @Inject constructor( // olm version findPreference(VectorPreferences.SETTINGS_OLM_VERSION_PREFERENCE_KEY)!! .summary = session.cryptoService().getCryptoVersion(requireContext(), false) - - // third party notice - findPreference(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(VectorPreferences.SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY)!! - .onPreferenceClickListener = Preference.OnPreferenceClickListener { - // See https://developers.google.com/android/guides/opensource - openOssLicensesMenuActivity(requireActivity()) - false - } } companion object { diff --git a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt index 5470bb3ace..754a31be31 100644 --- a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt @@ -15,6 +15,7 @@ */ package im.vector.app.features.settings.legals +import android.content.res.Resources import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.Async import com.airbnb.mvrx.Fail @@ -35,6 +36,7 @@ import javax.inject.Inject class LegalsController @Inject constructor( private val stringProvider: StringProvider, + private val resources: Resources, private val elementLegals: ElementLegals, private val errorFormatter: ErrorFormatter ) : TypedEpoxyController() { @@ -45,6 +47,7 @@ class LegalsController @Inject constructor( buildAppSection() buildHomeserverSection(data) buildIdentityServerSection(data) + buildThirdPartyNotices() } 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 { fun onTapRetry() fun openPolicy(policy: ServerPolicy) + fun openThirdPartyNotice() + fun openThirdPartyNoticeGplay() } } diff --git a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt index c6b5c2bf1c..6a3db28702 100644 --- a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt @@ -27,9 +27,13 @@ import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith import im.vector.app.core.extensions.exhaustive 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.databinding.FragmentGenericRecyclerBinding import im.vector.app.features.discovery.ServerPolicy +import im.vector.app.features.settings.VectorSettingsUrls +import im.vector.app.openOssLicensesMenuActivity import javax.inject.Inject class LegalsFragment @Inject constructor( @@ -42,6 +46,7 @@ class LegalsFragment @Inject constructor( } private val viewModel by fragmentViewModel(LegalsViewModel::class) + private val firstThrottler = FirstThrottler(1000) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -79,6 +84,27 @@ class LegalsFragment @Inject constructor( } 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()) + } } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index e23cc02235..2759f0ebc5 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1400,6 +1400,7 @@ ${app_name} policy Your homeserver policy Your identity server policy + Third party libraries This server does not provide any policy. Integrations are disabled diff --git a/vector/src/main/res/xml/vector_settings_help_about.xml b/vector/src/main/res/xml/vector_settings_help_about.xml index 9171d1e6fe..c532536785 100644 --- a/vector/src/main/res/xml/vector_settings_help_about.xml +++ b/vector/src/main/res/xml/vector_settings_help_about.xml @@ -1,6 +1,5 @@ - - - - \ No newline at end of file