mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-20 13:30:15 -07:00
- Migrated from viewPager to viewPager2
- Implemented new settings screens - Removed Context out of logging functions - W.I.P Streamlining the UI, a few things are broken rn
This commit is contained in:
parent
5812761838
commit
71e39273c9
8 changed files with 186 additions and 2743 deletions
|
|
@ -1,5 +1,10 @@
|
|||
package net.kdt.pojavlaunch;
|
||||
|
||||
import static android.os.Build.VERSION_CODES.P;
|
||||
import static net.kdt.pojavlaunch.Tools.ignoreNotch;
|
||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_HIDE_SIDEBAR;
|
||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
|
|
@ -8,7 +13,6 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.design.widget.VerticalTabLayout.ViewPagerAdapter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
|
@ -19,54 +23,72 @@ import android.widget.Spinner;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.constraintlayout.widget.Guideline;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import net.kdt.pojavlaunch.extra.ExtraCore;
|
||||
import net.kdt.pojavlaunch.extra.ExtraListener;
|
||||
import net.kdt.pojavlaunch.fragments.ConsoleFragment;
|
||||
import net.kdt.pojavlaunch.fragments.CrashFragment;
|
||||
import net.kdt.pojavlaunch.fragments.LauncherFragment;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferenceFragment;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment;
|
||||
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.os.Build.VERSION_CODES.P;
|
||||
import static net.kdt.pojavlaunch.Tools.ignoreNotch;
|
||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_HIDE_SIDEBAR;
|
||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
|
||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
|
||||
|
||||
public class PojavLauncherActivity extends BaseLauncherActivity
|
||||
{
|
||||
|
||||
private ViewPager viewPager;
|
||||
// An equivalent ViewPager2 adapter class
|
||||
private static class ScreenSlidePagerAdapter extends FragmentStateAdapter {
|
||||
public ScreenSlidePagerAdapter(FragmentActivity fa) {
|
||||
super(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
if (position == 0) return new LauncherFragment();
|
||||
if (position == 1) return new ConsoleFragment();
|
||||
if (position == 2) return new CrashFragment();
|
||||
if (position == 3) return new LauncherPreferenceFragment();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private TextView tvConnectStatus;
|
||||
private Spinner accountSelector;
|
||||
private ViewPagerAdapter viewPageAdapter;
|
||||
private ViewPager2 viewPager;
|
||||
private final Button[] Tabs = new Button[4];
|
||||
private View selected;
|
||||
private View selectedTab;
|
||||
private ImageView accountFaceImageView;
|
||||
|
||||
private Button logoutBtn; // MineButtons
|
||||
private ExtraListener backPreferenceListener;
|
||||
|
||||
public PojavLauncherActivity() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.launcher_main_v4);
|
||||
|
||||
//Boilerplate linking/initialisation
|
||||
viewPager = findViewById(R.id.launchermainTabPager);
|
||||
selected = findViewById(R.id.viewTabSelected);
|
||||
selectedTab = findViewById(R.id.viewTabSelected);
|
||||
tvConnectStatus = findViewById(R.id.launchermain_text_accountstatus);
|
||||
accountFaceImageView = findViewById(R.id.launchermain_account_image);
|
||||
accountSelector = findViewById(R.id.launchermain_spinner_account);
|
||||
|
|
@ -85,48 +107,46 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
|||
Toast.makeText(this, "Launcher process id: " + android.os.Process.myPid(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
mConsoleView = new ConsoleFragment();
|
||||
mCrashView = new CrashFragment();
|
||||
|
||||
viewPageAdapter = new ViewPagerAdapter(getSupportFragmentManager());
|
||||
viewPageAdapter.addFragment(new LauncherFragment(), 0, getString(R.string.mcl_tab_news));
|
||||
viewPageAdapter.addFragment(mConsoleView, 0, getString(R.string.mcl_tab_console));
|
||||
viewPageAdapter.addFragment(mCrashView, 0, getString(R.string.mcl_tab_crash));
|
||||
viewPageAdapter.addFragment(new LauncherPreferenceFragment(), 0, getString(R.string.mcl_option_settings));
|
||||
|
||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
// Setup the viewPager to slide across fragments
|
||||
viewPager.setAdapter(new ScreenSlidePagerAdapter(this));
|
||||
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
setTabActive(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels){}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {}
|
||||
});
|
||||
viewPager.setAdapter(viewPageAdapter);
|
||||
initTabs(0);
|
||||
|
||||
//Setup listener to the backPreference system
|
||||
backPreferenceListener = new ExtraListener() {
|
||||
@Override
|
||||
public boolean onValueSet(String key, String value) {
|
||||
if(value.equals("true")){
|
||||
onBackPressed();
|
||||
ExtraCore.setValue(key, "false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
ExtraCore.addExtraListener("back_preference", backPreferenceListener);
|
||||
|
||||
|
||||
pickAccount();
|
||||
|
||||
|
||||
final List<String> accountList = new ArrayList<String>();
|
||||
final MinecraftAccount tempProfile = PojavProfile.getTempProfileContent(this);
|
||||
// Try to load the temporary account
|
||||
final List<String> accountList = new ArrayList<>();
|
||||
final MinecraftAccount tempProfile = PojavProfile.getTempProfileContent();
|
||||
if (tempProfile != null) {
|
||||
accountList.add(tempProfile.username);
|
||||
}
|
||||
for (String s : new File(Tools.DIR_ACCOUNT_NEW).list()) {
|
||||
accountList.add(s.substring(0, s.length() - 5));
|
||||
}
|
||||
|
||||
|
||||
// Setup account spinner
|
||||
pickAccount();
|
||||
ArrayAdapter<String> adapterAcc = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, accountList);
|
||||
adapterAcc.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
|
||||
|
||||
//TODO AUTHENTICATION WHEN CHANGING ACCOUNT
|
||||
//TODO SHOW ACCOUNT IMAGE IF AVAILABLE
|
||||
accountSelector.setAdapter(adapterAcc);
|
||||
|
||||
if (tempProfile != null) {
|
||||
accountSelector.setSelection(0);
|
||||
} else {
|
||||
|
|
@ -155,7 +175,8 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
|||
// TODO: Implement this method
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Setup the minecraft version list
|
||||
List<String> versions = new ArrayList<>();
|
||||
final File fVers = new File(Tools.DIR_HOME_VERSION);
|
||||
|
||||
|
|
@ -183,7 +204,6 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
|||
|
||||
statusIsLaunching(false);
|
||||
|
||||
initTabs(0);
|
||||
|
||||
//Add the preference changed listener
|
||||
LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> {
|
||||
|
|
@ -247,9 +267,9 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
|||
Tabs[index].setTextColor(Color.WHITE);
|
||||
|
||||
//Animating the white bar on the left
|
||||
ValueAnimator animation = ValueAnimator.ofFloat(selected.getY(), Tabs[index].getY()+(Tabs[index].getHeight()-selected.getHeight())/2f);
|
||||
ValueAnimator animation = ValueAnimator.ofFloat(selectedTab.getY(), Tabs[index].getY()+(Tabs[index].getHeight()- selectedTab.getHeight())/2f);
|
||||
animation.setDuration(250);
|
||||
animation.addUpdateListener(animation1 -> selected.setY((float) animation1.getAnimatedValue()));
|
||||
animation.addUpdateListener(animation1 -> selectedTab.setY((float) animation1.getAnimatedValue()));
|
||||
animation.start();
|
||||
}
|
||||
|
||||
|
|
@ -272,7 +292,7 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
|||
guideLine.setLayoutParams(params);
|
||||
|
||||
//Remove the selected Tab and the head image
|
||||
selected.setVisibility(View.GONE);
|
||||
selectedTab.setVisibility(View.GONE);
|
||||
accountFaceImageView.setVisibility(View.GONE);
|
||||
|
||||
//Enlarge the button, but just a bit.
|
||||
|
|
@ -285,7 +305,7 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
|||
guideLine.setLayoutParams(params);
|
||||
|
||||
//Show the selected Tab
|
||||
selected.setVisibility(View.VISIBLE);
|
||||
selectedTab.setVisibility(View.VISIBLE);
|
||||
accountFaceImageView.setVisibility(View.VISIBLE);
|
||||
|
||||
//Set the default button size
|
||||
|
|
@ -310,5 +330,22 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom back stack system. Use the classic backstack when the focus is on the setting screen,
|
||||
* finish the activity and remove the back_preference listener otherwise
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
int count = getSupportFragmentManager().getBackStackEntryCount();
|
||||
|
||||
if (count == 0 && viewPager.getCurrentItem() == 3) {
|
||||
super.onBackPressed();
|
||||
//additional code
|
||||
ExtraCore.removeExtraListener("back_preference", backPreferenceListener);
|
||||
finish();
|
||||
} else {
|
||||
getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue