Skip to content

Commit

Permalink
Save screen gamepad visibility and some fixes
Browse files Browse the repository at this point in the history
Fix Gson serialization error on GlobalConfig
Now screen gamepad visibility saves last visibility state
  • Loading branch information
GabrielBRDeveloper committed Dec 22, 2023
1 parent d0c4b8f commit 13136c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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);
Expand Down Expand Up @@ -64,7 +67,7 @@ private Key(String name, T defaultValue) {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -95,6 +96,6 @@ public static Bitmap loadGameIcon(String id) {
}

private static class DataModel {
public final ArrayList<GameMetadata> games = new ArrayList<>();
public final List<GameMetadata> games = new ArrayList<>();
}
}

0 comments on commit 13136c6

Please sign in to comment.