Add refreshRequired xml attribute in IntegerListPreference

This attribute controls whether a rom list refresh will be triggered when the setting value changes.
This commit is contained in:
sspacelynx 2021-08-28 11:52:42 +02:00 committed by ◱ Mark
parent 221039084e
commit 6135f531ae
3 changed files with 16 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import androidx.preference.R
import androidx.preference.DialogPreference
import androidx.preference.PreferenceDialogFragmentCompat
import emu.skyline.R as sR
import emu.skyline.di.getSettings
/**
* A Preference that displays a list of entries as a dialog.
@ -65,6 +66,7 @@ class IntegerListPreference @JvmOverloads constructor(
}
private var isValueSet = false
val refreshRequired : Boolean
init {
val res : Resources = context.resources
@ -91,6 +93,12 @@ class IntegerListPreference @JvmOverloads constructor(
) {
summaryProvider = SimpleSummaryProvider.instance
}
refreshRequired = TypedArrayUtils.getBoolean(
a, sR.styleable.IntegerListPreference_refreshRequired,
sR.styleable.IntegerListPreference_refreshRequired, false
)
a.recycle()
}
@ -274,7 +282,11 @@ class IntegerListPreference @JvmOverloads constructor(
builder.setSingleChoiceItems(
entries, clickedDialogEntryIndex
) { dialog, which ->
clickedDialogEntryIndex = which
if (clickedDialogEntryIndex != which) {
clickedDialogEntryIndex = which
if (listPreference.refreshRequired)
context?.getSettings()?.refreshRequired = true
}
// Clicking on an item simulates the positive button click, and dismisses
// the dialog.

View File

@ -17,5 +17,7 @@
<!-- Whether the preference should automatically set its summary to the value saved for the
preference, and update the summary when the value is changed. Defaults to false. -->
<attr format="boolean" name="useSimpleSummaryProvider"/>
<!-- Whether the preference should request a game list refresh or not. Defaults to false. -->
<attr format="boolean" name="refreshRequired"/>
</declare-styleable>
</resources>

View File

@ -77,6 +77,7 @@
android:entries="@array/system_languages"
app:key="system_language"
app:title="@string/system_language"
app:refreshRequired="true"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory