Save screen gamepad visibility and some fixes

Fix Gson serialization error on GlobalConfig
Now screen gamepad visibility saves last visibility state
This commit is contained in:
Gabriel 2023-12-22 14:41:41 -04:00
parent d0c4b8ff3b
commit 13136c6686
4 changed files with 15 additions and 4 deletions

View file

@ -16,6 +16,7 @@ import androidx.annotation.Nullable;
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 @@ public class GameActivity extends BaseActivity {
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

View file

@ -19,7 +19,7 @@ public class GsonConfigParser {
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();
}

View file

@ -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<Integer> KEY_APP_THEME = new Key<>("app.theme", THEME_ANDROID);
public static final Key<Boolean> KEY_SCREEN_GAMEPAD_VISIBLE = new Key<>("app.screen_gamepad.visible", true);
public static void initialize() {
data = parser.load(DataModel.class);
@ -64,7 +67,7 @@ public class GlobalConfig {
}
private static class DataModel {
private final HashMap<String, Object> configs = new HashMap<>();
private final Map<String, Object> configs = new LinkedTreeMap<>();
public Object get(String key){
return configs.get(key);

View file

@ -14,6 +14,7 @@ import com.panda3ds.pandroid.data.game.GameMetadata;
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 class GameUtils {
}
private static class DataModel {
public final ArrayList<GameMetadata> games = new ArrayList<>();
public final List<GameMetadata> games = new ArrayList<>();
}
}