This commit is contained in:
wangcongtao
2020-01-08 15:13:56 +08:00
parent 420098c704
commit ad03c651f2
18 changed files with 239 additions and 108 deletions

View File

@@ -199,7 +199,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
if ( mCardModulesAdapter != null ) {
int position = mCardModulesAdapter.getProviderPosition( cardType );
if ( position != -1 ) {
mCardsContainer.setCurrentItem( position, false );
mCardsContainer.setCurrentItem( position, Math.abs( mCurrentPosition - position ) == 1 );
} else {
Logger.e( TAG, "Can't find type of %s's position", cardType );
}

View File

@@ -232,7 +232,7 @@ public class OrientedViewPager extends ViewGroup {
}
/**
* Used internally to tag special types of child views that should be added as
* Used internally to mTag special types of child views that should be added as
* pager decorations by default.
*/
interface Decor {

View File

@@ -3,10 +3,10 @@ package com.mogo.module.main.fragmentmanager;
import android.app.Activity;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.mogo.service.fragmentmanager.FragmentDescriptor;
import com.mogo.utils.logger.Logger;
import java.util.Stack;
@@ -23,12 +23,12 @@ public class FragmentStack {
private static volatile FragmentStack sInstance;
private Stack< Fragment > mFragmentStack = new Stack<>();
private Stack< FragmentDescriptor > mFragmentStack = new Stack<>();
private FragmentManager mFragmentManager;
private FragmentTransaction mFragmentTransaction;
private int mContainerId;
private Activity mActivity;
private Fragment mCurrentFragment;
private FragmentDescriptor mCurrentFragment;
private FragmentStackTransactionListener mFragmentStackTransactionListener;
@@ -56,11 +56,11 @@ public class FragmentStack {
mContainerId = containerId;
}
public void push( Fragment fragment, String tag ) {
if ( fragment == null ) {
public void push( FragmentDescriptor descriptor ) {
if ( descriptor == null || descriptor.getFragment() == null ) {
return;
}
if ( mFragmentStack.contains( fragment ) ) {
if ( mFragmentStack.contains( descriptor ) ) {
Logger.w( TAG, "fragment has already in stack." );
return;
}
@@ -68,15 +68,15 @@ public class FragmentStack {
mFragmentTransaction = mFragmentManager.beginTransaction();
if ( mCurrentFragment != null ) {
mFragmentTransaction.hide( mCurrentFragment );
mFragmentTransaction.hide( mCurrentFragment.getFragment() );
}
mFragmentTransaction.add( mContainerId, fragment );
mFragmentTransaction.add( mContainerId, descriptor.getFragment() );
mFragmentTransaction.addToBackStack( null );
mFragmentTransaction.commitAllowingStateLoss();
mFragmentStack.push( fragment );
mCurrentFragment = fragment;
mFragmentStack.push( descriptor );
mCurrentFragment = descriptor;
if ( getFragmentStackTransactionListener() != null ) {
if ( descriptor.isNotifyMainModule() && getFragmentStackTransactionListener() != null ) {
getFragmentStackTransactionListener().onTransaction();
}
}
@@ -90,26 +90,26 @@ public class FragmentStack {
mCurrentFragment = mFragmentStack.pop();
if ( mCurrentFragment != null ) {
mFragmentTransaction.remove( mCurrentFragment );
mFragmentTransaction.remove( mCurrentFragment.getFragment() );
}
if ( mFragmentStack.isEmpty() ) {
mFragmentTransaction.commitAllowingStateLoss();
mCurrentFragment = null;
if ( getFragmentStackTransactionListener() != null ) {
if ( mCurrentFragment.isNotifyMainModule() && getFragmentStackTransactionListener() != null ) {
getFragmentStackTransactionListener().onTransaction();
}
mCurrentFragment = null;
return;
}
Fragment fragment = mFragmentStack.peek();
FragmentDescriptor fragment = mFragmentStack.peek();
if ( fragment != null ) {
mFragmentTransaction.show( fragment );
mFragmentTransaction.show( fragment.getFragment() );
mFragmentTransaction.commitAllowingStateLoss();
}
mCurrentFragment = fragment;
if ( getFragmentStackTransactionListener() != null ) {
if ( mCurrentFragment.isNotifyMainModule() && getFragmentStackTransactionListener() != null ) {
getFragmentStackTransactionListener().onTransaction();
}
mCurrentFragment = fragment;
}
public boolean isEmpty() {

View File

@@ -2,10 +2,9 @@ package com.mogo.module.main.fragmentmanager;
import android.content.Context;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.fragmentmanager.FragmentDescriptor;
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
/**
@@ -18,8 +17,8 @@ import com.mogo.service.fragmentmanager.IMogoFragmentManager;
public class MogoFragmentManager implements IMogoFragmentManager {
@Override
public void push( Fragment fragment, String tag ) {
FragmentStack.getInstance().push( fragment, tag );
public void push( FragmentDescriptor descriptor ) {
FragmentStack.getInstance().push( descriptor );
}
@Override