refactor: 重构
This commit is contained in:
1
lib_common/.gitignore
vendored
Normal file
1
lib_common/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
||||
1
lib_common/build.gradle.kts
Normal file
1
lib_common/build.gradle.kts
Normal file
@ -0,0 +1 @@
|
||||
apply("../buildGradleScript/lib_common.gradle")
|
||||
0
lib_common/consumer-rules.pro
Normal file
0
lib_common/consumer-rules.pro
Normal file
21
lib_common/proguard-rules.pro
vendored
Normal file
21
lib_common/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
34
lib_common/src/main/AndroidManifest.xml
Normal file
34
lib_common/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.quyunshuo.androidbaseframemvvm.common">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
|
||||
<application android:name="com.quyunshuo.androidbaseframemvvm.base.app.BaseApplication">
|
||||
|
||||
<!-- 屏幕适配基准DP -->
|
||||
<meta-data
|
||||
android:name="design_width_in_dp"
|
||||
android:value="360" />
|
||||
|
||||
<meta-data
|
||||
android:name="design_height_in_dp"
|
||||
android:value="640" />
|
||||
|
||||
<!-- 腾讯TBS X5内核初始化 dex2oat优化方案 -->
|
||||
<service
|
||||
android:name="com.tencent.smtt.export.external.DexClassLoaderProviderService"
|
||||
android:label="dexopt"
|
||||
android:process=":dexopt" />
|
||||
|
||||
<!-- Android P 限制 -->
|
||||
<uses-library
|
||||
android:name="org.apache.http.legacy"
|
||||
android:required="false" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -0,0 +1,141 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.google.auto.service.AutoService
|
||||
import com.quyunshuo.androidbaseframemvvm.base.app.ApplicationLifecycle
|
||||
import com.quyunshuo.androidbaseframemvvm.base.app.BaseApplication
|
||||
import com.quyunshuo.androidbaseframemvvm.base.app.InitDepend
|
||||
import com.quyunshuo.androidbaseframemvvm.base.constant.VersionStatus
|
||||
import com.quyunshuo.androidbaseframemvvm.base.utils.ProcessUtils
|
||||
import com.quyunshuo.androidbaseframemvvm.base.utils.SpUtils
|
||||
import com.tencent.bugly.crashreport.CrashReport
|
||||
import com.tencent.smtt.export.external.TbsCoreSettings
|
||||
import com.tencent.smtt.sdk.QbSdk
|
||||
import com.tencent.smtt.sdk.QbSdk.PreInitCallback
|
||||
|
||||
/**
|
||||
* 项目相关的Application
|
||||
*
|
||||
* @author Qu Yunshuo
|
||||
* @since 4/16/21 3:37 PM
|
||||
*/
|
||||
@AutoService(ApplicationLifecycle::class)
|
||||
class CommonApplication : ApplicationLifecycle {
|
||||
|
||||
/**
|
||||
* 项目当前的版本状态
|
||||
*/
|
||||
val versionStatus: String by lazy { BaseApplication.context.getString(R.string.VERSION_STATUS) }
|
||||
|
||||
companion object {
|
||||
// 全局CommonApplication
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
lateinit var mCommonApplication: CommonApplication
|
||||
}
|
||||
|
||||
/**
|
||||
* 同[Application.attachBaseContext]
|
||||
* @param context Context
|
||||
*/
|
||||
override fun onAttachBaseContext(context: Context) {
|
||||
mCommonApplication = this
|
||||
}
|
||||
|
||||
/**
|
||||
* 同[Application.onCreate]
|
||||
* @param application Application
|
||||
*/
|
||||
override fun onCreate(application: Application) {}
|
||||
|
||||
/**
|
||||
* 同[Application.onTerminate]
|
||||
* @param application Application
|
||||
*/
|
||||
override fun onTerminate(application: Application) {}
|
||||
|
||||
override fun initByFrontDesk(): InitDepend {
|
||||
val worker = mutableListOf<() -> String>()
|
||||
val main = mutableListOf<() -> String>()
|
||||
// 以下只需要在主进程当中初始化 按需要调整
|
||||
if (ProcessUtils.isMainProcess(BaseApplication.context)) {
|
||||
worker.add { initMMKV() }
|
||||
worker.add { initARouter() }
|
||||
}
|
||||
worker.add { initTencentBugly() }
|
||||
return InitDepend(main, worker)
|
||||
}
|
||||
|
||||
/**
|
||||
* 不需要立即初始化的放在这里进行后台初始化
|
||||
*/
|
||||
override fun initByBackstage() {
|
||||
initX5WebViewCore()
|
||||
}
|
||||
|
||||
/**
|
||||
* 腾讯TBS WebView X5 内核初始化
|
||||
*/
|
||||
private fun initX5WebViewCore() {
|
||||
// dex2oat优化方案
|
||||
val map = HashMap<String, Any>()
|
||||
map[TbsCoreSettings.TBS_SETTINGS_USE_SPEEDY_CLASSLOADER] = true
|
||||
map[TbsCoreSettings.TBS_SETTINGS_USE_DEXLOADER_SERVICE] = true
|
||||
QbSdk.initTbsSettings(map)
|
||||
|
||||
// 允许使用非wifi网络进行下载
|
||||
QbSdk.setDownloadWithoutWifi(true)
|
||||
|
||||
// 初始化
|
||||
QbSdk.initX5Environment(BaseApplication.context, object : PreInitCallback {
|
||||
|
||||
override fun onCoreInitFinished() {
|
||||
Log.d("ApplicationInit", " TBS X5 init finished")
|
||||
}
|
||||
|
||||
override fun onViewInitFinished(p0: Boolean) {
|
||||
// 初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核
|
||||
Log.d("ApplicationInit", " TBS X5 init is $p0")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 腾讯 MMKV 初始化
|
||||
*/
|
||||
private fun initMMKV(): String {
|
||||
val result = SpUtils.initMMKV(BaseApplication.context)
|
||||
return "MMKV -->> $result"
|
||||
}
|
||||
|
||||
/**
|
||||
* 阿里路由 ARouter 初始化
|
||||
*/
|
||||
private fun initARouter(): String {
|
||||
// 测试环境下打开ARouter的日志和调试模式 正式环境需要关闭
|
||||
if (versionStatus == VersionStatus.ALPHA || versionStatus == VersionStatus.BETA) {
|
||||
ARouter.openLog() // 打印日志
|
||||
ARouter.openDebug() // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
|
||||
}
|
||||
ARouter.init(BaseApplication.application)
|
||||
return "ARouter -->> init complete"
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 腾讯Bugly
|
||||
* 测试环境应该与正式环境的日志收集渠道分隔开
|
||||
* 目前有两个渠道 测试版本/正式版本
|
||||
*/
|
||||
private fun initTencentBugly(): String {
|
||||
// 第三个参数为SDK调试模式开关
|
||||
CrashReport.initCrashReport(
|
||||
BaseApplication.context,
|
||||
BaseApplication.context.getString(R.string.BUGLY_APP_ID),
|
||||
versionStatus == VersionStatus.ALPHA || versionStatus == VersionStatus.BETA
|
||||
)
|
||||
return "Bugly -->> init complete"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.constant
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/8/28
|
||||
* @Class: RouteKey
|
||||
* @Remark: 路由使用中 用到的Key 统一写在此类中
|
||||
*/
|
||||
object RouteKey
|
||||
@ -0,0 +1,9 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.constant
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/8/28
|
||||
* @Class: RoutePath
|
||||
* @Remark: 路由地址
|
||||
*/
|
||||
object RouteUrl
|
||||
@ -0,0 +1,9 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.constant
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/8/29
|
||||
* @Class: SpKey
|
||||
* @Remark: 本地存储的键 放在此类中
|
||||
*/
|
||||
object SpKey
|
||||
@ -0,0 +1,13 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.ui
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.quyunshuo.androidbaseframemvvm.base.mvvm.v.BaseFrameActivity
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/8/27
|
||||
* @Class: BaseActivity
|
||||
* @Remark: 项目相关的Activity基类
|
||||
*/
|
||||
abstract class BaseActivity<VB : ViewBinding, VM : ViewModel> : BaseFrameActivity<VB, VM>()
|
||||
@ -0,0 +1,13 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.ui
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.quyunshuo.androidbaseframemvvm.base.mvvm.v.BaseFrameFragment
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/8/27
|
||||
* @Class: BaseFragment
|
||||
* @Remark: 项目相关的Fragment基类
|
||||
*/
|
||||
abstract class BaseFragment<VB : ViewBinding, VM : ViewModel> : BaseFrameFragment<VB, VM>()
|
||||
@ -0,0 +1,12 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.ui
|
||||
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.quyunshuo.androidbaseframemvvm.base.mvvm.v.BaseFrameNotMVVMActivity
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/9/10
|
||||
* @Class: BaseNotMVVMActivity
|
||||
* @Remark: 不是 MVVM 模式的基类
|
||||
*/
|
||||
abstract class BaseNotMVVMActivity<VB : ViewBinding> : BaseFrameNotMVVMActivity<VB>()
|
||||
@ -0,0 +1,12 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.ui
|
||||
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.quyunshuo.androidbaseframemvvm.base.mvvm.v.BaseFrameNotMVVMFragment
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/9/10
|
||||
* @Class: BaseNotMVVMFragment
|
||||
* @Remark: 不是 MVVM 模式的基类
|
||||
*/
|
||||
abstract class BaseNotMVVMFragment<VB : ViewBinding> : BaseFrameNotMVVMFragment<VB>()
|
||||
Reference in New Issue
Block a user