Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Rename ProfileConstants to ExtraConstants and move it to extra package
Browse files Browse the repository at this point in the history
Add the 3rd constant
  • Loading branch information
artdeell committed Mar 20, 2022
1 parent 05cf75e commit 8685b49
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,7 +131,7 @@ public void launchGame(View v) {
}

public static String getVersionId(String input) {
Map<String,String> lReleaseMaps = (Map<String,String>)ExtraCore.getValue(ProfileConstants.RELEASE_TABLE);
Map<String,String> lReleaseMaps = (Map<String,String>)ExtraCore.getValue(ExtraConstants.RELEASE_TABLE);
if(lReleaseMaps == null || lReleaseMaps.isEmpty()) return input;
switch(input) {
case "latest-release":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -395,7 +395,7 @@ public void onBackPressed() {
}else{
super.onBackPressed();
//additional code
ExtraCore.removeExtraListenerFromValue("back_preference", backPreferenceListener);
ExtraCore.removeExtraListenerFromValue(ExtraConstants.BACK_PREFERENCE, backPreferenceListener);
finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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<String,String> releaseTable = (Map<String,String>)ExtraCore.getValue(ProfileConstants.RELEASE_TABLE);
Map<String,String> releaseTable = (Map<String,String>)ExtraCore.getValue(ExtraConstants.RELEASE_TABLE);
if(releaseTable != null) {
switch (minecraftProfile.lastVersionId) {
case "latest-release":
Expand All @@ -141,7 +141,7 @@ else if(minecraftProfile.lastVersionId != null) {
selectedVersionId = PojavLauncherActivity.basicVersionList[0];
}
}
ArrayList<String> versions = (ArrayList<String>) ExtraCore.getValue(ProfileConstants.VERSION_LIST);
ArrayList<String> versions = (ArrayList<String>) ExtraCore.getValue(ExtraConstants.VERSION_LIST);
BaseLauncherActivity.updateVersionSpinner(context,versions,versionSpinner, selectedVersionId);
dialog.show();
return true;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Void, Void, ArrayList<String>>
{
Expand All @@ -44,8 +32,8 @@ protected ArrayList<String> 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();
Expand All @@ -65,7 +53,7 @@ protected ArrayList<String> doInBackground(Void[] p1)
protected void onPostExecute(ArrayList<String> result)
{
super.onPostExecute(result);
ExtraCore.setValue(ProfileConstants.VERSION_LIST,result);
ExtraCore.setValue(ExtraConstants.VERSION_LIST,result);
}

private ArrayList<String> filter(JMinecraftVersionList.Version[] list1, File[] list2) {
Expand Down

0 comments on commit 8685b49

Please sign in to comment.