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 cab45e4705..8c40570c46 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java @@ -107,31 +107,28 @@ public void launchGame(View v) { } else if (canBack) { v.setEnabled(false); mTask = new MinecraftDownloaderTask(this); - if(LauncherPreferences.PREF_ENABLE_PROFILES) { LauncherProfiles.update(); if (LauncherProfiles.mainProfileJson != null && LauncherProfiles.mainProfileJson.profiles != null && LauncherProfiles.mainProfileJson.profiles.containsKey(mProfile.selectedProfile + "")) { MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile + ""); if (prof != null && prof.lastVersionId != null) { if (mProfile.accessToken.equals("0")) { - File verJsonFile = new File(Tools.DIR_HOME_VERSION, - mProfile.selectedVersion + "/" + mProfile.selectedVersion + ".json"); - if (verJsonFile.exists()) { - mTask.onPostExecute(null); - } else { - new AlertDialog.Builder(this) - .setTitle(R.string.global_error) - .setMessage(R.string.mcl_launch_error_localmode) - .setPositiveButton(android.R.string.ok, null) - .show(); - } + String versionId = getVersionId(prof.lastVersionId); + File verJsonFile = new File(Tools.DIR_HOME_VERSION, + versionId + "/" + versionId + ".json"); + if (verJsonFile.exists()) { + mTask.onPostExecute(null); + } else { + new AlertDialog.Builder(this) + .setTitle(R.string.global_error) + .setMessage(R.string.mcl_launch_error_localmode) + .setPositiveButton(android.R.string.ok, null) + .show(); + } + }else { + mTask.execute(getVersionId(prof.lastVersionId)); } - mTask.execute(getVersionId(prof.lastVersionId)); } } - }else{ - mTask.execute(mProfile.selectedVersion); - } - } } @@ -196,7 +193,6 @@ public void onNothingSelected(AdapterView p1) @Override protected void onPause() { super.onPause(); - if((!LauncherPreferences.PREF_ENABLE_PROFILES) && versionListener != null) ExtraCore.removeExtraListenerFromValue("lac_version_list",versionListener); } public static void updateVersionSpinner(Context ctx, ArrayList value, Spinner mVersionSelector, String defaultSelection) { @@ -213,22 +209,6 @@ public static void updateVersionSpinner(Context ctx, ArrayList value, Sp protected void onResume(){ super.onResume(); new RefreshVersionListTask(this).execute(); - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - - ArrayList vlst = (ArrayList) ExtraCore.getValue("lac_version_list"); - if(vlst != null) { - setupVersionSelector(); - updateVersionSpinner(this, vlst, mVersionSelector, mProfile.selectedVersion); - } - versionListener = (key, value) -> { - if(value != null) { - setupVersionSelector(); - updateVersionSpinner(this, value, mVersionSelector, mProfile.selectedVersion); - } - return false; - }; - ExtraCore.addExtraListener("lac_version_list",versionListener); - } if(listRefreshListener != null) { LauncherPreferences.DEFAULT_PREF.unregisterOnSharedPreferenceChangeListener(listRefreshListener); } @@ -243,17 +223,6 @@ protected void onResume(){ } }; LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener(listRefreshListener); - if(profileEnableListener != null) { - LauncherPreferences.DEFAULT_PREF.unregisterOnSharedPreferenceChangeListener(profileEnableListener); - } - profileEnableListener = ((sharedPreferences, key) -> { - if(key.equals("enable_profiles")) { - LauncherPreferences.PREF_ENABLE_PROFILES = sharedPreferences.getBoolean("enable_profiles",false); - this.recreate(); - profileEnableListener = null; - } - }); - LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener(profileEnableListener); System.out.println("call to onResume"); final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; final View decorView = getWindow().getDecorView(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java index b8b0ada863..21b9628c17 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java @@ -27,7 +27,6 @@ import net.kdt.pojavlaunch.multirt.MultiRTUtils; import net.kdt.pojavlaunch.prefs.*; -import net.kdt.pojavlaunch.profiles.ProfileAdapter; import net.kdt.pojavlaunch.utils.*; import net.kdt.pojavlaunch.value.*; import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; @@ -50,6 +49,7 @@ public class BaseMainActivity extends BaseActivity { private LoggerView loggerView; MinecraftAccount mProfile; + MinecraftProfile minecraftProfile; private DrawerLayout drawerLayout; private NavigationView navDrawer; @@ -71,44 +71,29 @@ protected void initLayout(int resId) { loggerView = findViewById(R.id.mainLoggerView); mProfile = PojavProfile.getCurrentProfileContent(this); + minecraftProfile = LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile); + if(minecraftProfile == null) { + Toast.makeText(this,"Attempted to launch nonexistent profile",Toast.LENGTH_SHORT).show(); + finish(); + return; + } String runtime = LauncherPreferences.PREF_DEFAULT_RUNTIME; - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - mVersionInfo = Tools.getVersionInfo(null, mProfile.selectedVersion); - PerVersionConfig.update(); - PerVersionConfig.VersionConfig config = PerVersionConfig.configMap.get(mProfile.selectedVersion); - if(config != null) { - if(config.selectedRuntime != null) { - if(MultiRTUtils.forceReread(config.selectedRuntime).versionString != null) { - runtime = config.selectedRuntime; - } - } - if(config.renderer != null) { - Tools.LOCAL_RENDERER = config.renderer; - } - } - }else{ LauncherProfiles.update(); - MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile); - if(prof == null) { - Toast.makeText(this,"Attempted to launch nonexistent profile",Toast.LENGTH_SHORT).show(); - finish(); - return; - } + mVersionInfo = Tools.getVersionInfo(null, BaseLauncherActivity.getVersionId( - prof.lastVersionId)); - if(prof.javaDir != null && prof.javaDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) { - String runtimeName = prof.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()); + minecraftProfile.lastVersionId)); + if(minecraftProfile.javaDir != null && minecraftProfile.javaDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) { + String runtimeName = minecraftProfile.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()); if(MultiRTUtils.forceReread(runtimeName).versionString != null) { runtime = runtimeName; } } - if(prof.__P_renderer_name != null) { - Log.i("RdrDebug","__P_renderer="+prof.__P_renderer_name); - Tools.LOCAL_RENDERER = prof.__P_renderer_name; + if(minecraftProfile.pojavRendererName != null) { + Log.i("RdrDebug","__P_renderer="+minecraftProfile.pojavRendererName); + Tools.LOCAL_RENDERER = minecraftProfile.pojavRendererName; } - } - setTitle("Minecraft " + mProfile.selectedVersion); + setTitle("Minecraft " + minecraftProfile.lastVersionId); MultiRTUtils.setRuntimeNamed(this,runtime); // Minecraft 1.13+ @@ -231,14 +216,10 @@ private void runCraft() throws Throwable { "" : " (" + mVersionInfo.inheritsFrom + ")")); - JREUtils.redirectAndPrintJRELog(this); - if(!LauncherPreferences.PREF_ENABLE_PROFILES){ - Tools.launchMinecraft(this, mProfile, mProfile.selectedVersion); - }else{ + JREUtils.redirectAndPrintJRELog(); LauncherProfiles.update(); Tools.launchMinecraft(this, mProfile, BaseLauncherActivity.getVersionId( - LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile).lastVersionId)); - } + minecraftProfile.lastVersionId)); } private void checkJavaArgsIsLaunchable(String jreVersion) throws Throwable { 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 83f13d9cef..f046f79f13 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java @@ -41,6 +41,7 @@ import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment; import net.kdt.pojavlaunch.profiles.ProfileAdapter; import net.kdt.pojavlaunch.profiles.ProfileEditor; +import net.kdt.pojavlaunch.profiles.ProfileIconCache; import net.kdt.pojavlaunch.value.MinecraftAccount; import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; @@ -91,7 +92,7 @@ public PojavLauncherActivity() { protected void onDestroy() { ExtraCore.removeExtraListenerFromValue("back_preference", backPreferenceListener); super.onDestroy(); - ProfileAdapter.clearIconCache(); + ProfileIconCache.clearIconCache(); Log.i("LauncherActivity","Destroyed!"); } @@ -191,32 +192,27 @@ public void onNothingSelected(AdapterView p1) { setupBasicList(this); //mAvailableVersions; - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - ArrayAdapter adapterVer = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, basicVersionList); - adapterVer.setDropDownViewResource(android.R.layout.simple_list_item_single_choice); - mVersionSelector.setAdapter(adapterVer); - }else{ - ProfileAdapter pad = new ProfileAdapter(this); - ProfileEditor dialog = new ProfileEditor(this,(name, isNew, deleting)->{ + ProfileAdapter profileAdapter = new ProfileAdapter(this); + ProfileEditor editor = new ProfileEditor(this,(name, isNew, deleting)->{ LauncherProfiles.update(); if(isNew) { - mVersionSelector.setSelection(pad.resolveProfileIndex(name)); + mVersionSelector.setSelection(profileAdapter.resolveProfileIndex(name)); } if(deleting) { mVersionSelector.setSelection(0); } - pad.notifyDataSetChanged(); + profileAdapter.notifyDataSetChanged(); }); - mVersionSelector.setOnLongClickListener((v)->dialog.show(mProfile.selectedProfile)); - mVersionSelector.setAdapter(pad); - mVersionSelector.setSelection(pad.resolveProfileIndex(mProfile.selectedProfile)); + mVersionSelector.setOnLongClickListener((v)->editor.show(mProfile.selectedProfile)); + mVersionSelector.setAdapter(profileAdapter); + mVersionSelector.setSelection(profileAdapter.resolveProfileIndex(mProfile.selectedProfile)); mVersionSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){ @Override public void onItemSelected(AdapterView p1, View p2, int p3, long p4) { String profileName = p1.getItemAtPosition(p3).toString(); if(profileName.equals(ProfileAdapter.CREATE_PROFILE_MAGIC)) { - dialog.show(profileName); + editor.show(profileName); mVersionSelector.setSelection(0); }else { mProfile.selectedProfile = p1.getItemAtPosition(p3).toString(); @@ -236,7 +232,6 @@ public void onNothingSelected(AdapterView p1) // TODO: Implement this method } }); - } // statusIsLaunching(false); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index c60a21e3ea..59dae5c6cf 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -120,24 +120,15 @@ public static void launchMinecraft(final Activity activity, MinecraftAccount pro JMinecraftVersionList.Version versionInfo = Tools.getVersionInfo(null,versionName); String gamedirPath = Tools.DIR_GAME_NEW; - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - PerVersionConfig.update(); - PerVersionConfig.VersionConfig pvcConfig = PerVersionConfig.configMap.get(versionName); - if (pvcConfig != null && pvcConfig.gamePath != null && !pvcConfig.gamePath.isEmpty()) - gamedirPath = pvcConfig.gamePath; - if (pvcConfig != null && pvcConfig.jvmArgs != null && !pvcConfig.jvmArgs.isEmpty()) - LauncherPreferences.PREF_CUSTOM_JAVA_ARGS = pvcConfig.jvmArgs; - }else{ if(activity instanceof BaseMainActivity) { LauncherProfiles.update(); - MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(((BaseMainActivity)activity).mProfile.selectedProfile); - if(prof == null) throw new Exception("Launching empty Profile"); - if(prof.gameDir != null && !prof.gameDir.isEmpty()) - gamedirPath = prof.gameDir; - if(prof.javaArgs != null && !prof.javaArgs.isEmpty()) - LauncherPreferences.PREF_CUSTOM_JAVA_ARGS = prof.javaArgs; + MinecraftProfile minecraftProfile = ((BaseMainActivity)activity).minecraftProfile; + if(minecraftProfile == null) throw new Exception("Launching empty Profile"); + if(minecraftProfile.gameDir != null && !minecraftProfile.gameDir.isEmpty()) + gamedirPath = minecraftProfile.gameDir; + if(minecraftProfile.javaArgs != null && !minecraftProfile.javaArgs.isEmpty()) + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS = minecraftProfile.javaArgs; } - } PojavLoginActivity.disableSplash(gamedirPath); String[] launchArgs = getMinecraftArgs(profile, versionInfo, gamedirPath); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java index 16013bfe6a..a2375ae02b 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java @@ -34,7 +34,6 @@ public class LauncherPreferences public static int PREF_CONTROL_BOTTOM_OFFSET = 0; public static int PREF_CONTROL_LEFT_OFFSET = 0; public static boolean PREF_SUSTAINED_PERFORMANCE = false; - public static boolean PREF_ENABLE_PROFILES = true; public static String PREF_GLES_SHRINK_HACK = "0"; public static boolean PREF_VBO_DISABLE_HACK = false; public static boolean PREF_VIRTUAL_MOUSE_START = false; @@ -71,7 +70,6 @@ public static void loadPreferences(Context ctx) { PREF_SUSTAINED_PERFORMANCE = DEFAULT_PREF.getBoolean("sustainedPerformance", false); PREF_GLES_SHRINK_HACK = DEFAULT_PREF.getString("gl4es_shrink_hack", "0"); PREF_VBO_DISABLE_HACK = DEFAULT_PREF.getBoolean("vbo_disable_hack", false); - PREF_ENABLE_PROFILES = DEFAULT_PREF.getBoolean("enable_profiles", false); PREF_VIRTUAL_MOUSE_START = DEFAULT_PREF.getBoolean("mouse_start", false); PREF_OPENGL_VERSION_HACK = DEFAULT_PREF.getBoolean("gles_version_hack", false); PREF_ARC_CAPES = DEFAULT_PREF.getBoolean("arc_capes",false); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileAdapter.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileAdapter.java index 308d68a99b..c641654e9d 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileAdapter.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileAdapter.java @@ -27,14 +27,12 @@ */ public class ProfileAdapter extends BaseAdapter { Map profiles; - ArrayList observers = new ArrayList<>(); - static final Map iconCache = new HashMap<>(); - static final String BASE64_PNG_HEADER = "data:image/png;base64,"; public static final String CREATE_PROFILE_MAGIC = "___extra____profile-create"; static final MinecraftProfile DUMMY = new MinecraftProfile(); static MinecraftProfile CREATE_PROFILE; List profileList; - public ProfileAdapter(Context ctx) { + public ProfileAdapter(Context context) { + ProfileIconCache.initDefault(context); LauncherProfiles.update(); profiles = new HashMap<>(LauncherProfiles.mainProfileJson.profiles); if(CREATE_PROFILE == null) { @@ -45,8 +43,7 @@ public ProfileAdapter(Context ctx) { profileList = new ArrayList<>(Arrays.asList(profiles.keySet().toArray(new String[0]))); profileList.add(ProfileAdapter.CREATE_PROFILE_MAGIC); profiles.put(CREATE_PROFILE_MAGIC, CREATE_PROFILE); - if(!iconCache.containsKey(null)) - iconCache.put(null,BitmapFactory.decodeResource(ctx.getResources(),R.drawable.ic_menu_java)); + } /* @@ -57,15 +54,6 @@ public ProfileAdapter(Context ctx) { public int getCount() { return profileList.size(); } - public static void clearIconCache() { - for(String s : iconCache.keySet()) { - Bitmap bmp = iconCache.get(s); - if(bmp != null) { - bmp.recycle(); - } - } - iconCache.clear(); - } /* * Gets the profile at a given index * @param position index to retreive @@ -115,35 +103,27 @@ public View getView(int position, View convertView, ViewGroup parent) { return v; } public void setViewProfile(View v, String nm) { - MinecraftProfile prof = profiles.get(nm); - if(prof == null) prof = DUMMY; - Bitmap cachedIcon = iconCache.get(nm); + MinecraftProfile minecraftProfile = profiles.get(nm); + if(minecraftProfile == null) minecraftProfile = DUMMY; + Bitmap cachedIcon = ProfileIconCache.getCachedIcon(nm); ImageView iconView = v.findViewById(R.id.vprof_icon_view); - if(cachedIcon == null && prof.icon != null) { - if (prof.icon.startsWith(BASE64_PNG_HEADER)) { - byte[] pngBytes = Base64.decode(prof.icon.substring(BASE64_PNG_HEADER.length()), Base64.DEFAULT); - cachedIcon = BitmapFactory.decodeByteArray(pngBytes,0,pngBytes.length); - iconCache.put(nm,cachedIcon); - }else{ - Log.i("IconParser","Unsupported icon: "+prof.icon); - cachedIcon = iconCache.get(null); - } + if(cachedIcon == null) { + cachedIcon = ProfileIconCache.tryResolveIcon(nm,minecraftProfile.icon); } - iconView.setImageBitmap(cachedIcon); - if(prof.name != null && !prof.name.isEmpty()) - ((TextView)v.findViewById(R.id.vprof_profile_name_view)).setText(prof.name); + if(minecraftProfile.name != null && !minecraftProfile.name.isEmpty()) + ((TextView)v.findViewById(R.id.vprof_profile_name_view)).setText(minecraftProfile.name); else ((TextView)v.findViewById(R.id.vprof_profile_name_view)).setText(R.string.unnamed); TextView tv = v.findViewById(R.id.vprof_version_id_view); - if(prof.lastVersionId != null) switch (prof.lastVersionId) { + if(minecraftProfile.lastVersionId != null) switch (minecraftProfile.lastVersionId) { case "latest-release": tv.setText(R.string.profiles_latest_release); case "latest-snapshot": tv.setText(R.string.profiles_latest_snapshot); default: - tv.setText(prof.lastVersionId); + tv.setText(minecraftProfile.lastVersionId); } else tv.setText(android.R.string.unknownName); } 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 bb845f9f0c..96cb9ece27 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 @@ -1,9 +1,11 @@ package net.kdt.pojavlaunch.profiles; -import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Bitmap; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -25,6 +27,7 @@ import net.kdt.pojavlaunch.multirt.RTSpinnerAdapter; import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile; +import net.kdt.pojavlaunch.multirt.Runtime; import java.util.ArrayList; import java.util.Arrays; @@ -34,37 +37,37 @@ import java.util.UUID; public class ProfileEditor implements ExtraListener> { - View mainView; - TextView profileNameView; - ImageView profileIconView; - Spinner versionSpinner; - Spinner javaRuntimeSpinner; - Spinner rendererSpinner; - List runtimes; - List renderNames; - AlertDialog dialog; - Context context; - String selectedVersionId; - String editingProfile; - EditSaveCallback cb; + private final View mainView; + private final TextView profileNameView; + private final ImageView profileIconView; + private final Spinner versionSpinner; + private final Spinner javaRuntimeSpinner; + private final Spinner rendererSpinner; + private final List renderNames; + private final AlertDialog dialog; + private String selectedVersionId; + private String editingProfile; + private final EditSaveCallback editSaveCallback; + private final Handler uiThreadHandler; public static MinecraftProfile generateTemplate() { MinecraftProfile TEMPLATE = new MinecraftProfile(); TEMPLATE.name = "New"; TEMPLATE.lastVersionId = "latest-release"; return TEMPLATE; } - public ProfileEditor(Context _ctx, EditSaveCallback cb) { - context = _ctx; - this.cb = cb; - LayoutInflater infl = LayoutInflater.from(_ctx); - mainView = infl.inflate(R.layout.version_profile_editor,null); - AlertDialog.Builder bldr = new AlertDialog.Builder(_ctx); - bldr.setView(mainView); + public ProfileEditor(Context _ctx, EditSaveCallback editSaveCallback) { + this.editSaveCallback = editSaveCallback; + uiThreadHandler = new Handler(Looper.getMainLooper()); + LayoutInflater inflater = LayoutInflater.from(_ctx); + mainView = inflater.inflate(R.layout.version_profile_editor,null); + AlertDialog.Builder builder = new AlertDialog.Builder(_ctx); + builder.setView(mainView); profileNameView = mainView.findViewById(R.id.vprof_editior_profile_name); versionSpinner = mainView.findViewById(R.id.vprof_editor_version_spinner); javaRuntimeSpinner = mainView.findViewById(R.id.vprof_editor_spinner_runtime); rendererSpinner = mainView.findViewById(R.id.vprof_editor_profile_renderer); { + Context context = rendererSpinner.getContext(); List renderList = new ArrayList<>(); Collections.addAll(renderList, context.getResources().getStringArray(R.array.renderer)); renderList.add("Default"); @@ -72,60 +75,58 @@ public ProfileEditor(Context _ctx, EditSaveCallback cb) { rendererSpinner.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item,renderList)); } profileIconView = mainView.findViewById(R.id.vprof_editor_icon); - bldr.setPositiveButton(R.string.global_save,this::save); - bldr.setNegativeButton(android.R.string.cancel,(dialog,which)->destroy(dialog)); - bldr.setNeutralButton(R.string.global_delete,(dialogInterface, i) -> { + builder.setPositiveButton(R.string.global_save,this::save); + builder.setNegativeButton(android.R.string.cancel,(dialog,which)->destroy(dialog)); + builder.setNeutralButton(R.string.global_delete,(dialogInterface, i) -> { LauncherProfiles.mainProfileJson.profiles.remove(editingProfile); - this.cb.onSave(editingProfile,false, true); + this.editSaveCallback.onSave(editingProfile,false, true); }); - bldr.setOnDismissListener(this::destroy); - dialog = bldr.create(); + builder.setOnDismissListener(this::destroy); + dialog = builder.create(); } public boolean show(@NonNull String profile) { - MinecraftProfile prof; + MinecraftProfile minecraftProfile; if(!ProfileAdapter.CREATE_PROFILE_MAGIC.equals(profile)) { - prof = LauncherProfiles.mainProfileJson.profiles.get(profile); - if (prof == null) return true; + minecraftProfile = LauncherProfiles.mainProfileJson.profiles.get(profile); + if (minecraftProfile == null) return true; editingProfile = profile; }else{ - prof = generateTemplate(); + minecraftProfile = generateTemplate(); String uuid = UUID.randomUUID().toString(); while(LauncherProfiles.mainProfileJson.profiles.containsKey(uuid)) { uuid = UUID.randomUUID().toString(); } editingProfile = uuid; } - runtimes = MultiRTUtils.getRuntimes(); + List runtimes = MultiRTUtils.getRuntimes(); + Context context = javaRuntimeSpinner.getContext(); javaRuntimeSpinner.setAdapter(new RTSpinnerAdapter(context, runtimes)); - int jvm_index = runtimes.indexOf(new MultiRTUtils.Runtime("")); - int rnd_index = rendererSpinner.getAdapter().getCount()-1; - if (prof.javaDir != null) { - String selectedRuntime = prof.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()); - int nindex = runtimes.indexOf(new MultiRTUtils.Runtime(selectedRuntime)); - if (nindex != -1) jvm_index = nindex; + int jvmIndex = runtimes.indexOf(new Runtime("")); + int rendererIndex = rendererSpinner.getAdapter().getCount()-1; + if (minecraftProfile.javaDir != null) { + String selectedRuntime = minecraftProfile.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()); + int nindex = runtimes.indexOf(new Runtime(selectedRuntime)); + if (nindex != -1) jvmIndex = nindex; } - if(prof.__P_renderer_name != null) { - int nindex = renderNames.indexOf(prof.__P_renderer_name); - if(nindex != -1) rnd_index = nindex; + if(minecraftProfile.pojavRendererName != null) { + int nindex = renderNames.indexOf(minecraftProfile.pojavRendererName); + if(nindex != -1) rendererIndex = nindex; } - javaRuntimeSpinner.setSelection(jvm_index); - rendererSpinner.setSelection(rnd_index); + javaRuntimeSpinner.setSelection(jvmIndex); + rendererSpinner.setSelection(rendererIndex); ExtraCore.addExtraListener("lac_version_list",this); - profileNameView.setText(prof.name); - if(ProfileAdapter.iconCache.containsKey(profile)) { - Log.i("ProfileEditor","Icon resolved!"); - profileIconView.setImageBitmap(ProfileAdapter.iconCache.get(profile)); - }else { - Log.i("ProfileEditor","No resolved icon."); - Log.i("ProfileEditor", ProfileAdapter.iconCache.keySet().toString()); - profileIconView.setImageBitmap(ProfileAdapter.iconCache.get(null)); + profileNameView.setText(minecraftProfile.name); + Bitmap profileIcon = ProfileIconCache.getCachedIcon(profile); + if(profileIcon == null) { + profileIcon = ProfileIconCache.tryResolveIcon(profile,minecraftProfile.icon); } - if(prof.lastVersionId != null && !"latest-release".equals(prof.lastVersionId) && !"latest-snapshot".equals(prof.lastVersionId)) - selectedVersionId = prof.lastVersionId; - else if(prof.lastVersionId != null) { + profileIconView.setImageBitmap(profileIcon); + 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("release_table"); if(releaseTable != null) { - switch (prof.lastVersionId) { + switch (minecraftProfile.lastVersionId) { case "latest-release": selectedVersionId = releaseTable.get("release"); case "latest-snapshot": @@ -146,32 +147,36 @@ else if(prof.lastVersionId != null) { return true; } public void save(DialogInterface dialog, int which) { - System.out.println(editingProfile); - MinecraftProfile prof; + MinecraftProfile profile; boolean isNew; if(LauncherProfiles.mainProfileJson.profiles.containsKey(editingProfile)) { - prof = LauncherProfiles.mainProfileJson.profiles.get(editingProfile); + profile = LauncherProfiles.mainProfileJson.profiles.get(editingProfile); + if(profile == null) { + profile = new MinecraftProfile(); + isNew = true; + }else{ + isNew = false; + } LauncherProfiles.mainProfileJson.profiles.remove(editingProfile); - isNew = false; }else{ - prof = new MinecraftProfile(); + profile = new MinecraftProfile(); isNew = true; } - prof.name = profileNameView.getText().toString(); - prof.lastVersionId = (String)versionSpinner.getSelectedItem(); - MultiRTUtils.Runtime selectedRuntime = (MultiRTUtils.Runtime) javaRuntimeSpinner.getSelectedItem(); + profile.name = profileNameView.getText().toString(); + profile.lastVersionId = (String)versionSpinner.getSelectedItem(); + Runtime selectedRuntime = (Runtime) javaRuntimeSpinner.getSelectedItem(); if(selectedRuntime.name.equals("")) { - prof.javaDir = null; + profile.javaDir = null; }else if(selectedRuntime.versionString == null) { - prof.javaDir = null; + profile.javaDir = null; }else{ - prof.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+selectedRuntime.name; + profile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+selectedRuntime.name; } - if(rendererSpinner.getSelectedItemPosition() == renderNames.size()) prof.__P_renderer_name = null; - else prof.__P_renderer_name = renderNames.get(rendererSpinner.getSelectedItemPosition()); - LauncherProfiles.mainProfileJson.profiles.put(editingProfile,prof); - cb.onSave(editingProfile,isNew, false); + if(rendererSpinner.getSelectedItemPosition() == renderNames.size()) profile.pojavRendererName = null; + else profile.pojavRendererName = renderNames.get(rendererSpinner.getSelectedItemPosition()); + LauncherProfiles.mainProfileJson.profiles.put(editingProfile,profile); + editSaveCallback.onSave(editingProfile,isNew, false); destroy(dialog); } public void destroy(@NonNull DialogInterface dialog) { @@ -181,9 +186,9 @@ public void destroy(@NonNull DialogInterface dialog) { } @Override public boolean onValueSet(String key, @Nullable ArrayList value) { - if(value != null) ((Activity)context).runOnUiThread(()->{ - BaseLauncherActivity.updateVersionSpinner(context,value,versionSpinner, selectedVersionId); - }); + if(value != null) { + uiThreadHandler.post(() -> BaseLauncherActivity.updateVersionSpinner(mainView.getContext(), value, versionSpinner, selectedVersionId)); + } return false; } public interface EditSaveCallback { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileIconCache.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileIconCache.java new file mode 100644 index 0000000000..0d0356c0b9 --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileIconCache.java @@ -0,0 +1,54 @@ +package net.kdt.pojavlaunch.profiles; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.util.Base64; +import android.util.Log; + +import net.kdt.pojavlaunch.R; + +import java.util.HashMap; +import java.util.Map; + +public class ProfileIconCache { + private static final String BASE64_PNG_HEADER = "data:image/png;base64,"; + private static final Map iconCache = new HashMap<>(); + private static Bitmap defaultIcon; + public static void initDefault(Context context) { + if(defaultIcon == null) + defaultIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_menu_java); + } + public static void clearIconCache() { + for(String key : iconCache.keySet()) { + Bitmap bitmap = iconCache.get(key); + if(bitmap != defaultIcon && bitmap != null) { + bitmap.recycle(); + } + } + iconCache.clear(); + } + public static Bitmap getCachedIcon(String key) { + return iconCache.get(key); + } + public static Bitmap submitIcon(String key, String base64) { + byte[] pngBytes = Base64.decode(base64, Base64.DEFAULT); + Bitmap cachedIcon = BitmapFactory.decodeByteArray(pngBytes,0,pngBytes.length); + iconCache.put(key, cachedIcon); + return cachedIcon; + } + public static Bitmap tryResolveIcon(String profileName, String b64Icon) { + Bitmap icon; + if (b64Icon != null && b64Icon.startsWith(BASE64_PNG_HEADER)) { + icon = ProfileIconCache.submitIcon(profileName, b64Icon.substring(BASE64_PNG_HEADER.length())); + }else{ + Log.i("IconParser","Unsupported icon: "+b64Icon); + icon = ProfileIconCache.pushDefaultIcon(profileName); + } + return icon; + } + public static Bitmap pushDefaultIcon(String key) { + iconCache.put(key, defaultIcon); + return defaultIcon; + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloaderTask.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloaderTask.java index 82e4e96adf..a4030835fb 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloaderTask.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloaderTask.java @@ -91,40 +91,19 @@ public void updateProgress(int curr, int max) { //Now we have the reliable information to check if our runtime settings are good enough if(verInfo.javaVersion != null) { //1.17+ + LauncherProfiles.update(); + MinecraftProfile minecraftProfile = LauncherProfiles.mainProfileJson.profiles.get(mActivity.mProfile.selectedProfile); + if(minecraftProfile == null) throw new SilentException(); String selectedRuntime = null; - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - PerVersionConfig.update(); - PerVersionConfig.VersionConfig cfg = PerVersionConfig.configMap.get(p1[0]); - if (cfg == null) { - cfg = new PerVersionConfig.VersionConfig(); - PerVersionConfig.configMap.put(p1[0], cfg); - } - }else{ - LauncherProfiles.update(); - MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(mActivity.mProfile.selectedProfile); - if(prof == null) throw new SilentException(); - if(prof.javaDir != null && prof.javaDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) { - selectedRuntime = prof.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()); - } + if(minecraftProfile.javaDir != null && minecraftProfile.javaDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) { + selectedRuntime = minecraftProfile.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()); } - MultiRTUtils.Runtime r = selectedRuntime != null?MultiRTUtils.read(selectedRuntime):MultiRTUtils.read(LauncherPreferences.PREF_DEFAULT_RUNTIME); - if(r.javaVersion < verInfo.javaVersion.majorVersion) { - String appropriateRuntime = MultiRTUtils.getNearestJREName(verInfo.javaVersion.majorVersion); + Runtime runtime = selectedRuntime != null?MultiRTUtils.read(selectedRuntime):MultiRTUtils.read(LauncherPreferences.PREF_DEFAULT_RUNTIME); + if(runtime.javaVersion < verInfo.javaVersion.majorVersion) { + String appropriateRuntime = MultiRTUtils.getNearestJreName(verInfo.javaVersion.majorVersion); if(appropriateRuntime != null) { - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - PerVersionConfig.VersionConfig cfg = PerVersionConfig.configMap.get(p1[0]); - if (cfg == null) { - cfg = new PerVersionConfig.VersionConfig(); - PerVersionConfig.configMap.put(p1[0], cfg); - } - cfg.selectedRuntime = appropriateRuntime; - PerVersionConfig.update(); - }else{ - MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(mActivity.mProfile.selectedProfile); - if(prof == null) throw new SilentException(); - prof.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+appropriateRuntime; - LauncherProfiles.update(); - } + minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+appropriateRuntime; + LauncherProfiles.update(); }else{ mActivity.runOnUiThread(()->{ AlertDialog.Builder bldr = new AlertDialog.Builder(mActivity); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/V117CompatUtil.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/V117CompatUtil.java index f7394eaf75..a8fcbbfcdc 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/V117CompatUtil.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/V117CompatUtil.java @@ -1,7 +1,6 @@ package net.kdt.pojavlaunch.utils; import android.app.Activity; -import android.content.Context; import android.content.res.AssetManager; import android.util.Log; @@ -25,7 +24,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; public class V117CompatUtil { @@ -114,18 +112,11 @@ public static void runCheck(String version, Activity ctx) throws Exception{ List packList =getTexturePackList(MCOptionUtils.get("resourcePacks")); String renderer; String gamePath; - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - PerVersionConfig.update(); - PerVersionConfig.VersionConfig cfg = PerVersionConfig.configMap.get(version); - renderer = cfg != null && cfg.renderer != null?cfg.renderer:LauncherPreferences.PREF_RENDERER; - gamePath = cfg != null && cfg.gamePath != null?cfg.gamePath:Tools.DIR_GAME_NEW; - }else{ LauncherProfiles.update(); MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(((BaseLauncherActivity)ctx).mProfile.selectedProfile); if(prof == null) throw new MinecraftDownloaderTask.SilentException(); - renderer = prof.__P_renderer_name != null?prof.__P_renderer_name:LauncherPreferences.PREF_RENDERER; + renderer = prof.pojavRendererName != null?prof.pojavRendererName :LauncherPreferences.PREF_RENDERER; gamePath = prof.gameDir != null?prof.gameDir:Tools.DIR_GAME_NEW; - } //String if(renderer.equals("vulkan_zink") || renderer.equals("opengles3_virgl")) return; //don't install for zink/virgl users; @@ -160,25 +151,14 @@ public static void runCheck(String version, Activity ctx) throws Exception{ } switch(proceed.get()) { case 1: - if(!LauncherPreferences.PREF_ENABLE_PROFILES) { - PerVersionConfig.VersionConfig cfg = PerVersionConfig.configMap.get(version); - if (cfg == null) { - cfg = new PerVersionConfig.VersionConfig(); - PerVersionConfig.configMap.put(version, cfg); - } - cfg.renderer = "opengles3"; - PerVersionConfig.update(); - }else{ - MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(((BaseLauncherActivity)ctx).mProfile.selectedProfile); - if(prof == null) throw new MinecraftDownloaderTask.SilentException(); - prof.__P_renderer_name = "opengles3"; + MinecraftProfile minecraftProfile = LauncherProfiles.mainProfileJson.profiles.get(((BaseLauncherActivity)ctx).mProfile.selectedProfile); + if(minecraftProfile == null) throw new MinecraftDownloaderTask.SilentException(); + minecraftProfile.pojavRendererName = "opengles3"; LauncherProfiles.update(); - } copyResourcePack(gamePath,ctx.getAssets()); if(!packList.contains("\"assets-v0.zip\"")) packList.add(0,"\"assets-v0.zip\""); MCOptionUtils.set("resourcePacks",regenPackList(packList)); MCOptionUtils.save(); - PerVersionConfig.update(); break; case 0: throw new MinecraftDownloaderTask.SilentException(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/MinecraftProfile.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/MinecraftProfile.java index 36c2c124e1..6736cc89b9 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/MinecraftProfile.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/MinecraftProfile.java @@ -13,6 +13,6 @@ public class MinecraftProfile public String javaArgs; public String logConfig; public boolean logConfigIsXML; - public String __P_renderer_name; + public String pojavRendererName; public MinecraftResolution[] resolution; }