opt
This commit is contained in:
@@ -24,14 +24,12 @@ import com.mogo.module.main.cards.MogoModulesManager;
|
||||
import com.mogo.module.main.cards.OnPageChangeListenerAdapter;
|
||||
import com.mogo.module.main.cards.OrientedViewPager;
|
||||
import com.mogo.module.main.cards.VerticalStackTransformer;
|
||||
import com.mogo.module.main.fragmentmanager.FragmentStack;
|
||||
import com.mogo.module.main.fragmentmanager.FragmentStackTransactionListener;
|
||||
import com.mogo.module.main.windowview.WindowViewHandler;
|
||||
import com.mogo.module.map.VoiceConstants;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
import com.mogo.service.connection.IMogoSocketManager;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.impl.fragmentmanager.FragmentStack;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -54,6 +52,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
private IMogoMapUIController mMogoMapUIController;
|
||||
private MogoModulesHandler mMogoModuleHandler;
|
||||
private IMogoCardManager mMogoCardManager;
|
||||
private IMogoFragmentManager mMogoFragmentManager;
|
||||
|
||||
private OrientedViewPager mCardsContainer;
|
||||
private CardModulesAdapter mCardModulesAdapter;
|
||||
@@ -95,15 +94,13 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
}
|
||||
} );
|
||||
|
||||
FragmentStack.getInstance().init( this, R.id.module_main_id_search_fragment );
|
||||
FragmentStack.getInstance().setFragmentStackTransactionListener( new FragmentStackTransactionListener() {
|
||||
@Override
|
||||
public void onTransaction() {
|
||||
if ( FragmentStack.getInstance().isEmpty() ) {
|
||||
show();
|
||||
} else if ( FragmentStack.getInstance().getStackSize() == 1 ) {
|
||||
hide();
|
||||
}
|
||||
mMogoFragmentManager = ( IMogoFragmentManager ) ARouter.getInstance().build( MogoServicePaths.PATH_FRAGMENT_MANAGER ).navigation( this );
|
||||
mMogoFragmentManager.init( this, R.id.module_main_id_search_fragment );
|
||||
mMogoFragmentManager.registerMainFragmentStackTransactionListener( ( size ) -> {
|
||||
if ( size == 0 ) {
|
||||
show();
|
||||
} else if ( size == 1 ) {
|
||||
hide();
|
||||
}
|
||||
} );
|
||||
mHeader = findViewById( R.id.module_main_id_header_fragment_container );
|
||||
@@ -226,7 +223,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if ( FragmentStack.getInstance().isEmpty() ) {
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
FragmentStack.getInstance().pop();
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
package com.mogo.module.main.fragmentmanager;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-08
|
||||
* <p>
|
||||
* fragment 任务栈
|
||||
*/
|
||||
public class FragmentStack {
|
||||
|
||||
private static final String TAG = "FragmentStack";
|
||||
|
||||
private static volatile FragmentStack sInstance;
|
||||
|
||||
private Stack< FragmentDescriptor > mFragmentStack = new Stack<>();
|
||||
private FragmentManager mFragmentManager;
|
||||
private FragmentTransaction mFragmentTransaction;
|
||||
private int mContainerId;
|
||||
private Activity mActivity;
|
||||
private FragmentDescriptor mCurrentFragment;
|
||||
|
||||
private FragmentStackTransactionListener mFragmentStackTransactionListener;
|
||||
|
||||
private FragmentStack() {
|
||||
}
|
||||
|
||||
public static FragmentStack getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( FragmentStack.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new FragmentStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
public void init( AppCompatActivity activity, int containerId ) {
|
||||
mActivity = activity;
|
||||
mFragmentManager = activity.getSupportFragmentManager();
|
||||
mContainerId = containerId;
|
||||
}
|
||||
|
||||
public void push( FragmentDescriptor descriptor ) {
|
||||
if ( descriptor == null || descriptor.getFragment() == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mFragmentStack.contains( descriptor ) ) {
|
||||
Logger.w( TAG, "fragment has already in stack." );
|
||||
return;
|
||||
}
|
||||
|
||||
mFragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
if ( mCurrentFragment != null ) {
|
||||
mFragmentTransaction.hide( mCurrentFragment.getFragment() );
|
||||
}
|
||||
mFragmentTransaction.add( mContainerId, descriptor.getFragment() );
|
||||
if ( descriptor.hasTransition() ) {
|
||||
mFragmentTransaction.setTransition( FragmentTransaction.TRANSIT_FRAGMENT_OPEN );
|
||||
}
|
||||
mFragmentTransaction.addToBackStack( null );
|
||||
mFragmentTransaction.commitAllowingStateLoss();
|
||||
if ( descriptor.hasTransition() ) {
|
||||
mFragmentManager.executePendingTransactions();
|
||||
}
|
||||
mFragmentStack.push( descriptor );
|
||||
mCurrentFragment = descriptor;
|
||||
|
||||
if ( descriptor.isNotifyMainModule() && getFragmentStackTransactionListener() != null ) {
|
||||
getFragmentStackTransactionListener().onTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
public void pop() {
|
||||
if ( mFragmentStack.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
mFragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
mCurrentFragment = mFragmentStack.pop();
|
||||
if ( mCurrentFragment != null ) {
|
||||
mFragmentTransaction.remove( mCurrentFragment.getFragment() );
|
||||
}
|
||||
if ( mFragmentStack.isEmpty() ) {
|
||||
mFragmentTransaction.commitAllowingStateLoss();
|
||||
if ( mCurrentFragment.isNotifyMainModule() && getFragmentStackTransactionListener() != null ) {
|
||||
getFragmentStackTransactionListener().onTransaction();
|
||||
}
|
||||
mCurrentFragment = null;
|
||||
return;
|
||||
}
|
||||
FragmentDescriptor fragment = mFragmentStack.peek();
|
||||
if ( fragment != null ) {
|
||||
mFragmentTransaction.show( fragment.getFragment() );
|
||||
mFragmentTransaction.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
if ( mCurrentFragment.isNotifyMainModule() && getFragmentStackTransactionListener() != null ) {
|
||||
getFragmentStackTransactionListener().onTransaction();
|
||||
}
|
||||
mCurrentFragment = fragment;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mFragmentStack.isEmpty();
|
||||
}
|
||||
|
||||
public int getStackSize() {
|
||||
return mFragmentStack.size();
|
||||
}
|
||||
|
||||
public FragmentStackTransactionListener getFragmentStackTransactionListener() {
|
||||
return mFragmentStackTransactionListener;
|
||||
}
|
||||
|
||||
public void setFragmentStackTransactionListener( FragmentStackTransactionListener fragmentStackTransactionListener ) {
|
||||
this.mFragmentStackTransactionListener = fragmentStackTransactionListener;
|
||||
}
|
||||
|
||||
public void clearAll() {
|
||||
if ( mFragmentStack.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
mFragmentTransaction = mFragmentManager.beginTransaction();
|
||||
for ( FragmentDescriptor descriptor : mFragmentStack ) {
|
||||
mFragmentTransaction.remove( descriptor.getFragment() );
|
||||
}
|
||||
mFragmentTransaction.commitAllowingStateLoss();
|
||||
mFragmentStack.clear();
|
||||
mCurrentFragment = null;
|
||||
if ( getFragmentStackTransactionListener() != null ) {
|
||||
getFragmentStackTransactionListener().onTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.mogo.module.main.fragmentmanager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-08
|
||||
* <p>
|
||||
* fragment 栈发生变化
|
||||
*/
|
||||
public interface FragmentStackTransactionListener {
|
||||
|
||||
void onTransaction();
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.mogo.module.main.fragmentmanager;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-08
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = MogoServicePaths.PATH_FRAGMENT_MANAGER )
|
||||
public class MogoFragmentManager implements IMogoFragmentManager {
|
||||
|
||||
@Override
|
||||
public void push( FragmentDescriptor descriptor ) {
|
||||
FragmentStack.getInstance().push( descriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pop() {
|
||||
FragmentStack.getInstance().pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackSize() {
|
||||
return FragmentStack.getInstance().getStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAll() {
|
||||
FragmentStack.getInstance().clearAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user