论坛列表数据同步
This commit is contained in:
@ -7,6 +7,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.base.BaseActivity
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.syncpage.ISyncAdapterHandler
|
||||
import com.gh.common.util.MtaHelper
|
||||
import com.gh.common.util.dip2px
|
||||
import com.gh.gamecenter.R
|
||||
@ -22,7 +23,7 @@ import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.gh.gamecenter.qa.entity.Questions
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity
|
||||
|
||||
class ForumArticleAskListAdapter(context: Context, val bbsId: String, val mEntrance: String, val path: String) : ListAdapter<AnswerEntity>(context) {
|
||||
class ForumArticleAskListAdapter(context: Context, val bbsId: String, val mEntrance: String, val path: String) : ListAdapter<AnswerEntity>(context), ISyncAdapterHandler {
|
||||
|
||||
override fun areItemsTheSame(oldItem: AnswerEntity?, newItem: AnswerEntity?): Boolean {
|
||||
return oldItem?.id == newItem?.id
|
||||
@ -85,4 +86,10 @@ class ForumArticleAskListAdapter(context: Context, val bbsId: String, val mEntra
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSyncData(position: Int): Pair<String, Any>? {
|
||||
if (position >= mEntityList.size) return null
|
||||
val entity = mEntityList[position]
|
||||
return Pair(entity.id?:"", entity)
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,7 @@ import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class ForumArticleAskListFragment : ListFragment<AnswerEntity, ForumArticleAskListViewModel>() {
|
||||
|
||||
private var mAdapter: ForumArticleAskListAdapter? = null
|
||||
private lateinit var mAdapter: ForumArticleAskListAdapter
|
||||
private var mViewModel: ForumArticleAskListViewModel? = null
|
||||
private var mPath = ""
|
||||
private var bbsId: String = ""
|
||||
@ -59,8 +59,10 @@ class ForumArticleAskListFragment : ListFragment<AnswerEntity, ForumArticleAskLi
|
||||
|
||||
|
||||
override fun provideListAdapter(): ListAdapter<*> {
|
||||
if (!::mAdapter.isInitialized) {
|
||||
mAdapter = ForumArticleAskListAdapter(requireContext(), bbsId, mEntrance, mPath)
|
||||
}
|
||||
return mAdapter
|
||||
?: ForumArticleAskListAdapter(requireContext(), bbsId, mEntrance, mPath).apply { mAdapter = this }
|
||||
}
|
||||
|
||||
override fun getItemDecoration(): RecyclerView.ItemDecoration {
|
||||
@ -69,4 +71,8 @@ class ForumArticleAskListFragment : ListFragment<AnswerEntity, ForumArticleAskLi
|
||||
.margin(20f.dip2px())
|
||||
.color(ContextCompat.getColor(requireContext(), R.color.text_eeeeee)).build()
|
||||
}
|
||||
|
||||
override fun addSyncPageObserver(): Boolean = true
|
||||
|
||||
override fun provideSyncAdapter(): ForumArticleAskListAdapter = mAdapter
|
||||
}
|
||||
@ -31,7 +31,7 @@ class ForumArticleListFragment : ListFragment<ArticleEntity, ForumArticleListVie
|
||||
|
||||
private var mViewModel: ForumArticleListViewModel? = null
|
||||
private var mUserViewModel: UserViewModel? = null
|
||||
private var mAdapter: ForumArticleListAdapter? = null
|
||||
private lateinit var mAdapter: ForumArticleListAdapter
|
||||
private var mPath = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -90,8 +90,10 @@ class ForumArticleListFragment : ListFragment<ArticleEntity, ForumArticleListVie
|
||||
}
|
||||
|
||||
override fun provideListAdapter(): ListAdapter<*> {
|
||||
if (!::mAdapter.isInitialized) {
|
||||
mAdapter = ForumArticleListAdapter(requireContext(), mEntrance, mPath)
|
||||
}
|
||||
return mAdapter
|
||||
?: ForumArticleListAdapter(requireContext(), mEntrance, mPath).apply { mAdapter = this }
|
||||
}
|
||||
|
||||
fun onRefresh(filter: String) {
|
||||
@ -136,4 +138,8 @@ class ForumArticleListFragment : ListFragment<ArticleEntity, ForumArticleListVie
|
||||
override fun scrollToTop() {
|
||||
mListRv.scrollToPosition(0)
|
||||
}
|
||||
|
||||
override fun addSyncPageObserver(): Boolean = true
|
||||
|
||||
override fun provideSyncAdapter(): ForumArticleListAdapter = mAdapter
|
||||
}
|
||||
Reference in New Issue
Block a user