Skip to content

Commit

Permalink
重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjianxiandev committed Jun 8, 2020
1 parent 21c54d7 commit 963b4da
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ abstract class ArticleListFragment<VM : ArticleViewModel<*>> : BaseLifeCycleFrag

article?.let {
mViewModel.addFootPrint(article)
CommonUtil.startWebView(activity!!, it.link, it.title)
CommonUtil.startWebView(requireActivity()!!, it.link, it.title)
}
}
mAdapter.setOnItemChildClickListener { _, _, position ->
UserInfo.instance.collect(activity!!, position, this)
UserInfo.instance.collect(requireActivity()!!, position, this)
}
mAdapter.setEnableLoadMore(true)
mAdapter.setOnLoadMoreListener({ onLoadMoreData() }, mRvArticle)
Expand All @@ -63,7 +63,7 @@ abstract class ArticleListFragment<VM : ArticleViewModel<*>> : BaseLifeCycleFrag

private fun initRefresh() {
// 设置下拉刷新的loading颜色
mSrlRefresh.setProgressBackgroundColorSchemeColor(ColorUtil.getColor(activity!!))
mSrlRefresh.setProgressBackgroundColorSchemeColor(ColorUtil.getColor(requireActivity()!!))
mSrlRefresh.setColorSchemeColors(Color.WHITE)
mSrlRefresh.setOnRefreshListener { onRefreshData() }
}
Expand Down Expand Up @@ -140,7 +140,7 @@ abstract class ArticleListFragment<VM : ArticleViewModel<*>> : BaseLifeCycleFrag

@Subscribe
fun settingEvent(event: ChangeThemeEvent) {
mSrlRefresh.setProgressBackgroundColorSchemeColor(ColorUtil.getColor(activity!!))
mSrlRefresh.setProgressBackgroundColorSchemeColor(ColorUtil.getColor(requireActivity()!!))
mAdapter.notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class HomeRepository(loadState: MutableLiveData<State>) : ArticleRepository(load
// 使用协程 + Retrofit2.6
suspend fun loadBannerCo(): List<BannerResponse> {
return apiService.loadBannerCo().dataConvert(loadState)

}

suspend fun loadTopArticleCo(): List<Article> {
Expand Down
3 changes: 1 addition & 2 deletions mvvm/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'
Expand All @@ -10,7 +10,6 @@ android {
buildToolsVersion "29.0.2"

defaultConfig {
applicationId "com.wjx.android.myapplication"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
Expand Down
11 changes: 2 additions & 9 deletions mvvm/src/main/java/com/wjx/android/mvvm/BaseApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package com.wjx.android.mvvm

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import com.kingja.loadsir.core.LoadSir
import com.wjx.android.wanandroidmvvm.common.utils.Constant
import com.wjx.android.wanandroidmvvm.common.utils.SPreference
import com.wjx.android.mvvm.common.utils.Constant
import com.wjx.android.mvvm.common.utils.SPreference

/**
* Created with Android Studio.
Expand All @@ -20,11 +19,5 @@ open class BaseApplication : Application() {
super.onCreate()
instance = this
SPreference.setContext(applicationContext)
initMode()
}

private fun initMode() {
var isNightMode: Boolean by SPreference(Constant.NIGHT_MODE, false)
AppCompatDelegate.setDefaultNightMode(if (isNightMode) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO)
}
}
16 changes: 0 additions & 16 deletions mvvm/src/main/java/com/wjx/android/mvvm/view/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,4 @@ abstract class BaseActivity<VM : BaseViewModel<*>, DB : ViewDataBinding> : AppCo
super.onDestroy()
AppManager.instance.removeActivity(this)
}

private fun initStatusColor(color: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.statusBarColor = ContextCompat.getColor(this,
R.color.always_white_text
)
}
if (ColorUtils.calculateLuminance(getColor(R.color.always_white_text)) >= 0.5) {
// 设置状态栏中字体的颜色为黑色
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
// 跟随系统
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
}
}

}
27 changes: 1 addition & 26 deletions mvvm/src/main/java/com/wjx/android/mvvm/view/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.kingja.loadsir.core.LoadService
import com.wjx.android.mvvm.R
import com.wjx.android.mvvm.common.utils.CommonUtil
import com.wjx.android.mvvm.viewmodel.BaseViewModel
import com.wjx.android.wanandroidmvvm.common.utils.CommonUtil

/**
* Created with Android Studio.
Expand All @@ -27,8 +23,6 @@ abstract class BaseFragment<VM : BaseViewModel<*>, DB : ViewDataBinding> : Fragm

protected lateinit var mDataBinding: DB

protected lateinit var loadService: LoadService<*>

open fun initView() {}

open fun initData() {}
Expand All @@ -51,24 +45,5 @@ abstract class BaseFragment<VM : BaseViewModel<*>, DB : ViewDataBinding> : Fragm
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
initView()
initData()
initStatusBarColor()
}

private fun initStatusBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
requireActivity().window.statusBarColor = ContextCompat.getColor(
requireActivity(),
R.color.always_white_text
)
}
if (ColorUtils.calculateLuminance(requireContext().getColor(R.color.always_white_text)) >= 0.5) {
// 设置状态栏中字体的颜色为黑色
requireActivity().window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
// 跟随系统
requireActivity().window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
}
}
}

0 comments on commit 963b4da

Please sign in to comment.