-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiahoulu
committed
Apr 18, 2022
0 parents
commit 511d761
Showing
222 changed files
with
10,605 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
/release/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
kotlin("kapt") | ||
} | ||
|
||
android { | ||
compileSdk = ModuleConfig.compileSdkVersion | ||
|
||
defaultConfig { | ||
minSdk = ModuleConfig.minSdkVersion | ||
targetSdk = ModuleConfig.targetSdkVersion | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
buildFeatures { | ||
viewBinding = true | ||
dataBinding = true | ||
} | ||
|
||
buildTypes { | ||
getByName("release") { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
// Some libs (such as androidx.core:core-ktx 1.2.0 and newer) require Java 8 | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
// To avoid the compile error: "Cannot inline bytecode built with JVM target 1.8 | ||
// into bytecode that is being built with JVM target 1.6" | ||
kotlinOptions { | ||
val options = this as org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions | ||
options.jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
// Android | ||
implementation(Android.appcompat) | ||
implementation(Android.startup) | ||
implementation(Android.coreKtx) | ||
implementation(Android.constraintLayout) | ||
implementation(Android.material) | ||
|
||
// Navigation | ||
implementation(Navigation.uiKtx) | ||
implementation(Navigation.fragmentKtx) | ||
|
||
// Architecture Components | ||
implementation(Lifecycle.runtimeKtx) | ||
|
||
// ImmersionBar | ||
api(Depends.immersionBar) | ||
api(Depends.immersionBarKtx) | ||
|
||
// Retrofit | ||
implementation(Retrofit.retrofit) | ||
|
||
// Gson | ||
implementation(Depends.gson) | ||
|
||
implementation(Depends.unPeekLiveData) | ||
|
||
implementation(MaterialDialogs.core) | ||
implementation(Depends.lottie) | ||
api(Depends.shimmer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Android jetpack去混淆 | ||
-keep class com.google.android.material.** {*;} | ||
-keep class androidx.** {*;} | ||
-keep public class * extends androidx.** | ||
-keep interface androidx.** {*;} | ||
-dontwarn com.google.android.material.** | ||
-dontnote com.google.android.material.** | ||
-dontwarn androidx.** | ||
|
||
|
||
# Glide 混淆配置 | ||
-keep public class * implements com.bumptech.glide.module.GlideModule | ||
-keep class * extends com.bumptech.glide.module.AppGlideModule { | ||
<init>(...); | ||
} | ||
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { | ||
**[] $VALUES; | ||
public *; | ||
} | ||
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder { | ||
*** rewind(); | ||
} | ||
|
||
# for DexGuard only | ||
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.kts. | ||
# | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.holo.architecture"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
|
||
<application> | ||
<provider | ||
android:name="androidx.startup.InitializationProvider" | ||
android:authorities="${applicationId}.androidx-startup" | ||
android:exported="false" | ||
tools:node="merge"> | ||
<meta-data | ||
android:name="com.holo.architecture.initializer.BaseInitializer" | ||
android:value="androidx.startup" /> | ||
</provider> | ||
</application> | ||
</manifest> |
Large diffs are not rendered by default.
Oops, something went wrong.
182 changes: 182 additions & 0 deletions
182
BaseMvvm/src/main/java/com/holo/architecture/base/activity/BaseActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package com.holo.architecture.base.activity | ||
|
||
import android.graphics.Color | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import androidx.viewbinding.ViewBinding | ||
import com.afollestad.materialdialogs.MaterialDialog | ||
import com.afollestad.materialdialogs.customview.customView | ||
import com.gyf.immersionbar.ktx.immersionBar | ||
import com.gyf.immersionbar.ktx.navigationBarHeight | ||
import com.holo.architecture.R | ||
import com.holo.architecture.ext.showErrToast | ||
import com.holo.architecture.logger.KLog | ||
import com.holo.architecture.network.ListState | ||
import com.holo.architecture.network.NetworkStateManager | ||
import com.holo.architecture.network.State | ||
import com.holo.architecture.utils.ViewBindingUtil | ||
import com.holo.architecture.utils.netstatus.NetType | ||
import com.holo.architecture.widget.TransBehavior | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* @Desc Activity基类 | ||
* @Author holo | ||
* @Date 2022/1/7 | ||
*/ | ||
abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() { | ||
|
||
protected lateinit var binding: VB | ||
private var loadingDialog: MaterialDialog? = null | ||
private var dialogJob: Job? = null | ||
|
||
/** | ||
* 供子类初始化view | ||
* @param savedInstanceState Bundle? | ||
*/ | ||
abstract fun initView(savedInstanceState: Bundle?) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ViewBindingUtil.inflateWithGeneric(this, layoutInflater) | ||
setContentView(binding.root) | ||
immersionBar { | ||
transparentBar() | ||
titleBar(R.id.title_bar) | ||
statusBarDarkFont(true) | ||
navigationBarColor(R.color.transparent) | ||
navigationBarDarkIcon(true) | ||
fullScreen(true) | ||
} | ||
if (bottomPaddingView() != null) { | ||
bottomPaddingView()!!.setPadding(0, 0, 0, navigationBarHeight) | ||
} else { | ||
binding.root.setPadding(0, 0, 0, navigationBarHeight) | ||
} | ||
|
||
initView(savedInstanceState) | ||
observeViewModel() | ||
NetworkStateManager.mNetworkStateCallback.observe(this) { netType -> | ||
onNetworkStateChanged(netType) | ||
} | ||
initData() | ||
} | ||
|
||
open fun initData() {} | ||
|
||
/** | ||
* 虚拟导航栏是否需要自动padding | ||
* @return Boolean | ||
*/ | ||
open fun bottomPaddingView(): View? = null | ||
|
||
/** | ||
* 网络变化监听 子类重写 | ||
*/ | ||
open fun onNetworkStateChanged(netType: @NetType String) {} | ||
|
||
/** | ||
* 创建LiveData数据观察者 | ||
*/ | ||
abstract fun observeViewModel() | ||
|
||
protected fun <T> observer(flow: Flow<State<T>>, showLoading: Boolean = true, success: (t: T) -> Unit, error: ((code: Int) -> Unit)? = null) { | ||
lifecycleScope.launch { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
flow.collect { state -> | ||
when (state) { | ||
is State.Loading -> if (showLoading) showLoading() | ||
is State.Success -> { | ||
hideLoading() | ||
success.invoke(state.data) | ||
} | ||
is State.Error -> { | ||
hideLoading() | ||
showErrToast(state.err) | ||
error?.invoke(state.err.errCode) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected fun <T> observer(flow: Flow<State<T>>, loading: () -> Unit, success: (t: T) -> Unit, error: (() -> Unit)? = null) { | ||
lifecycleScope.launch { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
flow.collect { state -> | ||
when (state) { | ||
is State.Loading -> loading.invoke() | ||
is State.Success -> { | ||
hideLoading() | ||
success.invoke(state.data) | ||
} | ||
is State.Error -> { | ||
hideLoading() | ||
showErrToast(state.err) | ||
error?.invoke() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected fun <T> observer(flow: Flow<State<T>>, action: (t: T?) -> Unit) { | ||
lifecycleScope.launch { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
flow.collect { state -> | ||
when (state) { | ||
is State.Success -> action.invoke(state.data) | ||
is State.Error -> action.invoke(null) | ||
is State.Loading -> {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected fun <T> observerList(flow: Flow<ListState<T>>, action: (st: ListState<T>) -> Unit) { | ||
lifecycleScope.launchWhenCreated { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
flow.collect { state -> | ||
action.invoke(state) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun showLoading() { | ||
if (loadingDialog == null) { | ||
loadingDialog = MaterialDialog(this, TransBehavior) | ||
.customView(R.layout.dialog_loading) | ||
.cancelOnTouchOutside(false) | ||
.cancelable(false) | ||
} | ||
if (loadingDialog?.isShowing != true) { | ||
dialogJob?.cancel() | ||
dialogJob = lifecycleScope.launch { | ||
delay(1000) | ||
loadingDialog?.show() | ||
delay(5000) | ||
KLog.d("Holo", "5s超时隐藏") | ||
hideLoading() | ||
} | ||
} | ||
} | ||
|
||
fun hideLoading() { | ||
dialogJob?.cancel() | ||
dialogJob = null | ||
if (isDestroyed || isFinishing) return | ||
loadingDialog?.dismiss() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
BaseMvvm/src/main/java/com/holo/architecture/base/bean/BaseBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.holo.architecture.base.bean | ||
|
||
import com.google.gson.Gson | ||
|
||
/** | ||
* | ||
* | ||
* @Author holo | ||
* @Date 2022/1/15 | ||
*/ | ||
open class BaseBean { | ||
|
||
/** | ||
* 重写toString方法,对象直接打印json串 | ||
* @return String | ||
*/ | ||
override fun toString(): String { | ||
return Gson().toJson(this) | ||
} | ||
} |
Oops, something went wrong.