Android: Allow reading global settings without a Settings object
This makes things more convenient for code that just wants to read the current value of a setting.
This commit is contained in:
parent
0f5bf90013
commit
195b551d87
|
@ -49,4 +49,10 @@ public class AdHocBooleanSetting implements AbstractBooleanSetting
|
|||
{
|
||||
NativeConfig.setBoolean(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
|
||||
}
|
||||
|
||||
public static boolean getBooleanGlobal(String file, String section, String key,
|
||||
boolean defaultValue)
|
||||
{
|
||||
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public class AdHocStringSetting implements AbstractStringSetting
|
||||
{
|
||||
private final String mFile;
|
||||
private final String mSection;
|
||||
private final String mKey;
|
||||
private final String mDefaultValue;
|
||||
|
||||
public AdHocStringSetting(String file, String section, String key, String defaultValue)
|
||||
{
|
||||
mFile = file;
|
||||
mSection = section;
|
||||
mKey = key;
|
||||
mDefaultValue = defaultValue;
|
||||
|
||||
if (!NativeConfig.isSettingSaveable(file, section, key))
|
||||
{
|
||||
throw new IllegalArgumentException("File/section/key is unknown or legacy");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverridden(Settings settings)
|
||||
{
|
||||
return NativeConfig.isOverridden(mFile, mSection, mKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntimeEditable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(Settings settings)
|
||||
{
|
||||
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setString(Settings settings, String newValue)
|
||||
{
|
||||
NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
|
||||
}
|
||||
|
||||
public static String getStringGlobal(String file, String section, String key, String defaultValue)
|
||||
{
|
||||
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue);
|
||||
}
|
||||
}
|
|
@ -191,4 +191,9 @@ public enum BooleanSetting implements AbstractBooleanSetting
|
|||
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getBooleanGlobal()
|
||||
{
|
||||
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,4 +73,9 @@ public enum FloatSetting implements AbstractFloatSetting
|
|||
settings.getSection(mFile, mSection).setFloat(mKey, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public float getFloatGlobal()
|
||||
{
|
||||
return NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,4 +130,9 @@ public enum IntSetting implements AbstractIntSetting
|
|||
settings.getSection(mFile, mSection).setInt(mKey, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public int getIntGlobal()
|
||||
{
|
||||
return NativeConfig.getInt(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,4 +104,9 @@ public enum StringSetting implements AbstractStringSetting
|
|||
settings.getSection(mFile, mSection).setString(mKey, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public String getStringGlobal()
|
||||
{
|
||||
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,8 +152,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
|||
|
||||
LinearLayout options = requireView().findViewById(R.id.layout_options);
|
||||
|
||||
Settings settings = ((EmulationActivity) requireActivity()).getSettings();
|
||||
boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBoolean(settings);
|
||||
boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBooleanGlobal();
|
||||
int savestateVisibility = savestatesEnabled ? View.VISIBLE : View.GONE;
|
||||
options.findViewById(R.id.menu_quicksave).setVisibility(savestateVisibility);
|
||||
options.findViewById(R.id.menu_quickload).setVisibility(savestateVisibility);
|
||||
|
|
|
@ -81,12 +81,7 @@ public class GameFileCache
|
|||
*/
|
||||
public boolean scanLibrary(Context context)
|
||||
{
|
||||
boolean recursiveScan;
|
||||
try (Settings settings = new Settings())
|
||||
{
|
||||
settings.loadSettings(null);
|
||||
recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBoolean(settings);
|
||||
}
|
||||
boolean recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBooleanGlobal();
|
||||
|
||||
removeNonExistentGameFolders(context);
|
||||
|
||||
|
|
|
@ -291,11 +291,7 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
|||
}
|
||||
});
|
||||
|
||||
try (Settings settings = new Settings())
|
||||
{
|
||||
settings.loadSettings(null);
|
||||
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getInt(settings));
|
||||
}
|
||||
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getIntGlobal());
|
||||
|
||||
showGames();
|
||||
GameFileCacheService.startLoad(this);
|
||||
|
|
|
@ -24,44 +24,41 @@ public class Analytics
|
|||
{
|
||||
new AfterDirectoryInitializationRunner().run(context, false, () ->
|
||||
{
|
||||
Settings settings = new Settings();
|
||||
settings.loadSettings(null);
|
||||
if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBoolean(settings))
|
||||
if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBooleanGlobal())
|
||||
{
|
||||
showMessage(context, settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.close();
|
||||
showMessage(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void showMessage(Context context, Settings settings)
|
||||
private static void showMessage(Context context)
|
||||
{
|
||||
new AlertDialog.Builder(context, R.style.DolphinDialogBase)
|
||||
.setTitle(context.getString(R.string.analytics))
|
||||
.setMessage(context.getString(R.string.analytics_desc))
|
||||
.setPositiveButton(R.string.yes, (dialogInterface, i) ->
|
||||
{
|
||||
firstAnalyticsAdd(settings, true);
|
||||
firstAnalyticsAdd(true);
|
||||
})
|
||||
.setNegativeButton(R.string.no, (dialogInterface, i) ->
|
||||
{
|
||||
firstAnalyticsAdd(settings, false);
|
||||
firstAnalyticsAdd(false);
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private static void firstAnalyticsAdd(Settings settings, boolean enabled)
|
||||
private static void firstAnalyticsAdd(boolean enabled)
|
||||
{
|
||||
BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled);
|
||||
BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true);
|
||||
try (Settings settings = new Settings())
|
||||
{
|
||||
settings.loadSettings(null);
|
||||
|
||||
// Context is set to null to avoid toasts
|
||||
settings.saveSettings(null, null);
|
||||
BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled);
|
||||
BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true);
|
||||
|
||||
settings.close();
|
||||
// Context is set to null to avoid toasts
|
||||
settings.saveSettings(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendReport(String endpoint, byte[] data)
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.util.SparseArray;
|
|||
import android.view.InputDevice;
|
||||
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AdHocStringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
|
@ -28,9 +29,8 @@ public class Rumble
|
|||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
String deviceName = activity.getSettings()
|
||||
.getSection(Settings.FILE_DOLPHIN, Settings.SECTION_BINDINGS)
|
||||
.getString(SettingsFile.KEY_EMU_RUMBLE + i, "");
|
||||
String deviceName = AdHocStringSetting.getStringGlobal(Settings.FILE_DOLPHIN,
|
||||
Settings.SECTION_BINDINGS, SettingsFile.KEY_EMU_RUMBLE + i, "");
|
||||
|
||||
if (!deviceName.isEmpty())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue