Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9043 from Ebola16/GS
Android: Prevent getSetting ClassCastExceptions in ItemViews
  • Loading branch information
lioncash committed Aug 22, 2020
2 parents a9c8f54 + d5ea4b4 commit f3431f3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 25 deletions.
Expand Up @@ -16,7 +16,7 @@ public CheckBoxSetting(String key, String section, int titleId, int descriptionI

public boolean isChecked()
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
{
return mDefaultValue;
}
Expand All @@ -34,7 +34,7 @@ public boolean isChecked()
*/
public BooleanSetting setChecked(boolean checked)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
{
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), checked);
setSetting(setting);
Expand Down
Expand Up @@ -25,14 +25,13 @@ public String getFile()

public String getSelectedValue()
{
StringSetting setting = (StringSetting) getSetting();

if (setting == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
return mDefaultValue;
}
else
{
StringSetting setting = (StringSetting) getSetting();
return setting.getValue();
}
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ public InputBindingSetting(String key, String section, int titleId, Setting sett

public String getValue()
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
return "";
}
Expand Down Expand Up @@ -78,7 +78,7 @@ public StringSetting setValue(String bind, String ui)
editor.putString(getKey() + gameId, ui);
editor.apply();

if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
StringSetting setting = new StringSetting(getKey(), getSection(), bind);
setSetting(setting);
Expand Down
Expand Up @@ -22,7 +22,7 @@ public RumbleBindingSetting(String key, String section, int titleId, Setting set
@Override
public String getValue()
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
return "";
}
Expand Down
Expand Up @@ -40,14 +40,14 @@ public int getValuesId()

public int getSelectedValue()
{
if (getSetting() != null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
return mDefaultValue;
}
else
{
return mDefaultValue;
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
}
}

Expand All @@ -65,7 +65,7 @@ public MenuTag getMenuTag()
*/
public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
setSetting(setting);
Expand Down
Expand Up @@ -59,14 +59,14 @@ public int getDescriptionValuesId()

public int getSelectedValue()
{
if (getSetting() != null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
return mDefaultValue;
}
else
{
return mDefaultValue;
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
}
}

Expand All @@ -84,7 +84,7 @@ public MenuTag getMenuTag()
*/
public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
setSetting(setting);
Expand Down
Expand Up @@ -75,7 +75,7 @@ public boolean isPercentSetting()
*/
public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
setSetting(setting);
Expand All @@ -98,7 +98,7 @@ public IntSetting setSelectedValue(int selection)
*/
public FloatSetting setSelectedValue(float selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof FloatSetting))
{
FloatSetting setting = new FloatSetting(getKey(), getSection(), selection);
setSetting(setting);
Expand Down
Expand Up @@ -71,14 +71,14 @@ public String getValueAt(int index)

public String getSelectedValue()
{
if (getSetting() != null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
StringSetting setting = (StringSetting) getSetting();
return setting.getValue();
return mDefaultValue;
}
else
{
return mDefaultValue;
StringSetting setting = (StringSetting) getSetting();
return setting.getValue();
}
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public MenuTag getMenuTag()
*/
public StringSetting setSelectedValue(String selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
StringSetting setting = new StringSetting(getKey(), getSection(), selection);
setSetting(setting);
Expand Down

0 comments on commit f3431f3

Please sign in to comment.