|
|
|
@ -18,6 +18,7 @@ import org.jetbrains.anko.toast |
|
|
|
|
class ReplaceRuleActivity : AppCompatActivity() { |
|
|
|
|
private lateinit var adapter: ReplaceRuleAdapter |
|
|
|
|
private var rulesLiveData: LiveData<PagedList<ReplaceRule>>? = null |
|
|
|
|
private var allEnabled = false |
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
@ -32,12 +33,23 @@ class ReplaceRuleActivity : AppCompatActivity() { |
|
|
|
|
adapter = ReplaceRuleAdapter(this) |
|
|
|
|
adapter.onClickListener = object: ReplaceRuleAdapter.OnClickListener { |
|
|
|
|
override fun update(rule: ReplaceRule) { |
|
|
|
|
doAsync { App.db.replaceRuleDao().update(rule) } |
|
|
|
|
doAsync { |
|
|
|
|
App.db.replaceRuleDao().update(rule) |
|
|
|
|
updateEnableAll() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
override fun delete(rule: ReplaceRule) { |
|
|
|
|
doAsync { App.db.replaceRuleDao().delete(rule) } |
|
|
|
|
doAsync { |
|
|
|
|
App.db.replaceRuleDao().delete(rule) |
|
|
|
|
updateEnableAll() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
override fun edit(rule: ReplaceRule) { |
|
|
|
|
doAsync { |
|
|
|
|
App.db.replaceRuleDao().enableAll(!allEnabled) |
|
|
|
|
allEnabled = !allEnabled |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
toast("Edit function not implemented!") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -50,4 +62,11 @@ class ReplaceRuleActivity : AppCompatActivity() { |
|
|
|
|
rulesLiveData?.observe(this, Observer<PagedList<ReplaceRule>> { adapter.submitList(it) }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun updateEnableAll() { |
|
|
|
|
doAsync { |
|
|
|
|
App.db.replaceRuleDao().summary.let { |
|
|
|
|
allEnabled = it == 0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |