From 631463348b943fc9544ec4396ba1e69d576a1314 Mon Sep 17 00:00:00 2001 From: weihuoya Date: Tue, 25 Dec 2018 22:14:09 +0800 Subject: [PATCH] Android: show setting value as description --- .../features/settings/ui/SettingsAdapter.java | 19 +++++++++--- .../ui/SettingsFragmentPresenter.java | 18 ++++++------ .../ui/viewholder/SingleChoiceViewHolder.java | 29 +++++++++++++++++-- .../ui/viewholder/SliderViewHolder.java | 6 +++- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java index d9cd764fd9..f23e4bbe78 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java @@ -48,6 +48,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter mSettings; private SettingsItem mClickedItem; + private int mClickedPosition; private int mSeekbarProgress; private AlertDialog mDialog; @@ -57,6 +58,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter= 320) || @@ -815,7 +815,7 @@ public final class SettingsFragmentPresenter MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)); sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION, Settings.SECTION_WIIMOTE + (wiimoteNumber - 3), R.string.wiimote_extensions, - R.string.wiimote_extensions_description, R.array.wiimoteExtensionsEntries, + 0, R.array.wiimoteExtensionsEntries, R.array.wiimoteExtensionsValues, 0, extension, MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber))); } @@ -827,7 +827,7 @@ public final class SettingsFragmentPresenter MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)); sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION + (wiimoteNumber - 4), Settings.SECTION_CONTROLS, R.string.wiimote_extensions, - R.string.wiimote_extensions_description, R.array.wiimoteExtensionsEntries, + 0, R.array.wiimoteExtensionsEntries, R.array.wiimoteExtensionsValues, 0, extension, MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber))); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java index 568361f887..6de38a4b1f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java @@ -1,5 +1,6 @@ package org.dolphinemu.dolphinemu.features.settings.ui.viewholder; +import android.content.res.Resources; import android.view.View; import android.widget.TextView; @@ -39,18 +40,42 @@ public final class SingleChoiceViewHolder extends SettingViewHolder { mTextSettingDescription.setText(item.getDescriptionId()); } + else if (item instanceof SingleChoiceSetting) + { + SingleChoiceSetting setting = (SingleChoiceSetting) item; + int selected = setting.getSelectedValue(); + Resources resMgr = mTextSettingDescription.getContext().getResources(); + String[] choices = resMgr.getStringArray(setting.getChoicesId()); + int[] values = resMgr.getIntArray(setting.getValuesId()); + for (int i = 0; i < values.length; ++i) + { + if (values[i] == selected) + { + mTextSettingDescription.setText(choices[i]); + } + } + } + else if (item instanceof StringSingleChoiceSetting) + { + StringSingleChoiceSetting setting = (StringSingleChoiceSetting) item; + String[] choices = setting.getChoicesId(); + int valueIndex = setting.getSelectValueIndex(); + if (valueIndex != -1) + mTextSettingDescription.setText(choices[valueIndex]); + } } @Override public void onClick(View clicked) { + int position = getAdapterPosition(); if (mItem instanceof SingleChoiceSetting) { - getAdapter().onSingleChoiceClick((SingleChoiceSetting) mItem); + getAdapter().onSingleChoiceClick((SingleChoiceSetting) mItem, position); } else if (mItem instanceof StringSingleChoiceSetting) { - getAdapter().onStringSingleChoiceClick((StringSingleChoiceSetting) mItem); + getAdapter().onStringSingleChoiceClick((StringSingleChoiceSetting) mItem, position); } } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java index 17fac794fb..b40311dcea 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java @@ -38,12 +38,16 @@ public final class SliderViewHolder extends SettingViewHolder { mTextSettingDescription.setText(item.getDescriptionId()); } + else + { + mTextSettingDescription.setText(mItem.getSelectedValue() + mItem.getUnits()); + } } @Override public void onClick(View clicked) { - getAdapter().onSliderClick(mItem); + getAdapter().onSliderClick(mItem, getAdapterPosition()); } }