opt
This commit is contained in:
@@ -24,17 +24,12 @@ import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy;
|
||||
import com.mogo.module.common.map.Scene;
|
||||
import com.mogo.module.main.cards.CardIntroduceConfigs;
|
||||
import com.mogo.module.main.cards.CardModulesAdapter;
|
||||
import com.mogo.module.main.cards.HorizentalStackTransformer;
|
||||
import com.mogo.module.main.cards.MogoModulesHandler;
|
||||
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.windowview.FloatingViewHandler;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
@@ -59,16 +54,10 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
private IMogoMapService mMogoMapService;
|
||||
private IMogoMapUIController mMogoMapUIController;
|
||||
private MogoModulesHandler mMogoModuleHandler;
|
||||
private IMogoCardManager mMogoCardManager;
|
||||
private IMogoFragmentManager mMogoFragmentManager;
|
||||
private IMogoStatusManager mMogoStatusManager;
|
||||
|
||||
private OrientedViewPager mCardsContainer;
|
||||
private HorizentalStackTransformer mTransformer;
|
||||
private CardModulesAdapter mCardModulesAdapter;
|
||||
|
||||
private View mHeader;
|
||||
private View mCards;
|
||||
private View mApps;
|
||||
private View mEntrance;
|
||||
private FrameLayout mFloatingLayout;
|
||||
@@ -102,82 +91,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
getWindow().setBackgroundDrawable( null );
|
||||
|
||||
mCardsContainer = findViewById( R.id.module_main_id_cards_container );
|
||||
mCardsContainer.setOrientation( OrientedViewPager.Orientation.HORIZONTAL );
|
||||
mTransformer = new HorizentalStackTransformer( this );
|
||||
mCardsContainer.setOnPageChangeListener( mOnPageChangeListener = new OnPageChangeListenerAdapter() {
|
||||
private boolean mIsLast = true;
|
||||
private boolean mCardFlipStatus = false;
|
||||
|
||||
@Override
|
||||
public void onPageSelected( int position ) {
|
||||
final long start = System.currentTimeMillis();
|
||||
try {
|
||||
IMogoModuleProvider provider = mCardModulesAdapter.getProvider( mCurrentPosition );
|
||||
if ( mCurrentPosition != position ) {
|
||||
mPresenter.postTrackLastCardShowEvent( provider );
|
||||
}
|
||||
mCurrentPosition = position;
|
||||
provider = mCardModulesAdapter.getProvider( mCurrentPosition );
|
||||
mMogoModuleHandler.setModuleEnable( provider.getModuleName() );
|
||||
mMogoCardManager.invoke( position, mMogoModuleHandler.getCurrentModuleName() );
|
||||
|
||||
if ( mLockCarStatus ) {
|
||||
mMogoStatusManager.setUserInteractionStatus( TAG, true, false );
|
||||
mMogoMapUIController.setLockZoom( 16 );
|
||||
mMogoMapUIController.recoverLockMode();
|
||||
}
|
||||
mLockCarStatus = true;
|
||||
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Logger.i( TAG, "onPageSelected cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged( int state ) {
|
||||
final long start = System.currentTimeMillis();
|
||||
super.onPageScrollStateChanged( state );
|
||||
if ( state == ViewPager.SCROLL_STATE_DRAGGING ) {
|
||||
if ( !mCardFlipStatus ) {
|
||||
mCardFlipStatus = true;
|
||||
final IMogoModuleProvider provider = mCardModulesAdapter.getProvider( mCurrentPosition );
|
||||
mPresenter.postTrackCardFlipEvent( provider );
|
||||
}
|
||||
} else if ( state == ViewPager.SCROLL_STATE_IDLE ) {
|
||||
mCardFlipStatus = false;
|
||||
mTransformer.resetOffsetScroll();
|
||||
}
|
||||
|
||||
int cardSize = mCardModulesAdapter.getCount();
|
||||
|
||||
if ( state == ViewPager.SCROLL_STATE_SETTLING ) {
|
||||
mIsLast = false;
|
||||
} else if ( state == ViewPager.SCROLL_STATE_IDLE && mIsLast ) {
|
||||
//此处为你需要的情况,再加入当前页码判断可知道是第一页还是最后一页
|
||||
if ( cardSize != 1 && mCurrentPosition == ( cardSize - 1 ) ) {
|
||||
mCardsContainer.setCurrentItem( 0, false );
|
||||
} else if ( cardSize != 1 && mCurrentPosition == 0 ) {
|
||||
mCardsContainer.setCurrentItem( cardSize - 1, false );
|
||||
}
|
||||
} else {
|
||||
mIsLast = true;
|
||||
}
|
||||
Logger.i( TAG, "onPageScrollStateChanged cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled( int position, float positionOffset,
|
||||
int positionOffsetPixels ) {
|
||||
super.onPageScrolled( position, positionOffset, positionOffsetPixels );
|
||||
Logger.d( TAG, "pageScrolled : offset --- " + positionOffset );
|
||||
mTransformer.offsetScrollChanged( positionOffset );
|
||||
}
|
||||
} );
|
||||
|
||||
mHeader = findViewById( R.id.module_main_id_header_fragment_container );
|
||||
mCards = findViewById( R.id.module_main_id_cards_container );
|
||||
mApps = findViewById( R.id.module_main_id_apps_fragment_container );
|
||||
mEntrance = findViewById( R.id.module_main_id_entrance_fragment_container );
|
||||
mFloatingLayout = findViewById( R.id.module_main_id_floating_view );
|
||||
@@ -194,7 +108,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
// 隐藏布局
|
||||
private void hideLayout() {
|
||||
mHeader.setVisibility( View.GONE );
|
||||
mCards.setVisibility( View.GONE );
|
||||
mApps.setVisibility( View.GONE );
|
||||
mEntrance.setVisibility( View.GONE );
|
||||
mFloatingLayout.setVisibility( View.GONE );
|
||||
@@ -205,7 +118,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
// 显示布局
|
||||
private void showLayout() {
|
||||
mHeader.setVisibility( View.VISIBLE );
|
||||
mCards.setVisibility( View.VISIBLE );
|
||||
mApps.setVisibility( View.VISIBLE );
|
||||
mEntrance.setVisibility( View.VISIBLE );
|
||||
mFloatingLayout.setVisibility( View.VISIBLE );
|
||||
@@ -249,6 +161,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
loadContainerModules();
|
||||
mMogoModuleHandler.loadModules();
|
||||
mPresenter.delayOperations();
|
||||
mPresenter.initADAS();
|
||||
hideCoverUpLayout();
|
||||
|
||||
// 显示左边遮罩
|
||||
@@ -264,8 +177,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
} );
|
||||
mMogoModuleHandler.loadMapModule( R.id.module_main_id_map_fragment_container );
|
||||
|
||||
mMogoCardManager = mServiceApis.getCardManagerApi();
|
||||
|
||||
mMogoFragmentManager = mServiceApis.getFragmentManagerApi();
|
||||
mMogoFragmentManager.init( this, R.id.module_main_id_search_fragment );
|
||||
mMogoFragmentManager.registerMainFragmentStackTransactionListener( ( size ) -> {
|
||||
@@ -291,17 +202,10 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoModuleHandler.loadEntrancesModule( R.id.module_main_id_entrance_fragment_container );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postPickFirstCardEvent() {
|
||||
if ( mOnPageChangeListener != null ) {
|
||||
// 默认触发第一个卡片
|
||||
mOnPageChangeListener.onPageSelected( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideCoverUpLayout() {
|
||||
mCoverUpLayout.setVisibility( View.GONE );
|
||||
mServiceApis.getAdasControllerApi().showADAS();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -336,23 +240,15 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
@Override
|
||||
public void switch2Card( String cardType, boolean lockCar ) {
|
||||
if ( mCardModulesAdapter == null ) {
|
||||
return;
|
||||
}
|
||||
mLockCarStatus = lockCar;
|
||||
int position = mCardModulesAdapter.getProviderPosition( cardType );
|
||||
if ( position != -1 ) {
|
||||
int lastFactPosition = mCardModulesAdapter.getFactPosition( mCurrentPosition );
|
||||
mCardsContainer.setCurrentItem( mCurrentPosition + position - lastFactPosition, Math.abs( lastFactPosition - position ) == 1 );
|
||||
} else {
|
||||
Logger.e( TAG, "Can't find type of %s's position", cardType );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mMogoStatusManager.setMainPageResumeStatus( TAG, true );
|
||||
if ( mCoverUpLayout.getVisibility() == View.VISIBLE ) {
|
||||
mServiceApis.getAdasControllerApi().showADAS();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -360,6 +256,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
super.onPause();
|
||||
mMogoStatusManager.setMainPageResumeStatus( TAG, false );
|
||||
CardIntroduceConfigs.flush( getApplicationContext() );
|
||||
mServiceApis.getAdasControllerApi().closeADAS();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -400,7 +297,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoModuleHandler = null;
|
||||
mMogoMapService = null;
|
||||
mMogoMapUIController = null;
|
||||
mMogoCardManager = null;
|
||||
mMogoFragmentManager = null;
|
||||
AIAssist.getInstance( this ).release();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mogo.module.main;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
@@ -12,7 +11,6 @@ import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.module.main.constants.MainConstants;
|
||||
import com.mogo.module.main.livedata.CardSwitchLiveData;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
@@ -33,8 +31,6 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
// 埋点接口
|
||||
private IMogoAnalytics mAnalytics;
|
||||
|
||||
private long mCardStartShowTime = 0;
|
||||
|
||||
private Handler mMsgHandler = new Handler( Looper.getMainLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
@@ -42,16 +38,6 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
switch ( msg.what ) {
|
||||
case MainConstants.MSG_LOAD_CARD_MODULES:
|
||||
mView.loadCardModules();
|
||||
mMsgHandler.sendEmptyMessageDelayed( MainConstants.MSG_LOAD_INVOKE_FIRST_CARD_PERFORM_EVENT, 1_000L );
|
||||
break;
|
||||
case MainConstants.MSG_LOAD_INVOKE_FIRST_CARD_PERFORM_EVENT:
|
||||
mView.postPickFirstCardEvent();
|
||||
break;
|
||||
case MainConstants.MSG_TRACK_LAST_CARD_DISPLAY_EVENT:
|
||||
trackLastCardShowEvent( ( IMogoModuleProvider ) msg.obj );
|
||||
break;
|
||||
case MainConstants.MSG_TRACK_CARD_FLIP_EVENT:
|
||||
trackCardFlipEvent( ( IMogoModuleProvider ) msg.obj );
|
||||
break;
|
||||
case MainConstants.MSG_HIDE_MAP_COVER_FRAME:
|
||||
mView.hideCoverUpLayout();
|
||||
@@ -65,7 +51,6 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
|
||||
public MainPresenter( MainView view ) {
|
||||
super( view );
|
||||
mCardStartShowTime = System.currentTimeMillis();
|
||||
SchemeIntent.getInstance().init( getContext(), mView.getApis() );
|
||||
}
|
||||
|
||||
@@ -81,38 +66,6 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
mAnalytics = ( IMogoAnalytics ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_ANALYTICS ).navigation( getContext() );
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡片展示时长埋点
|
||||
*
|
||||
* @param provider
|
||||
*/
|
||||
public void trackLastCardShowEvent( IMogoModuleProvider provider ) {
|
||||
if ( provider == null ) {
|
||||
return;
|
||||
}
|
||||
Map< String, Object > properties = new HashMap<>();
|
||||
properties.put( "appname", provider.getAppName() );
|
||||
properties.put( "packagename", provider.getAppPackage() );
|
||||
properties.put( "activeTime", System.currentTimeMillis() - mCardStartShowTime );
|
||||
properties.put( "type", provider.getModuleName() );
|
||||
mAnalytics.track( "Launcher_Card_Show", properties );
|
||||
mCardStartShowTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡片滑动埋点,WTF
|
||||
*/
|
||||
public void trackCardFlipEvent( IMogoModuleProvider provider ) {
|
||||
if ( provider == null ) {
|
||||
return;
|
||||
}
|
||||
Map< String, Object > properties = new HashMap<>();
|
||||
properties.put( "appname", provider.getAppName() );
|
||||
properties.put( "packagename", provider.getAppPackage() );
|
||||
properties.put( "type", provider.getModuleName() );
|
||||
mAnalytics.track( "Launcher_Card_Slide", properties );
|
||||
}
|
||||
|
||||
/**
|
||||
* 延时操作
|
||||
*/
|
||||
@@ -121,20 +74,6 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
mMsgHandler.sendEmptyMessageDelayed( MainConstants.MSG_HIDE_MAP_COVER_FRAME, 150L );
|
||||
}
|
||||
|
||||
public void postTrackLastCardShowEvent( IMogoModuleProvider provider ) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MainConstants.MSG_TRACK_LAST_CARD_DISPLAY_EVENT;
|
||||
msg.obj = provider;
|
||||
mMsgHandler.sendMessage( msg );
|
||||
}
|
||||
|
||||
public void postTrackCardFlipEvent( IMogoModuleProvider provider ) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MainConstants.MSG_TRACK_CARD_FLIP_EVENT;
|
||||
msg.obj = provider;
|
||||
mMsgHandler.sendMessage( msg );
|
||||
}
|
||||
|
||||
public void postLoadModuleMsg() {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MainConstants.MSG_LOAD_MODULES;
|
||||
@@ -144,4 +83,8 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
public void handleSchemeIntent( Intent intent ) {
|
||||
SchemeIntent.getInstance().handle( intent );
|
||||
}
|
||||
|
||||
public void initADAS(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,6 @@ public interface MainView extends IView {
|
||||
*/
|
||||
void loadCardModules();
|
||||
|
||||
/**
|
||||
* 触发第一张卡片选中
|
||||
*/
|
||||
void postPickFirstCardEvent();
|
||||
|
||||
/**
|
||||
* 隐藏背景
|
||||
*/
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
package com.mogo.module.main.cards;
|
||||
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.navi.IMogoAimlessModeListener;
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener;
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.callback.Callback;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-24
|
||||
@@ -64,22 +52,8 @@ public interface MogoModulesHandler {
|
||||
*/
|
||||
void loadEntrancesModule( int containerId );
|
||||
|
||||
/**
|
||||
* 设置某一个module可用
|
||||
*
|
||||
* @param module
|
||||
*/
|
||||
void setModuleEnable( String module );
|
||||
|
||||
/**
|
||||
* 销毁
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* 当前卡片名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getCurrentModuleName();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mogo.module.main.cards;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
@@ -11,24 +10,13 @@ import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.extensions.ExtensionsModuleConst;
|
||||
import com.mogo.module.main.EventDispatchCenter;
|
||||
import com.mogo.module.main.MainActivity;
|
||||
import com.mogo.module.main.registercenter.MogoRegisterCenterHandler;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
import com.mogo.utils.ResourcesHelper;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -38,7 +26,7 @@ import java.util.Map;
|
||||
* <p>
|
||||
* 卡片加载
|
||||
*/
|
||||
public class MogoModulesManager implements MogoModulesHandler{
|
||||
public class MogoModulesManager implements MogoModulesHandler {
|
||||
|
||||
private static final String TAG = "MogoModulesManager";
|
||||
|
||||
@@ -48,17 +36,12 @@ public class MogoModulesManager implements MogoModulesHandler{
|
||||
// 空间换效率
|
||||
private Map< String, IMogoModuleProvider > mModuleNameProviders = new HashMap<>();
|
||||
|
||||
private String mEnableModuleName = null;
|
||||
|
||||
public static final String KEY_SORTED_CARD_MODULES = "sortedCards";
|
||||
private List< String > mSortedCards = new ArrayList<>();
|
||||
|
||||
public MogoModulesManager( MainActivity activity , IMogoServiceApis apis) {
|
||||
public MogoModulesManager( MainActivity activity, IMogoServiceApis apis ) {
|
||||
if ( activity == null ) {
|
||||
throw new NullPointerException( "activity can't be null." );
|
||||
}
|
||||
this.mActivity = activity;
|
||||
EventDispatchCenter.getInstance().registerReceiver(apis.getIntentManagerApi());
|
||||
EventDispatchCenter.getInstance().registerReceiver( apis.getIntentManagerApi() );
|
||||
CardIntroduceConfigs.init( getContext(), apis );
|
||||
}
|
||||
|
||||
@@ -88,61 +71,13 @@ public class MogoModulesManager implements MogoModulesHandler{
|
||||
@Override
|
||||
public List< IMogoModuleProvider > loadCardsModule() {
|
||||
|
||||
String sortedJson = SharedPrefsMgr.getInstance( getContext() ).getString( KEY_SORTED_CARD_MODULES );
|
||||
try {
|
||||
JSONArray array = new JSONArray( sortedJson );
|
||||
mSortedCards = new ArrayList<>( array.length() );
|
||||
for ( int i = 0; i < array.length(); i++ ) {
|
||||
mSortedCards.add( array.getString( i ) );
|
||||
}
|
||||
Logger.d( TAG, "Last cache card: %s", mSortedCards );
|
||||
} catch ( JSONException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
final List< MogoModule > modules = MogoModulePaths.getModules();
|
||||
final ArrayList< IMogoModuleProvider > providers = new ArrayList<>();
|
||||
for ( MogoModule module : modules ) {
|
||||
IMogoModuleProvider provider = mModuleProviders.get( module );
|
||||
if ( provider.getType() == ModuleType.TYPE_CARD_FRAGMENT ) {
|
||||
if ( mEnableModuleName == null ) {
|
||||
mEnableModuleName = provider.getModuleName();
|
||||
}
|
||||
providers.add( provider );
|
||||
}
|
||||
providers.add( provider );
|
||||
}
|
||||
return providers;
|
||||
// return sort( providers ); v2.0.2暂不支持变顺序
|
||||
}
|
||||
|
||||
private List< IMogoModuleProvider > sort( List< IMogoModuleProvider > modules ) {
|
||||
if ( modules == null || modules.size() == 0 ) {
|
||||
return modules;
|
||||
}
|
||||
if ( mSortedCards == null ) {
|
||||
mSortedCards = new ArrayList<>();
|
||||
}
|
||||
List< IMogoModuleProvider > sortedList = new ArrayList<>( modules.size() );
|
||||
|
||||
for ( String sortedCard : mSortedCards ) {
|
||||
for ( IMogoModuleProvider module : modules ) {
|
||||
if ( TextUtils.equals( module.getModuleName(), sortedCard ) ) {
|
||||
sortedList.add( module );
|
||||
Logger.d( TAG, "%s sorted.", sortedCard );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( IMogoModuleProvider module : modules ) {
|
||||
if ( !sortedList.contains( module ) ) {
|
||||
sortedList.add( module );
|
||||
}
|
||||
}
|
||||
mSortedCards.clear();
|
||||
for ( IMogoModuleProvider provider : sortedList ) {
|
||||
mSortedCards.add( provider.getModuleName() );
|
||||
}
|
||||
return sortedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,14 +118,12 @@ public class MogoModulesManager implements MogoModulesHandler{
|
||||
|
||||
private void addFragment( IMogoModuleProvider provider, int containerId ) {
|
||||
if ( provider == null ) {
|
||||
Logger.e( TAG, "add fragment fail cause provider == null, container is %s",
|
||||
ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
|
||||
Logger.e( TAG, "add fragment fail cause provider == null, container is %s", ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
|
||||
return;
|
||||
}
|
||||
final Fragment fragment = provider.createFragment( getContext(), null );
|
||||
if ( fragment == null ) {
|
||||
Logger.e( TAG, "add fragment fail cause fragment == null, container is %s",
|
||||
ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
|
||||
Logger.e( TAG, "add fragment fail cause fragment == null, container is %s", ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
|
||||
return;
|
||||
}
|
||||
mActivity.getSupportFragmentManager().beginTransaction()
|
||||
@@ -198,52 +131,6 @@ public class MogoModulesManager implements MogoModulesHandler{
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModuleEnable( String module ) {
|
||||
final long start1 = System.currentTimeMillis();
|
||||
// 仅操作上一个模块和当前模块
|
||||
Iterator< IMogoModuleProvider > iterator = mModuleProviders.values().iterator();
|
||||
int counter = 0;
|
||||
|
||||
// 上一个卡片设置为 disable
|
||||
IMogoModuleProvider prev = mModuleNameProviders.get( mEnableModuleName );
|
||||
if ( prev != null ) {
|
||||
final IMogoModuleLifecycle lifecycle = MogoRegisterCenterHandler.getInstance().getLifecycleListener( mEnableModuleName );
|
||||
if ( lifecycle != null ) {
|
||||
try {
|
||||
final long start = System.currentTimeMillis();
|
||||
lifecycle.onDisable();
|
||||
Logger.i( TAG, "set %s module disable event cost " + ( System.currentTimeMillis() - start ) + "ms", mEnableModuleName );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当前卡片设置为 perform
|
||||
IMogoModuleProvider current = mModuleNameProviders.get( module );
|
||||
if ( current != null ) {
|
||||
final IMogoModuleLifecycle lifecycle = MogoRegisterCenterHandler.getInstance().getLifecycleListener( module );
|
||||
if ( lifecycle != null ) {
|
||||
try {
|
||||
final long start = System.currentTimeMillis();
|
||||
lifecycle.onPerform();
|
||||
Logger.i( TAG, "set %s module perform event cost " + ( System.currentTimeMillis() - start ) + "ms", module );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mEnableModuleName = module;
|
||||
mSortedCards.remove( mEnableModuleName );
|
||||
mSortedCards.add( 0, mEnableModuleName );
|
||||
SharedPrefsMgr.getInstance( getContext() ).putString( KEY_SORTED_CARD_MODULES, GsonUtil.jsonFromObject( mSortedCards ) );
|
||||
Logger.i( TAG, "enable & disable card cost " + ( System.currentTimeMillis() - start1 ) + "ms" );
|
||||
|
||||
CardIntroduceConfigs.broadcastCardIntroduce( mActivity, mEnableModuleName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mActivity = null;
|
||||
@@ -251,11 +138,5 @@ public class MogoModulesManager implements MogoModulesHandler{
|
||||
mModuleProviders.clear();
|
||||
}
|
||||
mModuleProviders = null;
|
||||
mEnableModuleName = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentModuleName() {
|
||||
return mEnableModuleName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,6 @@ public class MainConstants {
|
||||
*/
|
||||
public static final int MSG_LOAD_CARD_MODULES = 5000;
|
||||
|
||||
/**
|
||||
* 消息:触发第一张卡片的onPerform 时间
|
||||
*/
|
||||
public static final int MSG_LOAD_INVOKE_FIRST_CARD_PERFORM_EVENT = 5001;
|
||||
|
||||
/**
|
||||
* 消息:卡片展示事件
|
||||
*/
|
||||
public static final int MSG_TRACK_LAST_CARD_DISPLAY_EVENT = 5002;
|
||||
|
||||
/**
|
||||
* 消息:卡片滑动事件
|
||||
*/
|
||||
public static final int MSG_TRACK_CARD_FLIP_EVENT = 5003;
|
||||
|
||||
/**
|
||||
* 消息:隐藏地图遮罩(避免地图加载白屏)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user