ブックマークボタンの表示をデフォルトONにする。デフォルト値の変化に追従しやすくするため、設定画面を開いた時や保存する時にスイッチの値がデフォルトと同じなら設定を削除する。

This commit is contained in:
tateisu 2020-01-28 11:44:08 +09:00
parent 20d7f8dbfe
commit 3844f7247b
2 changed files with 19 additions and 6 deletions

View File

@ -704,9 +704,13 @@ class ActAppSettingChild : AppCompatActivity()
private fun loadUIFromData() {
load_busy = true
for(si in booleanViewList) {
si.view.isChecked = si.info(pref)
}
pref.edit().also{ e->
for(si in booleanViewList) {
val curVal = si.info(pref)
si.view.isChecked = curVal
if( curVal == si.info.defVal) si.info.remove(e)
}
}.apply()
spBackButtonAction?.setSelection(Pref.ipBackButtonAction(pref))
spRepliesCount?.setSelection(Pref.ipRepliesCount(pref))
@ -834,7 +838,7 @@ class ActAppSettingChild : AppCompatActivity()
val e = pref.edit()
for(si in booleanViewList) {
e.putBoolean(si.info.key, si.view.isChecked)
si.info.putOrRemove(e,si.view.isChecked)
}
spDefaultAccount?.let {

View File

@ -40,7 +40,7 @@ fun SharedPreferences.Editor.remove(item : BasePref<*>) : SharedPreferences.Edit
class BooleanPref(
key : String,
private val defVal : Boolean,
val defVal : Boolean,
val id : Int =0
) : BasePref<Boolean>(key) {
@ -51,6 +51,15 @@ class BooleanPref(
override fun put(editor : SharedPreferences.Editor, v : Boolean) {
editor.putBoolean(key, v)
}
// put if value is not default, remove if value is same to default
fun putOrRemove(editor : SharedPreferences.Editor, v : Boolean) {
if( v != defVal) {
editor.putBoolean(key, v)
}else{
editor.remove(key)
}
}
}
class IntPref(key : String, val defVal : Int) : BasePref<Int>(key) {
@ -460,7 +469,7 @@ object Pref {
val bpShowBookmarkButton = BooleanPref(
"ShowBookmarkButton",
false,
true,
R.id.swShowBookmarkButton
)