From dcdcdff363090ecb2169425269447977cedd2fc3 Mon Sep 17 00:00:00 2001 From: alexytomi <60690056+alexytomi@users.noreply.github.com> Date: Sat, 21 Jun 2025 12:48:03 +0800 Subject: [PATCH] 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) --- .../main/java/net/kdt/pojavlaunch/Tools.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) 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 24acb1ef1..a5f876aff 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -1461,22 +1461,29 @@ public final class Tools { } return false; } - public static void hasNoOnlineProfileDialog(Activity activity){ - if (hasOnlineProfile()){ - } 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, @Nullable Runnable run, @Nullable String customTitle, @Nullable String customMessage){ + if (hasOnlineProfile() && !Tools.isDemoProfile(activity)){ + if (run != null) { // Demo profile handling should be using customTitle and customMessage + run.run(); + } + } else { // If there is no online profile, show a dialog + customTitle = customTitle == null ? activity.getString(R.string.no_minecraft_account_found) : customTitle; + customMessage = customMessage == null ? activity.getString(R.string.feature_requires_java_account) : customMessage; + dialogOnUiThread(activity, customTitle, customMessage); + } } - public static void hasNoOnlineProfileDialog(Activity activity, String customTitle, String customMessage){ - if (hasOnlineProfile()){ - } else 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){ - if (hasOnlineProfile()){ - run.run(); - } else dialogOnUiThread(activity, activity.getString(R.string.no_minecraft_account_found), activity.getString(R.string.feature_requires_java_account)); + hasNoOnlineProfileDialog(activity, run, null, null); } - public static void hasNoOnlineProfileDialog(Activity activity, Runnable run, String customTitle, String customMessage){ - if (hasOnlineProfile()){ - run.run(); - } else dialogOnUiThread(activity, customTitle, customMessage); + public static void hasNoOnlineProfileDialog(Activity activity, String customTitle, String customMessage){ + hasNoOnlineProfileDialog(activity, null, customTitle, customMessage); } + + }