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.setOnPreferenceChangeListener((preference, value) -> {
InputMap.setDeadZone(((int)value/100.0f));
InputMap.setDeadZone(((int)value / 100.0f));
refreshList();
return false;
});
@ -62,7 +63,7 @@ public class InputMapPreferences extends BasePreferenceFragment implements Activ
@Override
public void onDetach() {
super.onDetach();
if (requestKey != null) {
requestKey.unregister();
requestKey = null;

View file

@ -8,15 +8,15 @@ public class GsonConfigParser {
private final Gson gson = new Gson();
private final String name;
public GsonConfigParser(String name){
public GsonConfigParser(String name) {
this.name = name;
}
private String getPath(){
private String getPath() {
return FileUtils.getConfigPath()+ "/" + name + ".json";
}
public void save(Object data){
public void save(Object data) {
synchronized (this) {
new Task(() -> {
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[] {"{}"};
new Task(()->{
if (FileUtils.exists(getPath())){
if (FileUtils.exists(getPath())) {
content[0] = FileUtils.readTextFile(getPath());
}
}).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) {
Serializable value;
if (!data.configs.containsKey(key.name)){
if (!data.configs.containsKey(key.name)) {
return key.defaultValue;
}
@ -52,7 +52,7 @@ public class GlobalConfig {
writeChanges();
}
private static void writeChanges(){
private static void writeChanges() {
parser.save(data);
}
@ -69,7 +69,7 @@ public class GlobalConfig {
private static class DataModel {
private final Map<String, Object> configs = new LinkedTreeMap<>();
public Object get(String key){
public Object get(String key) {
return configs.get(key);
}
}

View file

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

View file

@ -1,16 +1,16 @@
package com.panda3ds.pandroid.lang;
public class Task extends Thread {
public Task(Runnable runnable){
public Task(Runnable runnable) {
super(runnable);
}
public void runSync(){
public void runSync() {
start();
waitFinish();
}
public void waitFinish(){
public void waitFinish() {
try {
join();
} 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) {}
@Override
default void afterTextChanged(Editable s){
default void afterTextChanged(Editable s) {
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));
}
@ -70,9 +70,9 @@ public class SingleSelectionPreferences extends PreferenceCategory implements Pr
public boolean onPreferenceClick(@NonNull Preference preference) {
int index = 0;
for (int i = 0; i < getPreferenceCount(); i++){
for (int i = 0; i < getPreferenceCount(); i++) {
Preference item = getPreference(i);
if (item == preference){
if (item == preference) {
index = i;
item.setIcon(R.drawable.ic_done);
} else {