-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update library and Settings Activity
- Loading branch information
Showing
15 changed files
with
254 additions
and
187 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,11 @@ | ||
package hoo.etahk.view.base | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.preference.CheckBoxPreference | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.SwitchPreference | ||
import hoo.etahk.common.extensions.setSummary | ||
import hoo.etahk.common.helper.SharedPrefsHelper | ||
|
||
abstract class BasePrefFragment: PreferenceFragmentCompat() { | ||
|
||
companion object { | ||
/** | ||
* A preference value change listener that updates the preference's summary | ||
* to reflect its new value. | ||
*/ | ||
private val bindSummaryOnPreferenceChangeListener = | ||
Preference.OnPreferenceChangeListener { preference, newValue -> | ||
preference?.setSummary(newValue) | ||
true | ||
} | ||
} | ||
|
||
fun findPreference(@StringRes resId: Int): Preference { | ||
return super.findPreference(getString(resId))!! | ||
} | ||
|
||
fun bindPreferenceSummary(@StringRes resId: Int, onPreferenceChangeListener: Preference.OnPreferenceChangeListener = bindSummaryOnPreferenceChangeListener) { | ||
val preference = findPreference(resId) | ||
preference.onPreferenceChangeListener = onPreferenceChangeListener | ||
|
||
// Trigger the listener immediately with the preference's | ||
// current value. | ||
if ( preference is SwitchPreference || preference is CheckBoxPreference ) { | ||
preference.setSummary(SharedPrefsHelper.get<Boolean>(resId)) | ||
} else { | ||
preference.setSummary(SharedPrefsHelper.get<String>(resId) as Any?) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.