Skip to content

Commit

Permalink
commit 1.移除 Ktx ContentProvider ,改为手动初始化 2.提升RxHttp版本
Browse files Browse the repository at this point in the history
  • Loading branch information
hegaojian committed Jan 13, 2022
1 parent 200c937 commit db327c6
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 78 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.zhixinhuixue.zsyte.xxx"
minSdkVersion 21
targetSdkVersion 30
versionCode 15
versionName "1.1.4"
versionCode 16
versionName "1.1.5"
}

buildTypes {
Expand Down Expand Up @@ -67,8 +67,8 @@ dependencies {
//微信开源项目,替代SP
implementation 'com.tencent:mmkv-static:1.2.10'
implementation project(path: ':helper')
// implementation 'com.github.hegaojian:MvvmHelper:1.1.4'
kapt 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.7.2'
// implementation 'com.github.hegaojian:MvvmHelper:1.1.5'
kapt 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.8.3'
//这是用来测试 navigation 的 可以忽略
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/zhixinhuixue/zsyte/xxx/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import com.effective.android.anchors.AnchorsManager
import com.effective.android.anchors.Project
import com.zhixinhuixue.zsyte.xxx.BuildConfig
import me.hgj.mvvmhelper.base.MvvmHelper
import me.hgj.mvvmhelper.ext.currentProcessName

/**
Expand All @@ -14,8 +15,9 @@ import me.hgj.mvvmhelper.ext.currentProcessName
class App : Application() {
override fun onCreate() {
super.onCreate()
MvvmHelper.init(this,BuildConfig.DEBUG)
val processName = currentProcessName
if (processName == packageName) {
if (currentProcessName == packageName) {
// 主进程初始化
onMainProcessInit()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ class InitUtils : Task(TASK_ID, true) {
override fun run(name: String) {
//初始化Log打印
MMKV.initialize(appContext)
//框架全局打印日志开关
mvvmHelperLog = BuildConfig.DEBUG
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import okhttp3.OkHttpClient
import rxhttp.wrapper.cookie.CookieStore
import java.io.File
import java.util.concurrent.TimeUnit
import rxhttp.wrapper.ssl.HttpsUtils


/**
* 作者 : hegaojian
Expand All @@ -15,6 +17,7 @@ import java.util.concurrent.TimeUnit
object NetHttpClient {
fun getDefaultOkHttpClient(): OkHttpClient.Builder {
//在这里面可以写你想要的配置 太多了,我就简单的写了一点,具体可以看rxHttp的文档,有很多
val sslParams = HttpsUtils.getSslSocketFactory()
return OkHttpClient.Builder()
//使用CookieStore对象磁盘缓存,自动管理cookie 玩安卓自动登录验证
.cookieJar(CookieStore(File(appContext.externalCacheDir, "RxHttpCookie")))
Expand All @@ -23,5 +26,7 @@ object NetHttpClient {
.writeTimeout(15, TimeUnit.SECONDS)
.addInterceptor(HeadInterceptor())//自定义头部参数拦截器
.addInterceptor(LogInterceptor())//添加Log拦截器
.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) //添加信任证书
.hostnameVerifier { hostname, session -> true } //忽略host验证
}
}
6 changes: 3 additions & 3 deletions helper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 15
versionName "1.1.4"
versionCode 16
versionName "1.1.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -83,5 +83,5 @@ dependencies {
api "com.kingja.loadsir:loadsir:1.3.8"
//rxHttp
api "com.squareup.okhttp3:okhttp:4.9.1"
api 'com.github.liujingxing.rxhttp:rxhttp:2.7.2'
api 'com.github.liujingxing.rxhttp:rxhttp:2.8.3'
}
9 changes: 1 addition & 8 deletions helper/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.hgj.mvvmhelper">
<manifest package="me.hgj.mvvmhelper">

<application>
<provider
android:name=".base.Ktx"
android:authorities="${applicationId}.KtxInstaller"
android:exported="false" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ abstract class BaseVmActivity<VM : BaseViewModel> : BaseInitActivity(), BaseIVie
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_base)
javaClass.simpleName.logD()
//生成ViewModel
mViewModel = createViewModel()
//初始化 status View
Expand Down
58 changes: 0 additions & 58 deletions helper/src/main/java/me/hgj/mvvmhelper/base/Ktx.kt

This file was deleted.

33 changes: 33 additions & 0 deletions helper/src/main/java/me/hgj/mvvmhelper/base/MvvmHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.hgj.mvvmhelper.base

import android.app.Application
import me.hgj.mvvmhelper.util.KtxActivityLifecycleCallbacks
import me.hgj.mvvmhelper.util.mvvmHelperLog

/**
* 作者 : hegaojian
* 时间 : 2022/1/13
* 描述 :
*/

/**
* 全局上下文,可直接拿
*/
val appContext: Application by lazy { MvvmHelper.app }

object MvvmHelper {

lateinit var app: Application

/**
* 框架初始化
* @param application Application 全局上下文
* @param debug Boolean true为debug模式,会打印Log日志 false 关闭Log日志
*/
fun init(application: Application, debug: Boolean){
app = application
mvvmHelperLog = debug
//注册全局 activity生命周期监听
application.registerActivityLifecycleCallbacks(KtxActivityLifecycleCallbacks())
}
}
1 change: 0 additions & 1 deletion helper/src/main/java/me/hgj/mvvmhelper/util/XLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var mvvmHelperLog :Boolean = true
field = value
XLog.init(value)
LogUtils.setLog(value)

}

object XLog {
Expand Down

0 comments on commit db327c6

Please sign in to comment.