From 8685b4969c0655032660506369075532f36e0b0f Mon Sep 17 00:00:00 2001 From: artdeell Date: Sun, 20 Mar 2022 13:17:58 +0300 Subject: [PATCH] Rename ProfileConstants to ExtraConstants and move it to extra package Add the 3rd constant --- .../kdt/pojavlaunch/BaseLauncherActivity.java | 7 ++----- .../pojavlaunch/PojavLauncherActivity.java | 10 +++++----- .../ExtraConstants.java} | 7 ++++--- .../prefs/BackButtonPreference.java | 3 ++- .../pojavlaunch/profiles/ProfileEditor.java | 10 +++++----- .../tasks/RefreshVersionListTask.java | 20 ++++--------------- 6 files changed, 22 insertions(+), 35 deletions(-) rename app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/{profiles/ProfileConstants.java => extra/ExtraConstants.java} (64%) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java index a73ea744d3..6da7fa414a 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java @@ -15,16 +15,13 @@ import java.util.ArrayList; import java.util.Map; import net.kdt.pojavlaunch.extra.ExtraCore; -import net.kdt.pojavlaunch.extra.ExtraListener; -import net.kdt.pojavlaunch.fragments.*; import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog; import net.kdt.pojavlaunch.multirt.MultiRTUtils; import net.kdt.pojavlaunch.prefs.*; -import net.kdt.pojavlaunch.profiles.ProfileConstants; +import net.kdt.pojavlaunch.extra.ExtraConstants; import net.kdt.pojavlaunch.tasks.*; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.PopupMenu; import net.kdt.pojavlaunch.value.*; import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; @@ -134,7 +131,7 @@ public void launchGame(View v) { } public static String getVersionId(String input) { - Map lReleaseMaps = (Map)ExtraCore.getValue(ProfileConstants.RELEASE_TABLE); + Map lReleaseMaps = (Map)ExtraCore.getValue(ExtraConstants.RELEASE_TABLE); if(lReleaseMaps == null || lReleaseMaps.isEmpty()) return input; switch(input) { case "latest-release": diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java index 9053210c74..6bef51a9b2 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java @@ -39,7 +39,7 @@ import net.kdt.pojavlaunch.prefs.LauncherPreferences; import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment; import net.kdt.pojavlaunch.profiles.ProfileAdapter; -import net.kdt.pojavlaunch.profiles.ProfileConstants; +import net.kdt.pojavlaunch.extra.ExtraConstants; import net.kdt.pojavlaunch.profiles.ProfileEditor; import net.kdt.pojavlaunch.profiles.ProfileIconCache; import net.kdt.pojavlaunch.value.MinecraftAccount; @@ -90,7 +90,7 @@ public PojavLauncherActivity() { @Override protected void onDestroy() { - ExtraCore.removeExtraListenerFromValue("back_preference", backPreferenceListener); + ExtraCore.removeExtraListenerFromValue(ExtraConstants.BACK_PREFERENCE, backPreferenceListener); super.onDestroy(); ProfileIconCache.clearIconCache(); Log.i("LauncherActivity","Destroyed!"); @@ -140,7 +140,7 @@ public void onPageSelected(int position) { } return false; }; - ExtraCore.addExtraListener("back_preference", backPreferenceListener); + ExtraCore.addExtraListener(ExtraConstants.BACK_PREFERENCE, backPreferenceListener); // Try to load the temporary account @@ -274,7 +274,7 @@ public static void setupBasicList(Context ctx) { } finally { basicVersionList = versions.toArray(new String[0]); - ExtraCore.setValue(ProfileConstants.VERSION_LIST,versions); + ExtraCore.setValue(ExtraConstants.VERSION_LIST,versions); } } private void pickAccount() { @@ -395,7 +395,7 @@ public void onBackPressed() { }else{ super.onBackPressed(); //additional code - ExtraCore.removeExtraListenerFromValue("back_preference", backPreferenceListener); + ExtraCore.removeExtraListenerFromValue(ExtraConstants.BACK_PREFERENCE, backPreferenceListener); finish(); } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileConstants.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/extra/ExtraConstants.java similarity index 64% rename from app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileConstants.java rename to app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/extra/ExtraConstants.java index 9e03b46aee..7f25bb7b22 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileConstants.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/extra/ExtraConstants.java @@ -1,9 +1,10 @@ -package net.kdt.pojavlaunch.profiles; +package net.kdt.pojavlaunch.extra; -public class ProfileConstants { +public class ExtraConstants { /* ExtraCore constant: a HashMap for converting values such as latest-snapshot or latest-release to actual game version names */ public static final String RELEASE_TABLE = "release_table"; /* ExtraCore constant: an ArrayList of Strings, where each String is a Minecraft version name */ public static final String VERSION_LIST= "lac_version_list"; - + /* ExraCore constant: Serpent's back button tracking thing */ + public static final String BACK_PREFERENCE = "back_preference"; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/BackButtonPreference.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/BackButtonPreference.java index 8621cbe2ff..5745513b04 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/BackButtonPreference.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/BackButtonPreference.java @@ -6,6 +6,7 @@ import androidx.preference.Preference; import net.kdt.pojavlaunch.R; +import net.kdt.pojavlaunch.extra.ExtraConstants; import net.kdt.pojavlaunch.extra.ExtraCore; public class BackButtonPreference extends Preference { @@ -31,6 +32,6 @@ private void init(){ @Override protected void onClick() { // It is caught by an ExtraListener in the LauncherActivity - ExtraCore.setValue("back_preference", "true"); + ExtraCore.setValue(ExtraConstants.BACK_PREFERENCE, "true"); } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java index ec0beb0df8..ea4a7fc661 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java @@ -6,7 +6,6 @@ import android.graphics.Bitmap; import android.os.Handler; import android.os.Looper; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ArrayAdapter; @@ -23,6 +22,7 @@ import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.extra.ExtraCore; import net.kdt.pojavlaunch.extra.ExtraListener; +import net.kdt.pojavlaunch.extra.ExtraConstants; import net.kdt.pojavlaunch.multirt.MultiRTUtils; import net.kdt.pojavlaunch.multirt.RTSpinnerAdapter; import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; @@ -114,7 +114,7 @@ public boolean show(@NonNull String profile) { } javaRuntimeSpinner.setSelection(jvmIndex); rendererSpinner.setSelection(rendererIndex); - ExtraCore.addExtraListener(ProfileConstants.VERSION_LIST,this); + ExtraCore.addExtraListener(ExtraConstants.VERSION_LIST,this); profileNameView.setText(minecraftProfile.name); Bitmap profileIcon = ProfileIconCache.getCachedIcon(profile); if(profileIcon == null) { @@ -124,7 +124,7 @@ public boolean show(@NonNull String profile) { if(minecraftProfile.lastVersionId != null && !"latest-release".equals(minecraftProfile.lastVersionId) && !"latest-snapshot".equals(minecraftProfile.lastVersionId)) selectedVersionId = minecraftProfile.lastVersionId; else if(minecraftProfile.lastVersionId != null) { - Map releaseTable = (Map)ExtraCore.getValue(ProfileConstants.RELEASE_TABLE); + Map releaseTable = (Map)ExtraCore.getValue(ExtraConstants.RELEASE_TABLE); if(releaseTable != null) { switch (minecraftProfile.lastVersionId) { case "latest-release": @@ -141,7 +141,7 @@ else if(minecraftProfile.lastVersionId != null) { selectedVersionId = PojavLauncherActivity.basicVersionList[0]; } } - ArrayList versions = (ArrayList) ExtraCore.getValue(ProfileConstants.VERSION_LIST); + ArrayList versions = (ArrayList) ExtraCore.getValue(ExtraConstants.VERSION_LIST); BaseLauncherActivity.updateVersionSpinner(context,versions,versionSpinner, selectedVersionId); dialog.show(); return true; @@ -180,7 +180,7 @@ public void save(DialogInterface dialog, int which) { destroy(dialog); } public void destroy(@NonNull DialogInterface dialog) { - ExtraCore.removeExtraListenerFromValue(ProfileConstants.VERSION_LIST,this); + ExtraCore.removeExtraListenerFromValue(ExtraConstants.VERSION_LIST,this); editingProfile = null; selectedVersionId = null; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/RefreshVersionListTask.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/RefreshVersionListTask.java index e040215e4b..eb7cad1774 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/RefreshVersionListTask.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/RefreshVersionListTask.java @@ -1,28 +1,16 @@ package net.kdt.pojavlaunch.tasks; -import android.app.AlertDialog; -import android.content.DialogInterface; import android.os.*; -import androidx.appcompat.widget.*; import android.util.Log; -import android.view.*; -import android.widget.*; -import android.widget.AdapterView.*; import java.io.*; import java.util.*; import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.extra.ExtraCore; -import net.kdt.pojavlaunch.extra.ExtraListener; -import net.kdt.pojavlaunch.multirt.MultiRTUtils; -import net.kdt.pojavlaunch.multirt.RTSpinnerAdapter; import net.kdt.pojavlaunch.prefs.*; -import net.kdt.pojavlaunch.profiles.ProfileConstants; +import net.kdt.pojavlaunch.extra.ExtraConstants; import net.kdt.pojavlaunch.utils.*; -import net.kdt.pojavlaunch.value.PerVersionConfig; - -import androidx.appcompat.widget.PopupMenu; public class RefreshVersionListTask extends AsyncTask> { @@ -44,8 +32,8 @@ protected ArrayList doInBackground(Void[] p1) Log.i("ExtVL", "Syncing to external: " + url); list = Tools.GLOBAL_GSON.fromJson(DownloadUtils.downloadString(url), JMinecraftVersionList.class); Log.i("ExtVL","Downloaded the version list, len="+list.versions.length); - if(list.latest != null && ExtraCore.getValue(ProfileConstants.RELEASE_TABLE) == null) - ExtraCore.setValue(ProfileConstants.RELEASE_TABLE,list.latest); + if(list.latest != null && ExtraCore.getValue(ExtraConstants.RELEASE_TABLE) == null) + ExtraCore.setValue(ExtraConstants.RELEASE_TABLE,list.latest); Collections.addAll(versions,list.versions); } mActivity.mVersionList = new JMinecraftVersionList(); @@ -65,7 +53,7 @@ protected ArrayList doInBackground(Void[] p1) protected void onPostExecute(ArrayList result) { super.onPostExecute(result); - ExtraCore.setValue(ProfileConstants.VERSION_LIST,result); + ExtraCore.setValue(ExtraConstants.VERSION_LIST,result); } private ArrayList filter(JMinecraftVersionList.Version[] list1, File[] list2) {