/**
  * Get the complete backstack
  *
  * @return the complete backstack for every tab
  */
 public ConcurrentHashMap<Integer, ArrayList<FragmentStateHolder>> getBackStack() {
   ArrayList<FragmentStateHolder> fragmentsStack = mMapOfStacks.get(mCurrentlyShownStack);
   FragmentStateHolder currentFragmentStateHolder = fragmentsStack.get(fragmentsStack.size() - 1);
   Fragment currentFragment =
       mFragmentManager.findFragmentByTag(currentFragmentStateHolder.fragmentTag);
   if (currentFragment != null && currentFragment instanceof TomahawkFragment) {
     currentFragmentStateHolder.listScrollPosition =
         ((TomahawkFragment) currentFragment).getListScrollPosition();
     fragmentsStack.set(fragmentsStack.size() - 1, currentFragmentStateHolder);
   }
   return mMapOfStacks;
 }
Ejemplo n.º 2
0
 /**
  * Get the complete backstack
  *
  * @return the complete backstack
  */
 public ArrayList<FragmentStateHolder> getBackStack() {
   FragmentStateHolder currentFragmentStateHolder = getCurrentFragmentStateHolder();
   Fragment currentFragment = null;
   if (mFragmentManager != null && mFragmentManager.getFragments() != null) {
     currentFragment = mFragmentManager.getFragments().get(0);
   }
   if (currentFragment != null && currentFragment instanceof TomahawkFragment) {
     currentFragmentStateHolder.listScrollPosition =
         ((TomahawkFragment) currentFragment).getListScrollPosition();
     mBackstack.set(mBackstack.size() - 1, currentFragmentStateHolder);
   }
   return mBackstack;
 }
Ejemplo n.º 3
0
 /**
  * Replaces the {@link Fragment} in the hub with the given hub id and adds it to the backstack, if
  * isBackAction is false.
  *
  * @param fragmentStateHolder {@link FragmentStateHolder} contains all information of the to be
  *     replaced {@link Fragment}
  * @param isBackAction whether or not the replacement is part of an action going back in the
  *     backstack
  */
 public void replace(FragmentStateHolder fragmentStateHolder, boolean isBackAction) {
   // Get fragmentsStack for the given (tabs)position
   FragmentStateHolder currentFragmentStateHolder = getCurrentFragmentStateHolder();
   // Replace the fragment using a transaction.
   FragmentTransaction ft = mFragmentManager.beginTransaction();
   if (isBackAction) {
     mBackstack.remove(currentFragmentStateHolder);
     ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
   } else {
     Fragment currentFragment = null;
     if (mFragmentManager != null && mFragmentManager.getFragments() != null) {
       currentFragment = mFragmentManager.findFragmentByTag(FRAGMENT_TAG);
     }
     if (currentFragmentStateHolder != null
         && currentFragment != null
         && currentFragment instanceof TomahawkFragment) {
       currentFragmentStateHolder.listScrollPosition =
           ((TomahawkFragment) currentFragment).getListScrollPosition();
     }
     mBackstack.add(fragmentStateHolder);
     ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
   }
   Bundle bundle = new Bundle();
   bundle.putString(
       fragmentStateHolder.tomahawkListItemType, fragmentStateHolder.tomahawkListItemKey);
   bundle.putBoolean(
       TomahawkFragment.TOMAHAWK_LIST_ITEM_IS_LOCAL, fragmentStateHolder.tomahawkListItemIsLocal);
   bundle.putInt(
       TomahawkFragment.TOMAHAWK_LIST_SCROLL_POSITION, fragmentStateHolder.listScrollPosition);
   bundle.putString(
       SearchableFragment.SEARCHABLEFRAGMENT_QUERY_STRING, fragmentStateHolder.queryString);
   ft.replace(
       mContentFrameId,
       Fragment.instantiate(mTomahawkMainActivity, fragmentStateHolder.clss.getName(), bundle),
       FRAGMENT_TAG);
   ft.commit();
   mTomahawkMainActivity.updateViewVisibility();
 }
 /** Replaces the view pager fragment at specified position. */
 public void replace(int stackId, FragmentStateHolder fragmentStateHolder, boolean isBackAction) {
   // Get fragmentsStack for the given (tabs)position
   ArrayList<FragmentStateHolder> fragmentStateHolders = mMapOfStacks.get(stackId);
   FragmentStateHolder currentFragmentStateHolder =
       fragmentStateHolders.get(fragmentStateHolders.size() - 1);
   if (currentFragmentStateHolder != null) {
     // Replace the fragment using a transaction.
     FragmentTransaction ft = mFragmentManager.beginTransaction();
     if (isBackAction) {
       fragmentStateHolders.remove(currentFragmentStateHolder);
       ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
     } else {
       Fragment currentFragment =
           mFragmentManager.findFragmentByTag(currentFragmentStateHolder.fragmentTag);
       if (currentFragment != null && currentFragment instanceof TomahawkFragment) {
         currentFragmentStateHolder.listScrollPosition =
             ((TomahawkFragment) currentFragment).getListScrollPosition();
       }
       fragmentStateHolders.add(fragmentStateHolder);
       ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
     }
     Bundle bundle = new Bundle();
     bundle.putLong(
         fragmentStateHolder.tomahawkListItemType, fragmentStateHolder.tomahawkListItemId);
     bundle.putInt(
         TomahawkFragment.TOMAHAWK_LIST_SCROLL_POSITION, fragmentStateHolder.listScrollPosition);
     bundle.putString(
         SearchableFragment.SEARCHABLEFRAGMENT_QUERY_STRING, fragmentStateHolder.queryString);
     ft.replace(
         mContentFrameId,
         Fragment.instantiate(mActivity, fragmentStateHolder.clss.getName(), bundle),
         fragmentStateHolder.fragmentTag);
     ft.commit();
   }
   mActivity.onBackStackChanged();
 }