Fix,refactor(profiles): prefer nameless profiles

Also refactored the use of a constant across the code
This commit is contained in:
Mathias-Boulay 2024-12-20 22:36:53 +01:00 committed by Maksim Belov
parent 38e47687fa
commit b3df2645e5
3 changed files with 21 additions and 17 deletions

View File

@ -95,21 +95,21 @@ public class ProfileAdapter extends BaseAdapter {
Drawable cachedIcon = ProfileIconCache.fetchIcon(v.getResources(), nm, minecraftProfile.icon);
extendedTextView.setCompoundDrawablesRelative(cachedIcon, null, extendedTextView.getCompoundsDrawables()[2], null);
if(Tools.isValidString(minecraftProfile.name))
extendedTextView.setText(minecraftProfile.name);
else
extendedTextView.setText(R.string.unnamed);
// Historically, the profile name "New" was hardcoded as the default profile name
// We consider "New" the same as putting no name at all
String profileName = (Tools.isValidString(minecraftProfile.name) && !"New".equalsIgnoreCase(minecraftProfile.name)) ? minecraftProfile.name : null;
String versionName = minecraftProfile.lastVersionId;
if(minecraftProfile.lastVersionId != null){
if(minecraftProfile.lastVersionId.equalsIgnoreCase("latest-release")){
extendedTextView.setText( String.format("%s - %s", extendedTextView.getText(), v.getContext().getText(R.string.profiles_latest_release)));
} else if(minecraftProfile.lastVersionId.equalsIgnoreCase("latest-snapshot")){
extendedTextView.setText( String.format("%s - %s", extendedTextView.getText(), v.getContext().getText(R.string.profiles_latest_snapshot)));
} else {
extendedTextView.setText( String.format("%s - %s", extendedTextView.getText(), minecraftProfile.lastVersionId));
}
if (MinecraftProfile.LATEST_RELEASE.equalsIgnoreCase(versionName))
versionName = v.getContext().getString(R.string.profiles_latest_release);
else if (MinecraftProfile.LATEST_SNAPSHOT.equalsIgnoreCase(versionName))
versionName = v.getContext().getString(R.string.profiles_latest_snapshot);
} else extendedTextView.setText(extendedTextView.getText());
if (versionName == null && profileName != null)
extendedTextView.setText(profileName);
else if (versionName != null && profileName == null)
extendedTextView.setText(versionName);
else extendedTextView.setText(String.format("%s - %s", profileName, versionName));
// Set selected background if needed
if(displaySelection){

View File

@ -3,13 +3,14 @@ package net.kdt.pojavlaunch.tasks;
import net.kdt.pojavlaunch.JMinecraftVersionList;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
public class AsyncMinecraftDownloader {
public static String normalizeVersionId(String versionString) {
JMinecraftVersionList versionList = (JMinecraftVersionList) ExtraCore.getValue(ExtraConstants.RELEASE_TABLE);
if(versionList == null || versionList.versions == null) return versionString;
if("latest-release".equals(versionString)) versionString = versionList.latest.get("release");
if("latest-snapshot".equals(versionString)) versionString = versionList.latest.get("snapshot");
if(MinecraftProfile.LATEST_RELEASE.equals(versionString)) versionString = versionList.latest.get("release");
if(MinecraftProfile.LATEST_SNAPSHOT.equals(versionString)) versionString = versionList.latest.get("snapshot");
return versionString;
}

View File

@ -5,6 +5,9 @@ import androidx.annotation.Keep;
@Keep
public class MinecraftProfile {
public static String LATEST_RELEASE = "latest-release";
public static String LATEST_SNAPSHOT= "latest-snapshot";
public String name;
public String type;
public String created;
@ -23,8 +26,8 @@ public class MinecraftProfile {
public static MinecraftProfile createTemplate(){
MinecraftProfile TEMPLATE = new MinecraftProfile();
TEMPLATE.name = "New";
TEMPLATE.lastVersionId = "latest-release";
TEMPLATE.name = "";
TEMPLATE.lastVersionId = LATEST_RELEASE;
return TEMPLATE;
}