diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java index 9c241eba8..61b9cb1dc 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java @@ -16,6 +16,7 @@ import com.panda3ds.pandroid.AlberDriver; import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.app.game.AlberInputListener; +import com.panda3ds.pandroid.data.config.GlobalConfig; import com.panda3ds.pandroid.input.InputHandler; import com.panda3ds.pandroid.input.InputMap; import com.panda3ds.pandroid.utils.Constants; @@ -47,7 +48,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { PandaLayoutController controllerLayout = findViewById(R.id.controller_layout); controllerLayout.initialize(); - ((CheckBox) findViewById(R.id.hide_screen_controller)).setOnCheckedChangeListener((buttonView, isChecked) -> findViewById(R.id.overlay_controller).setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE)); + ((CheckBox) findViewById(R.id.hide_screen_controller)).setOnCheckedChangeListener((buttonView, checked) -> { + findViewById(R.id.overlay_controller).setVisibility(checked ? View.VISIBLE : View.GONE); + findViewById(R.id.overlay_controller).invalidate(); + findViewById(R.id.overlay_controller).requestLayout(); + GlobalConfig.set(GlobalConfig.KEY_SCREEN_GAMEPAD_VISIBLE, checked); + }); + ((CheckBox) findViewById(R.id.hide_screen_controller)).setChecked(GlobalConfig.get(GlobalConfig.KEY_SCREEN_GAMEPAD_VISIBLE)); } @Override diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/GsonConfigParser.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/GsonConfigParser.java index 76ffdbac2..f88687f2d 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/GsonConfigParser.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/GsonConfigParser.java @@ -19,7 +19,7 @@ private String getPath(){ public void save(Object data){ synchronized (this) { new Task(() -> { - String json = gson.toJson(data); + String json = gson.toJson(data, data.getClass()); FileUtils.writeTextFile(FileUtils.getConfigPath(), name + ".json", json); }).runSync(); } diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/config/GlobalConfig.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/config/GlobalConfig.java index 038c27ced..d05d9f22b 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/config/GlobalConfig.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/data/config/GlobalConfig.java @@ -1,10 +1,12 @@ package com.panda3ds.pandroid.data.config; +import com.google.gson.internal.LinkedTreeMap; import com.panda3ds.pandroid.data.GsonConfigParser; import com.panda3ds.pandroid.utils.Constants; import java.io.Serializable; import java.util.HashMap; +import java.util.Map; public class GlobalConfig { @@ -18,6 +20,7 @@ public class GlobalConfig { public static DataModel data; public static final Key KEY_APP_THEME = new Key<>("app.theme", THEME_ANDROID); + public static final Key KEY_SCREEN_GAMEPAD_VISIBLE = new Key<>("app.screen_gamepad.visible", true); public static void initialize() { data = parser.load(DataModel.class); @@ -64,7 +67,7 @@ private Key(String name, T defaultValue) { } private static class DataModel { - private final HashMap configs = new HashMap<>(); + private final Map configs = new LinkedTreeMap<>(); public Object get(String key){ return configs.get(key); diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/GameUtils.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/GameUtils.java index 7fe111d79..cb3ebb39b 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/GameUtils.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/GameUtils.java @@ -14,6 +14,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.List; import java.util.Objects; public class GameUtils { @@ -95,6 +96,6 @@ public static Bitmap loadGameIcon(String id) { } private static class DataModel { - public final ArrayList games = new ArrayList<>(); + public final List games = new ArrayList<>(); } }