Skip to content

Commit

Permalink
clean up and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
seelchen committed Feb 5, 2024
1 parent 5b81154 commit c964a79
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,12 @@ public void goToMain(String path) {
goToMain(path, false);
}

/**
* Sets up the main view with the {@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);
Expand All @@ -1017,6 +1023,7 @@ public void goToMain(String path, boolean hideFab) {
if (path != null && path.length() > 0) {
b.putString("path", path);
}
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ 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;
Expand Down Expand Up @@ -170,7 +171,7 @@ public class MainFragment extends Fragment
private MainFragmentViewModel mainFragmentViewModel;
private MainActivityViewModel mainActivityViewModel;

private boolean hideFab;
private boolean hideFab = false;

private final ActivityResultLauncher<Intent> handleDocumentUriForRestrictedDirectories =
registerForActivityResult(
Expand Down Expand Up @@ -1537,10 +1538,12 @@ > requireContext().getResources().getDisplayMetrics().heightPixels) {
}
}

/** 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,10 @@ private void addNewTab(int num, String path) {
* 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, boolean hideFabInCurrentTab) {
public void refactorDrawerStorages(boolean addTab, boolean hideFabInCurrentMainFragment) {
TabHandler tabHandler = TabHandler.getInstance();
Tab tab1 = tabHandler.findTab(1);
Tab tab2 = tabHandler.findTab(2);
Expand All @@ -371,13 +373,13 @@ public void refactorDrawerStorages(boolean addTab, boolean hideFabInCurrentTab)
} else {
if (path != null && path.length() != 0) {
if (MainActivity.currentTab == 0) {
addTab(tab1, path, hideFabInCurrentTab);
addTab(tab1, path, hideFabInCurrentMainFragment);
addTab(tab2, "", false);
}

if (MainActivity.currentTab == 1) {
addTab(tab1, "", false);
addTab(tab2, path, hideFabInCurrentTab);
addTab(tab2, path, hideFabInCurrentMainFragment);
}
} else {
addTab(tab1, "", false);
Expand All @@ -386,7 +388,6 @@ public void refactorDrawerStorages(boolean addTab, boolean hideFabInCurrentTab)
}
}

// TODO
private void addTab(@NonNull Tab tab, String path, boolean hideFabInTab) {
MainFragment main = new MainFragment();
Bundle b = new Bundle();
Expand All @@ -400,6 +401,7 @@ private void addTab(@NonNull Tab tab, String path, boolean hideFabInTab) {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ public void onDrawerClosed() {
MainFragment mainFragment = mainActivity.getCurrentMainFragment();
if (mainFragment != null) {
mainFragment.loadlist(pendingPath.getPath(), false, OpenMode.UNKNOWN, false);
// Set if the FAB should be hidden when displaying the pendingPath
mainFragment.setHideFab(pendingPath.getHideFabInMainFragment());
resetPendingPath();
} else {
Expand Down

0 comments on commit c964a79

Please sign in to comment.