parent
00aebd8b86
commit
d5f7d1051d
|
|
@ -176,6 +176,8 @@ tasks.withType<JavaCompile>().configureEach {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// 手动启动延后到隐私授权之后的初始化器。
|
||||||
|
implementation("androidx.startup:startup-runtime:1.2.0")
|
||||||
api(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar","*.aar"))))
|
api(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar","*.aar"))))
|
||||||
// 基础依赖
|
// 基础依赖
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<!-- 不允许依赖库重新引入读取安装列表/运行任务的权限。 -->
|
||||||
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:node="remove" />
|
||||||
|
<uses-permission android:name="android.permission.GET_TASKS" tools:node="remove" />
|
||||||
|
<uses-permission android:name="android.permission.REAL_GET_TASKS" tools:node="remove" />
|
||||||
<!-- 在Android14及以上版本读取SelectedPhotoAccess需要添加READ_MEDIA_VISUAL_USER_SELECTED权限 -->
|
<!-- 在Android14及以上版本读取SelectedPhotoAccess需要添加READ_MEDIA_VISUAL_USER_SELECTED权限 -->
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
|
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
|
||||||
<!-- 写入外部存储权限,用于截长图保存,主要兼容Android 13及以下版本(Android13以上高版本不需要,但低版本必须) -->
|
<!-- 写入外部存储权限,用于截长图保存,主要兼容Android 13及以下版本(Android13以上高版本不需要,但低版本必须) -->
|
||||||
|
|
@ -37,7 +41,7 @@
|
||||||
<package android:name="com.eg.android.AlipayGphone" /> <!-- 支付宝 -->
|
<package android:name="com.eg.android.AlipayGphone" /> <!-- 支付宝 -->
|
||||||
<package android:name="hk.alipay.wallet" /> <!-- AlipayHK -->
|
<package android:name="hk.alipay.wallet" /> <!-- AlipayHK -->
|
||||||
<package android:name="com.tencent.mm" />
|
<package android:name="com.tencent.mm" />
|
||||||
<intent>
|
<intent tools:node="remove">
|
||||||
<action android:name="com.getui.sdk.action" />
|
<action android:name="com.getui.sdk.action" />
|
||||||
</intent>
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
|
|
@ -62,6 +66,20 @@
|
||||||
tools:replace="android:allowBackup,android:supportsRtl"
|
tools:replace="android:allowBackup,android:supportsRtl"
|
||||||
tools:targetApi="33">
|
tools:targetApi="33">
|
||||||
|
|
||||||
|
<!-- SDK 自动初始化发生在 Application.onCreate 之前,改为同意后手动初始化。 -->
|
||||||
|
<provider android:name="com.google.mlkit.common.internal.MlKitInitProvider"
|
||||||
|
tools:node="remove" />
|
||||||
|
<provider android:name="com.getui.gtc.base.GtcProvider" tools:node="remove" />
|
||||||
|
<provider android:name=".provider.ConsentGtcProvider"
|
||||||
|
android:authorities="${applicationId}.getui.gtc.provider"
|
||||||
|
android:exported="false" />
|
||||||
|
<provider android:name="androidx.startup.InitializationProvider"
|
||||||
|
android:authorities="${applicationId}.androidx-startup"
|
||||||
|
tools:node="merge">
|
||||||
|
<meta-data android:name="okhttp3.internal.platform.PlatformInitializer"
|
||||||
|
tools:node="remove" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.img.rabbit.MainActivity"
|
android:name="com.img.rabbit.MainActivity"
|
||||||
android:theme="@style/SplashTheme"
|
android:theme="@style/SplashTheme"
|
||||||
|
|
@ -103,6 +121,16 @@
|
||||||
|
|
||||||
|
|
||||||
<!--如果是小程序模式,还需要添加这行配置-->
|
<!--如果是小程序模式,还需要添加这行配置-->
|
||||||
|
<activity
|
||||||
|
android:name=".wxapi.AuthorizedWXEntryActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||||
|
<activity
|
||||||
|
android:name=".wxapi.AuthorizedWXPayEntryActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||||
<activity
|
<activity
|
||||||
android:name="io.dcloud.feature.payment.weixin.WXPayProcessMeadiatorActivity"
|
android:name="io.dcloud.feature.payment.weixin.WXPayProcessMeadiatorActivity"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.img.rabbit
|
package com.img.rabbit
|
||||||
|
|
||||||
import android.app.ActivityManager
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
|
@ -8,53 +7,45 @@ import android.util.Log
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.img.rabbit.utils.NetworkMonitor
|
import com.img.rabbit.utils.NetworkMonitor
|
||||||
import com.g.gysdk.GYManager
|
import com.g.gysdk.GYManager
|
||||||
import com.getui.gtc.base.util.CommonUtil.isMainProcess
|
import androidx.startup.AppInitializer
|
||||||
|
import com.google.mlkit.common.sdkinternal.MlKitContext
|
||||||
import com.github.gzuliyujiang.oaid.DeviceID
|
import com.github.gzuliyujiang.oaid.DeviceID
|
||||||
import com.github.gzuliyujiang.oaid.IGetter
|
import com.github.gzuliyujiang.oaid.IGetter
|
||||||
import com.img.rabbit.config.Constants
|
import com.img.rabbit.config.Constants
|
||||||
import com.img.rabbit.provider.storage.PreferenceUtil
|
import com.img.rabbit.provider.storage.PreferenceUtil
|
||||||
|
import com.img.rabbit.provider.storage.PrivacyConsentStore
|
||||||
|
import com.img.rabbit.provider.ConsentGtcProvider
|
||||||
|
import com.img.rabbit.provider.utils.HeadParamUtils
|
||||||
import com.img.rabbit.uni.UniMPImmersiveWindow
|
import com.img.rabbit.uni.UniMPImmersiveWindow
|
||||||
import com.img.rabbit.utils.ChannelUtils
|
import com.img.rabbit.utils.ChannelUtils
|
||||||
import com.tencent.mmkv.MMKV
|
import com.tencent.mmkv.MMKV
|
||||||
import com.umeng.analytics.MobclickAgent
|
import com.umeng.analytics.MobclickAgent
|
||||||
import com.umeng.commonsdk.UMConfigure
|
import com.umeng.commonsdk.UMConfigure
|
||||||
import com.umeng.socialize.PlatformConfig
|
import com.umeng.socialize.PlatformConfig
|
||||||
import io.dcloud.common.util.RuningAcitvityUtil
|
import okhttp3.internal.platform.PlatformInitializer
|
||||||
import io.dcloud.feature.sdk.DCSDKInitConfig
|
import io.dcloud.feature.sdk.DCSDKInitConfig
|
||||||
import io.dcloud.feature.sdk.DCUniMPSDK
|
import io.dcloud.feature.sdk.DCUniMPSDK
|
||||||
import io.dcloud.feature.sdk.MenuActionSheetItem
|
import io.dcloud.feature.sdk.MenuActionSheetItem
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
class BaseApplication : Application() {
|
class BaseApplication : Application() {
|
||||||
private val TAG = "BaseApplication"
|
private val TAG = "BaseApplication"
|
||||||
private var batiaoInitialized = false
|
private var batiaoInitialized = false
|
||||||
|
private var thirdPartyInitialized = false
|
||||||
private var uniAppInitialized = false
|
private var uniAppInitialized = false
|
||||||
private var uniAppOaid: String? = null
|
private var uniAppOaid: String? = null
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
// UniMP Activity 运行在独立进程,窗口适配必须在主进程判断之前注册。
|
initThirdParty()
|
||||||
UniMPImmersiveWindow.register(this)
|
|
||||||
// 只有是主进程时,才执行重量级初始化
|
|
||||||
if (getProcessName(this) == packageName) {
|
|
||||||
Log.i(TAG, "进行必要的SDK初始化...")
|
|
||||||
// 初始化MMKV
|
|
||||||
initMMKV()
|
|
||||||
// 非小程序进程(使用unimp 关键字 可以根据宿主的具体情况进行调整)
|
|
||||||
if (PreferenceUtil.getAgreement() && !RuningAcitvityUtil.getAppName(baseContext).contains("unimp")) {
|
|
||||||
Log.i(TAG, "已同意隐私政策,BaseApplication开始初始化SDK服务...")
|
|
||||||
initThirdParty()
|
|
||||||
initUM()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context?) {
|
override fun attachBaseContext(base: Context?) {
|
||||||
//MultiDex.install(base)
|
|
||||||
super.attachBaseContext(base)
|
super.attachBaseContext(base)
|
||||||
|
PrivacyConsentStore.initialize(this)
|
||||||
|
HeadParamUtils.applicationContext = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,8 +54,19 @@ class BaseApplication : Application() {
|
||||||
*/
|
*/
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun initThirdParty(){
|
fun initThirdParty(){
|
||||||
//需要在隐私框架下才能处理的逻辑
|
if (!PrivacyConsentStore.isAccepted() || thirdPartyInitialized) return
|
||||||
if(PreferenceUtil.getAgreement()){
|
// 独立进程也必须先检查授权;只注册其所需的窗口适配。
|
||||||
|
UniMPImmersiveWindow.register(this)
|
||||||
|
if (currentProcessName() == packageName) {
|
||||||
|
initMMKV()
|
||||||
|
AppInitializer.getInstance(this).initializeComponent(PlatformInitializer::class.java)
|
||||||
|
MlKitContext.initializeIfNeeded(this)
|
||||||
|
// 采集开关必须在任何 SDK(包括构建插件注入代码)启动前设置。
|
||||||
|
UMConfigure.enableAplCollection(false)
|
||||||
|
check(GYManager.getInstance().setSecurity(this, false)) {
|
||||||
|
"无法关闭个验扩展采集"
|
||||||
|
}
|
||||||
|
ConsentGtcProvider.initializeAfterConsent(this)
|
||||||
if (!batiaoInitialized) {
|
if (!batiaoInitialized) {
|
||||||
initializeBatiaoAfterConsent()
|
initializeBatiaoAfterConsent()
|
||||||
batiaoInitialized = true
|
batiaoInitialized = true
|
||||||
|
|
@ -76,9 +78,11 @@ class BaseApplication : Application() {
|
||||||
Glide.get(this)
|
Glide.get(this)
|
||||||
// 初始化个推SDK
|
// 初始化个推SDK
|
||||||
initGeTuiOneKeyLogin()
|
initGeTuiOneKeyLogin()
|
||||||
|
initUM()
|
||||||
// 初始化OAID和uni-app SDK
|
// 初始化OAID和uni-app SDK
|
||||||
initOAIDAndUniAPPSdk()
|
initOAIDAndUniAPPSdk()
|
||||||
}
|
}
|
||||||
|
thirdPartyInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Batiao 构建插件只向此方法注入初始化,调用前必须检查隐私协议。
|
// Batiao 构建插件只向此方法注入初始化,调用前必须检查隐私协议。
|
||||||
|
|
@ -129,7 +133,7 @@ class BaseApplication : Application() {
|
||||||
|
|
||||||
//初始化uni-app SDK
|
//初始化uni-app SDK
|
||||||
private fun initUniAPPSdk() {
|
private fun initUniAPPSdk() {
|
||||||
if (PreferenceUtil.getAgreement() && isMainProcess(this)) {
|
if (PreferenceUtil.getAgreement() && currentProcessName() == packageName) {
|
||||||
val oaid = PreferenceUtil.getOAID()
|
val oaid = PreferenceUtil.getOAID()
|
||||||
if (uniAppInitialized && uniAppOaid == oaid) return
|
if (uniAppInitialized && uniAppOaid == oaid) return
|
||||||
uniAppInitialized = true
|
uniAppInitialized = true
|
||||||
|
|
@ -158,19 +162,15 @@ class BaseApplication : Application() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getProcessName(context: Context): String? {
|
private fun currentProcessName(): String? {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
return getProcessName()
|
return getProcessName()
|
||||||
}
|
}
|
||||||
|
|
||||||
val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
// 旧系统只读取当前进程名,不枚举其他应用的进程。
|
||||||
val runningApps = am.runningAppProcesses ?: return null
|
return runCatching {
|
||||||
for (proInfo in runningApps) {
|
File("/proc/self/cmdline").readText().substringBefore('\u0000')
|
||||||
if (proInfo.pid == android.os.Process.myPid()) {
|
}.getOrNull()
|
||||||
return proInfo.processName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,22 @@ import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||||
|
import androidx.compose.foundation.layout.widthIn
|
||||||
import androidx.compose.foundation.layout.wrapContentHeight
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
import androidx.compose.foundation.layout.wrapContentSize
|
import androidx.compose.foundation.layout.wrapContentSize
|
||||||
import androidx.compose.foundation.layout.wrapContentWidth
|
import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.text.ClickableText
|
import androidx.compose.foundation.text.ClickableText
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
|
@ -38,6 +44,7 @@ import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
|
@ -47,6 +54,7 @@ import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
@ -57,7 +65,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.img.rabbit.bean.response.UniVersionEntity
|
import com.img.rabbit.bean.response.UniVersionEntity
|
||||||
import com.img.rabbit.components.GlobalToast
|
import com.img.rabbit.components.GlobalToast
|
||||||
import com.img.rabbit.config.Constants
|
|
||||||
import com.img.rabbit.config.Constants.agreementUrl
|
import com.img.rabbit.config.Constants.agreementUrl
|
||||||
import com.img.rabbit.config.Constants.privacyUrl
|
import com.img.rabbit.config.Constants.privacyUrl
|
||||||
import com.img.rabbit.pages.LoadingCallback
|
import com.img.rabbit.pages.LoadingCallback
|
||||||
|
|
@ -70,7 +77,6 @@ import com.img.rabbit.pages.dialog.UpdateDialog
|
||||||
import com.img.rabbit.provider.storage.PreferenceUtil
|
import com.img.rabbit.provider.storage.PreferenceUtil
|
||||||
import com.img.rabbit.utils.AppEventBus
|
import com.img.rabbit.utils.AppEventBus
|
||||||
import com.img.rabbit.utils.AppUpdate
|
import com.img.rabbit.utils.AppUpdate
|
||||||
import com.img.rabbit.utils.ChannelUtils
|
|
||||||
import com.img.rabbit.utils.FileUtils
|
import com.img.rabbit.utils.FileUtils
|
||||||
import com.img.rabbit.utils.GlobalEvent
|
import com.img.rabbit.utils.GlobalEvent
|
||||||
import com.img.rabbit.utils.GlobalEventBus
|
import com.img.rabbit.utils.GlobalEventBus
|
||||||
|
|
@ -83,12 +89,9 @@ import com.img.rabbit.viewmodel.GeneralViewModel
|
||||||
import com.img.rabbit.viewmodel.LoginViewModel
|
import com.img.rabbit.viewmodel.LoginViewModel
|
||||||
import com.img.rabbit.viewmodel.ReportViewModel
|
import com.img.rabbit.viewmodel.ReportViewModel
|
||||||
import com.img.rabbit.viewmodel.SplashViewModel
|
import com.img.rabbit.viewmodel.SplashViewModel
|
||||||
import com.umeng.analytics.MobclickAgent
|
|
||||||
import com.umeng.commonsdk.UMConfigure
|
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.system.exitProcess
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity(), LoadingCallback {
|
class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
private lateinit var generalViewModel: GeneralViewModel
|
private lateinit var generalViewModel: GeneralViewModel
|
||||||
|
|
@ -103,8 +106,26 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
|
// 授权前仅渲染原生协议页,不创建会访问 MMKV/网络/微信的业务 ViewModel。
|
||||||
|
var consentAccepted by remember { mutableStateOf(PreferenceUtil.getAgreement()) }
|
||||||
|
if (!consentAccepted) {
|
||||||
|
splashScreen.setKeepOnScreenCondition { false }
|
||||||
|
AppTheme {
|
||||||
|
SplashScreenContent {
|
||||||
|
PrivacyPolicyScreen { accepted ->
|
||||||
|
if (accepted) {
|
||||||
|
PreferenceUtil.saveAgreement(true)
|
||||||
|
(application as BaseApplication).initThirdParty()
|
||||||
|
consentAccepted = true
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@setContent
|
||||||
|
}
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
var showSplash by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val loginViewModel: LoginViewModel = viewModel()
|
val loginViewModel: LoginViewModel = viewModel()
|
||||||
|
|
@ -267,40 +288,10 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
|
|
||||||
AppTheme {
|
AppTheme {
|
||||||
SplashScreenContent{
|
SplashScreenContent{
|
||||||
//未同意提示政策弹窗
|
if(isLogout){
|
||||||
if (!generalViewModel.agreementStatus.value){
|
LoginScreen(generalViewModel = generalViewModel, loginViewModel = loginViewModel, isVisibilityBreak = false)
|
||||||
//同意继续
|
} else {
|
||||||
PrivacyPolicyScreen(
|
MainScreen(generalViewModel = generalViewModel, loginViewModel = loginViewModel)
|
||||||
viewModel = loginViewModel,
|
|
||||||
) { isAllowPrivacyPolicy ->
|
|
||||||
if (isAllowPrivacyPolicy) {
|
|
||||||
generalViewModel.setIsAgreement(true)
|
|
||||||
loginViewModel.setIsPolicyAgreement(true)
|
|
||||||
(applicationContext as BaseApplication).initThirdParty()
|
|
||||||
initUM()
|
|
||||||
showSplash = true
|
|
||||||
} else {
|
|
||||||
// 不同意隐私协议政策,直接退出应用
|
|
||||||
(context as MainActivity).finish()
|
|
||||||
// 强制退出应用进程
|
|
||||||
exitProcess(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
showSplash = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if(showSplash){
|
|
||||||
//val token = PreferenceUtil.getAccessToken()
|
|
||||||
// 未登录,显示登录页
|
|
||||||
//if (token.isNullOrEmpty() && loginViewModel.userConfigResult.value == null) {
|
|
||||||
if(isLogout){// 退出登录后,显示登录页
|
|
||||||
// 显示登录页
|
|
||||||
LoginScreen(generalViewModel = generalViewModel, loginViewModel = loginViewModel, isVisibilityBreak = false)
|
|
||||||
} else {
|
|
||||||
//已登录,显示主页面
|
|
||||||
MainScreen(generalViewModel = generalViewModel, loginViewModel = loginViewModel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(showLoginDialog){
|
if(showLoginDialog){
|
||||||
|
|
@ -436,15 +427,6 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化友盟(同意协议的时候,进行一次初始化)
|
|
||||||
*/
|
|
||||||
private fun initUM() {
|
|
||||||
UMConfigure.preInit(applicationContext, Constants.UmengAppkey, ChannelUtils.getChannel(applicationContext))
|
|
||||||
UMConfigure.init(this, Constants.UmengAppkey, ChannelUtils.getChannel(applicationContext), UMConfigure.DEVICE_TYPE_PHONE, "")
|
|
||||||
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showLoading() {
|
override fun showLoading() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
generalViewModel.setLoading(true)
|
generalViewModel.setLoading(true)
|
||||||
|
|
@ -517,205 +499,200 @@ fun SplashScreenContent(
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (Boolean) -> Unit) {
|
private fun PrivacyPolicyScreen(onAgreementChange: (Boolean) -> Unit) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
Box(
|
BoxWithConstraints(
|
||||||
modifier = Modifier.fillMaxSize()
|
modifier = Modifier
|
||||||
){
|
.fillMaxSize()
|
||||||
|
.background(Color(0xCC000000))
|
||||||
|
.safeDrawingPadding()
|
||||||
|
.padding(horizontal = 24.dp, vertical = 24.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.widthIn(max = 400.dp)
|
||||||
.background(Color(0xCC000000))
|
.fillMaxWidth()
|
||||||
|
.heightIn(max = maxHeight)
|
||||||
|
.clip(RoundedCornerShape(26.dp))
|
||||||
|
.background(Color.White)
|
||||||
){
|
){
|
||||||
Box(
|
Image(
|
||||||
|
painter = painterResource(id = R.mipmap.ic_privacy_policy_top_mask),
|
||||||
|
contentDescription = null,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 38.dp, vertical = 213.dp)
|
.height(64.dp),
|
||||||
.align(Alignment.Center)
|
contentScale = ContentScale.FillBounds
|
||||||
.background(Color.White, shape = RoundedCornerShape(26.dp))
|
)
|
||||||
){
|
|
||||||
Image(
|
Column(
|
||||||
painter = painterResource(id = R.mipmap.ic_privacy_policy_top_mask),
|
modifier = Modifier
|
||||||
contentDescription = null,
|
.fillMaxWidth()
|
||||||
|
// 内容与按钮使用同一条纵向布局,空间不足时整体滚动。
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(start = 24.dp, end = 24.dp, top = 32.dp, bottom = 12.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "用户协议与隐私政策",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize(),
|
.wrapContentSize()
|
||||||
alignment = Alignment.TopCenter
|
.align(Alignment.CenterHorizontally),
|
||||||
|
fontWeight = FontWeight.Normal,
|
||||||
|
fontSize = 18.sp,
|
||||||
|
lineHeight = 26.sp,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
color = Color(0xFF1A1A1A)
|
||||||
|
)
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(24.dp)
|
||||||
)
|
)
|
||||||
|
|
||||||
Column(
|
val agreement = "请您务必审慎阅读、充分理解《服务协议》与《隐私政策》各条款,包括但不限于:为了更好的向您提供服务,我们需要访问您的相册、相机等。您可以阅读《隐私政策》了解详细信息。如果您同意,请点击下面同意按钮开始接受我们的服务。"
|
||||||
modifier = Modifier
|
val annotatedText = buildAnnotatedString {
|
||||||
.padding(top = 36.dp)
|
append(agreement)
|
||||||
.align(Alignment.TopCenter)
|
val startIndexForService = agreement.indexOf("《服务协议》")
|
||||||
) {
|
val startIndexPrivacy1 = agreement.indexOf("《隐私政策》")
|
||||||
Text(
|
val startIndexPrivacy2 = agreement.lastIndexOf("《隐私政策》")
|
||||||
text = "用户协议与隐私政策",
|
|
||||||
modifier = Modifier
|
|
||||||
.wrapContentSize()
|
|
||||||
.align(Alignment.CenterHorizontally),
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
fontSize = 18.sp,
|
|
||||||
color = Color(0xFF1A1A1A)
|
|
||||||
)
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(24.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
val agreement = "请您务必审慎阅读、充分理解《服务协议》与《隐私政策》各条款,包括但不限于:为了更好的向您提供服务,我们需要访问您的相册、相机等。您可以阅读《隐私政策》了解详细信息。如果您同意,请点击下面同意按钮开始接受我们的服务。"
|
val serviceLength = "《服务协议》".length
|
||||||
val annotatedText = buildAnnotatedString {
|
val privacyLength = "《隐私政策》".length
|
||||||
append(agreement)
|
|
||||||
val startIndexForService = agreement.indexOf("《服务协议》")
|
|
||||||
val startIndexPrivacy1 = agreement.indexOf("《隐私政策》")
|
|
||||||
val startIndexPrivacy2 = agreement.lastIndexOf("《隐私政策》")
|
|
||||||
|
|
||||||
val serviceLength = "《服务协议》".length
|
// 高亮显示 "《服务协议》"
|
||||||
val privacyLength = "《服务协议》".length
|
addStyle(
|
||||||
|
style = SpanStyle(
|
||||||
// 高亮显示 "《服务协议》"
|
color = Color(0xFF0066CC),
|
||||||
addStyle(
|
textDecoration = TextDecoration.None
|
||||||
style = SpanStyle(
|
|
||||||
color = Color(0xFF0066CC),
|
|
||||||
textDecoration = TextDecoration.None
|
|
||||||
),
|
|
||||||
start = startIndexForService, // "《服务协议》" 开始下标13
|
|
||||||
end = startIndexForService + serviceLength // "《服务协议》" 结束下标19
|
|
||||||
)
|
|
||||||
addStringAnnotation(
|
|
||||||
tag = "AGREEMENT",
|
|
||||||
annotation = "service_agreement",
|
|
||||||
start = startIndexForService,
|
|
||||||
end = startIndexForService + serviceLength
|
|
||||||
)
|
|
||||||
|
|
||||||
// 高亮显示 "《隐私政策》"
|
|
||||||
addStyle(
|
|
||||||
style = SpanStyle(
|
|
||||||
color = Color(0xFF0066CC),
|
|
||||||
textDecoration = TextDecoration.None
|
|
||||||
),
|
|
||||||
start = startIndexPrivacy1, // "《隐私政策》" 开始下标20
|
|
||||||
end = startIndexPrivacy1 + privacyLength // "《隐私政策》" 结束下标26
|
|
||||||
)
|
|
||||||
addStringAnnotation(
|
|
||||||
tag = "PRIVACY",
|
|
||||||
annotation = "privacy_policy",
|
|
||||||
start = startIndexPrivacy1,
|
|
||||||
end = startIndexPrivacy1 + privacyLength
|
|
||||||
)
|
|
||||||
|
|
||||||
// 高亮显示 "《隐私政策》"
|
|
||||||
addStyle(
|
|
||||||
style = SpanStyle(
|
|
||||||
color = Color(0xFF0066CC),
|
|
||||||
textDecoration = TextDecoration.None
|
|
||||||
),
|
|
||||||
start = startIndexPrivacy2, // "《隐私政策》" 开始下标
|
|
||||||
end = startIndexPrivacy2 + privacyLength // "《隐私政策》" 结束下标
|
|
||||||
)
|
|
||||||
addStringAnnotation(
|
|
||||||
tag = "PRIVACY",
|
|
||||||
annotation = "privacy_policy",
|
|
||||||
start = startIndexPrivacy2,
|
|
||||||
end = startIndexPrivacy2 + privacyLength
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
ClickableText(
|
|
||||||
text = annotatedText,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.wrapContentHeight()
|
|
||||||
.align(Alignment.CenterHorizontally)
|
|
||||||
.padding(horizontal = 12.dp),
|
|
||||||
style = TextStyle(
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = Color(0xFF1A1A1A)
|
|
||||||
),
|
),
|
||||||
onClick = { offset ->
|
start = startIndexForService, // "《服务协议》" 开始下标13
|
||||||
val agreementAnnotation = annotatedText.getStringAnnotations("AGREEMENT", offset, offset).firstOrNull()
|
end = startIndexForService + serviceLength // "《服务协议》" 结束下标19
|
||||||
val privacyAnnotation = annotatedText.getStringAnnotations("PRIVACY", offset, offset).firstOrNull()
|
)
|
||||||
|
addStringAnnotation(
|
||||||
when {
|
tag = "AGREEMENT",
|
||||||
agreementAnnotation != null -> {
|
annotation = "service_agreement",
|
||||||
openAgreement(context, "服务协议", agreementUrl, false)
|
start = startIndexForService,
|
||||||
}
|
end = startIndexForService + serviceLength
|
||||||
privacyAnnotation != null -> {
|
|
||||||
openAgreement(context, "隐私政策", privacyUrl, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 高亮显示 "《隐私政策》"
|
||||||
|
addStyle(
|
||||||
|
style = SpanStyle(
|
||||||
|
color = Color(0xFF0066CC),
|
||||||
|
textDecoration = TextDecoration.None
|
||||||
|
),
|
||||||
|
start = startIndexPrivacy1, // "《隐私政策》" 开始下标20
|
||||||
|
end = startIndexPrivacy1 + privacyLength // "《隐私政策》" 结束下标26
|
||||||
|
)
|
||||||
|
addStringAnnotation(
|
||||||
|
tag = "PRIVACY",
|
||||||
|
annotation = "privacy_policy",
|
||||||
|
start = startIndexPrivacy1,
|
||||||
|
end = startIndexPrivacy1 + privacyLength
|
||||||
|
)
|
||||||
|
|
||||||
|
// 高亮显示 "《隐私政策》"
|
||||||
|
addStyle(
|
||||||
|
style = SpanStyle(
|
||||||
|
color = Color(0xFF0066CC),
|
||||||
|
textDecoration = TextDecoration.None
|
||||||
|
),
|
||||||
|
start = startIndexPrivacy2, // "《隐私政策》" 开始下标
|
||||||
|
end = startIndexPrivacy2 + privacyLength // "《隐私政策》" 结束下标
|
||||||
|
)
|
||||||
|
addStringAnnotation(
|
||||||
|
tag = "PRIVACY",
|
||||||
|
annotation = "privacy_policy",
|
||||||
|
start = startIndexPrivacy2,
|
||||||
|
end = startIndexPrivacy2 + privacyLength
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
@Suppress("DEPRECATION")
|
||||||
|
ClickableText(
|
||||||
|
text = annotatedText,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.wrapContentHeight()
|
.wrapContentHeight()
|
||||||
.align(Alignment.BottomCenter)
|
.align(Alignment.CenterHorizontally),
|
||||||
|
style = TextStyle(
|
||||||
|
fontWeight = FontWeight.Normal,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
lineHeight = 20.sp,
|
||||||
|
color = Color(0xFF1A1A1A)
|
||||||
|
),
|
||||||
|
onClick = { offset ->
|
||||||
|
val agreementAnnotation = annotatedText.getStringAnnotations("AGREEMENT", offset, offset).firstOrNull()
|
||||||
|
val privacyAnnotation = annotatedText.getStringAnnotations("PRIVACY", offset, offset).firstOrNull()
|
||||||
|
|
||||||
|
when {
|
||||||
|
agreementAnnotation != null -> {
|
||||||
|
openAgreement(context, "服务协议", agreementUrl, false)
|
||||||
|
}
|
||||||
|
privacyAnnotation != null -> {
|
||||||
|
openAgreement(context, "隐私政策", privacyUrl, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
Box(Modifier.height(24.dp))
|
||||||
|
//同意按钮,用户协议与隐私政策
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.wrapContentHeight()
|
||||||
|
.background(
|
||||||
|
Color(0xFF252525),
|
||||||
|
shape = RoundedCornerShape(359.dp),
|
||||||
|
)
|
||||||
|
.clickable(
|
||||||
|
indication = null,
|
||||||
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
|
) {
|
||||||
|
onAgreementChange(true)
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
//同意按钮,用户协议与隐私政策
|
Text(
|
||||||
Box(
|
"同意",
|
||||||
|
color = Color(0xFFC2FF43),
|
||||||
|
fontSize = 16.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.wrapContentWidth()
|
||||||
.wrapContentHeight()
|
.wrapContentHeight()
|
||||||
.padding(start = 33.dp, end = 33.dp)
|
.padding(vertical = 12.dp)
|
||||||
.background(
|
.align(Alignment.Center)
|
||||||
Color(0xFF252525),
|
)
|
||||||
shape = RoundedCornerShape(359.dp),
|
}
|
||||||
)
|
//不同按钮,意用户协议与隐私政策
|
||||||
.clickable(
|
Box(
|
||||||
indication = null,
|
modifier = Modifier
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
.fillMaxWidth()
|
||||||
) {
|
.wrapContentHeight()
|
||||||
onAgreementChange(true)
|
.background(
|
||||||
}
|
Color(0x00000000),
|
||||||
) {
|
shape = RoundedCornerShape(359.dp),
|
||||||
Text(
|
|
||||||
"同意",
|
|
||||||
color = Color(0xFFC2FF43),
|
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
modifier = Modifier
|
|
||||||
.wrapContentWidth()
|
|
||||||
.wrapContentHeight()
|
|
||||||
.padding(vertical = 12.dp)
|
|
||||||
.align(Alignment.Center)
|
|
||||||
)
|
)
|
||||||
}
|
.clickable(
|
||||||
//不同按钮,意用户协议与隐私政策
|
indication = null,
|
||||||
Box(
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
|
) {
|
||||||
|
onAgreementChange(false)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"不同意",
|
||||||
|
color = Color(0xFFAAAAAA),
|
||||||
|
fontSize = 14.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.wrapContentWidth()
|
||||||
.wrapContentHeight()
|
.wrapContentHeight()
|
||||||
.padding(start = 33.dp, end = 33.dp)
|
.padding(vertical = 12.dp)
|
||||||
.background(
|
.align(Alignment.Center)
|
||||||
Color(0x00000000),
|
)
|
||||||
shape = RoundedCornerShape(359.dp),
|
|
||||||
)
|
|
||||||
.clickable(
|
|
||||||
indication = null,
|
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
|
||||||
) {
|
|
||||||
onAgreementChange(false)
|
|
||||||
viewModel.setIsPolicyAgreement(false)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"不同意",
|
|
||||||
color = Color(0xFFAAAAAA),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
modifier = Modifier
|
|
||||||
.wrapContentWidth()
|
|
||||||
.wrapContentHeight()
|
|
||||||
.padding(vertical = 12.dp)
|
|
||||||
.align(Alignment.Center)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -724,6 +701,15 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Preview(name = "隐私弹窗-小屏", widthDp = 360, heightDp = 640, showBackground = true)
|
||||||
|
@Preview(name = "隐私弹窗-大字体", widthDp = 320, heightDp = 480, fontScale = 1.5f, showBackground = true)
|
||||||
|
@Composable
|
||||||
|
private fun PrivacyPolicyPreview() {
|
||||||
|
MaterialTheme {
|
||||||
|
PrivacyPolicyScreen(onAgreementChange = {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreenPreview() {
|
fun MainScreenPreview() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.img.rabbit.provider
|
||||||
|
|
||||||
|
import android.content.ContentProvider
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.ProviderInfo
|
||||||
|
import android.database.Cursor
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import com.getui.gtc.base.GtcProvider
|
||||||
|
import com.img.rabbit.provider.storage.PrivacyConsentStore
|
||||||
|
|
||||||
|
/** 保留个推的进程通信地址,但在授权前不创建 SDK Provider。 */
|
||||||
|
class ConsentGtcProvider : ContentProvider() {
|
||||||
|
private var delegate: ContentProvider? = null
|
||||||
|
private lateinit var providerInfo: ProviderInfo
|
||||||
|
|
||||||
|
override fun attachInfo(context: Context, info: ProviderInfo) {
|
||||||
|
providerInfo = info
|
||||||
|
super.attachInfo(context, info)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(): Boolean = true
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private fun initialize(): ContentProvider? {
|
||||||
|
if (!PrivacyConsentStore.isAccepted()) return null
|
||||||
|
return delegate ?: GtcProvider().also {
|
||||||
|
it.attachInfo(requireNotNull(context), providerInfo)
|
||||||
|
delegate = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun call(method: String, arg: String?, extras: Bundle?): Bundle? {
|
||||||
|
val provider = initialize() ?: return null
|
||||||
|
return if (method == INITIALIZE) Bundle() else provider.call(method, arg, extras)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun query(uri: Uri, projection: Array<out String>?, selection: String?,
|
||||||
|
selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
|
||||||
|
override fun getType(uri: Uri): String? = null
|
||||||
|
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||||
|
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||||
|
override fun update(uri: Uri, values: ContentValues?, selection: String?,
|
||||||
|
selectionArgs: Array<out String>?): Int = 0
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val INITIALIZE = "rabbit.initializeAfterConsent"
|
||||||
|
|
||||||
|
fun initializeAfterConsent(context: Context) {
|
||||||
|
if (!PrivacyConsentStore.isAccepted()) return
|
||||||
|
context.contentResolver.call(
|
||||||
|
Uri.parse("content://${context.packageName}.getui.gtc.provider"),
|
||||||
|
INITIALIZE, null, null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -22,7 +22,6 @@ object PreferenceUtil {
|
||||||
private const val KEY_USER_CONFIG = "user_config"
|
private const val KEY_USER_CONFIG = "user_config"
|
||||||
private const val KEY_WX_CODE = "wx_code"
|
private const val KEY_WX_CODE = "wx_code"
|
||||||
private const val KEY_USER_INFO = "user_info"
|
private const val KEY_USER_INFO = "user_info"
|
||||||
private const val KEY_AGREEMENT = "agreement"
|
|
||||||
private const val KEY_WGT_VERSION = "uni_wgt_version"
|
private const val KEY_WGT_VERSION = "uni_wgt_version"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -33,7 +32,7 @@ object PreferenceUtil {
|
||||||
|
|
||||||
|
|
||||||
// Gson实例
|
// Gson实例
|
||||||
private val gson: Gson = GsonBuilder().create()
|
private val gson: Gson by lazy { GsonBuilder().create() }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -69,11 +68,11 @@ object PreferenceUtil {
|
||||||
|
|
||||||
|
|
||||||
fun saveAgreement(agreement: Boolean) {
|
fun saveAgreement(agreement: Boolean) {
|
||||||
mmkv.putBoolean(KEY_AGREEMENT, agreement)
|
PrivacyConsentStore.setAccepted(agreement)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAgreement(): Boolean {
|
fun getAgreement(): Boolean {
|
||||||
return mmkv.decodeBool(KEY_AGREEMENT, false)
|
return PrivacyConsentStore.isAccepted()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveUserConfig(config: UserConfigEntity?) {
|
fun saveUserConfig(config: UserConfigEntity?) {
|
||||||
|
|
@ -209,5 +208,6 @@ object PreferenceUtil {
|
||||||
*/
|
*/
|
||||||
fun clearAll() {
|
fun clearAll() {
|
||||||
mmkv.clearAll()
|
mmkv.clearAll()
|
||||||
|
PrivacyConsentStore.setAccepted(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.img.rabbit.provider.storage
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
|
||||||
|
/** 协议判断不能依赖尚未获准初始化的 MMKV 或其他 SDK。 */
|
||||||
|
object PrivacyConsentStore {
|
||||||
|
private lateinit var preferences: SharedPreferences
|
||||||
|
|
||||||
|
fun initialize(context: Context) {
|
||||||
|
preferences = context.getSharedPreferences("privacy_consent", Context.MODE_PRIVATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAccepted(): Boolean = preferences.getBoolean("accepted", false)
|
||||||
|
|
||||||
|
fun setAccepted(accepted: Boolean) {
|
||||||
|
// 在启动小程序等独立进程前落盘,保证它们读取到明确的授权状态。
|
||||||
|
check(preferences.edit().putBoolean("accepted", accepted).commit()) {
|
||||||
|
"无法保存隐私协议状态"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,15 +3,9 @@ package com.img.rabbit.provider.utils
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import com.img.rabbit.R
|
import com.img.rabbit.R
|
||||||
import okhttp3.internal.platform.ContextAwarePlatform
|
|
||||||
import okhttp3.internal.platform.Platform
|
|
||||||
|
|
||||||
object HeadParamUtils {
|
object HeadParamUtils {
|
||||||
var applicationContext: Context?
|
var applicationContext: Context? = null
|
||||||
get() = (Platform.get() as? ContextAwarePlatform)?.applicationContext
|
|
||||||
set(value) {
|
|
||||||
(Platform.get() as? ContextAwarePlatform)?.applicationContext = value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getAppVersionName(): String? {
|
fun getAppVersionName(): String? {
|
||||||
return try {
|
return try {
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,10 @@ class BindViewModel : BaseViewModel() {
|
||||||
|
|
||||||
|
|
||||||
fun oneKeyLoginForGeTuiSdk(activity: Activity, onShowOneKeyScreen:(Boolean)->Unit) {
|
fun oneKeyLoginForGeTuiSdk(activity: Activity, onShowOneKeyScreen:(Boolean)->Unit) {
|
||||||
|
if (!PreferenceUtil.getAgreement()) {
|
||||||
|
onShowOneKeyScreen(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
// 初始化 SDK
|
// 初始化 SDK
|
||||||
GYManager.getInstance().init(GyConfig.with(activity.applicationContext).callBack(object : GyCallBack {
|
GYManager.getInstance().init(GyConfig.with(activity.applicationContext).callBack(object : GyCallBack {
|
||||||
override fun onSuccess(response: GYResponse?) {
|
override fun onSuccess(response: GYResponse?) {
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ class GeneralViewModel: BaseViewModel(){
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initWXApi(context: Context) {
|
private fun initWXApi(context: Context) {
|
||||||
|
if (!PreferenceUtil.getAgreement()) return
|
||||||
api = WXAPIFactory.createWXAPI(context, Constants.WxAppId, true)
|
api = WXAPIFactory.createWXAPI(context, Constants.WxAppId, true)
|
||||||
api.registerApp(Constants.WxAppId)
|
api.registerApp(Constants.WxAppId)
|
||||||
|
|
||||||
|
|
@ -118,6 +119,10 @@ class GeneralViewModel: BaseViewModel(){
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
connectivityManager.unregisterNetworkCallback(networkCallback)
|
connectivityManager.unregisterNetworkCallback(networkCallback)
|
||||||
|
if (::receiver.isInitialized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
HeadParamUtils.applicationContext?.unregisterReceiver(receiver)
|
||||||
|
}
|
||||||
|
if (::api.isInitialized) api.detach()
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,11 @@ import com.tencent.mm.opensdk.modelmsg.SendAuth
|
||||||
import com.umeng.socialize.weixin.view.WXCallbackActivity
|
import com.umeng.socialize.weixin.view.WXCallbackActivity
|
||||||
|
|
||||||
|
|
||||||
class WXEntryActivity : WXCallbackActivity() {
|
class WXEntryActivity : WechatConsentActivity() {
|
||||||
|
override val callbackClassName = "com.img.rabbit.wxapi.AuthorizedWXEntryActivity"
|
||||||
|
}
|
||||||
|
|
||||||
|
class AuthorizedWXEntryActivity : WXCallbackActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
try {
|
try {
|
||||||
// The SDK dispatches handleIntent/onResp synchronously.
|
// The SDK dispatches handleIntent/onResp synchronously.
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,11 @@ import com.tencent.mm.opensdk.modelbase.BaseReq
|
||||||
import com.tencent.mm.opensdk.modelbase.BaseResp
|
import com.tencent.mm.opensdk.modelbase.BaseResp
|
||||||
import io.dcloud.feature.payment.weixin.AbsWXPayCallbackActivity
|
import io.dcloud.feature.payment.weixin.AbsWXPayCallbackActivity
|
||||||
|
|
||||||
class WXPayEntryActivity : AbsWXPayCallbackActivity() {
|
class WXPayEntryActivity : WechatConsentActivity() {
|
||||||
|
override val callbackClassName = "com.img.rabbit.wxapi.AuthorizedWXPayEntryActivity"
|
||||||
|
}
|
||||||
|
|
||||||
|
class AuthorizedWXPayEntryActivity : AbsWXPayCallbackActivity() {
|
||||||
//val scope = CoroutineScope(Dispatchers.Main)
|
//val scope = CoroutineScope(Dispatchers.Main)
|
||||||
private lateinit var generalViewModel: GeneralViewModel
|
private lateinit var generalViewModel: GeneralViewModel
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.img.rabbit.wxapi
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import com.img.rabbit.provider.storage.PrivacyConsentStore
|
||||||
|
|
||||||
|
/** 外部回调先经过原生 Activity,避免 SDK 父类在未授权时执行 onCreate。 */
|
||||||
|
abstract class WechatConsentActivity : Activity() {
|
||||||
|
protected abstract val callbackClassName: String
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
dispatch(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
dispatch(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dispatch(callback: Intent) {
|
||||||
|
if (PrivacyConsentStore.isAccepted()) {
|
||||||
|
startActivity(Intent(callback).setClassName(this, callbackClassName))
|
||||||
|
}
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
See https://developer.android.com/about/versions/12/backup-restore
|
See https://developer.android.com/about/versions/12/backup-restore
|
||||||
-->
|
-->
|
||||||
<full-backup-content>
|
<full-backup-content>
|
||||||
|
<exclude domain="sharedpref" path="privacy_consent.xml" />
|
||||||
<!--
|
<!--
|
||||||
<include domain="sharedpref" path="."/>
|
<include domain="sharedpref" path="."/>
|
||||||
<exclude domain="sharedpref" path="device.xml"/>
|
<exclude domain="sharedpref" path="device.xml"/>
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,15 @@
|
||||||
-->
|
-->
|
||||||
<data-extraction-rules>
|
<data-extraction-rules>
|
||||||
<cloud-backup>
|
<cloud-backup>
|
||||||
|
<exclude domain="sharedpref" path="privacy_consent.xml" />
|
||||||
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||||
<include .../>
|
<include .../>
|
||||||
<exclude .../>
|
<exclude .../>
|
||||||
-->
|
-->
|
||||||
</cloud-backup>
|
</cloud-backup>
|
||||||
|
<device-transfer>
|
||||||
|
<exclude domain="sharedpref" path="privacy_consent.xml" />
|
||||||
|
</device-transfer>
|
||||||
<!--
|
<!--
|
||||||
<device-transfer>
|
<device-transfer>
|
||||||
<include .../>
|
<include .../>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue