From 0be5ffca80ae478109aa277cae85fcbc5e3029f8 Mon Sep 17 00:00:00 2001 From: aderan Date: Wed, 11 Sep 2024 19:33:25 +0800 Subject: [PATCH] update protocol urls --- app/src/main/java/io/agora/flat/Constants.kt | 4 -- .../java/io/agora/flat/MainApplication.kt | 2 + .../flat/common/android/ProtocolUrlManager.kt | 61 +++++++++++++++++++ .../agora/flat/ui/activity/LoginActivity.kt | 10 +-- .../ui/activity/setting/AboutUsActivity.kt | 5 +- .../flat/ui/activity/setting/Settings.kt | 5 +- .../io/agora/flat/ui/compose/FlatAgreement.kt | 14 ++--- 7 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/io/agora/flat/common/android/ProtocolUrlManager.kt diff --git a/app/src/main/java/io/agora/flat/Constants.kt b/app/src/main/java/io/agora/flat/Constants.kt index 3514a3b5..a5daf87f 100644 --- a/app/src/main/java/io/agora/flat/Constants.kt +++ b/app/src/main/java/io/agora/flat/Constants.kt @@ -8,10 +8,6 @@ class Constants { } object URL { - const val Service = "https://www.flat.apprtc.cn/service.html" - - const val Privacy = "https://www.flat.apprtc.cn/privacy.html" - const val Registration = "https://beian.miit.gov.cn" const val Libraries = "https://www.flat.apprtc.cn/privacy-extra/libraries.html" diff --git a/app/src/main/java/io/agora/flat/MainApplication.kt b/app/src/main/java/io/agora/flat/MainApplication.kt index 67bc18f7..dad94e9c 100644 --- a/app/src/main/java/io/agora/flat/MainApplication.kt +++ b/app/src/main/java/io/agora/flat/MainApplication.kt @@ -10,6 +10,7 @@ import dagger.hilt.android.HiltAndroidApp import io.agora.flat.common.android.CallingCodeManager import io.agora.flat.common.android.DarkModeManager import io.agora.flat.common.android.LanguageManager +import io.agora.flat.common.android.ProtocolUrlManager import io.agora.flat.common.upload.UploadManager import io.agora.flat.di.GlobalInstanceProvider import io.agora.flat.util.isApkInDebug @@ -23,6 +24,7 @@ class MainApplication : Application(), CameraXConfig.Provider { DarkModeManager.init(this) CallingCodeManager.init(this) GlobalInstanceProvider.init(this) + ProtocolUrlManager.init(this) WebView.setWebContentsDebuggingEnabled(isApkInDebug()) WhiteboardView.setEntryUrl("file:///android_asset/flatboard/index.html") } diff --git a/app/src/main/java/io/agora/flat/common/android/ProtocolUrlManager.kt b/app/src/main/java/io/agora/flat/common/android/ProtocolUrlManager.kt new file mode 100644 index 00000000..e120ff31 --- /dev/null +++ b/app/src/main/java/io/agora/flat/common/android/ProtocolUrlManager.kt @@ -0,0 +1,61 @@ +package io.agora.flat.common.android + +import android.app.Application +import android.content.Context +import io.agora.flat.data.AppEnv +import io.agora.flat.data.AppEnv.Companion.ENV_CN_DEV +import io.agora.flat.data.AppEnv.Companion.ENV_CN_PROD +import io.agora.flat.data.AppEnv.Companion.ENV_SG_DEV +import io.agora.flat.data.AppEnv.Companion.ENV_SG_PROD + +object ProtocolUrlManager { + private const val PRIVACY = "privacy" + private const val SERVICE = "service" + + private lateinit var application: Context + + private val appEnv by lazy { AppEnv(application) } + + private val urls: Map>> = mapOf( + PRIVACY to mapOf( + ENV_CN_PROD to mapOf( + "en" to "https://www.flat.apprtc.cn/en/privacy.html", "zh" to "https://www.flat.apprtc.cn/privacy.html" + ), ENV_CN_DEV to mapOf( + "en" to "https://www.flat.apprtc.cn/en/privacy.html", "zh" to "https://www.flat.apprtc.cn/privacy.html" + ), ENV_SG_PROD to mapOf( + "en" to "https://flat.agora.io/privacy.html", "zh" to "https://flat.agora.io/zh/privacy.html" + ), ENV_SG_DEV to mapOf( + "en" to "https://flat.agora.io/privacy.html", "zh" to "https://flat.agora.io/zh/privacy.html" + ) + ), + SERVICE to mapOf( + ENV_CN_PROD to mapOf( + "en" to "https://www.flat.apprtc.cn/en/service.html", "zh" to "https://www.flat.apprtc.cn/service.html" + ), ENV_CN_DEV to mapOf( + "en" to "https://www.flat.apprtc.cn/en/service.html", "zh" to "https://www.flat.apprtc.cn/service.html" + ), ENV_SG_PROD to mapOf( + "en" to "https://flat.agora.io/en/service.html", "zh" to "https://flat.agora.io/zh/service.html" + ), ENV_SG_DEV to mapOf( + "en" to "https://flat.agora.io/en/service.html", "zh" to "https://flat.agora.io/zh/service.html" + ) + ), + ) + + fun init(app: Application) { + application = app + } + + val Service: String + get() { + val env = appEnv.getEnv() + val lang = LanguageManager.currentLocale().language + return urls[SERVICE]!![env]?.get(lang) ?: "https://www.flat.apprtc.cn/service.html" + } + + val Privacy: String + get() { + val env = appEnv.getEnv() + val lang = LanguageManager.currentLocale().language + return urls[PRIVACY]!![env]?.get(lang) ?: "https://www.flat.apprtc.cn/privacy.html" + } +} \ No newline at end of file diff --git a/app/src/main/java/io/agora/flat/ui/activity/LoginActivity.kt b/app/src/main/java/io/agora/flat/ui/activity/LoginActivity.kt index 2e542d21..0c46b6bc 100644 --- a/app/src/main/java/io/agora/flat/ui/activity/LoginActivity.kt +++ b/app/src/main/java/io/agora/flat/ui/activity/LoginActivity.kt @@ -49,10 +49,10 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.core.view.WindowCompat import dagger.hilt.android.AndroidEntryPoint -import io.agora.flat.Constants import io.agora.flat.R import io.agora.flat.common.Navigator import io.agora.flat.common.android.LanguageManager +import io.agora.flat.common.android.ProtocolUrlManager import io.agora.flat.common.login.LoginActivityHandler import io.agora.flat.common.login.LoginState import io.agora.flat.common.login.LoginType @@ -125,11 +125,11 @@ class LoginActivity : BaseComposeActivity() { } LoginUiAction.OpenServiceProtocol -> { - Navigator.launchWebViewActivity(this, Constants.URL.Service) + Navigator.launchWebViewActivity(this, ProtocolUrlManager.Service) } LoginUiAction.OpenPrivacyProtocol -> { - Navigator.launchWebViewActivity(this, Constants.URL.Privacy) + Navigator.launchWebViewActivity(this, ProtocolUrlManager.Privacy) } is LoginUiAction.PhoneLogin -> { @@ -618,8 +618,8 @@ fun LoginAgreement( Checkbox(checked = checked, onCheckedChange = onCheckedChange) Spacer(Modifier.width(4.dp)) val items = listOf( - ClickableItem(stringResource(R.string.privacy_policy), "privacy", Constants.URL.Privacy), - ClickableItem(stringResource(R.string.term_of_service), "service", Constants.URL.Service) + ClickableItem(stringResource(R.string.privacy_policy), "privacy", ProtocolUrlManager.Privacy), + ClickableItem(stringResource(R.string.term_of_service), "service", ProtocolUrlManager.Service) ) FlatClickableText(stringResource(R.string.login_agreement_message), items = items) } diff --git a/app/src/main/java/io/agora/flat/ui/activity/setting/AboutUsActivity.kt b/app/src/main/java/io/agora/flat/ui/activity/setting/AboutUsActivity.kt index 1f63aa6d..d2260815 100644 --- a/app/src/main/java/io/agora/flat/ui/activity/setting/AboutUsActivity.kt +++ b/app/src/main/java/io/agora/flat/ui/activity/setting/AboutUsActivity.kt @@ -29,6 +29,7 @@ import dagger.hilt.android.AndroidEntryPoint import io.agora.flat.Constants import io.agora.flat.R import io.agora.flat.common.Navigator +import io.agora.flat.common.android.ProtocolUrlManager import io.agora.flat.data.AppEnv import io.agora.flat.ui.activity.base.BaseComposeActivity import io.agora.flat.ui.compose.BackTopAppBar @@ -54,11 +55,11 @@ class AboutUsActivity : BaseComposeActivity() { when (action) { is AboutUiAction.Back -> finish() is AboutUiAction.OpenServiceProtocol -> { - Navigator.launchWebViewActivity(this@AboutUsActivity, Constants.URL.Service) + Navigator.launchWebViewActivity(this@AboutUsActivity, ProtocolUrlManager.Service) } is AboutUiAction.OpenPrivacyProtocol -> { - Navigator.launchWebViewActivity(this@AboutUsActivity, Constants.URL.Privacy) + Navigator.launchWebViewActivity(this@AboutUsActivity, ProtocolUrlManager.Privacy) } is AboutUiAction.OpenRegistration -> { diff --git a/app/src/main/java/io/agora/flat/ui/activity/setting/Settings.kt b/app/src/main/java/io/agora/flat/ui/activity/setting/Settings.kt index b22835e4..94e2ec29 100644 --- a/app/src/main/java/io/agora/flat/ui/activity/setting/Settings.kt +++ b/app/src/main/java/io/agora/flat/ui/activity/setting/Settings.kt @@ -37,6 +37,7 @@ import androidx.navigation.NavController import io.agora.flat.Constants import io.agora.flat.R import io.agora.flat.common.Navigator +import io.agora.flat.common.android.ProtocolUrlManager import io.agora.flat.ui.compose.BackTopAppBar import io.agora.flat.ui.compose.FlatColumnPage import io.agora.flat.ui.compose.FlatDivider @@ -126,12 +127,12 @@ private fun SettingsList(state: SettingsUiState, onDownload: suspend () -> Uri, SettingItem( id = R.drawable.ic_settings_privacy_policy, tip = stringResource(R.string.privacy_policy), - onClick = { Navigator.launchWebViewActivity(context, Constants.URL.Privacy) }) + onClick = { Navigator.launchWebViewActivity(context, ProtocolUrlManager.Privacy) }) SettingItemDivider() SettingItem( id = R.drawable.ic_settings_term_of_service, tip = stringResource(R.string.term_of_service), - onClick = { Navigator.launchWebViewActivity(context, Constants.URL.Service) }) + onClick = { Navigator.launchWebViewActivity(context, ProtocolUrlManager.Service) }) SettingItemDivider() SettingItem( id = R.drawable.ic_settings_info_gathering, diff --git a/app/src/main/java/io/agora/flat/ui/compose/FlatAgreement.kt b/app/src/main/java/io/agora/flat/ui/compose/FlatAgreement.kt index 77e1f366..7ee40d7c 100644 --- a/app/src/main/java/io/agora/flat/ui/compose/FlatAgreement.kt +++ b/app/src/main/java/io/agora/flat/ui/compose/FlatAgreement.kt @@ -10,8 +10,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog -import io.agora.flat.Constants import io.agora.flat.R +import io.agora.flat.common.android.ProtocolUrlManager import io.agora.flat.data.model.Agreement import io.agora.flat.ui.theme.Shapes @@ -82,8 +82,8 @@ internal fun AgreementDialog(agreement: Agreement? = null, onAgree: () -> Unit, private fun LoginAgreementDialogMessage(agreement: Agreement?) { var text = agreement?.message ?: stringResource(R.string.login_agreement_dialog_message) val items = listOf( - ClickableItem(stringResource(R.string.agreement_global_privacy), "privacy", Constants.URL.Privacy), - ClickableItem(stringResource(R.string.agreement_global_service), "service", Constants.URL.Service) + ClickableItem(stringResource(R.string.agreement_global_privacy), "privacy", ProtocolUrlManager.Privacy), + ClickableItem(stringResource(R.string.agreement_global_service), "service", ProtocolUrlManager.Service) ) FlatClickableText(text = text, items = items) @@ -93,8 +93,8 @@ private fun LoginAgreementDialogMessage(agreement: Agreement?) { private fun GlobalAgreementMessage() { val text = stringResource(R.string.agreement_global_dialog_message) val items = listOf( - ClickableItem(stringResource(R.string.agreement_global_privacy), "privacy", Constants.URL.Privacy), - ClickableItem(stringResource(R.string.agreement_global_service), "service", Constants.URL.Service) + ClickableItem(stringResource(R.string.agreement_global_privacy), "privacy", ProtocolUrlManager.Privacy), + ClickableItem(stringResource(R.string.agreement_global_service), "service", ProtocolUrlManager.Service) ) FlatClickableText(text = text, items = items) @@ -104,8 +104,8 @@ private fun GlobalAgreementMessage() { private fun GlobalRecheckAgreementMessage() { val text = stringResource(R.string.agreement_global_recheck_dialog_message) val items = listOf( - ClickableItem(stringResource(R.string.agreement_global_privacy), "privacy", Constants.URL.Privacy), - ClickableItem(stringResource(R.string.agreement_global_service), "service", Constants.URL.Service) + ClickableItem(stringResource(R.string.agreement_global_privacy), "privacy", ProtocolUrlManager.Privacy), + ClickableItem(stringResource(R.string.agreement_global_service), "service", ProtocolUrlManager.Service) ) FlatClickableText(text = text, items = items)