opt
This commit is contained in:
@@ -18,8 +18,7 @@
|
||||
android:paddingLeft="@dimen/module_ext_search_paddingLeft"
|
||||
android:paddingRight="@dimen/module_ext_search_paddingRight"
|
||||
android:text="@string/module_map_str_search_hint"
|
||||
android:textColorHint="#FFFFFF"
|
||||
android:textColor="#99FFFFFF"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="@dimen/module_ext_search_textSize"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.mogo.module.main;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -28,6 +30,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.constants.MainConstants;
|
||||
import com.mogo.module.main.windowview.WindowViewHandler;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
@@ -48,7 +51,7 @@ import java.util.Map;
|
||||
* <p>
|
||||
* 描述:加载各个模块
|
||||
*/
|
||||
public class MainActivity extends MvpActivity<MainView, MainPresenter> implements MainView,
|
||||
public class MainActivity extends MvpActivity< MainView, MainPresenter > implements MainView,
|
||||
IMogoLocationListener,
|
||||
IMogoMarkerClickListener {
|
||||
|
||||
@@ -83,8 +86,35 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
|
||||
|
||||
private long mCardStartShowTime = 0;
|
||||
|
||||
// 埋点接口
|
||||
private IMogoAnalytics mAnalytics;
|
||||
|
||||
private Handler mMsgHandler = new Handler( Looper.getMainLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
switch ( msg.what ) {
|
||||
case MainConstants.MSG_LOAD_CARD_MODULES:
|
||||
loadCardModules();
|
||||
mMsgHandler.sendEmptyMessageDelayed( MainConstants.MSG_LOAD_INVOKE_FIRST_CARD_PERFORM_EVENT, 1_000L );
|
||||
break;
|
||||
case MainConstants.MSG_LOAD_INVOKE_FIRST_CARD_PERFORM_EVENT:
|
||||
if ( mOnPageChangeListener != null ) {
|
||||
// 默认触发第一个卡片
|
||||
mOnPageChangeListener.onPageSelected( 0 );
|
||||
}
|
||||
break;
|
||||
case MainConstants.MSG_TRACK_LAST_CARD_DISPLAY_EVENT:
|
||||
trackLastCardShowEvent( ( IMogoModuleProvider ) msg.obj );
|
||||
break;
|
||||
case MainConstants.MSG_TRACK_CARD_FLIP_EVENT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private ViewPager.OnPageChangeListener mOnPageChangeListener;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.module_main_activity_main;
|
||||
@@ -92,193 +122,200 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
mCardsContainer = findViewById(R.id.module_main_id_cards_container);
|
||||
mCardsContainer.setOrientation(OrientedViewPager.Orientation.VERTICAL);
|
||||
mCardsContainer = findViewById( R.id.module_main_id_cards_container );
|
||||
mCardsContainer.setOrientation( OrientedViewPager.Orientation.VERTICAL );
|
||||
|
||||
mCardsContainer.setOnPageChangeListener(new OnPageChangeListenerAdapter() {
|
||||
mCardsContainer.setOnPageChangeListener( mOnPageChangeListener = new OnPageChangeListenerAdapter() {
|
||||
private boolean mIsLast = true;
|
||||
private boolean mCardFlipStatus = false;
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
public void onPageSelected( int position ) {
|
||||
final long start = System.currentTimeMillis();
|
||||
try {
|
||||
IMogoModuleProvider provider = mCardModulesAdapter.getProvider(mCurrentPosition);
|
||||
trackLastCardShowEvent(provider);
|
||||
IMogoModuleProvider provider = mCardModulesAdapter.getProvider( mCurrentPosition );
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MainConstants.MSG_TRACK_LAST_CARD_DISPLAY_EVENT;
|
||||
msg.obj = provider;
|
||||
mMsgHandler.sendMessage(msg );
|
||||
|
||||
mCurrentPosition = position;
|
||||
provider = mCardModulesAdapter.getProvider(mCurrentPosition);
|
||||
mMogoModuleHandler.setModuleEnable(provider.getModuleName());
|
||||
if (!isClickMarker) {
|
||||
mMogoCardManager.invoke(position, mMogoModuleHandler.getCurrentModuleName());
|
||||
provider = mCardModulesAdapter.getProvider( mCurrentPosition );
|
||||
mMogoModuleHandler.setModuleEnable( provider.getModuleName() );
|
||||
if ( !isClickMarker ) {
|
||||
mMogoCardManager.invoke( position, mMogoModuleHandler.getCurrentModuleName() );
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.i(TAG, "onPageSelected cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
Log.i( TAG, "onPageSelected cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
public void onPageScrollStateChanged( int state ) {
|
||||
final long start = System.currentTimeMillis();
|
||||
super.onPageScrollStateChanged(state);
|
||||
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
|
||||
if (!mCardFlipStatus) {
|
||||
super.onPageScrollStateChanged( state );
|
||||
if ( state == ViewPager.SCROLL_STATE_DRAGGING ) {
|
||||
if ( !mCardFlipStatus ) {
|
||||
mCardFlipStatus = true;
|
||||
final IMogoModuleProvider provider = mCardModulesAdapter.getProvider(mCurrentPosition);
|
||||
trackCardFlipEvent(provider);
|
||||
final IMogoModuleProvider provider = mCardModulesAdapter.getProvider( mCurrentPosition );
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MainConstants.MSG_TRACK_CARD_FLIP_EVENT;
|
||||
msg.obj = provider;
|
||||
mMsgHandler.sendMessage(msg );
|
||||
}
|
||||
} else if (state == ViewPager.SCROLL_STATE_IDLE) {
|
||||
} else if ( state == ViewPager.SCROLL_STATE_IDLE ) {
|
||||
mCardFlipStatus = false;
|
||||
}
|
||||
|
||||
int cardSize = mCardModulesAdapter.getCount();
|
||||
|
||||
if (state == ViewPager.SCROLL_STATE_SETTLING) {
|
||||
if ( state == ViewPager.SCROLL_STATE_SETTLING ) {
|
||||
mIsLast = false;
|
||||
} else if (state == ViewPager.SCROLL_STATE_IDLE && mIsLast) {
|
||||
} 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);
|
||||
if ( cardSize != 1 && mCurrentPosition == ( cardSize - 1 ) ) {
|
||||
mCardsContainer.setCurrentItem( 0, false );
|
||||
} else if ( cardSize != 1 && mCurrentPosition == 0 ) {
|
||||
mCardsContainer.setCurrentItem( cardSize - 1, false );
|
||||
}
|
||||
} else {
|
||||
mIsLast = true;
|
||||
}
|
||||
Log.i(TAG, "onPageScrollStateChanged cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
Log.i( TAG, "onPageScrollStateChanged cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
* 卡片展示时长埋点
|
||||
* @param provider
|
||||
*/
|
||||
private 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
|
||||
*/
|
||||
private 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);
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
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 ) {
|
||||
showLayout();
|
||||
} else if (size == 1) {
|
||||
} else if ( size == 1 ) {
|
||||
hideLayout();
|
||||
}
|
||||
});
|
||||
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);
|
||||
mLeftShadowFrame = findViewById(R.id.module_main_id_map_left_shadow_frame);
|
||||
mTopShadowFrame = findViewById(R.id.module_main_id_map_top_shadow_frame);
|
||||
} );
|
||||
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 );
|
||||
mLeftShadowFrame = findViewById( R.id.module_main_id_map_left_shadow_frame );
|
||||
mTopShadowFrame = findViewById( R.id.module_main_id_map_top_shadow_frame );
|
||||
|
||||
WindowViewHandler.init(mFloatingLayout);
|
||||
WindowViewHandler.init( mFloatingLayout );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 卡片展示时长埋点
|
||||
*
|
||||
* @param provider
|
||||
*/
|
||||
private 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
|
||||
*/
|
||||
private 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 );
|
||||
}
|
||||
|
||||
// 隐藏布局
|
||||
private void hideLayout() {
|
||||
mHeader.setVisibility(View.GONE);
|
||||
mCards.setVisibility(View.GONE);
|
||||
mApps.setVisibility(View.GONE);
|
||||
mEntrance.setVisibility(View.GONE);
|
||||
mFloatingLayout.setVisibility(View.GONE);
|
||||
mLeftShadowFrame.setVisibility(View.GONE);
|
||||
mHeader.setVisibility( View.GONE );
|
||||
mCards.setVisibility( View.GONE );
|
||||
mApps.setVisibility( View.GONE );
|
||||
mEntrance.setVisibility( View.GONE );
|
||||
mFloatingLayout.setVisibility( View.GONE );
|
||||
mLeftShadowFrame.setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
// 显示布局
|
||||
private void showLayout() {
|
||||
mHeader.setVisibility(View.VISIBLE);
|
||||
mCards.setVisibility(View.VISIBLE);
|
||||
mApps.setVisibility(View.VISIBLE);
|
||||
mEntrance.setVisibility(View.VISIBLE);
|
||||
mFloatingLayout.setVisibility(View.VISIBLE);
|
||||
mLeftShadowFrame.setVisibility(View.VISIBLE);
|
||||
mHeader.setVisibility( View.VISIBLE );
|
||||
mCards.setVisibility( View.VISIBLE );
|
||||
mApps.setVisibility( View.VISIBLE );
|
||||
mEntrance.setVisibility( View.VISIBLE );
|
||||
mFloatingLayout.setVisibility( View.VISIBLE );
|
||||
mLeftShadowFrame.setVisibility( View.VISIBLE );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
protected void onCreate( @Nullable Bundle savedInstanceState ) {
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
MogoModulePaths.addModule(new MogoModule(ServiceConst.PATH_REFRESH_STRATEGY, ServiceConst.PATH_REFRESH_STRATEGY));
|
||||
MogoModulePaths.addModule( new MogoModule( ServiceConst.PATH_REFRESH_STRATEGY, ServiceConst.PATH_REFRESH_STRATEGY ) );
|
||||
|
||||
mMogoModuleHandler = new MogoModulesManager(this);
|
||||
mMogoMapService = (IMogoMapService) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_MAP).navigation();
|
||||
if (mMogoMapService != null) {
|
||||
mMogoMapService.getHostListenerRegister().registerHostMapListener(mMogoModuleHandler);
|
||||
mMogoMapService.getHostListenerRegister().registerHostNaviListener(mMogoModuleHandler);
|
||||
mMogoMapService.getHostListenerRegister().registerMarkerClickListener(this);
|
||||
mMogoModuleHandler = new MogoModulesManager( this );
|
||||
mMogoMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
||||
if ( mMogoMapService != null ) {
|
||||
mMogoMapService.getHostListenerRegister().registerHostMapListener( mMogoModuleHandler );
|
||||
mMogoMapService.getHostListenerRegister().registerHostNaviListener( mMogoModuleHandler );
|
||||
mMogoMapService.getHostListenerRegister().registerMarkerClickListener( this );
|
||||
}
|
||||
|
||||
mMogoModuleHandler.setMapLoadedCallback(() -> {
|
||||
Logger.d(TAG, "map loaded." + Thread.currentThread().getName());
|
||||
mMogoModuleHandler.setMapLoadedCallback( () -> {
|
||||
Logger.d( TAG, "map loaded." + Thread.currentThread().getName() );
|
||||
// 加载地图,触发地图加载完毕回调,在初始化其他卡片模块,保证卡片模块可以正确获取地图相关服务。
|
||||
mMogoModuleHandler.loadModules();
|
||||
loadContainerModules();
|
||||
new Handler().postDelayed(() -> loadCardModules(), 5000);
|
||||
mMsgHandler.sendEmptyMessageDelayed( MainConstants.MSG_LOAD_CARD_MODULES, 5_000L );
|
||||
|
||||
// 显示左边遮罩
|
||||
mLeftShadowFrame.setVisibility(View.VISIBLE);
|
||||
mTopShadowFrame.setVisibility(View.VISIBLE);
|
||||
mLeftShadowFrame.setVisibility( View.VISIBLE );
|
||||
mTopShadowFrame.setVisibility( View.VISIBLE );
|
||||
|
||||
// 右移地图中心点
|
||||
mMogoMapUIController = mMogoMapService.getMapUIController();
|
||||
mMogoMapUIController.setPointToCenter(0.66145, 0.590688);
|
||||
mMogoMapUIController.setPointToCenter( 0.66145, 0.590688 );
|
||||
|
||||
// 开启定位
|
||||
startLocation();
|
||||
});
|
||||
mMogoModuleHandler.loadMapModule(R.id.module_main_id_map_fragment_container);
|
||||
} );
|
||||
mMogoModuleHandler.loadMapModule( R.id.module_main_id_map_fragment_container );
|
||||
|
||||
mMogoCardManager = (IMogoCardManager) ARouter.getInstance().build(MogoServicePaths.PATH_CARD_MANAGER).navigation(this);
|
||||
mAnalytics = (IMogoAnalytics) ARouter.getInstance().build(MogoServicePaths.PATH_UTILS_ANALYTICS).navigation(this);
|
||||
mMogoCardManager = ( IMogoCardManager ) ARouter.getInstance().build( MogoServicePaths.PATH_CARD_MANAGER ).navigation( this );
|
||||
mAnalytics = ( IMogoAnalytics ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_ANALYTICS ).navigation( this );
|
||||
}
|
||||
|
||||
private void startLocation() {
|
||||
mLocationClient = mMogoMapService.getSingletonLocationClient(getApplicationContext());
|
||||
mLocationClient.addLocationListener(this);
|
||||
mLocationClient = mMogoMapService.getSingletonLocationClient( getApplicationContext() );
|
||||
mLocationClient.addLocationListener( this );
|
||||
mLocationClient.start();
|
||||
}
|
||||
|
||||
private void loadContainerModules() {
|
||||
mMogoModuleHandler.loadAppsListModule(R.id.module_main_id_apps_fragment_container);
|
||||
mMogoModuleHandler.loadExtensionsModule(R.id.module_main_id_header_fragment_container);
|
||||
mMogoModuleHandler.loadEntrancesModule(R.id.module_main_id_entrance_fragment_container);
|
||||
mMogoModuleHandler.loadAppsListModule( R.id.module_main_id_apps_fragment_container );
|
||||
mMogoModuleHandler.loadExtensionsModule( R.id.module_main_id_header_fragment_container );
|
||||
mMogoModuleHandler.loadEntrancesModule( R.id.module_main_id_entrance_fragment_container );
|
||||
}
|
||||
|
||||
private void loadCardModules() {
|
||||
|
||||
List<IMogoModuleProvider> providers = mMogoModuleHandler.loadCardsModule();
|
||||
mCardModulesAdapter = new CardModulesAdapter(this, providers);
|
||||
mCardsContainer.setOffscreenPageLimit(providers.size());
|
||||
mCardsContainer.setPageTransformer(true, new VerticalStackTransformer(this));
|
||||
mCardsContainer.setAdapter(mCardModulesAdapter);
|
||||
mCardsContainer.setCurrentItem(mCurrentPosition);
|
||||
List< IMogoModuleProvider > providers = mMogoModuleHandler.loadCardsModule();
|
||||
mCardModulesAdapter = new CardModulesAdapter( this, providers );
|
||||
mCardsContainer.setOffscreenPageLimit( providers.size() );
|
||||
mCardsContainer.setPageTransformer( true, new VerticalStackTransformer( this ) );
|
||||
mCardsContainer.setAdapter( mCardModulesAdapter );
|
||||
|
||||
mCardStartShowTime = System.currentTimeMillis();
|
||||
}
|
||||
@@ -287,62 +324,62 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
|
||||
@NonNull
|
||||
@Override
|
||||
protected MainPresenter createPresenter() {
|
||||
return new MainPresenter(this);
|
||||
return new MainPresenter( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(MogoLocation location) {
|
||||
if (mMogoModuleHandler != null) {
|
||||
mMogoModuleHandler.onLocationChanged(location);
|
||||
public void onLocationChanged( MogoLocation location ) {
|
||||
if ( mMogoModuleHandler != null ) {
|
||||
mMogoModuleHandler.onLocationChanged( location );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClicked(IMogoMarker marker) {
|
||||
public boolean onMarkerClicked( IMogoMarker marker ) {
|
||||
isClickMarker = true;
|
||||
switch2(marker.getOwner());
|
||||
if (mMogoModuleHandler != null) {
|
||||
mMogoModuleHandler.onMarkerClicked(marker);
|
||||
switch2( marker.getOwner() );
|
||||
if ( mMogoModuleHandler != null ) {
|
||||
mMogoModuleHandler.onMarkerClicked( marker );
|
||||
}
|
||||
isClickMarker = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switch2(String cardType) {
|
||||
if (mCardModulesAdapter != null) {
|
||||
public void switch2( String cardType ) {
|
||||
if ( mCardModulesAdapter != null ) {
|
||||
|
||||
int position = mCardModulesAdapter.getProviderPosition(cardType);
|
||||
if (position != -1) {
|
||||
int lastFactPosition = mCardModulesAdapter.getFactPosition(mCurrentPosition);
|
||||
mCardsContainer.setCurrentItem(mCurrentPosition + position - lastFactPosition, Math.abs(lastFactPosition - position) == 1);
|
||||
if (!isClickMarker) {
|
||||
mMogoCardManager.invoke(position, mMogoModuleHandler.getCurrentModuleName());
|
||||
int position = mCardModulesAdapter.getProviderPosition( cardType );
|
||||
if ( position != -1 ) {
|
||||
int lastFactPosition = mCardModulesAdapter.getFactPosition( mCurrentPosition );
|
||||
mCardsContainer.setCurrentItem( mCurrentPosition + position - lastFactPosition, Math.abs( lastFactPosition - position ) == 1 );
|
||||
if ( !isClickMarker ) {
|
||||
mMogoCardManager.invoke( position, mMogoModuleHandler.getCurrentModuleName() );
|
||||
}
|
||||
} else {
|
||||
Logger.e(TAG, "Can't find type of %s's position", cardType);
|
||||
Logger.e( TAG, "Can't find type of %s's position", cardType );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
MapBroadCastHelper.getInstance(this).mapFrount();
|
||||
MapBroadCastHelper.getInstance( this ).mapFrount();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
MapBroadCastHelper.getInstance(this).mapBackground();
|
||||
MapBroadCastHelper.getInstance( this ).mapBackground();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mMogoFragmentManager.getStackSize() == 0) {
|
||||
if ( mMogoFragmentManager.getStackSize() == 0 ) {
|
||||
return;
|
||||
}
|
||||
if (mMogoFragmentManager != null) {
|
||||
if ( mMogoFragmentManager != null ) {
|
||||
mMogoFragmentManager.pop();
|
||||
}
|
||||
}
|
||||
@@ -351,12 +388,12 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mLocationClient != null) {
|
||||
mLocationClient.removeLocationListener(this);
|
||||
if ( mLocationClient != null ) {
|
||||
mLocationClient.removeLocationListener( this );
|
||||
mLocationClient.destroy();
|
||||
}
|
||||
mLocationClient = null;
|
||||
if (mMogoModuleHandler != null) {
|
||||
if ( mMogoModuleHandler != null ) {
|
||||
mMogoModuleHandler.destroy();
|
||||
}
|
||||
mMogoModuleHandler = null;
|
||||
@@ -365,6 +402,6 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
|
||||
mMogoCardManager = null;
|
||||
mMogoFragmentManager = null;
|
||||
|
||||
AIAssist.getInstance(this).release();
|
||||
AIAssist.getInstance( this ).release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mogo.module.main.constants;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-02-12
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.datamanager.IMogoDataChangedListener;
|
||||
import com.mogo.service.datamanager.IMogoDataManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -21,6 +22,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class MogoDataHandler {
|
||||
|
||||
private static final String TAG = "MogoDataHandler";
|
||||
|
||||
private Map< String, List< IMogoDataChangedListener > > mListeners = new HashMap<>();
|
||||
|
||||
private MogoDataHandler() {
|
||||
@@ -42,6 +45,7 @@ public class MogoDataHandler {
|
||||
if ( !mListeners.containsKey( tag ) || mListeners.get( tag ) == null ) {
|
||||
mListeners.put( tag, new ArrayList< IMogoDataChangedListener >() );
|
||||
}
|
||||
mListeners.get( tag ).add( listener );
|
||||
}
|
||||
|
||||
public synchronized void unregisterListener( String tag, IMogoDataChangedListener listener ) {
|
||||
@@ -53,16 +57,20 @@ public class MogoDataHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void invoke( String tag, List< Object > datums ) {
|
||||
if ( tag == null ) {
|
||||
public void invoke( String tag, Object data ) {
|
||||
if ( tag == null || mListeners.get( tag ) == null ) {
|
||||
return;
|
||||
}
|
||||
Iterator< IMogoDataChangedListener > iterator = mListeners.get( tag ).iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoDataChangedListener listener = iterator.next();
|
||||
if ( listener != null ) {
|
||||
listener.onDataSetChanged( datums );
|
||||
try {
|
||||
Iterator< IMogoDataChangedListener > iterator = mListeners.get( tag ).iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoDataChangedListener listener = iterator.next();
|
||||
if ( listener != null ) {
|
||||
listener.onDataSetChanged( data );
|
||||
}
|
||||
}
|
||||
} catch( Exception e ){
|
||||
Logger.e(TAG, e, "error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.mogo.module.common.entity.MarkerShowEntity;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.module.service.Utils;
|
||||
import com.mogo.module.service.datamanager.MogoDataHandler;
|
||||
import com.mogo.service.cardmanager.IMogoCardChangedListener;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -325,6 +326,8 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
|
||||
}
|
||||
}
|
||||
|
||||
// 将数据同步给探路,避免探路每次 perform 的时候去拉取,造成消耗
|
||||
MogoDataHandler.getInstance().invoke( ServiceConst.CARD_TYPE_ROAD_CONDITION, exploreWayList);
|
||||
if (exploreWayList != null) {
|
||||
for (MarkerExploreWay markerExploreWay : exploreWayList) {
|
||||
if (!markerExploreWay.getCanLive()) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.mogo.module.tanlu.callback;
|
||||
|
||||
import com.mogo.service.datamanager.IMogoDataChangedListener;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-02-12
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class DataSetChangedAdapter implements IMogoDataChangedListener {
|
||||
|
||||
private Object mData;
|
||||
|
||||
private DataSetChangedAdapter(){
|
||||
// private constructor
|
||||
}
|
||||
|
||||
private static final class InstanceHolder{
|
||||
private static final DataSetChangedAdapter INSTANCE = new DataSetChangedAdapter();
|
||||
}
|
||||
|
||||
private IMogoDataChangedListener mDelegate;
|
||||
|
||||
public void setDelegate( IMogoDataChangedListener delegate ) {
|
||||
this.mDelegate = delegate;
|
||||
}
|
||||
|
||||
public static DataSetChangedAdapter getInstance(){
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataSetChanged( Object data ) {
|
||||
mData = data;
|
||||
if ( mDelegate != null ) {
|
||||
mDelegate.onDataSetChanged( data );
|
||||
}
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@ import com.mogo.module.common.entity.MarkerUserInfo;
|
||||
import com.mogo.module.service.receiver.MogoReceiver;
|
||||
import com.mogo.module.share.ShareControl;
|
||||
import com.mogo.module.tanlu.R;
|
||||
import com.mogo.module.tanlu.callback.DataSetChangedAdapter;
|
||||
import com.mogo.module.tanlu.callback.NaviCallback;
|
||||
import com.mogo.module.tanlu.callback.RoadLineCallback;
|
||||
import com.mogo.module.tanlu.callback.UploadShareCallback;
|
||||
@@ -77,6 +78,8 @@ import com.mogo.module.tanlu.view.AutoZoomInImageView;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.analytics.IMogoAnalytics;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
import com.mogo.service.datamanager.IMogoDataChangedListener;
|
||||
import com.mogo.service.datamanager.IMogoDataManager;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.imageloader.IMogoImageLoaderListener;
|
||||
import com.mogo.service.imageloader.IMogoImageloader;
|
||||
@@ -117,7 +120,8 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
IMogoMapListener,
|
||||
IMogoPoiSearchListener,
|
||||
IMogoLocationListener,
|
||||
View.OnClickListener {
|
||||
View.OnClickListener,
|
||||
IMogoDataChangedListener {
|
||||
|
||||
private static final String TAG = "TanluCardViewFragment";
|
||||
SimpleCoverVideoPlayer simpleCoverVideoPlayer;
|
||||
@@ -295,6 +299,7 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
}
|
||||
}
|
||||
});
|
||||
DataSetChangedAdapter.getInstance().setDelegate( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -307,6 +312,8 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
initMap();
|
||||
initStrings();
|
||||
initListener();
|
||||
// 数据先到,卡片后创建
|
||||
initData( DataSetChangedAdapter.getInstance().getData() );
|
||||
}
|
||||
|
||||
private void initModelData() {
|
||||
@@ -744,23 +751,20 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
|
||||
isCurrentPage = true;
|
||||
Logger.d(TAG, "tanlu卡片 onPerform 有效 ---->");
|
||||
mMarkerManager = mMogoMapService.getMarkerManager(getActivity());
|
||||
List<IMogoMarker> markers = mMarkerManager.getMarkers(TanluConstants.MODEL_NAME);
|
||||
renderCardViews();
|
||||
}
|
||||
|
||||
if (markers != null && markers.size() > 0) {
|
||||
/**
|
||||
* 根究数据展示页面
|
||||
*/
|
||||
private void renderCardViews(){
|
||||
if (markerExploreWayList != null && markerExploreWayList.size() > 0) {
|
||||
mEmptyLayout.setVisibility(View.GONE);
|
||||
mRootLayout.setVisibility(View.VISIBLE);
|
||||
Logger.d(TAG, "onPerform markers.size() =" + markers.size());
|
||||
for (int i = 0; i < markers.size(); i++) {
|
||||
MarkerExploreWay exploreWay = extractFromMarker(markers.get(i));
|
||||
if (exploreWay == null) {
|
||||
break;
|
||||
}
|
||||
markerExploreWayList.add(exploreWay);
|
||||
}
|
||||
Logger.d(TAG, "onPerform markers.size() =" + markerExploreWayList.size());
|
||||
|
||||
Log.d("TAG", "tanlu卡片 onPerform 有效 markerExploreWayList.size() =" + markerExploreWayList.size());
|
||||
if (markers.size() == 1) {
|
||||
if (markerExploreWayList.size() == 1) {
|
||||
mPreviousTv.setVisibility(View.GONE);
|
||||
mNextTv.setVisibility(View.GONE);
|
||||
} else {
|
||||
@@ -778,6 +782,28 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataSetChanged( Object data ) {
|
||||
Logger.d( TAG, "receive data changed." );
|
||||
initData( data );
|
||||
if ( isCurrentPage ) {
|
||||
renderCardViews();
|
||||
}
|
||||
}
|
||||
|
||||
private void initData(Object data ){
|
||||
if ( markerExploreWayList != null ) {
|
||||
markerExploreWayList.clear();
|
||||
} else {
|
||||
markerExploreWayList = new ArrayList<>();
|
||||
}
|
||||
try {
|
||||
markerExploreWayList.addAll( (List<MarkerExploreWay>)data );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 离开C位事件
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.module.tanlu.callback.DataSetChangedAdapter;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
@@ -40,6 +41,7 @@ public class TanluCardViewProvider implements IMogoModuleProvider {
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
TanluServiceHandler.init( context );
|
||||
TanluServiceHandler.getDataManager().registerDataListener( TanluConstants.MODEL_NAME, DataSetChangedAdapter.getInstance() );
|
||||
Logger.d(TAG, "init ----------> ");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.datamanager.IMogoDataChangedListener;
|
||||
import com.mogo.service.datamanager.IMogoDataManager;
|
||||
import com.mogo.service.imageloader.IMogoImageloader;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
|
||||
@@ -28,6 +30,7 @@ public class TanluServiceHandler {
|
||||
private static IMogoNavi mNavi;
|
||||
private static IMogoMapUIController mMapUIController;
|
||||
private static IMogoImageloader mImageloader;
|
||||
private static IMogoDataManager mDataManager;
|
||||
|
||||
public static void init( Context context ) {
|
||||
mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( context );
|
||||
@@ -38,6 +41,7 @@ public class TanluServiceHandler {
|
||||
mMarkerManager = mMapService.getMarkerManager( context );
|
||||
mNavi = mMapService.getNavi( context );
|
||||
mMapUIController = mMapService.getMapUIController();
|
||||
mDataManager = (IMogoDataManager)ARouter.getInstance().build( MogoServicePaths.PATH_DATA_MANAGER ).navigation(context);
|
||||
}
|
||||
|
||||
public static IMogoMapService getMapService() {
|
||||
@@ -67,4 +71,8 @@ public class TanluServiceHandler {
|
||||
public static IMogoImageloader getImageloader() {
|
||||
return mImageloader;
|
||||
}
|
||||
|
||||
public static IMogoDataManager getDataManager() {
|
||||
return mDataManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface IMogoDataChangedListener {
|
||||
/**
|
||||
* 大而全数据变化回调
|
||||
*
|
||||
* @param datums
|
||||
* @param data
|
||||
*/
|
||||
void onDataSetChanged( List< Object > datums );
|
||||
void onDataSetChanged( Object data );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user