opt
This commit is contained in:
@@ -12,6 +12,7 @@ import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.extensions.ExtensionsModuleConst;
|
||||
@@ -21,6 +22,7 @@ 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.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
@@ -44,6 +46,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
private IMogoMapService mMogoMapService;
|
||||
private IMogoMapUIController mMogoMapUIController;
|
||||
private MogoModulesHandler mMogoModuleHandler;
|
||||
|
||||
private IMogoSocketManager mMogoSocketManager;
|
||||
@@ -79,6 +82,8 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
FragmentStack.getInstance().init( this, R.id.module_main_id_search_fragment );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,12 +104,16 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoMapService.getHostListenerRegister().registerMarkerClickListener( this );
|
||||
}
|
||||
|
||||
mMogoMapUIController = mMogoMapService.getMapUIController();
|
||||
|
||||
mMogoModuleHandler.loadModules();
|
||||
mMogoModuleHandler.onMapLoadedCallback( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Logger.d( TAG, "map loaded." + Thread.currentThread().getName() );
|
||||
loadModules();
|
||||
|
||||
mMogoMapUIController.setPointToCenter( 0.66145, 0.590688 );
|
||||
}
|
||||
} );
|
||||
// 加载地图,触发地图加载完毕回调,在初始化其他卡片模块,保证卡片模块可以正确获取地图相关服务。
|
||||
@@ -163,6 +172,14 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
if ( getSupportFragmentManager().getBackStackEntryCount() > 0 ) {
|
||||
getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
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.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< Fragment > mFragmentStack = new Stack<>();
|
||||
private FragmentManager mFragmentManager;
|
||||
private FragmentTransaction mFragmentTransaction;
|
||||
private int mContainerId;
|
||||
private Activity mActivity;
|
||||
private Fragment 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;
|
||||
mFragmentTransaction = mFragmentManager.beginTransaction();
|
||||
}
|
||||
|
||||
public void push( Fragment fragment, String tag ) {
|
||||
if ( fragment == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mFragmentStack.contains( fragment ) ) {
|
||||
Logger.w( TAG, "fragment has already in stack." );
|
||||
return;
|
||||
}
|
||||
if ( mCurrentFragment != null ) {
|
||||
mFragmentTransaction.hide( mCurrentFragment );
|
||||
}
|
||||
mFragmentTransaction.add( mContainerId, fragment, tag );
|
||||
mFragmentTransaction.addToBackStack( null );
|
||||
mFragmentTransaction.commitAllowingStateLoss();
|
||||
mFragmentStack.push( fragment );
|
||||
mCurrentFragment = fragment;
|
||||
|
||||
if ( getFragmentStackTransactionListener() != null ) {
|
||||
getFragmentStackTransactionListener().onTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
public void pop() {
|
||||
if ( mCurrentFragment != null ) {
|
||||
mFragmentTransaction.remove( mCurrentFragment );
|
||||
}
|
||||
if ( mFragmentStack.isEmpty() ) {
|
||||
mFragmentTransaction.commitAllowingStateLoss();
|
||||
mCurrentFragment = null;
|
||||
} else {
|
||||
Fragment fragment = mFragmentStack.pop();
|
||||
if ( fragment != null ) {
|
||||
mFragmentTransaction.show( fragment );
|
||||
mFragmentTransaction.commitAllowingStateLoss();
|
||||
}
|
||||
mCurrentFragment = fragment;
|
||||
}
|
||||
|
||||
if ( getFragmentStackTransactionListener() != null ) {
|
||||
getFragmentStackTransactionListener().onTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mFragmentStack.isEmpty();
|
||||
}
|
||||
|
||||
public FragmentStackTransactionListener getFragmentStackTransactionListener() {
|
||||
return mFragmentStackTransactionListener;
|
||||
}
|
||||
|
||||
public void setFragmentStackTransactionListener( FragmentStackTransactionListener fragmentStackTransactionListener ) {
|
||||
this.mFragmentStackTransactionListener = fragmentStackTransactionListener;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.mogo.module.main.fragmentmanager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-08
|
||||
* <p>
|
||||
* fragment 栈发生变化
|
||||
*/
|
||||
public interface FragmentStackTransactionListener {
|
||||
|
||||
void onTransaction();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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.IMogoFragmentManager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-08
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = MogoServicePaths.PATH_FRAGMENT_MANAGER )
|
||||
public class MogoFragmentManager implements IMogoFragmentManager {
|
||||
|
||||
@Override
|
||||
public void push( Fragment fragment, String tag ) {
|
||||
FragmentStack.getInstance().push( fragment, tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pop() {
|
||||
FragmentStack.getInstance().pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user