Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide FAB in some screens #4071

Merged
merged 8 commits into from
Feb 15, 2024
Merged
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
Expand Up @@ -538,7 +538,7 @@ public void onPermissionGranted() {
.subscribe(
() -> {
if (tabFragment != null) {
tabFragment.refactorDrawerStorages(false);
tabFragment.refactorDrawerStorages(false, false);
Fragment main = tabFragment.getFragmentAtIndex(0);
if (main != null) ((MainFragment) main).updateTabWithDb(tabHandler.findTab(1));
Fragment main1 = tabFragment.getFragmentAtIndex(1);
Expand Down Expand Up @@ -948,7 +948,7 @@ public void onBackPressed() {
fragmentTransaction.remove(compressedExplorerFragment);
fragmentTransaction.commit();
supportInvalidateOptionsMenu();
floatingActionButton.show();
showFab();
}
} else {
compressedExplorerFragment.mActionMode.finish();
Expand Down Expand Up @@ -999,6 +999,16 @@ public void exit() {
}

public void goToMain(String path) {
goToMain(path, false);
}

/**
* Sets up the main view with a {@link MainFragment}
*
* @param path The path to which to go in the {@link MainFragment}
* @param hideFab Whether the FAB should be hidden in the new created {@link MainFragment} or not
*/
public void goToMain(String path, boolean hideFab) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// title.setText(R.string.app_name);
TabFragment tabFragment = new TabFragment();
Expand All @@ -1009,17 +1019,19 @@ public void goToMain(String path) {
path = "6";
}
}
Bundle b = new Bundle();
if (path != null && path.length() > 0) {
Bundle b = new Bundle();
b.putString("path", path);
tabFragment.setArguments(b);
}
// This boolean will be given to the newly created MainFragment
b.putBoolean(MainFragment.BUNDLE_HIDE_FAB, hideFab);
tabFragment.setArguments(b);
transaction.replace(R.id.content_frame, tabFragment);
// Commit the transaction
transaction.addToBackStack("tabt" + 1);
transaction.commitAllowingStateLoss();
appbar.setTitle(null);
floatingActionButton.show();

if (isCompressedOpen && pathInCompressedArchive != null) {
openCompressed(pathInCompressedArchive);
pathInCompressedArchive = null;
Expand Down Expand Up @@ -1527,7 +1539,11 @@ public SpeedDialView getFAB() {
}

public void showFab() {
showFab(getFAB());
if (getCurrentMainFragment() != null && getCurrentMainFragment().getHideFab()) {
hideFab();
} else {
showFab(getFAB());
}
}

private void showFab(SpeedDialView fab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public class MainFragment extends Fragment
private static final Logger LOG = LoggerFactory.getLogger(MainFragment.class);
private static final String KEY_FRAGMENT_MAIN = "main";

/** Key for boolean in arguments whether to hide the FAB if this {@link MainFragment} is shown */
public static final String BUNDLE_HIDE_FAB = "hideFab";

public SwipeRefreshLayout mSwipeRefreshLayout;

public RecyclerAdapter adapter;
Expand All @@ -168,6 +171,8 @@ public class MainFragment extends Fragment
private MainFragmentViewModel mainFragmentViewModel;
private MainActivityViewModel mainActivityViewModel;

private boolean hideFab = false;

private final ActivityResultLauncher<Intent> handleDocumentUriForRestrictedDirectories =
registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
Expand Down Expand Up @@ -207,6 +212,9 @@ public void onCreate(Bundle savedInstanceState) {
requireMainActivity().getCurrentColorPreference().getPrimaryFirstTab());
mainFragmentViewModel.setPrimaryTwoColor(
requireMainActivity().getCurrentColorPreference().getPrimarySecondTab());
if (getArguments() != null) {
hideFab = getArguments().getBoolean(BUNDLE_HIDE_FAB, false);
}
}

@Override
Expand Down Expand Up @@ -1073,6 +1081,7 @@ public void goBack() {
if (mainFragmentViewModel.getOpenMode() == OpenMode.CUSTOM
|| mainFragmentViewModel.getOpenMode() == OpenMode.TRASH_BIN) {
loadlist(mainFragmentViewModel.getHome(), false, OpenMode.FILE, false);
setHideFab(false);
return;
}

Expand All @@ -1081,6 +1090,7 @@ public void goBack() {
if (requireMainActivity().getListItemSelected()) {
adapter.toggleChecked(false);
} else {
setHideFab(false);
if (OpenMode.SMB.equals(mainFragmentViewModel.getOpenMode())) {
if (mainFragmentViewModel.getSmbPath() != null
&& !mainFragmentViewModel.getSmbPath().equals(mainFragmentViewModel.getCurrentPath())) {
Expand Down Expand Up @@ -1527,4 +1537,14 @@ > requireContext().getResources().getDisplayMetrics().heightPixels) {
LOG.warn("Failed to adjust scrollview for tv", e);
}
}

/** Whether the FAB should be hidden when this MainFragment is shown */
public boolean getHideFab() {
return this.hideFab;
}

/** Set whether the FAB should be hidden when this MainFragment is shown */
public void setHideFab(boolean hideFab) {
this.hideFab = hideFab;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ public View onCreateView(

viewPager = rootView.findViewById(R.id.pager);

boolean hideFab = false;
if (getArguments() != null) {
path = getArguments().getString(KEY_PATH);
hideFab = getArguments().getBoolean(MainFragment.BUNDLE_HIDE_FAB);
}

requireMainActivity().supportInvalidateOptionsMenu();
Expand All @@ -138,7 +140,7 @@ public View onCreateView(
int lastOpenTab = sharedPrefs.getInt(PREFERENCE_CURRENT_TAB, DEFAULT_CURRENT_TAB);
MainActivity.currentTab = lastOpenTab;

refactorDrawerStorages(true);
refactorDrawerStorages(true, hideFab);

viewPager.setAdapter(sectionsPagerAdapter);

Expand Down Expand Up @@ -299,6 +301,9 @@ public void onPageSelected(int p1) {
if (ma.getCurrentPath() != null) {
requireMainActivity().getDrawer().selectCorrectDrawerItemForPath(ma.getCurrentPath());
updateBottomBar(ma);
// FAB might be hidden in the previous tab
// so we check if it should be shown for the new tab
requireMainActivity().showFab();
}
}

Expand Down Expand Up @@ -331,16 +336,18 @@ public Fragment createFragment(int position) {
}

private void addNewTab(int num, String path) {
addTab(new Tab(num, path, path), "");
addTab(new Tab(num, path, path), "", false);
}

/**
* Fetches new storage paths from drawer and apply to tabs This method will just create tabs in UI
* change paths in database. Calls should implement updating each tab's list for new paths.
*
* @param addTab whether new tabs should be added to ui or just change values in database
* @param hideFabInCurrentMainFragment whether the FAB should be hidden in the current {@link
* MainFragment}
*/
public void refactorDrawerStorages(boolean addTab) {
public void refactorDrawerStorages(boolean addTab, boolean hideFabInCurrentMainFragment) {
TabHandler tabHandler = TabHandler.getInstance();
Tab tab1 = tabHandler.findTab(1);
Tab tab2 = tabHandler.findTab(2);
Expand All @@ -366,22 +373,22 @@ public void refactorDrawerStorages(boolean addTab) {
} else {
if (path != null && path.length() != 0) {
if (MainActivity.currentTab == 0) {
addTab(tab1, path);
addTab(tab2, "");
addTab(tab1, path, hideFabInCurrentMainFragment);
addTab(tab2, "", false);
}

if (MainActivity.currentTab == 1) {
addTab(tab1, "");
addTab(tab2, path);
addTab(tab1, "", false);
addTab(tab2, path, hideFabInCurrentMainFragment);
}
} else {
addTab(tab1, "");
addTab(tab2, "");
addTab(tab1, "", false);
addTab(tab2, "", false);
}
}
}

private void addTab(@NonNull Tab tab, String path) {
private void addTab(@NonNull Tab tab, String path, boolean hideFabInTab) {
MainFragment main = new MainFragment();
Bundle b = new Bundle();

Expand All @@ -394,6 +401,8 @@ private void addTab(@NonNull Tab tab, String path) {

b.putString("home", tab.home);
b.putInt("no", tab.tabNumber);
// specifies if the constructed MainFragment hides the FAB when it is shown
b.putBoolean(MainFragment.BUNDLE_HIDE_FAB, hideFabInTab);
main.setArguments(b);
fragments.add(main);
sectionsPagerAdapter.notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public void revealSearchView() {
}

mainActivity.showSmokeScreen();
mainActivity.hideFab();

animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(600);
Expand Down Expand Up @@ -546,6 +547,7 @@ public void hideSearchView() {

// removing background fade view
mainActivity.hideSmokeScreen();
mainActivity.showFab();
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(600);
animator.start();
Expand Down
Loading
Loading