Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
beiger committed Dec 16, 2018
1 parent ee773d2 commit 89d5407
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/bing/mvvmbase/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
}

override fun bindAndObserve() {

mBinding.isInitialized()
}

override fun onClick(v: View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract class BaseRecycleViewActivity<DB : ViewDataBinding, VM : BaseViewModel,
protected abstract fun initAdapter()

open fun bindAndObserve() {
data.observe(this, Observer { data -> mAdapter.data = data })
data.observe(this, Observer { data -> mAdapter.mData = data })
networkState.observe(this, Observer { status ->
if (status == null) {
return@Observer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView

abstract class BaseRecycleViewAdapter<T : IsSame, VH: BaseViewHolder<*>> : RecyclerView.Adapter<VH>() {
protected var mData: List<T>? = ArrayList()
protected var mListener: OnClickListener? = null
open var mData: List<T>? = ArrayList()
open var mListener: OnClickListener? = null

var data: List<T>?
get() = mData
set(data) {
fun setData(data: List<T>?) {
if (data == null) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ abstract class BaseRecycleViewFragment<DB : ViewDataBinding, VM : BaseViewModel,
/**
* 此时还没有viewModel
*/
protected fun initView() {
open fun initView() {
initStatusLayout()
initRefreshLayout()
initRefreshHeader()
initRecycleView()
}

protected abstract fun initStatusLayout()
protected fun initRefreshLayout() {
open fun initRefreshLayout() {
mRefreshLayout = refreshLayout
mRefreshLayout.setEnableLoadMore(false)
mRefreshLayout.setEnableOverScrollDrag(true)//是否启用越界拖动
Expand All @@ -91,12 +91,12 @@ abstract class BaseRecycleViewFragment<DB : ViewDataBinding, VM : BaseViewModel,

protected abstract fun refresh(refreshLayout: RefreshLayout)

protected fun initRefreshHeader() {
open fun initRefreshHeader() {
mClassicsHeader = mRefreshLayout.refreshHeader as ClassicsHeader
mClassicsHeader.setTimeFormat(DynamicTimeFormat(getString(R.string.refresh_at) + " %s"))
}

protected fun initRecycleView() {
open fun initRecycleView() {
mRecyclerView = recyclerView
mRecyclerView.layoutManager = layoutManager
mRecyclerView.itemAnimator = itemAnimator
Expand All @@ -109,7 +109,7 @@ abstract class BaseRecycleViewFragment<DB : ViewDataBinding, VM : BaseViewModel,
protected abstract fun handleArguments()
protected abstract fun layoutId(): Int

protected fun bindAndObserve() {
open fun bindAndObserve() {
networkState.observe(this, Observer { status ->
if (status == null) {
return@Observer
Expand All @@ -129,7 +129,7 @@ abstract class BaseRecycleViewFragment<DB : ViewDataBinding, VM : BaseViewModel,
}
}
})
data.observe(this, Observer { list -> mAdapter.data = list })
data.observe(this, Observer { list -> mAdapter.mData = list })
refreshState.observe(this, Observer { status ->
if (status != Status.LOADING) {
mRefreshLayout.finishRefresh(status == Status.SUCCESS)
Expand Down

0 comments on commit 89d5407

Please sign in to comment.