This commit is contained in:
wheremyfoodat 2023-12-26 02:24:53 +02:00
parent f2fac171a0
commit 1c691e1690
7 changed files with 25 additions and 23 deletions

View file

@ -40,8 +40,9 @@ public class InputMapPreferences extends BasePreferenceFragment implements Activ
deadZonePreference = getPreferenceScreen().findPreference("dead_zone"); deadZonePreference = getPreferenceScreen().findPreference("dead_zone");
deadZonePreference.setOnPreferenceChangeListener((preference, value) -> { deadZonePreference.setOnPreferenceChangeListener((preference, value) -> {
InputMap.setDeadZone(((int)value/100.0f)); InputMap.setDeadZone(((int)value / 100.0f));
refreshList(); refreshList();
return false; return false;
}); });
@ -62,7 +63,7 @@ public class InputMapPreferences extends BasePreferenceFragment implements Activ
@Override @Override
public void onDetach() { public void onDetach() {
super.onDetach(); super.onDetach();
if (requestKey != null) { if (requestKey != null) {
requestKey.unregister(); requestKey.unregister();
requestKey = null; requestKey = null;

View file

@ -8,15 +8,15 @@ public class GsonConfigParser {
private final Gson gson = new Gson(); private final Gson gson = new Gson();
private final String name; private final String name;
public GsonConfigParser(String name){ public GsonConfigParser(String name) {
this.name = name; this.name = name;
} }
private String getPath(){ private String getPath() {
return FileUtils.getConfigPath()+ "/" + name + ".json"; return FileUtils.getConfigPath()+ "/" + name + ".json";
} }
public void save(Object data){ public void save(Object data) {
synchronized (this) { synchronized (this) {
new Task(() -> { new Task(() -> {
String json = gson.toJson(data, data.getClass()); String json = gson.toJson(data, data.getClass());
@ -25,13 +25,14 @@ public class GsonConfigParser {
} }
} }
public <T> T load(Class<T> clazz){ public <T> T load(Class<T> myClass) {
String[] content = new String[] {"{}"}; String[] content = new String[] {"{}"};
new Task(()->{ new Task(()->{
if (FileUtils.exists(getPath())){ if (FileUtils.exists(getPath())) {
content[0] = FileUtils.readTextFile(getPath()); content[0] = FileUtils.readTextFile(getPath());
} }
}).runSync(); }).runSync();
return gson.fromJson(content[0], clazz);
return gson.fromJson(content[0], myClass);
} }
} }

View file

@ -29,7 +29,7 @@ public class GlobalConfig {
public static <T extends Serializable> T get(Key<T> key) { public static <T extends Serializable> T get(Key<T> key) {
Serializable value; Serializable value;
if (!data.configs.containsKey(key.name)){ if (!data.configs.containsKey(key.name)) {
return key.defaultValue; return key.defaultValue;
} }
@ -52,7 +52,7 @@ public class GlobalConfig {
writeChanges(); writeChanges();
} }
private static void writeChanges(){ private static void writeChanges() {
parser.save(data); parser.save(data);
} }
@ -69,7 +69,7 @@ public class GlobalConfig {
private static class DataModel { private static class DataModel {
private final Map<String, Object> configs = new LinkedTreeMap<>(); private final Map<String, Object> configs = new LinkedTreeMap<>();
public Object get(String key){ public Object get(String key) {
return configs.get(key); return configs.get(key);
} }
} }

View file

@ -20,7 +20,7 @@ public class GameMetadata {
private final GameRegion[] regions; private final GameRegion[] regions;
private transient Bitmap icon; private transient Bitmap icon;
private GameMetadata(String id, String romPath, String title, String publisher, Bitmap icon, GameRegion[] regions){ private GameMetadata(String id, String romPath, String title, String publisher, Bitmap icon, GameRegion[] regions) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.publisher = publisher; this.publisher = publisher;
@ -35,7 +35,7 @@ public class GameMetadata {
this(UUID.randomUUID().toString(), romPath, title, publisher, null, regions); this(UUID.randomUUID().toString(), romPath, title, publisher, null, regions);
} }
public GameMetadata(String romPath,String title, String publisher){ public GameMetadata(String romPath,String title, String publisher) {
this(romPath,title, publisher, new GameRegion[]{GameRegion.None}); this(romPath,title, publisher, new GameRegion[]{GameRegion.None});
} }
@ -56,7 +56,7 @@ public class GameMetadata {
} }
public Bitmap getIcon() { public Bitmap getIcon() {
if (icon == null){ if (icon == null) {
icon = GameUtils.loadGameIcon(id); icon = GameUtils.loadGameIcon(id);
} }
return icon; return icon;
@ -68,13 +68,13 @@ public class GameMetadata {
@Override @Override
public boolean equals(@Nullable Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof GameMetadata){ if (obj instanceof GameMetadata) {
return Objects.equals(((GameMetadata) obj).id, id); return Objects.equals(((GameMetadata) obj).id, id);
} }
return false; return false;
} }
public static GameMetadata applySMDH(GameMetadata meta, SMDH smdh){ public static GameMetadata applySMDH(GameMetadata meta, SMDH smdh) {
Bitmap icon = smdh.getBitmapIcon(); Bitmap icon = smdh.getBitmapIcon();
GameMetadata newMeta = new GameMetadata(meta.getId(), meta.getRomPath(), smdh.getTitle(), smdh.getPublisher(), icon, new GameRegion[]{smdh.getRegion()}); GameMetadata newMeta = new GameMetadata(meta.getId(), meta.getRomPath(), smdh.getTitle(), smdh.getPublisher(), icon, new GameRegion[]{smdh.getRegion()});
icon.recycle(); icon.recycle();

View file

@ -1,16 +1,16 @@
package com.panda3ds.pandroid.lang; package com.panda3ds.pandroid.lang;
public class Task extends Thread { public class Task extends Thread {
public Task(Runnable runnable){ public Task(Runnable runnable) {
super(runnable); super(runnable);
} }
public void runSync(){ public void runSync() {
start(); start();
waitFinish(); waitFinish();
} }
public void waitFinish(){ public void waitFinish() {
try { try {
join(); join();
} catch (InterruptedException e) { } catch (InterruptedException e) {

View file

@ -13,7 +13,7 @@ public interface SimpleTextWatcher extends TextWatcher {
default void beforeTextChanged(CharSequence s, int start, int count, int after) {} default void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override @Override
default void afterTextChanged(Editable s){ default void afterTextChanged(Editable s) {
onChange(s.toString()); onChange(s.toString());
} }
} }

View file

@ -62,7 +62,7 @@ public class SingleSelectionPreferences extends PreferenceCategory implements Pr
} }
} }
public void setSelectedItem(int index){ public void setSelectedItem(int index) {
onPreferenceClick(getPreference(index)); onPreferenceClick(getPreference(index));
} }
@ -70,9 +70,9 @@ public class SingleSelectionPreferences extends PreferenceCategory implements Pr
public boolean onPreferenceClick(@NonNull Preference preference) { public boolean onPreferenceClick(@NonNull Preference preference) {
int index = 0; int index = 0;
for (int i = 0; i < getPreferenceCount(); i++){ for (int i = 0; i < getPreferenceCount(); i++) {
Preference item = getPreference(i); Preference item = getPreference(i);
if (item == preference){ if (item == preference) {
index = i; index = i;
item.setIcon(R.drawable.ic_done); item.setIcon(R.drawable.ic_done);
} else { } else {