Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package net.kdt.pojavlaunch.fragments;

import static net.kdt.pojavlaunch.Tools.dialogOnUiThread;
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.runOnUiThread;
import static net.kdt.pojavlaunch.Tools.shareLog;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
Expand All @@ -17,7 +14,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;

import com.kdt.mcgui.mcVersionSpinner;
Expand All @@ -39,63 +35,93 @@ public class MainMenuFragment extends Fragment {

private mcVersionSpinner mVersionSpinner;

public MainMenuFragment(){
public MainMenuFragment() {
super(R.layout.fragment_launcher);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Button mNewsButton = view.findViewById(R.id.news_button);
Button mDiscordButton = view.findViewById(R.id.discord_button);
Button mCustomControlButton = view.findViewById(R.id.custom_control_button);
Button mInstallJarButton = view.findViewById(R.id.install_jar_button);
Button mShareLogsButton = view.findViewById(R.id.share_logs_button);
Button mOpenDirectoryButton = view.findViewById(R.id.open_files_button);
Button mNewsButton = view.findViewById(R.id.news_button);
Button mDiscordButton = view.findViewById(R.id.discord_button);
Button mCustomControlButton = view.findViewById(R.id.custom_control_button);
Button mInstallJarButton = view.findViewById(R.id.install_jar_button);
Button mShareLogsButton = view.findViewById(R.id.share_logs_button);
Button mManageModsButton = view.findViewById(R.id.open_files_button);
Button mOpenDirectoryButton = view.findViewById(R.id.open_directory_button);
Button mModStoreButton = view.findViewById(R.id.mod_store_button);

ImageButton mEditProfileButton = view.findViewById(R.id.edit_profile_button);
Button mPlayButton = view.findViewById(R.id.play_button);
mVersionSpinner = view.findViewById(R.id.mc_version_spinner);

// Wiki
mNewsButton.setOnClickListener(v -> Tools.openURL(requireActivity(), Tools.URL_HOME));

// Discord
mDiscordButton.setOnClickListener(v -> Tools.openURL(requireActivity(), getString(R.string.discord_invite)));
mCustomControlButton.setOnClickListener(v -> startActivity(new Intent(requireContext(), CustomControlsActivity.class)));

// Custom controls
mCustomControlButton.setOnClickListener(v ->
startActivity(new Intent(requireContext(), CustomControlsActivity.class)));

// Mod Store → individual mod search
if (mModStoreButton != null)
mModStoreButton.setOnClickListener(v ->
Tools.swapFragment(requireActivity(), ModsSearchFragment.class, ModsSearchFragment.TAG, null));

// Execute .jar
if (hasOnlineProfile()) {
mInstallJarButton.setOnClickListener(v -> runInstallerWithConfirmation(false));
mInstallJarButton.setOnLongClickListener(v -> {
runInstallerWithConfirmation(true);
return true;
});
} else mInstallJarButton.setOnClickListener(v -> hasNoOnlineProfileDialog(requireActivity()));
mEditProfileButton.setOnClickListener(v -> mVersionSpinner.openProfileEditor(requireActivity()));

mPlayButton.setOnClickListener(v -> {
ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true);
});

mShareLogsButton.setOnClickListener((v) -> shareLog(requireContext()));

mOpenDirectoryButton.setOnClickListener((v)-> {
if (Tools.isDemoProfile(v.getContext())){ // Say a different message when on demo profile since they might see the hidden demo folder
hasNoOnlineProfileDialog(getActivity(), getString(R.string.demo_unsupported), getString(R.string.change_account));
} else if (!hasOnlineProfile()) { // Otherwise display the generic pop-up to log in
hasNoOnlineProfileDialog(requireActivity());
} else openPath(v.getContext(), getCurrentProfileDirectory(), false);
} else {
mInstallJarButton.setOnClickListener(v -> hasNoOnlineProfileDialog(requireActivity()));
}

// Share logs
if (mShareLogsButton != null)
mShareLogsButton.setOnClickListener(v -> shareLog(requireContext()));

// Manage Mods & Tools → new UI
mManageModsButton.setOnClickListener(v ->
Tools.swapFragment(requireActivity(), ManageModsFragment.class, ManageModsFragment.TAG, null));

// Open game directory (original behaviour)
if (mOpenDirectoryButton != null) {
mOpenDirectoryButton.setOnClickListener(v -> {
if (Tools.isDemoProfile(v.getContext())) {
hasNoOnlineProfileDialog(getActivity(),
getString(R.string.demo_unsupported), getString(R.string.change_account));
} else if (!hasOnlineProfile()) {
hasNoOnlineProfileDialog(requireActivity());
} else {
openPath(v.getContext(), getCurrentProfileDirectory(), false);
}
});
}

});
// Edit profile
mEditProfileButton.setOnClickListener(v -> mVersionSpinner.openProfileEditor(requireActivity()));

// Play
mPlayButton.setOnClickListener(v -> ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true));

mNewsButton.setOnLongClickListener((v)->{
// Long-press wiki → gamepad mapper (hidden)
mNewsButton.setOnLongClickListener(v -> {
Tools.swapFragment(requireActivity(), GamepadMapperFragment.class, GamepadMapperFragment.TAG, null);
return true;
});
}

private File getCurrentProfileDirectory() {
String currentProfile = LauncherPreferences.DEFAULT_PREF.getString(LauncherPreferences.PREF_KEY_CURRENT_PROFILE, null);
if(!Tools.isValidString(currentProfile)) return new File(Tools.DIR_GAME_NEW);
String currentProfile = LauncherPreferences.DEFAULT_PREF
.getString(LauncherPreferences.PREF_KEY_CURRENT_PROFILE, null);
if (!Tools.isValidString(currentProfile)) return new File(Tools.DIR_GAME_NEW);
LauncherProfiles.load();
MinecraftProfile profileObject = LauncherProfiles.mainProfileJson.profiles.get(currentProfile);
if(profileObject == null) return new File(Tools.DIR_GAME_NEW);
if (profileObject == null) return new File(Tools.DIR_GAME_NEW);
return Tools.getGameDirPath(profileObject);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package net.kdt.pojavlaunch.fragments;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.fragments.ModsSearchFragment;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.modloaders.InstalledModAdapter;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;

import java.io.File;

public class ManageModsFragment extends Fragment {

public static final String TAG = "ManageModsFragment";

public ManageModsFragment() {
super(R.layout.fragment_manage_mods);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
ImageButton backButton = view.findViewById(R.id.manage_mods_back);
ImageButton addButton = view.findViewById(R.id.manage_mods_add);
TextView title = view.findViewById(R.id.manage_mods_title);
RecyclerView recycler = view.findViewById(R.id.manage_mods_recycler);
View emptyState = view.findViewById(R.id.manage_mods_empty);

// Back
backButton.setOnClickListener(v -> Tools.removeCurrentFragment(requireActivity()));

// Add → open mod store
addButton.setOnClickListener(v ->
Tools.swapFragment(requireActivity(), ModsSearchFragment.class, ModsSearchFragment.TAG, null));

// Title: "ProfileName - Mods"
String profileName = getCurrentProfileName();
title.setText(profileName.isEmpty()
? getString(R.string.mcl_button_manage_mods)
: profileName + " - Mods");

// Build mod list
File modsDir = getModsDir();
InstalledModAdapter adapter = new InstalledModAdapter(modsDir, isEmpty -> {
recycler.setVisibility(isEmpty ? View.GONE : View.VISIBLE);
emptyState.setVisibility(isEmpty ? View.VISIBLE : View.GONE);
});

recycler.setLayoutManager(new LinearLayoutManager(requireContext()));
recycler.setAdapter(adapter);
}

// ── Helpers ─────────────────────────────────────────────────────────────

private String getCurrentProfileName() {
try {
String key = LauncherPreferences.DEFAULT_PREF
.getString(LauncherPreferences.PREF_KEY_CURRENT_PROFILE, null);
if (key == null || key.isEmpty()) return "";
LauncherProfiles.load();
MinecraftProfile profile = LauncherProfiles.mainProfileJson.profiles.get(key);
if (profile == null) return "";
return profile.name != null ? profile.name : key;
} catch (Exception e) {
return "";
}
}

private File getModsDir() {
try {
String key = LauncherPreferences.DEFAULT_PREF
.getString(LauncherPreferences.PREF_KEY_CURRENT_PROFILE, null);
if (key != null && !key.isEmpty()) {
LauncherProfiles.load();
MinecraftProfile profile = LauncherProfiles.mainProfileJson.profiles.get(key);
if (profile != null) {
File gameDir = Tools.getGameDirPath(profile);
return new File(gameDir, "mods");
}
}
} catch (Exception ignored) {}
return new File(Tools.DIR_GAME_NEW, "mods");
}
}
Loading
Loading