1.Tab layout
This commit is contained in:
parent
d4e291e22e
commit
a55ad194eb
|
@ -63,7 +63,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private AppBarConfiguration mAppBarConfiguration;
|
private AppBarConfiguration mAppBarConfiguration;
|
||||||
|
|
||||||
@BindView(R.id.launch)
|
@BindView(R.id.launch)
|
||||||
FloatingActionButton buttonLaunch;
|
public FloatingActionButton buttonLaunch;
|
||||||
|
|
||||||
@BindView(R.id.toolbar)
|
@BindView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
|
@ -74,7 +74,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
@BindView(R.id.nav_view)
|
@BindView(R.id.nav_view)
|
||||||
NavigationView navigationView;
|
NavigationView navigationView;
|
||||||
|
|
||||||
private int currentFragment = R.id.nav_install;
|
private int currentFragment = R.id.nav_main;
|
||||||
|
|
||||||
|
public static MainActivity instance;
|
||||||
|
|
||||||
private void requestPermissions() {
|
private void requestPermissions() {
|
||||||
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||||
|
@ -98,6 +100,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
instance = this;
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
AppConfig appConfig = ConfigUtils.getConfig((MainApplication) this.getApplication(), AppConfigKey.PRIVACY_POLICY_CONFIRM, false);
|
AppConfig appConfig = ConfigUtils.getConfig((MainApplication) this.getApplication(), AppConfigKey.PRIVACY_POLICY_CONFIRM, false);
|
||||||
|
@ -122,7 +125,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
// Passing each menu ID as a set of Ids because each
|
// Passing each menu ID as a set of Ids because each
|
||||||
// menu should be considered as top level destinations.
|
// menu should be considered as top level destinations.
|
||||||
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
||||||
R.id.nav_install, R.id.nav_config, R.id.nav_help, R.id.nav_download, R.id.nav_about)
|
R.id.nav_main, R.id.nav_config, R.id.nav_help, R.id.nav_download, R.id.nav_about)
|
||||||
.setOpenableLayout(drawer)
|
.setOpenableLayout(drawer)
|
||||||
.build();
|
.build();
|
||||||
final NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
final NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||||
|
@ -406,5 +409,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
DialogUtils.dismissDialog();
|
DialogUtils.dismissDialog();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFloatingBarVisibility(boolean value) {
|
||||||
|
buttonLaunch.setVisibility(value ? View.VISIBLE: View.INVISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ import com.zane.smapiinstaller.constant.DialogAction;
|
||||||
import com.zane.smapiinstaller.logic.ApkPatcher;
|
import com.zane.smapiinstaller.logic.ApkPatcher;
|
||||||
import com.zane.smapiinstaller.logic.CommonLogic;
|
import com.zane.smapiinstaller.logic.CommonLogic;
|
||||||
import com.zane.smapiinstaller.logic.ModAssetsManager;
|
import com.zane.smapiinstaller.logic.ModAssetsManager;
|
||||||
|
import com.zane.smapiinstaller.ui.main.MainTabsFragment;
|
||||||
|
import com.zane.smapiinstaller.ui.main.MainTabsFragmentDirections;
|
||||||
import com.zane.smapiinstaller.utils.ConfigUtils;
|
import com.zane.smapiinstaller.utils.ConfigUtils;
|
||||||
import com.zane.smapiinstaller.utils.DialogUtils;
|
import com.zane.smapiinstaller.utils.DialogUtils;
|
||||||
|
|
||||||
|
@ -128,7 +130,7 @@ public class InstallFragment extends Fragment {
|
||||||
DialogUtils.showConfirmDialog(root, R.string.error, StringUtils.firstNonBlank(patcher.getErrorMessage().get(), context.getString(R.string.failed_to_patch_game)), R.string.menu_download, R.string.cancel, (d, which) -> {
|
DialogUtils.showConfirmDialog(root, R.string.error, StringUtils.firstNonBlank(patcher.getErrorMessage().get(), context.getString(R.string.failed_to_patch_game)), R.string.menu_download, R.string.cancel, (d, which) -> {
|
||||||
if (which == DialogAction.POSITIVE) {
|
if (which == DialogAction.POSITIVE) {
|
||||||
NavController controller = Navigation.findNavController(installButton);
|
NavController controller = Navigation.findNavController(installButton);
|
||||||
controller.navigate(InstallFragmentDirections.actionNavInstallToNavDownload());
|
controller.navigate(MainTabsFragmentDirections.actionNavMainToNavDownload());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -198,7 +200,7 @@ public class InstallFragment extends Fragment {
|
||||||
DialogUtils.showConfirmDialog(root, R.string.error, StringUtils.firstNonBlank(patcher.getErrorMessage().get(), context.getString(R.string.failed_to_patch_game)), R.string.menu_download, R.string.cancel, (d, which) -> {
|
DialogUtils.showConfirmDialog(root, R.string.error, StringUtils.firstNonBlank(patcher.getErrorMessage().get(), context.getString(R.string.failed_to_patch_game)), R.string.menu_download, R.string.cancel, (d, which) -> {
|
||||||
if (which == DialogAction.POSITIVE) {
|
if (which == DialogAction.POSITIVE) {
|
||||||
NavController controller = Navigation.findNavController(installButton);
|
NavController controller = Navigation.findNavController(installButton);
|
||||||
controller.navigate(InstallFragmentDirections.actionNavInstallToNavDownload());
|
controller.navigate(MainTabsFragmentDirections.actionNavMainToNavDownload());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.zane.smapiinstaller.ui.main;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.zane.smapiinstaller.R;
|
||||||
|
import com.zane.smapiinstaller.ui.about.AboutFragment;
|
||||||
|
import com.zane.smapiinstaller.ui.config.ConfigFragment;
|
||||||
|
import com.zane.smapiinstaller.ui.download.DownloadableContentFragment;
|
||||||
|
import com.zane.smapiinstaller.ui.help.HelpFragment;
|
||||||
|
import com.zane.smapiinstaller.ui.install.InstallFragment;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||||
|
|
||||||
|
class MainTabPagerAdapter extends FragmentStateAdapter {
|
||||||
|
private Fragment fragment;
|
||||||
|
|
||||||
|
public MainTabPagerAdapter(Fragment fragment) {
|
||||||
|
super(fragment);
|
||||||
|
this.fragment = fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Fragment createFragment(int position) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
Fragment fragment;
|
||||||
|
switch (position){
|
||||||
|
case 1:
|
||||||
|
fragment = new ConfigFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
case 2:
|
||||||
|
fragment = new DownloadableContentFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
case 3:
|
||||||
|
fragment = new HelpFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
case 4:
|
||||||
|
fragment = new AboutFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
fragment = new InstallFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle(int position) {
|
||||||
|
switch (position){
|
||||||
|
case 1:
|
||||||
|
return fragment.getString(R.string.menu_config);
|
||||||
|
case 2:
|
||||||
|
return fragment.getString(R.string.menu_download);
|
||||||
|
case 3:
|
||||||
|
return fragment.getString(R.string.menu_help);
|
||||||
|
case 4:
|
||||||
|
return fragment.getString(R.string.menu_about);
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
return fragment.getString(R.string.menu_install);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.zane.smapiinstaller.ui.main;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
import com.google.android.material.tabs.TabLayoutMediator;
|
||||||
|
import com.zane.smapiinstaller.MainActivity;
|
||||||
|
import com.zane.smapiinstaller.R;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.viewpager2.widget.ViewPager2;
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zane
|
||||||
|
*/
|
||||||
|
public class MainTabsFragment extends Fragment {
|
||||||
|
|
||||||
|
@BindView(R.id.main_tab_layout)
|
||||||
|
TabLayout tabLayout;
|
||||||
|
@BindView(R.id.main_pager)
|
||||||
|
ViewPager2 viewPager;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_main, container, false);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
MainTabPagerAdapter pagerAdapter = new MainTabPagerAdapter(this);
|
||||||
|
viewPager.setAdapter(pagerAdapter);
|
||||||
|
new TabLayoutMediator(tabLayout, viewPager,
|
||||||
|
(tab, position) -> tab.setText(pagerAdapter.getTitle(position))
|
||||||
|
).attach();
|
||||||
|
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
super.onPageSelected(position);
|
||||||
|
if (position >= 3) {
|
||||||
|
MainActivity.instance.setFloatingBarVisibility(false);
|
||||||
|
} else {
|
||||||
|
MainActivity.instance.setFloatingBarVisibility(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:id="@+id/main_tab_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
</com.google.android.material.tabs.TabLayout>
|
||||||
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
|
android:id="@+id/main_pager"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
</androidx.viewpager2.widget.ViewPager2>
|
||||||
|
</LinearLayout>
|
|
@ -5,9 +5,9 @@
|
||||||
|
|
||||||
<group android:checkableBehavior="single">
|
<group android:checkableBehavior="single">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_install"
|
android:id="@+id/nav_main"
|
||||||
android:icon="@drawable/add"
|
android:icon="@drawable/add"
|
||||||
android:title="@string/menu_install" />
|
android:title="@string/nav_header_title" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_config"
|
android:id="@+id/nav_config"
|
||||||
android:icon="@drawable/edit"
|
android:icon="@drawable/edit"
|
||||||
|
|
|
@ -3,16 +3,21 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/mobile_navigation"
|
android:id="@+id/mobile_navigation"
|
||||||
app:startDestination="@+id/nav_install">
|
app:startDestination="@+id/nav_main">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_install"
|
android:id="@+id/nav_main"
|
||||||
|
android:name="com.zane.smapiinstaller.ui.main.MainTabsFragment"
|
||||||
|
android:label="@string/nav_header_title"
|
||||||
|
tools:layout="@layout/fragment_main">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_nav_main_to_nav_download"
|
||||||
|
app:destination="@id/nav_download" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/install_fragment"
|
||||||
android:name="com.zane.smapiinstaller.ui.install.InstallFragment"
|
android:name="com.zane.smapiinstaller.ui.install.InstallFragment"
|
||||||
android:label="@string/menu_install"
|
android:label="@string/menu_install"
|
||||||
tools:layout="@layout/fragment_install">
|
tools:layout="@layout/fragment_install">
|
||||||
<action
|
|
||||||
android:id="@+id/action_nav_install_to_nav_download"
|
|
||||||
app:destination="@id/nav_download" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/config_edit_fragment"
|
android:id="@+id/config_edit_fragment"
|
||||||
|
|
Loading…
Reference in New Issue