Skip to content

Commit

Permalink
Update pojav core files
Browse files Browse the repository at this point in the history
  • Loading branch information
SolDev69 committed Apr 3, 2024
2 parents af9568b + 73532d1 commit dd480ff
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Crowdin](https://badges.crowdin.net/pojavlauncher/localized.svg)](https://crowdin.com/project/pojavlauncher)
[![Discord](https://img.shields.io/discord/724163890803638273.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.com/invite/pojavlauncher-724163890803638273)
[![Twitter Follow](https://img.shields.io/twitter/follow/plaunchteam?color=blue&style=flat-square)](https://twitter.com/PLaunchTeam)
---------

* From [Boardwalk](https://github.com/zhuowei/Boardwalk)'s ashes here comes PojavLauncher!

* PojavLauncher is a launcher that allows you to play Minecraft: Java Edition on your Android device!
Expand Down
2 changes: 1 addition & 1 deletion app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ dependencies {
implementation 'com.github.PojavLauncherTeam:portrait-sdp:ed33e89cbc'
implementation 'com.github.PojavLauncherTeam:portrait-ssp:6c02fd739b'
implementation 'com.github.Mathias-Boulay:ExtendedView:1.0.0'
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:a0fe7e72f2'
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:06184ddbce'
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:2e7aa25e50'

// implementation 'com.intuit.sdp:sdp-android:1.0.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Toast;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.core.content.res.ResourcesCompat;


import net.kdt.pojavlaunch.PojavProfile;
Expand All @@ -39,6 +44,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import fr.spse.extended_view.ExtendedTextView;
Expand Down Expand Up @@ -251,7 +257,7 @@ private void reloadAccounts(boolean fromFiles, int overridePosition){
}

String[] accountArray = mAccountList.toArray(new String[0]);
ArrayAdapter<String> accountAdapter = new ArrayAdapter<>(getContext(), R.layout.item_minecraft_account, accountArray);
AccountAdapter accountAdapter = new AccountAdapter(getContext(), R.layout.item_minecraft_account, accountArray);
accountAdapter.setDropDownViewResource(R.layout.item_minecraft_account);
setAdapter(accountAdapter);

Expand Down Expand Up @@ -306,6 +312,12 @@ private void pickAccount(int position){
}

mSelectecAccount = selectedAccount;
setImageFromSelectedAccount();
}

@Deprecated()
/* Legacy behavior, update the head image manually for the selected account */
private void setImageFromSelectedAccount(){
BitmapDrawable oldBitmapDrawable = mHeadDrawable;

if(mSelectecAccount != null){
Expand All @@ -314,21 +326,54 @@ private void pickAccount(int position){
Bitmap bitmap = mSelectecAccount.getSkinFace();
if(bitmap != null) {
mHeadDrawable = new BitmapDrawable(getResources(), bitmap);
mHeadDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());

view.setCompoundDrawables(mHeadDrawable, null, null, null);
view.postProcessDrawables();
}else{
view.setCompoundDrawables(null, null, null, null);
view.postProcessDrawables();
}
view.postProcessDrawables();
}
}

if(oldBitmapDrawable != null){
oldBitmapDrawable.getBitmap().recycle();
}
}


private static class AccountAdapter extends ArrayAdapter<String> {

private final HashMap<String, Drawable> mImageCache = new HashMap<>();
public AccountAdapter(@NonNull Context context, int resource, @NonNull String[] objects) {
super(context, resource, objects);
}

@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getView(position, convertView, parent);
}

@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
if(convertView == null){
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_minecraft_account, parent, false);
}
ExtendedTextView textview = (ExtendedTextView) convertView;
textview.setText(super.getItem(position));

// Handle the "Add account section"
if(position == 0) textview.setCompoundDrawables(ResourcesCompat.getDrawable(parent.getResources(), R.drawable.ic_add, null), null, null, null);
else {
String username = super.getItem(position);
Drawable accountHead = mImageCache.get(username);
if (accountHead == null){
accountHead = new BitmapDrawable(parent.getResources(), MinecraftAccount.getSkinFace(username));
mImageCache.put(username, accountHead);
}
textview.setCompoundDrawables(accountHead, null, null, null);
}
return convertView;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void openProfileEditor(FragmentActivity fragmentActivity) {
if(currentSelection instanceof ProfileAdapterExtra) {
performExtraAction((ProfileAdapterExtra) currentSelection);
}else{
Tools.swapFragment(fragmentActivity, ProfileEditorFragment.class, ProfileEditorFragment.TAG, true, null);
Tools.swapFragment(fragmentActivity, ProfileEditorFragment.class, ProfileEditorFragment.TAG, null);
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ private void performExtraAction(ProfileAdapterExtra extra) {
//Replace with switch-case if you want to add more extra actions
if (extra.id == VERSION_SPINNER_PROFILE_CREATE) {
Tools.swapFragment((FragmentActivity) getContext(), ProfileTypeSelectFragment.class,
ProfileTypeSelectFragment.TAG, true, null);
ProfileTypeSelectFragment.TAG, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,18 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f)
// Allow starting the add account only from the main menu, should it be moved to fragment itself ?
if(!(fragment instanceof MainMenuFragment)) return false;

Tools.swapFragment(this, SelectAuthFragment.class, SelectAuthFragment.TAG, true, null);
Tools.swapFragment(this, SelectAuthFragment.class, SelectAuthFragment.TAG, null);
return false;
};

/* Listener for the settings fragment */
private final View.OnClickListener mSettingButtonListener = v -> {
Fragment fragment = getSupportFragmentManager().findFragmentById(mFragmentView.getId());
if(fragment instanceof MainMenuFragment){
Tools.swapFragment(this, LauncherPreferenceFragment.class, SETTING_FRAGMENT_TAG, true, null);
Tools.swapFragment(this, LauncherPreferenceFragment.class, SETTING_FRAGMENT_TAG, null);
} else{
// The setting button doubles as a home button now
while(!(getSupportFragmentManager().findFragmentById(mFragmentView.getId()) instanceof MainMenuFragment)){
getSupportFragmentManager().popBackStackImmediate();
}
Tools.backToMainMenu(this);
}
};

Expand Down Expand Up @@ -159,6 +157,11 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pojav_launcher);
this.getSupportFragmentManager().beginTransaction()
.setReorderingAllowed(true)
.addToBackStack("ROOT")
.replace(R.id.container_fragment, MainMenuFragment.class, null, "ROOT").commit();

IconCacheJanitor.runJanitor();
mRequestNotificationPermissionLauncher = registerForActivityResult(
new ActivityResultContracts.RequestPermission(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void onCreate() {

try {
super.onCreate();
Tools.APP_NAME = getResources().getString(R.string.app_short_name);

Tools.DIR_DATA = getDir("files", MODE_PRIVATE).getParent();
Tools.DIR_CACHE = getCacheDir();
Expand Down
63 changes: 34 additions & 29 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import androidx.core.app.NotificationManagerCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -94,7 +93,7 @@
public final class Tools {
public static final float BYTE_TO_MB = 1024 * 1024;
public static final Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
public static String APP_NAME = "null";
public static String APP_NAME = "PojavLauncher";

public static final Gson GLOBAL_GSON = new GsonBuilder().setPrettyPrinting().create();

Expand Down Expand Up @@ -757,31 +756,34 @@ public static JMinecraftVersionList.Version getVersionInfo(String versionName, b
"releaseTime", "time", "type"
);

List<DependentLibrary> libList = new ArrayList<>(Arrays.asList(inheritsVer.libraries));
try {
loop_1:
for (DependentLibrary lib : customVer.libraries) {
String libName = lib.name.substring(0, lib.name.lastIndexOf(":"));
for (int i = 0; i < libList.size(); i++) {
DependentLibrary libAdded = libList.get(i);
String libAddedName = libAdded.name.substring(0, libAdded.name.lastIndexOf(":"));

if (libAddedName.equals(libName)) {
Log.d(APP_NAME, "Library " + libName + ": Replaced version " +
libName.substring(libName.lastIndexOf(":") + 1) + " with " +
libAddedName.substring(libAddedName.lastIndexOf(":") + 1));
libList.set(i, lib);
continue loop_1;
}
}
// Go through the libraries, remove the ones overridden by the custom version
List<DependentLibrary> inheritLibraryList = new ArrayList<>(Arrays.asList(inheritsVer.libraries));
outer_loop:
for(DependentLibrary library : customVer.libraries){
// Clean libraries overridden by the custom version
String libName = library.name.substring(0, library.name.lastIndexOf(":"));

for(DependentLibrary inheritLibrary : inheritLibraryList) {
String inheritLibName = inheritLibrary.name.substring(0, inheritLibrary.name.lastIndexOf(":"));

if(libName.equals(inheritLibName)){
Log.d(APP_NAME, "Library " + libName + ": Replaced version " +
libName.substring(libName.lastIndexOf(":") + 1) + " with " +
inheritLibName.substring(inheritLibName.lastIndexOf(":") + 1));

libList.add(0, lib);
// Remove the library , superseded by the overriding libs
inheritLibraryList.remove(inheritLibrary);
continue outer_loop;
}
}
} finally {
inheritsVer.libraries = libList.toArray(new DependentLibrary[0]);
preProcessLibraries(inheritsVer.libraries);
}

// Fuse libraries
inheritLibraryList.addAll(Arrays.asList(customVer.libraries));
inheritsVer.libraries = inheritLibraryList.toArray(new DependentLibrary[0]);
preProcessLibraries(inheritsVer.libraries);


// Inheriting Minecraft 1.13+ with append custom args
if (inheritsVer.arguments != null && customVer.arguments != null) {
List totalArgList = new ArrayList(Arrays.asList(inheritsVer.arguments.game));
Expand Down Expand Up @@ -940,20 +942,23 @@ public static String getFileName(Context ctx, Uri uri) {

/** Swap the main fragment with another */
public static void swapFragment(FragmentActivity fragmentActivity , Class<? extends Fragment> fragmentClass,
@Nullable String fragmentTag, boolean addCurrentToBackstack, @Nullable Bundle bundle) {
@Nullable String fragmentTag, @Nullable Bundle bundle) {
// When people tab out, it might happen
//TODO handle custom animations
FragmentTransaction transaction = fragmentActivity.getSupportFragmentManager().beginTransaction()
fragmentActivity.getSupportFragmentManager().beginTransaction()
.setReorderingAllowed(true)
.replace(R.id.container_fragment, fragmentClass, bundle, fragmentTag);
if(addCurrentToBackstack) transaction.addToBackStack(null);
.addToBackStack(fragmentClass.getName())
.replace(R.id.container_fragment, fragmentClass, bundle, fragmentTag).commit();
}

transaction.commit();
public static void backToMainMenu(FragmentActivity fragmentActivity) {
fragmentActivity.getSupportFragmentManager()
.popBackStack("ROOT", 0);
}

/** Remove the current fragment */
public static void removeCurrentFragment(FragmentActivity fragmentActivity){
fragmentActivity.getSupportFragmentManager().popBackStackImmediate();
fragmentActivity.getSupportFragmentManager().popBackStack();
}

public static void installMod(Activity activity, boolean customJavaArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
ExtraCore.setValue(ExtraConstants.MOJANG_LOGIN_TODO, new String[]{
mUsernameEditText.getText().toString(), "" });

Tools.swapFragment(requireActivity(), MainMenuFragment.class, MainMenuFragment.TAG, false, null);
Tools.swapFragment(requireActivity(), MainMenuFragment.class, MainMenuFragment.TAG, null);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper;
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;

public class MainMenuFragment extends Fragment {
public static final String TAG = "MainMenuFragment";
Expand Down Expand Up @@ -57,7 +56,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mShareLogsButton.setOnClickListener((v) -> shareLog(requireContext()));

mNewsButton.setOnLongClickListener((v)->{
Tools.swapFragment(requireActivity(), SearchModFragment.class, SearchModFragment.TAG, true, null);
Tools.swapFragment(requireActivity(), SearchModFragment.class, SearchModFragment.TAG, null);
return true;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Should be captured by the activity to kill the fragment and get
ExtraCore.setValue(ExtraConstants.MICROSOFT_LOGIN_TODO, Uri.parse(url));
Toast.makeText(view.getContext(), "Login started !", Toast.LENGTH_SHORT).show();
Tools.removeCurrentFragment(requireActivity());
Tools.backToMainMenu(requireActivity());

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mSaveButton.setOnClickListener(v -> {
ProfileIconCache.dropIcon(mProfileKey);
save();
Tools.removeCurrentFragment(requireActivity());
Tools.backToMainMenu(requireActivity());
});

mDeleteButton.setOnClickListener(v -> {
Expand All @@ -115,15 +115,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mValueToConsume = FileSelectorFragment.BUNDLE_SELECT_FOLDER;

Tools.swapFragment(requireActivity(),
FileSelectorFragment.class, FileSelectorFragment.TAG, true, bundle);
FileSelectorFragment.class, FileSelectorFragment.TAG, bundle);
});

mControlSelectButton.setOnClickListener(v -> {
Bundle bundle = new Bundle(3);
bundle.putBoolean(FileSelectorFragment.BUNDLE_SELECT_FOLDER, false);
bundle.putString(FileSelectorFragment.BUNDLE_ROOT_PATH, Tools.CTRLMAP_PATH);
Tools.swapFragment(requireActivity(),
FileSelectorFragment.class, FileSelectorFragment.TAG, true, bundle);
FileSelectorFragment.class, FileSelectorFragment.TAG, bundle);
});

// Setup the expendable list behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public ProfileTypeSelectFragment() {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.vanilla_profile).setOnClickListener(v -> Tools.swapFragment(requireActivity(), ProfileEditorFragment.class,
ProfileEditorFragment.TAG, false, new Bundle(1)));
ProfileEditorFragment.TAG, new Bundle(1)));

// NOTE: Special care needed! If you wll decide to add these to the back stack, please read
// the comment in FabricInstallFragment.onDownloadFinished() and amend the code
// in FabricInstallFragment.onDownloadFinished() and ModVersionListFragment.onDownloadFinished()
view.findViewById(R.id.optifine_profile).setOnClickListener(v -> Tools.swapFragment(requireActivity(), OptiFineInstallFragment.class,
OptiFineInstallFragment.TAG, false, null));
OptiFineInstallFragment.TAG, null));
view.findViewById(R.id.modded_profile_fabric).setOnClickListener((v)->
Tools.swapFragment(requireActivity(), FabricInstallFragment.class, FabricInstallFragment.TAG, false, null));
Tools.swapFragment(requireActivity(), FabricInstallFragment.class, FabricInstallFragment.TAG, null));
view.findViewById(R.id.modded_profile_forge).setOnClickListener((v)->
Tools.swapFragment(requireActivity(), ForgeInstallFragment.class, ForgeInstallFragment.TAG, false, null));
Tools.swapFragment(requireActivity(), ForgeInstallFragment.class, ForgeInstallFragment.TAG, null));
view.findViewById(R.id.modded_profile_modpack).setOnClickListener((v)->
Tools.swapFragment(requireActivity(), SearchModFragment.class, SearchModFragment.TAG, false, null));
Tools.swapFragment(requireActivity(), SearchModFragment.class, SearchModFragment.TAG, null));
view.findViewById(R.id.modded_profile_quilt).setOnClickListener((v)->
Tools.swapFragment(requireActivity(), QuiltInstallFragment.class, QuiltInstallFragment.TAG, false, null));
Tools.swapFragment(requireActivity(), QuiltInstallFragment.class, QuiltInstallFragment.TAG, null));
}
}
Loading

0 comments on commit dd480ff

Please sign in to comment.