decouples the flavor code / OSS licenses activity launching

This commit is contained in:
Adam Brown 2022-08-09 10:32:43 +01:00
parent 0c61595ace
commit ed3b73a989
6 changed files with 40 additions and 12 deletions

View file

@ -27,6 +27,7 @@ import im.vector.app.core.services.GuardServiceStarter
import im.vector.app.fdroid.service.FDroidGuardServiceStarter
import im.vector.app.features.home.NightlyProxy
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.legals.FlavourLegals
import im.vector.app.push.fcm.FdroidFcmHelper
@InstallIn(SingletonComponent::class)
@ -45,6 +46,15 @@ abstract class FlavorModule {
// no op
}
}
@Provides
fun providesFlavorLegals() = object : FlavourLegals {
override fun hasThirdPartyNotices() = false
override fun navigateToThirdPartyNotices(context: Context) {
// no op
}
}
}
@Binds

View file

@ -1,5 +1,5 @@
/*
* Copyright 2020 New Vector Ltd
* Copyright (c) 2022 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.
@ -19,5 +19,15 @@ package im.vector.app
import android.content.Context
import android.content.Intent
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import im.vector.app.features.settings.legals.FlavourLegals
import javax.inject.Inject
fun openOssLicensesMenuActivity(context: Context) = context.startActivity(Intent(context, OssLicensesMenuActivity::class.java))
class GoogleFlavorLegals @Inject constructor() : FlavourLegals {
override fun hasThirdPartyNotices() = true
override fun navigateToThirdPartyNotices(context: Context) {
// See https://developers.google.com/android/guides/opensource
context.startActivity(Intent(context, OssLicensesMenuActivity::class.java))
}
}

View file

@ -21,9 +21,11 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import im.vector.app.GoogleFlavorLegals
import im.vector.app.core.pushers.FcmHelper
import im.vector.app.core.services.GuardServiceStarter
import im.vector.app.features.home.NightlyProxy
import im.vector.app.features.settings.legals.FlavourLegals
import im.vector.app.nightly.FirebaseNightlyProxy
import im.vector.app.push.fcm.GoogleFcmHelper
@ -43,4 +45,8 @@ abstract class FlavorModule {
@Binds
abstract fun bindsFcmHelper(fcmHelper: GoogleFcmHelper): FcmHelper
@Binds
abstract fun bindsFlavorLegals(legals: GoogleFlavorLegals): FlavourLegals
}

View file

@ -1,5 +1,5 @@
/*
* Copyright 2020 New Vector Ltd
* Copyright (c) 2022 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.
@ -14,9 +14,11 @@
* limitations under the License.
*/
package im.vector.app
package im.vector.app.features.settings.legals
import android.content.Context
// No op
fun openOssLicensesMenuActivity(@Suppress("UNUSED_PARAMETER") context: Context) = Unit
interface FlavourLegals {
fun hasThirdPartyNotices(): Boolean
fun navigateToThirdPartyNotices(context: Context)
}

View file

@ -38,7 +38,8 @@ class LegalsController @Inject constructor(
private val stringProvider: StringProvider,
private val resources: Resources,
private val elementLegals: ElementLegals,
private val errorFormatter: ErrorFormatter
private val errorFormatter: ErrorFormatter,
private val flavourLegals: FlavourLegals,
) : TypedEpoxyController<LegalsState>() {
var listener: Listener? = null
@ -134,7 +135,7 @@ class LegalsController @Inject constructor(
clickListener { host.listener?.openThirdPartyNotice() }
}
// Only on Gplay
if (resources.getBoolean(R.bool.isGplay)) {
if (flavourLegals.hasThirdPartyNotices()) {
discoveryPolicyItem {
id("eltpn2")
name(host.stringProvider.getString(R.string.settings_other_third_party_notices))

View file

@ -33,11 +33,11 @@ import im.vector.app.databinding.FragmentGenericRecyclerBinding
import im.vector.app.features.analytics.plan.MobileScreen
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(
private val controller: LegalsController
private val controller: LegalsController,
private val flavourLegals: FlavourLegals,
) : VectorBaseFragment<FragmentGenericRecyclerBinding>(),
LegalsController.Listener {
@ -100,8 +100,7 @@ class LegalsFragment @Inject constructor(
override fun openThirdPartyNoticeGplay() {
if (firstThrottler.canHandle() is FirstThrottler.CanHandlerResult.Yes) {
// See https://developers.google.com/android/guides/opensource
openOssLicensesMenuActivity(requireActivity())
flavourLegals.navigateToThirdPartyNotices(requireContext())
}
}
}