feat:初步搭建google隔离架构
This commit is contained in:
1
libs/lib_core/.gitignore
vendored
Normal file
1
libs/lib_core/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
19
libs/lib_core/build.gradle
Normal file
19
libs/lib_core/build.gradle
Normal file
@@ -0,0 +1,19 @@
|
||||
apply from : "../lib_standard.gradle"
|
||||
|
||||
android {
|
||||
namespace 'com.example.lib_core'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// 工具集
|
||||
api project(path: ":libs:lib_utils")
|
||||
|
||||
api 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
api 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
api 'com.google.android.material:material:1.6.1'
|
||||
api 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
|
||||
api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||
|
||||
|
||||
api "com.alibaba:fastjson:1.2.41"
|
||||
}
|
0
libs/lib_core/consumer-rules.pro
Normal file
0
libs/lib_core/consumer-rules.pro
Normal file
21
libs/lib_core/proguard-rules.pro
vendored
Normal file
21
libs/lib_core/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
|
@@ -0,0 +1,24 @@
|
||||
package com.example.lib_core
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.example.lib_core.test", appContext.packageName)
|
||||
}
|
||||
}
|
4
libs/lib_core/src/main/AndroidManifest.xml
Normal file
4
libs/lib_core/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
@@ -0,0 +1,62 @@
|
||||
import androidx.lifecycle.*
|
||||
|
||||
/**
|
||||
* Created by Max on 2023/10/24 15:11
|
||||
* Desc:跟随目标生命周期销毁
|
||||
**/
|
||||
interface LifecycleCleared : LifecycleEventObserver {
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
fun isEnabledLifecycleClear(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监听的目标生命周期
|
||||
*/
|
||||
abstract fun getTargetLifecycle(): Lifecycle?
|
||||
|
||||
/**
|
||||
* 目标生命周期已销毁:执行清除资源操作
|
||||
*/
|
||||
abstract fun onTargetCleared()
|
||||
|
||||
/**
|
||||
* 获取要执行清理的事件
|
||||
*/
|
||||
fun getClearEvent(): Lifecycle.Event? {
|
||||
return Lifecycle.Event.ON_DESTROY
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定生命周期
|
||||
*/
|
||||
fun bindLifecycleClear() {
|
||||
if (!isEnabledLifecycleClear()) {
|
||||
return
|
||||
}
|
||||
getTargetLifecycle()?.addObserver(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消绑定生命周期(如果实现类是自己主动销毁的,需要主动调下本方法)
|
||||
*/
|
||||
fun unBindLifecycleClear() {
|
||||
if (!isEnabledLifecycleClear()) {
|
||||
return
|
||||
}
|
||||
getTargetLifecycle()?.removeObserver(this)
|
||||
}
|
||||
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||
if (!isEnabledLifecycleClear()) {
|
||||
return
|
||||
}
|
||||
if (getClearEvent() == event) {
|
||||
unBindLifecycleClear()
|
||||
onTargetCleared()
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package com.example.lib_core.component
|
||||
|
||||
import LifecycleCleared
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import com.example.lib_utils.ktx.asLifecycle
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
|
||||
|
||||
/**
|
||||
* Created by Max on 2023/10/24 15:11
|
||||
* Desc:BottomSheetDialog
|
||||
*/
|
||||
open class SuperBottomSheetDialog : BottomSheetDialog, LifecycleCleared {
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(context: Context, theme: Int) : super(context, theme) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
cancelable: Boolean,
|
||||
cancelListener: DialogInterface.OnCancelListener?
|
||||
) : super(context, cancelable, cancelListener) {
|
||||
init()
|
||||
}
|
||||
|
||||
protected open fun init() {
|
||||
|
||||
}
|
||||
|
||||
override fun getTargetLifecycle(): Lifecycle? {
|
||||
return context.asLifecycle()
|
||||
}
|
||||
|
||||
override fun onTargetCleared() {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
bindLifecycleClear()
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
super.dismiss()
|
||||
unBindLifecycleClear()
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.example.lib_core
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user