Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
junix committed Aug 29, 2024
1 parent fb5773e commit facdbd7
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 289 deletions.
5 changes: 1 addition & 4 deletions app/src/main/java/com/lxj/androidktxdemo/AndroidKtxApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class AndroidKtxApp: MultiDexApplication(){
override fun onCreate() {
super.onCreate()
// AndroidKtxConfig.init(this)
AndroidKTX.init(context = this,
isDebug = BuildConfig.DEBUG,
defaultLogTag = "androidktx",
sharedPrefName = "demo")
AndroidKTX.init(context = this)
ExoPlayerManager.init(preloadLength = 1024)

val user = sp().getObject<User>("user")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
android.enableJetifier=false
12 changes: 3 additions & 9 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,23 @@ dependencies {
api "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api "com.github.bumptech.glide:glide:4.13.2"
// api "com.github.bumptech.glide:okhttp3-integration:4.12.0"
// api 'com.github.bumptech.glide:annotations:4.12.0'

api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1"
api 'com.github.li-xiaojun:EasyAdapter:1.2.8'
api 'com.google.code.gson:gson:2.10.1'
// inline函数在运行时插入使用处,需要暴露出去
api "com.squareup.okhttp3:okhttp:3.14.9"
api 'com.blankj:utilcodex:1.31.1' //
api 'io.github.scwang90:refresh-layout-kernel:2.0.5' //
api 'io.github.scwang90:refresh-header-classics:2.0.5'
api 'io.github.scwang90:refresh-footer-classics:2.0.5'
// api 'io.github.scwang90:refresh-layout-kernel:2.1.0'
// api 'io.github.scwang90:refresh-header-classics:2.1.0'
// api 'io.github.scwang90:refresh-footer-classics:2.1.0'
api 'io.github.jeremyliao:live-event-bus-x:1.8.0' //事件总线

compileOnly 'com.github.li-xiaojun:XPopup:2.10.0' //弹窗
api 'com.github.bingoogolapple.BGAQRCode-Android:zxing:1.3.8'
api 'com.google.android.flexbox:flexbox:3.0.0'
api 'com.github.li-xiaojun:StateLayout:1.3.4'
api "androidx.viewpager2:viewpager2:1.0.0"
// api 'com.otaliastudios:cameraview:2.7.2'
implementation 'com.github.getActivity:Toaster:12.6'

// api 'com.github.zhpanvip:bannerviewpager:3.5.7'
// api project(':matisse')
api project(':ext')
// api project(':widget')
Expand Down
44 changes: 14 additions & 30 deletions library/src/main/java/com/lxj/androidktx/AndroidKTX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import android.content.Context
import android.graphics.Color
import android.view.Gravity
import com.blankj.utilcode.util.ToastUtils
import com.blankj.utilcode.util.Utils
import com.hjq.toast.Toaster
import com.lxj.androidktx.util.DirManager
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout

/**
* Description: 统一配置扩展方法中的变量
Expand All @@ -21,42 +17,30 @@ import com.scwang.smart.refresh.layout.SmartRefreshLayout
object AndroidKTX {

lateinit var context: Context
var isDebug = true
var defaultLogTag = "androidktx"
var sharedPrefName = "androidktx"

/**
* 初始化配置信息,必须调用
* @param isDebug 是否是debug模式,默认为true
*/
fun init(context: Application,
isDebug: Boolean = true,
defaultLogTag: String = AndroidKTX.defaultLogTag,
sharedPrefName: String = AndroidKTX.sharedPrefName
) {
fun init(context: Application) {
this.context = context
this.isDebug = isDebug
this.defaultLogTag = defaultLogTag
this.sharedPrefName = sharedPrefName
ToastUtils.getDefaultMaker().setGravity(Gravity.CENTER, 0 , 0)
ToastUtils.getDefaultMaker().setBgResource(R.drawable._ktx_toast_bg)
ToastUtils.getDefaultMaker().setTextColor(Color.WHITE)
initRefresh()
DirManager.init()
Toaster.init(context)
}

fun initRefresh() {
//设置全局的Header构建器
SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
// layout.setPrimaryColorsId(R.color.bg_color, R.color.colorPrimary)
layout.setPrimaryColors(Color.parseColor("#f0f0f0"), Color.parseColor("#111111"))
ClassicsHeader(context)
}
//设置全局的Footer构建器
SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
layout.setPrimaryColors(Color.parseColor("#f0f0f0"), Color.parseColor("#111111"))
ClassicsFooter(context)
}
}
// fun initRefresh() {
// //设置全局的Header构建器
// SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
//// layout.setPrimaryColorsId(R.color.bg_color, R.color.colorPrimary)
// layout.setPrimaryColors(Color.parseColor("#f0f0f0"), Color.parseColor("#111111"))
// ClassicsHeader(context)
// }
// //设置全局的Footer构建器
// SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
// layout.setPrimaryColors(Color.parseColor("#f0f0f0"), Color.parseColor("#111111"))
// ClassicsFooter(context)
// }
// }
}
2 changes: 1 addition & 1 deletion library/src/main/java/com/lxj/androidktx/base/ListVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract class ListVM<T>() : ViewModel(){
*/
fun insertList(t: List<T>, position: Int? = null){
val list = listData.value ?: return
if(position ==null){
if(position == null){
updateOldData()
list.addAll(t)
listData.postValueAndSuccess(list)
Expand Down
Loading

0 comments on commit facdbd7

Please sign in to comment.