mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 07:05:40 -04:00
Fix[profiles]: properly reload profiles on resume
This commit is contained in:
parent
b8e3b2a6f9
commit
b23787e5a4
@ -77,6 +77,11 @@ public class mcVersionSpinner extends ExtendedTextView {
|
||||
mProfileAdapter.setViewProfile(this, (String) mProfileAdapter.getItem(position), false);
|
||||
}
|
||||
|
||||
/** Reload profiles from the file, forcing the spinner to consider the new data */
|
||||
public void reloadProfiles(){
|
||||
mProfileAdapter.reloadProfiles();
|
||||
}
|
||||
|
||||
/** Initialize various behaviors */
|
||||
private void init(){
|
||||
// Setup various attributes
|
||||
|
@ -13,6 +13,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.kdt.mcgui.mcVersionSpinner;
|
||||
|
||||
import net.kdt.pojavlaunch.CustomControlsActivity;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
@ -24,6 +26,8 @@ import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
|
||||
public class MainMenuFragment extends Fragment {
|
||||
public static final String TAG = "MainMenuFragment";
|
||||
|
||||
private mcVersionSpinner mVersionSpinner;
|
||||
|
||||
public MainMenuFragment(){
|
||||
super(R.layout.fragment_launcher);
|
||||
}
|
||||
@ -37,6 +41,7 @@ public class MainMenuFragment extends Fragment {
|
||||
|
||||
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);
|
||||
|
||||
mNewsButton.setOnClickListener(v -> Tools.openURL(requireActivity(), Tools.URL_HOME));
|
||||
mCustomControlButton.setOnClickListener(v -> startActivity(new Intent(requireContext(), CustomControlsActivity.class)));
|
||||
@ -60,7 +65,7 @@ public class MainMenuFragment extends Fragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
LauncherProfiles.load();
|
||||
mVersionSpinner.reloadProfiles();
|
||||
}
|
||||
|
||||
private void runInstallerWithConfirmation(boolean isCustomArgs) {
|
||||
|
@ -31,15 +31,11 @@ public class ProfileAdapter extends BaseAdapter {
|
||||
private Map<String, MinecraftProfile> mProfiles;
|
||||
private final MinecraftProfile dummy = new MinecraftProfile();
|
||||
private List<String> mProfileList;
|
||||
private final ProfileAdapterExtra[] mExtraEntires;
|
||||
private ProfileAdapterExtra[] mExtraEntires;
|
||||
|
||||
public ProfileAdapter(Context context, ProfileAdapterExtra[] extraEntries) {
|
||||
ProfileIconCache.initDefault(context);
|
||||
LauncherProfiles.load();
|
||||
mProfiles = new HashMap<>(LauncherProfiles.mainProfileJson.profiles);
|
||||
if(extraEntries == null) mExtraEntires = new ProfileAdapterExtra[0];
|
||||
else mExtraEntires = extraEntries;
|
||||
mProfileList = new ArrayList<>(Arrays.asList(mProfiles.keySet().toArray(new String[0])));
|
||||
reloadProfiles(extraEntries);
|
||||
}
|
||||
/*
|
||||
* Gets how much profiles are loaded in the adapter right now
|
||||
@ -67,6 +63,8 @@ public class ProfileAdapter extends BaseAdapter {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int resolveProfileIndex(String name) {
|
||||
return mProfileList.indexOf(name);
|
||||
}
|
||||
@ -134,4 +132,19 @@ public class ProfileAdapter extends BaseAdapter {
|
||||
extendedTextView.setText(extra.name);
|
||||
extendedTextView.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
/** Reload profiles from the file */
|
||||
public void reloadProfiles(){
|
||||
LauncherProfiles.load();
|
||||
mProfiles = new HashMap<>(LauncherProfiles.mainProfileJson.profiles);
|
||||
mProfileList = new ArrayList<>(Arrays.asList(mProfiles.keySet().toArray(new String[0])));
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/** Reload profiles from the file, with additional extra entries */
|
||||
public void reloadProfiles(ProfileAdapterExtra[] extraEntries) {
|
||||
if(extraEntries == null) mExtraEntires = new ProfileAdapterExtra[0];
|
||||
else mExtraEntires = extraEntries;
|
||||
this.reloadProfiles();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user