Skip to content

Commit

Permalink
Correctly manage views when changing tabs with a QuickView active
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelMess committed Oct 14, 2021
1 parent 2d7350b commit c5aa971
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import com.amaze.filemanager.ui.views.DividerItemDecoration;
import com.amaze.filemanager.ui.views.FastScroller;
import com.amaze.filemanager.ui.views.WarnableTextInputValidator;
import com.amaze.filemanager.ui.views.appbar.BottomBar;
import com.amaze.filemanager.utils.BottomBarButtonPath;
import com.amaze.filemanager.utils.DataUtils;
import com.amaze.filemanager.utils.MainActivityHelper;
Expand Down Expand Up @@ -737,6 +736,28 @@ public void onDestroyActionMode(ActionMode mode) {
}
};

/** When TabFragment detects this fragment is in view it calls this method */
public void onWorkspaceSelected() {
if (getCurrentPath() != null) {
getMainActivity().getDrawer().selectCorrectDrawerItemForPath(getCurrentPath());
}

final QuickViewFragment quickViewFragment = getCurrentQuickView();

if (quickViewFragment != null) {
quickViewFragment.runOpenVisibilityChanges();
}
}

/** When TabFragment detects this fragment is not in view it calls this method */
public void onWorkspaceUnselected() {
final QuickViewFragment quickViewFragment = getCurrentQuickView();

if (quickViewFragment != null) {
quickViewFragment.runExitVisibilityChanges();
}
}

private BroadcastReceiver receiver2 =
new BroadcastReceiver() {

Expand Down Expand Up @@ -915,23 +936,14 @@ public void onQuickViewClicked(LayoutElementParcelable layoutElementParcelable)
final QuickViewType quickViewType = new QuickViewImage(iconData, layoutElementParcelable.title);
final QuickViewFragment fragment = QuickViewFragment.newInstance(quickViewType);

final Menu menu = getMainActivity().getAppbar().getToolbar().getMenu();
menu.setGroupVisible(0, false);

final BottomBar bottomBar = getMainActivity().getAppbar().getBottomBar();
bottomBar.setIsClickEnabled(false);

getMainActivity().getFAB().getMainFab().setVisibility(View.GONE);

getChildFragmentManager()
.beginTransaction()
.replace(R.id.quickViewContainer, fragment, MainActivity.TAG_QUICK_VIEW_FRAGMENT)
.commit();
}

private void assureNoQuickView() {
QuickViewFragment fragment =
(QuickViewFragment) getChildFragmentManager().findFragmentById(R.id.quickViewContainer);
QuickViewFragment fragment = getCurrentQuickView();

if (fragment == null) {
return;
Expand All @@ -940,6 +952,11 @@ private void assureNoQuickView() {
fragment.exit();
}

@Nullable
private QuickViewFragment getCurrentQuickView() {
return (QuickViewFragment) getChildFragmentManager().findFragmentById(R.id.quickViewContainer);
}

public void updateTabWithDb(Tab tab) {
mainFragmentViewModel.setCurrentPath(tab.path);
mainFragmentViewModel.setHome(tab.home);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
/** Created by Arpit on 15-12-2014. */
public class TabFragment extends Fragment implements ViewPager.OnPageChangeListener {

public List<Fragment> fragments = new ArrayList<>();
public List<Fragment> fragments = new ArrayList<>(2);
public ScreenSlidePagerAdapter mSectionsPagerAdapter;
public DisablableViewPager mViewPager;

Expand Down Expand Up @@ -265,7 +265,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
}

@Override
public void onPageSelected(int p1) {
public void onPageSelected(int selectedTabId) {
mainActivity
.getAppbar()
.getAppbarLayout()
Expand All @@ -274,7 +274,7 @@ public void onPageSelected(int p1) {
.setInterpolator(new DecelerateInterpolator(2))
.start();

MainActivity.currentTab = p1;
MainActivity.currentTab = selectedTabId;

if (sharedPrefs != null) {
sharedPrefs
Expand All @@ -283,19 +283,25 @@ public void onPageSelected(int p1) {
.apply();
}

// Log.d(getClass().getSimpleName(), "Page Selected: " + MainActivity.currentTab, new
// Exception());
Fragment notInView = fragments.get(selectedTabId == 0 ? 1 : 0);
if (notInView instanceof MainFragment) {
((MainFragment) notInView).onWorkspaceUnselected();
}

Fragment inView = fragments.get(selectedTabId);
if (inView instanceof MainFragment) {
MainFragment mainFragment = (MainFragment) inView;

Fragment fragment = fragments.get(p1);
if (fragment != null && fragment instanceof MainFragment) {
MainFragment ma = (MainFragment) fragment;
if (ma.getCurrentPath() != null) {
mainActivity.getDrawer().selectCorrectDrawerItemForPath(ma.getCurrentPath());
updateBottomBar(ma);
if (mainFragment.getCurrentPath() != null) {
updateBottomBar(mainFragment);
}

((MainFragment) inView).onWorkspaceSelected();
}

if (circleDrawable1 != null && circleDrawable2 != null) updateIndicator(p1);
if (circleDrawable1 != null && circleDrawable2 != null) {
updateIndicator(selectedTabId);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,25 @@ class QuickViewFragment : Fragment() {
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setHasOptionsMenu(true) // HACK its needed to get a onPrepareOptionsMenu() callback
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
setHasOptionsMenu(true)

): View {
return inflater.inflate(R.layout.quick_view_fragment, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

runOpenVisibilityChanges()

val constraintLayout = view.findViewById<ConstraintLayout>(R.id.frameLayout)
constraintLayout.setOnClickListener {
exit()
Expand Down Expand Up @@ -225,13 +231,32 @@ class QuickViewFragment : Fragment() {
* see [MainFragment.onQuickViewClicked]
*/
fun exit() {
// TODO Fix fab visibility when changing workspaces

parentFragmentManager
.beginTransaction()
.remove(this)
.commit()

runExitVisibilityChanges()
}

/**
* Run the visibility changes needed for this fragment to look good
*/
fun runOpenVisibilityChanges() {
(requireActivity() as MainActivity)
.appbar.toolbar.menu.setGroupVisible(0, false)

(requireActivity() as MainActivity)
.appbar.bottomBar.setIsClickEnabled(false)

(requireActivity() as MainActivity)
.fab.mainFab.visibility = View.GONE
}

/**
* Undo the visibility changes needed for this fragment to look good
*/
fun runExitVisibilityChanges() {
(requireActivity() as MainActivity)
.appbar.toolbar.menu.setGroupVisible(0, true)

Expand Down

0 comments on commit c5aa971

Please sign in to comment.