Merge pull request #7591 from weihuoya/setting-desc

Android: show setting value as description
This commit is contained in:
JMC47 2019-01-02 15:09:20 -05:00 committed by GitHub
commit aac17bf0d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 16 deletions

View File

@ -48,6 +48,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
private ArrayList<SettingsItem> mSettings; private ArrayList<SettingsItem> mSettings;
private SettingsItem mClickedItem; private SettingsItem mClickedItem;
private int mClickedPosition;
private int mSeekbarProgress; private int mSeekbarProgress;
private AlertDialog mDialog; private AlertDialog mDialog;
@ -57,6 +58,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
{ {
mView = view; mView = view;
mContext = context; mContext = context;
mClickedPosition = -1;
} }
@Override @Override
@ -157,9 +159,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mView.onSettingChanged(); mView.onSettingChanged();
} }
public void onSingleChoiceClick(SingleChoiceSetting item) public void onSingleChoiceClick(SingleChoiceSetting item, int position)
{ {
mClickedItem = item; mClickedItem = item;
mClickedPosition = position;
int value = getSelectionForSingleChoiceValue(item); int value = getSelectionForSingleChoiceValue(item);
@ -171,9 +174,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mDialog = builder.show(); mDialog = builder.show();
} }
public void onStringSingleChoiceClick(StringSingleChoiceSetting item) public void onStringSingleChoiceClick(StringSingleChoiceSetting item, int position)
{ {
mClickedItem = item; mClickedItem = item;
mClickedPosition = position;
AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity());
@ -183,9 +187,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mDialog = builder.show(); mDialog = builder.show();
} }
public void onSliderClick(SliderSetting item) public void onSliderClick(SliderSetting item, int position)
{ {
mClickedItem = item; mClickedItem = item;
mClickedPosition = position;
mSeekbarProgress = item.getSelectedValue(); mSeekbarProgress = item.getSelectedValue();
AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity());
@ -195,7 +200,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
builder.setTitle(item.getNameId()); builder.setTitle(item.getNameId());
builder.setView(view); builder.setView(view);
builder.setPositiveButton(R.string.ok, this); builder.setPositiveButton(R.string.ok, this);
builder.setNegativeButton(R.string.cancel, this);
mDialog = builder.show(); mDialog = builder.show();
mTextSliderValue = (TextView) view.findViewById(R.id.text_value); mTextSliderValue = (TextView) view.findViewById(R.id.text_value);
@ -347,6 +351,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mView.putSetting(setting); mView.putSetting(setting);
} }
} }
closeDialog();
} }
mView.onSettingChanged(); mView.onSettingChanged();
@ -358,6 +364,11 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
{ {
if (mDialog != null) if (mDialog != null)
{ {
if (mClickedPosition != -1)
{
notifyItemChanged(mClickedPosition);
mClickedPosition = -1;
}
mDialog.dismiss(); mDialog.dismiss();
mDialog = null; mDialog = null;
} }

View File

@ -404,7 +404,7 @@ public final class SettingsFragmentPresenter
sl.add(new HeaderSetting(null, null, R.string.graphics_general, 0)); sl.add(new HeaderSetting(null, null, R.string.graphics_general, 0));
sl.add(new SingleChoiceSetting(SettingsFile.KEY_VIDEO_BACKEND_INDEX, Settings.SECTION_INI_CORE, sl.add(new SingleChoiceSetting(SettingsFile.KEY_VIDEO_BACKEND_INDEX, Settings.SECTION_INI_CORE,
R.string.video_backend, R.string.video_backend_description, R.array.videoBackendEntries, R.string.video_backend, 0, R.array.videoBackendEntries,
R.array.videoBackendValues, 0, videoBackend)); R.array.videoBackendValues, 0, videoBackend));
sl.add(new CheckBoxSetting(SettingsFile.KEY_SHOW_FPS, Settings.SECTION_GFX_SETTINGS, sl.add(new CheckBoxSetting(SettingsFile.KEY_SHOW_FPS, Settings.SECTION_GFX_SETTINGS,
R.string.show_fps, R.string.show_fps_description, false, showFps)); R.string.show_fps, R.string.show_fps_description, false, showFps));
@ -466,7 +466,7 @@ public final class SettingsFragmentPresenter
shaderListValues[0] = ""; shaderListValues[0] = "";
sl.add(new StringSingleChoiceSetting(SettingsFile.KEY_POST_SHADER, sl.add(new StringSingleChoiceSetting(SettingsFile.KEY_POST_SHADER,
Settings.SECTION_GFX_ENHANCEMENTS, R.string.post_processing_shader, Settings.SECTION_GFX_ENHANCEMENTS, R.string.post_processing_shader,
R.string.post_processing_shader_description, shaderListEntries, shaderListValues, "", 0, shaderListEntries, shaderListValues, "",
shader)); shader));
sl.add(new CheckBoxSetting(SettingsFile.KEY_SCALED_EFB, Settings.SECTION_GFX_HACKS, sl.add(new CheckBoxSetting(SettingsFile.KEY_SCALED_EFB, Settings.SECTION_GFX_HACKS,
@ -815,7 +815,7 @@ public final class SettingsFragmentPresenter
MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)); MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber));
sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION, sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION,
Settings.SECTION_WIIMOTE + (wiimoteNumber - 3), R.string.wiimote_extensions, 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, R.array.wiimoteExtensionsValues, 0, extension,
MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber))); MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)));
} }
@ -827,7 +827,7 @@ public final class SettingsFragmentPresenter
MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)); MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber));
sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION + (wiimoteNumber - 4), sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION + (wiimoteNumber - 4),
Settings.SECTION_CONTROLS, R.string.wiimote_extensions, Settings.SECTION_CONTROLS, R.string.wiimote_extensions,
R.string.wiimote_extensions_description, R.array.wiimoteExtensionsEntries, 0, R.array.wiimoteExtensionsEntries,
R.array.wiimoteExtensionsValues, 0, extension, R.array.wiimoteExtensionsValues, 0, extension,
MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber))); MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)));
} }

View File

@ -1,5 +1,6 @@
package org.dolphinemu.dolphinemu.features.settings.ui.viewholder; package org.dolphinemu.dolphinemu.features.settings.ui.viewholder;
import android.content.res.Resources;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
@ -39,18 +40,42 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
{ {
mTextSettingDescription.setText(item.getDescriptionId()); 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 @Override
public void onClick(View clicked) public void onClick(View clicked)
{ {
int position = getAdapterPosition();
if (mItem instanceof SingleChoiceSetting) if (mItem instanceof SingleChoiceSetting)
{ {
getAdapter().onSingleChoiceClick((SingleChoiceSetting) mItem); getAdapter().onSingleChoiceClick((SingleChoiceSetting) mItem, position);
} }
else if (mItem instanceof StringSingleChoiceSetting) else if (mItem instanceof StringSingleChoiceSetting)
{ {
getAdapter().onStringSingleChoiceClick((StringSingleChoiceSetting) mItem); getAdapter().onStringSingleChoiceClick((StringSingleChoiceSetting) mItem, position);
} }
} }
} }

View File

@ -38,12 +38,16 @@ public final class SliderViewHolder extends SettingViewHolder
{ {
mTextSettingDescription.setText(item.getDescriptionId()); mTextSettingDescription.setText(item.getDescriptionId());
} }
else
{
mTextSettingDescription.setText(mItem.getSelectedValue() + mItem.getUnits());
}
} }
@Override @Override
public void onClick(View clicked) public void onClick(View clicked)
{ {
getAdapter().onSliderClick(mItem); getAdapter().onSliderClick(mItem, getAdapterPosition());
} }
} }