Skip to content

Commit

Permalink
Fix,refactor(profiles): prefer nameless profiles
Browse files Browse the repository at this point in the history
Also refactored the use of a constant across the code
  • Loading branch information
Mathias-Boulay committed Dec 22, 2024
1 parent 3feb692 commit 0bc6e78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ public void setViewProfile(View v, String nm, boolean displaySelection) {
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);

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));
}

} else extendedTextView.setText(extendedTextView.getText());
// 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.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);

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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 0bc6e78

Please sign in to comment.