pull/52/head
kunfei 5 years ago
parent 10a0441b61
commit 2ef37fbcc5
  1. 7
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt

@ -37,13 +37,13 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
private var groups = hashSetOf<String>() private var groups = hashSetOf<String>()
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null
private var dataInit = false
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()
observeReplaceRuleData() observeReplaceRuleData()
observeGroupData() observeGroupData()
setResult(Activity.RESULT_OK)
} }
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
@ -100,15 +100,20 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
private fun observeReplaceRuleData(key: String? = null) { private fun observeReplaceRuleData(key: String? = null) {
replaceRuleLiveData?.removeObservers(this) replaceRuleLiveData?.removeObservers(this)
dataInit = false
replaceRuleLiveData = if (key.isNullOrEmpty()) { replaceRuleLiveData = if (key.isNullOrEmpty()) {
App.db.replaceRuleDao().liveDataAll() App.db.replaceRuleDao().liveDataAll()
} else { } else {
App.db.replaceRuleDao().liveDataSearch(key) App.db.replaceRuleDao().liveDataSearch(key)
} }
replaceRuleLiveData?.observe(this, Observer { replaceRuleLiveData?.observe(this, Observer {
if (dataInit) {
setResult(Activity.RESULT_OK)
}
val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it)) val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it))
adapter.setItems(it, false) adapter.setItems(it, false)
diffResult.dispatchUpdatesTo(adapter) diffResult.dispatchUpdatesTo(adapter)
dataInit = true
}) })
} }

Loading…
Cancel
Save