Skip to content

Commit 8fcbe7e

Browse files
authored
Merge pull request #4071 from seelchen/bugfix/hide-fab
Hide FAB in some screens
2 parents 358777c + f71bf6a commit 8fcbe7e

File tree

7 files changed

+114
-39
lines changed

7 files changed

+114
-39
lines changed

app/src/main/java/com/amaze/filemanager/ui/activities/MainActivity.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ public void onPermissionGranted() {
538538
.subscribe(
539539
() -> {
540540
if (tabFragment != null) {
541-
tabFragment.refactorDrawerStorages(false);
541+
tabFragment.refactorDrawerStorages(false, false);
542542
Fragment main = tabFragment.getFragmentAtIndex(0);
543543
if (main != null) ((MainFragment) main).updateTabWithDb(tabHandler.findTab(1));
544544
Fragment main1 = tabFragment.getFragmentAtIndex(1);
@@ -948,7 +948,7 @@ public void onBackPressed() {
948948
fragmentTransaction.remove(compressedExplorerFragment);
949949
fragmentTransaction.commit();
950950
supportInvalidateOptionsMenu();
951-
floatingActionButton.show();
951+
showFab();
952952
}
953953
} else {
954954
compressedExplorerFragment.mActionMode.finish();
@@ -999,6 +999,16 @@ public void exit() {
999999
}
10001000

10011001
public void goToMain(String path) {
1002+
goToMain(path, false);
1003+
}
1004+
1005+
/**
1006+
* Sets up the main view with a {@link MainFragment}
1007+
*
1008+
* @param path The path to which to go in the {@link MainFragment}
1009+
* @param hideFab Whether the FAB should be hidden in the new created {@link MainFragment} or not
1010+
*/
1011+
public void goToMain(String path, boolean hideFab) {
10021012
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
10031013
// title.setText(R.string.app_name);
10041014
TabFragment tabFragment = new TabFragment();
@@ -1009,17 +1019,19 @@ public void goToMain(String path) {
10091019
path = "6";
10101020
}
10111021
}
1022+
Bundle b = new Bundle();
10121023
if (path != null && path.length() > 0) {
1013-
Bundle b = new Bundle();
10141024
b.putString("path", path);
1015-
tabFragment.setArguments(b);
10161025
}
1026+
// This boolean will be given to the newly created MainFragment
1027+
b.putBoolean(MainFragment.BUNDLE_HIDE_FAB, hideFab);
1028+
tabFragment.setArguments(b);
10171029
transaction.replace(R.id.content_frame, tabFragment);
10181030
// Commit the transaction
10191031
transaction.addToBackStack("tabt" + 1);
10201032
transaction.commitAllowingStateLoss();
10211033
appbar.setTitle(null);
1022-
floatingActionButton.show();
1034+
10231035
if (isCompressedOpen && pathInCompressedArchive != null) {
10241036
openCompressed(pathInCompressedArchive);
10251037
pathInCompressedArchive = null;
@@ -1527,7 +1539,11 @@ public SpeedDialView getFAB() {
15271539
}
15281540

15291541
public void showFab() {
1530-
showFab(getFAB());
1542+
if (getCurrentMainFragment() != null && getCurrentMainFragment().getHideFab()) {
1543+
hideFab();
1544+
} else {
1545+
showFab(getFAB());
1546+
}
15311547
}
15321548

15331549
private void showFab(SpeedDialView fab) {

app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public class MainFragment extends Fragment
143143
private static final Logger LOG = LoggerFactory.getLogger(MainFragment.class);
144144
private static final String KEY_FRAGMENT_MAIN = "main";
145145

146+
/** Key for boolean in arguments whether to hide the FAB if this {@link MainFragment} is shown */
147+
public static final String BUNDLE_HIDE_FAB = "hideFab";
148+
146149
public SwipeRefreshLayout mSwipeRefreshLayout;
147150

148151
public RecyclerAdapter adapter;
@@ -168,6 +171,8 @@ public class MainFragment extends Fragment
168171
private MainFragmentViewModel mainFragmentViewModel;
169172
private MainActivityViewModel mainActivityViewModel;
170173

174+
private boolean hideFab = false;
175+
171176
private final ActivityResultLauncher<Intent> handleDocumentUriForRestrictedDirectories =
172177
registerForActivityResult(
173178
new ActivityResultContracts.StartActivityForResult(),
@@ -207,6 +212,9 @@ public void onCreate(Bundle savedInstanceState) {
207212
requireMainActivity().getCurrentColorPreference().getPrimaryFirstTab());
208213
mainFragmentViewModel.setPrimaryTwoColor(
209214
requireMainActivity().getCurrentColorPreference().getPrimarySecondTab());
215+
if (getArguments() != null) {
216+
hideFab = getArguments().getBoolean(BUNDLE_HIDE_FAB, false);
217+
}
210218
}
211219

212220
@Override
@@ -1073,6 +1081,7 @@ public void goBack() {
10731081
if (mainFragmentViewModel.getOpenMode() == OpenMode.CUSTOM
10741082
|| mainFragmentViewModel.getOpenMode() == OpenMode.TRASH_BIN) {
10751083
loadlist(mainFragmentViewModel.getHome(), false, OpenMode.FILE, false);
1084+
setHideFab(false);
10761085
return;
10771086
}
10781087

@@ -1081,6 +1090,7 @@ public void goBack() {
10811090
if (requireMainActivity().getListItemSelected()) {
10821091
adapter.toggleChecked(false);
10831092
} else {
1093+
setHideFab(false);
10841094
if (OpenMode.SMB.equals(mainFragmentViewModel.getOpenMode())) {
10851095
if (mainFragmentViewModel.getSmbPath() != null
10861096
&& !mainFragmentViewModel.getSmbPath().equals(mainFragmentViewModel.getCurrentPath())) {
@@ -1527,4 +1537,14 @@ > requireContext().getResources().getDisplayMetrics().heightPixels) {
15271537
LOG.warn("Failed to adjust scrollview for tv", e);
15281538
}
15291539
}
1540+
1541+
/** Whether the FAB should be hidden when this MainFragment is shown */
1542+
public boolean getHideFab() {
1543+
return this.hideFab;
1544+
}
1545+
1546+
/** Set whether the FAB should be hidden when this MainFragment is shown */
1547+
public void setHideFab(boolean hideFab) {
1548+
this.hideFab = hideFab;
1549+
}
15301550
}

app/src/main/java/com/amaze/filemanager/ui/fragments/TabFragment.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ public View onCreateView(
126126

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

129+
boolean hideFab = false;
129130
if (getArguments() != null) {
130131
path = getArguments().getString(KEY_PATH);
132+
hideFab = getArguments().getBoolean(MainFragment.BUNDLE_HIDE_FAB);
131133
}
132134

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

141-
refactorDrawerStorages(true);
143+
refactorDrawerStorages(true, hideFab);
142144

143145
viewPager.setAdapter(sectionsPagerAdapter);
144146

@@ -299,6 +301,9 @@ public void onPageSelected(int p1) {
299301
if (ma.getCurrentPath() != null) {
300302
requireMainActivity().getDrawer().selectCorrectDrawerItemForPath(ma.getCurrentPath());
301303
updateBottomBar(ma);
304+
// FAB might be hidden in the previous tab
305+
// so we check if it should be shown for the new tab
306+
requireMainActivity().showFab();
302307
}
303308
}
304309

@@ -331,16 +336,18 @@ public Fragment createFragment(int position) {
331336
}
332337

333338
private void addNewTab(int num, String path) {
334-
addTab(new Tab(num, path, path), "");
339+
addTab(new Tab(num, path, path), "", false);
335340
}
336341

337342
/**
338343
* Fetches new storage paths from drawer and apply to tabs This method will just create tabs in UI
339344
* change paths in database. Calls should implement updating each tab's list for new paths.
340345
*
341346
* @param addTab whether new tabs should be added to ui or just change values in database
347+
* @param hideFabInCurrentMainFragment whether the FAB should be hidden in the current {@link
348+
* MainFragment}
342349
*/
343-
public void refactorDrawerStorages(boolean addTab) {
350+
public void refactorDrawerStorages(boolean addTab, boolean hideFabInCurrentMainFragment) {
344351
TabHandler tabHandler = TabHandler.getInstance();
345352
Tab tab1 = tabHandler.findTab(1);
346353
Tab tab2 = tabHandler.findTab(2);
@@ -366,22 +373,22 @@ public void refactorDrawerStorages(boolean addTab) {
366373
} else {
367374
if (path != null && path.length() != 0) {
368375
if (MainActivity.currentTab == 0) {
369-
addTab(tab1, path);
370-
addTab(tab2, "");
376+
addTab(tab1, path, hideFabInCurrentMainFragment);
377+
addTab(tab2, "", false);
371378
}
372379

373380
if (MainActivity.currentTab == 1) {
374-
addTab(tab1, "");
375-
addTab(tab2, path);
381+
addTab(tab1, "", false);
382+
addTab(tab2, path, hideFabInCurrentMainFragment);
376383
}
377384
} else {
378-
addTab(tab1, "");
379-
addTab(tab2, "");
385+
addTab(tab1, "", false);
386+
addTab(tab2, "", false);
380387
}
381388
}
382389
}
383390

384-
private void addTab(@NonNull Tab tab, String path) {
391+
private void addTab(@NonNull Tab tab, String path, boolean hideFabInTab) {
385392
MainFragment main = new MainFragment();
386393
Bundle b = new Bundle();
387394

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

395402
b.putString("home", tab.home);
396403
b.putInt("no", tab.tabNumber);
404+
// specifies if the constructed MainFragment hides the FAB when it is shown
405+
b.putBoolean(MainFragment.BUNDLE_HIDE_FAB, hideFabInTab);
397406
main.setArguments(b);
398407
fragments.add(main);
399408
sectionsPagerAdapter.notifyDataSetChanged();

app/src/main/java/com/amaze/filemanager/ui/views/appbar/SearchView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ public void revealSearchView() {
415415
}
416416

417417
mainActivity.showSmokeScreen();
418+
mainActivity.hideFab();
418419

419420
animator.setInterpolator(new AccelerateDecelerateInterpolator());
420421
animator.setDuration(600);
@@ -546,6 +547,7 @@ public void hideSearchView() {
546547

547548
// removing background fade view
548549
mainActivity.hideSmokeScreen();
550+
mainActivity.showFab();
549551
animator.setInterpolator(new AccelerateDecelerateInterpolator());
550552
animator.setDuration(600);
551553
animator.start();

0 commit comments

Comments
 (0)