refactor[Tools]: Refactor better demo/local dialog

Should also fix demo message being missing in some cases (particularly
in the open directory button when both a demo and ms acc is logged on)
This commit is contained in:
alexytomi 2025-06-21 12:48:03 +08:00
parent 9e877dfb12
commit dcdcdff363

View File

@ -1461,22 +1461,29 @@ public final class Tools {
} }
return false; return false;
} }
public static void hasNoOnlineProfileDialog(Activity activity){
if (hasOnlineProfile()){ public static void hasNoOnlineProfileDialog(Activity activity, @Nullable Runnable run, @Nullable String customTitle, @Nullable String customMessage){
} else dialogOnUiThread(activity, activity.getString(R.string.no_minecraft_account_found), activity.getString(R.string.feature_requires_java_account)); if (hasOnlineProfile() && !Tools.isDemoProfile(activity)){
if (run != null) { // Demo profile handling should be using customTitle and customMessage
run.run();
} }
public static void hasNoOnlineProfileDialog(Activity activity, String customTitle, String customMessage){ } else { // If there is no online profile, show a dialog
if (hasOnlineProfile()){ customTitle = customTitle == null ? activity.getString(R.string.no_minecraft_account_found) : customTitle;
} else dialogOnUiThread(activity, customTitle, customMessage); customMessage = customMessage == null ? activity.getString(R.string.feature_requires_java_account) : customMessage;
dialogOnUiThread(activity, customTitle, customMessage);
}
}
// Some boilerplate to reduce boilerplate elsewhere
public static void hasNoOnlineProfileDialog(Activity activity){
hasNoOnlineProfileDialog(activity, null, null, null);
} }
public static void hasNoOnlineProfileDialog(Activity activity, Runnable run){ public static void hasNoOnlineProfileDialog(Activity activity, Runnable run){
if (hasOnlineProfile()){ hasNoOnlineProfileDialog(activity, run, null, null);
run.run();
} else dialogOnUiThread(activity, activity.getString(R.string.no_minecraft_account_found), activity.getString(R.string.feature_requires_java_account));
} }
public static void hasNoOnlineProfileDialog(Activity activity, Runnable run, String customTitle, String customMessage){ public static void hasNoOnlineProfileDialog(Activity activity, String customTitle, String customMessage){
if (hasOnlineProfile()){ hasNoOnlineProfileDialog(activity, null, customTitle, customMessage);
run.run();
} else dialogOnUiThread(activity, customTitle, customMessage);
} }
} }