mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-10 13:16:04 -04:00
qol[Demo]: Turn demo mode error into box
TODO: actually make these translatable
This commit is contained in:
parent
e7ec20a79c
commit
17c435da39
@ -1,6 +1,8 @@
|
|||||||
package net.kdt.pojavlaunch;
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
|
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
|
||||||
|
import static net.kdt.pojavlaunch.Tools.hasNoOnlineProfileDialog;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -139,7 +141,7 @@ public class LauncherActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOlderThan13) {
|
if (isOlderThan13) {
|
||||||
Toast.makeText(this, R.string.toast_not_available_demo, Toast.LENGTH_LONG).show();
|
hasNoOnlineProfileDialog(this, getString(R.string.global_error), "This version is not available in demo mode.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,13 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class PojavProfile {
|
public class PojavProfile {
|
||||||
private static final String PROFILE_PREF = "pojav_profile";
|
private static final String PROFILE_PREF = "pojav_profile";
|
||||||
private static final String PROFILE_PREF_FILE = "file";
|
private static final String PROFILE_PREF_FILE = "file";
|
||||||
@ -30,6 +37,25 @@ public class PojavProfile {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<MinecraftAccount> getAllProfiles(){
|
||||||
|
List<MinecraftAccount> mcAccountList = new ArrayList<>();;
|
||||||
|
for (String accountName : getAllProfilesList()){
|
||||||
|
mcAccountList.add(MinecraftAccount.load(accountName));
|
||||||
|
}
|
||||||
|
return mcAccountList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getAllProfilesList(){
|
||||||
|
List<String> accountList = new ArrayList<>();
|
||||||
|
File accountFolder = new File(Tools.DIR_ACCOUNT_NEW);
|
||||||
|
if(accountFolder.exists() && accountFolder.list() != null){
|
||||||
|
for (String fileName : Objects.requireNonNull(accountFolder.list())) {
|
||||||
|
accountList.add(fileName.substring(0, fileName.length() - 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return accountList;
|
||||||
|
}
|
||||||
|
|
||||||
public static void setCurrentProfile(@NonNull Context ctx, @Nullable Object obj) {
|
public static void setCurrentProfile(@NonNull Context ctx, @Nullable Object obj) {
|
||||||
SharedPreferences.Editor pref = getPrefs(ctx).edit();
|
SharedPreferences.Editor pref = getPrefs(ctx).edit();
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.kdt.pojavlaunch;
|
|||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.os.Build.VERSION_CODES.P;
|
import static android.os.Build.VERSION_CODES.P;
|
||||||
import static net.kdt.pojavlaunch.PojavApplication.sExecutorService;
|
import static net.kdt.pojavlaunch.PojavApplication.sExecutorService;
|
||||||
|
import static net.kdt.pojavlaunch.PojavProfile.getAllProfiles;
|
||||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
|
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
|
||||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
|
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
|
||||||
|
|
||||||
@ -1452,4 +1453,30 @@ public final class Tools {
|
|||||||
MinecraftAccount currentProfile = PojavProfile.getCurrentProfileContent(ctx, null);
|
MinecraftAccount currentProfile = PojavProfile.getCurrentProfileContent(ctx, null);
|
||||||
return currentProfile == null || currentProfile.isLocal();
|
return currentProfile == null || currentProfile.isLocal();
|
||||||
}
|
}
|
||||||
|
public static boolean hasOnlineProfile(){
|
||||||
|
for (MinecraftAccount accountToCheck : getAllProfiles()) {
|
||||||
|
if (!accountToCheck.isLocal() || !accountToCheck.isDemo()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static void hasNoOnlineProfileDialog(Activity activity){
|
||||||
|
if (hasOnlineProfile()){
|
||||||
|
} else dialogOnUiThread(activity, "No Minecraft Account Found", "Please log into your Minecraft: Java Edition account to use this feature.");
|
||||||
|
}
|
||||||
|
public static void hasNoOnlineProfileDialog(Activity activity, String customTitle, String customMessage){
|
||||||
|
if (hasOnlineProfile()){
|
||||||
|
} else dialogOnUiThread(activity, customTitle, customMessage);
|
||||||
|
}
|
||||||
|
public static void hasNoOnlineProfileDialog(Activity activity, Runnable run){
|
||||||
|
if (hasOnlineProfile()){
|
||||||
|
run.run();
|
||||||
|
} else dialogOnUiThread(activity, "No Minecraft Account Found", "Please log into your Minecraft: Java Edition account to use this feature.");
|
||||||
|
}
|
||||||
|
public static void hasNoOnlineProfileDialog(Activity activity, Runnable run, String customTitle, String customMessage){
|
||||||
|
if (hasOnlineProfile()){
|
||||||
|
run.run();
|
||||||
|
} else dialogOnUiThread(activity, customTitle, customMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.kdt.pojavlaunch.fragments;
|
package net.kdt.pojavlaunch.fragments;
|
||||||
|
|
||||||
|
import static net.kdt.pojavlaunch.Tools.hasOnlineProfile;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -31,6 +33,10 @@ public class LocalLoginFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
// This is overkill but meh
|
||||||
|
if (!hasOnlineProfile()){
|
||||||
|
Tools.swapFragment(requireActivity(), MainMenuFragment.class, MainMenuFragment.TAG, null);
|
||||||
|
}
|
||||||
mUsernameEditText = view.findViewById(R.id.login_edit_email);
|
mUsernameEditText = view.findViewById(R.id.login_edit_email);
|
||||||
view.findViewById(R.id.login_button).setOnClickListener(v -> {
|
view.findViewById(R.id.login_button).setOnClickListener(v -> {
|
||||||
if(!checkEditText()) {
|
if(!checkEditText()) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.kdt.pojavlaunch.fragments;
|
package net.kdt.pojavlaunch.fragments;
|
||||||
|
|
||||||
|
import static net.kdt.pojavlaunch.Tools.hasNoOnlineProfileDialog;
|
||||||
|
import static net.kdt.pojavlaunch.Tools.hasOnlineProfile;
|
||||||
import static net.kdt.pojavlaunch.Tools.openPath;
|
import static net.kdt.pojavlaunch.Tools.openPath;
|
||||||
import static net.kdt.pojavlaunch.Tools.shareLog;
|
import static net.kdt.pojavlaunch.Tools.shareLog;
|
||||||
|
|
||||||
@ -53,11 +55,13 @@ public class MainMenuFragment extends Fragment {
|
|||||||
mNewsButton.setOnClickListener(v -> Tools.openURL(requireActivity(), Tools.URL_HOME));
|
mNewsButton.setOnClickListener(v -> Tools.openURL(requireActivity(), Tools.URL_HOME));
|
||||||
mDiscordButton.setOnClickListener(v -> Tools.openURL(requireActivity(), getString(R.string.discord_invite)));
|
mDiscordButton.setOnClickListener(v -> Tools.openURL(requireActivity(), getString(R.string.discord_invite)));
|
||||||
mCustomControlButton.setOnClickListener(v -> startActivity(new Intent(requireContext(), CustomControlsActivity.class)));
|
mCustomControlButton.setOnClickListener(v -> startActivity(new Intent(requireContext(), CustomControlsActivity.class)));
|
||||||
mInstallJarButton.setOnClickListener(v -> runInstallerWithConfirmation(false));
|
if (hasOnlineProfile()) {
|
||||||
mInstallJarButton.setOnLongClickListener(v->{
|
mInstallJarButton.setOnClickListener(v -> runInstallerWithConfirmation(false));
|
||||||
runInstallerWithConfirmation(true);
|
mInstallJarButton.setOnLongClickListener(v -> {
|
||||||
return true;
|
runInstallerWithConfirmation(true);
|
||||||
});
|
return true;
|
||||||
|
});
|
||||||
|
} else mInstallJarButton.setOnClickListener(v -> hasNoOnlineProfileDialog(requireActivity()));
|
||||||
mEditProfileButton.setOnClickListener(v -> mVersionSpinner.openProfileEditor(requireActivity()));
|
mEditProfileButton.setOnClickListener(v -> mVersionSpinner.openProfileEditor(requireActivity()));
|
||||||
|
|
||||||
mPlayButton.setOnClickListener(v -> ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true));
|
mPlayButton.setOnClickListener(v -> ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true));
|
||||||
@ -65,13 +69,12 @@ public class MainMenuFragment extends Fragment {
|
|||||||
mShareLogsButton.setOnClickListener((v) -> shareLog(requireContext()));
|
mShareLogsButton.setOnClickListener((v) -> shareLog(requireContext()));
|
||||||
|
|
||||||
mOpenDirectoryButton.setOnClickListener((v)-> {
|
mOpenDirectoryButton.setOnClickListener((v)-> {
|
||||||
Tools.switchDemo(Tools.isDemoProfile(v.getContext())); // avoid switching accounts being able to access
|
if (hasOnlineProfile()) {
|
||||||
if(Tools.isDemoProfile(v.getContext())){
|
if (Tools.isDemoProfile(v.getContext())){
|
||||||
Toast.makeText(v.getContext(), R.string.toast_not_available_demo, Toast.LENGTH_LONG).show();
|
hasNoOnlineProfileDialog(getActivity(), "Demo Profile not supported", "Please change accounts to use this function");
|
||||||
return;
|
}
|
||||||
}
|
openPath(v.getContext(), getCurrentProfileDirectory(), false);
|
||||||
|
} else hasNoOnlineProfileDialog(requireActivity());
|
||||||
openPath(v.getContext(), getCurrentProfileDirectory(), false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -97,12 +100,6 @@ public class MainMenuFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void runInstallerWithConfirmation(boolean isCustomArgs) {
|
private void runInstallerWithConfirmation(boolean isCustomArgs) {
|
||||||
// avoid using custom installers to install a version
|
|
||||||
if(Tools.isLocalProfile(requireContext()) || Tools.isDemoProfile(requireContext())){
|
|
||||||
Toast.makeText(requireContext(), R.string.toast_not_available_demo, Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ProgressKeeper.getTaskCount() == 0)
|
if (ProgressKeeper.getTaskCount() == 0)
|
||||||
Tools.installMod(requireActivity(), isCustomArgs);
|
Tools.installMod(requireActivity(), isCustomArgs);
|
||||||
else
|
else
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package net.kdt.pojavlaunch.fragments;
|
package net.kdt.pojavlaunch.fragments;
|
||||||
|
|
||||||
|
import static net.kdt.pojavlaunch.Tools.hasNoOnlineProfileDialog;
|
||||||
|
import static net.kdt.pojavlaunch.Tools.hasOnlineProfile;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -42,8 +45,8 @@ public class ProfileTypeSelectFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void tryInstall(Class<? extends Fragment> fragmentClass, String tag){
|
private void tryInstall(Class<? extends Fragment> fragmentClass, String tag){
|
||||||
if(Tools.isLocalProfile(requireContext()) || Tools.isDemoProfile(requireContext())){
|
if(!hasOnlineProfile()){
|
||||||
Toast.makeText(requireContext(), R.string.toast_not_available_demo, Toast.LENGTH_LONG).show();
|
hasNoOnlineProfileDialog(requireActivity());
|
||||||
} else {
|
} else {
|
||||||
Tools.swapFragment(requireActivity(), fragmentClass, tag, null);
|
Tools.swapFragment(requireActivity(), fragmentClass, tag, null);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user