dev
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.mogo.module.main;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-01
|
||||
* <p>
|
||||
* 常量
|
||||
*/
|
||||
public class AppConstants {
|
||||
|
||||
/**
|
||||
* 长链 appId
|
||||
*/
|
||||
public static final String SOCKET_APP_ID = "com.mogo.launcher";
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mogo.module.main;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -20,6 +19,7 @@ import com.mogo.module.main.cards.MogoModulesManager;
|
||||
import com.mogo.module.main.cards.OrientedViewPager;
|
||||
import com.mogo.module.main.cards.VerticalStackTransformer;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.connection.IMogoSocketManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -41,6 +41,8 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
private IMogoMapService mMogoMapService;
|
||||
private MogoModulesHandler mMogoModuleHandler;
|
||||
|
||||
private IMogoSocketManager mMogoSocketManager;
|
||||
|
||||
private OrientedViewPager mCardsContainer;
|
||||
private CardModulesAdapter mCardModulesAdapter;
|
||||
|
||||
@@ -49,7 +51,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
*/
|
||||
private IMogoLocationClient mLocationClient;
|
||||
|
||||
private int mCurrentPosition = 1;
|
||||
private int mCurrentPosition = 0;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -63,17 +65,9 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
mCardsContainer.setOnPageChangeListener( new ViewPager.OnPageChangeListener() {
|
||||
|
||||
private int mLastPosition = -1;
|
||||
|
||||
@Override
|
||||
public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels ) {
|
||||
Logger.i( TAG, "position = " + position );
|
||||
if ( mLastPosition != position ) {
|
||||
if ( mCardModulesAdapter != null ) {
|
||||
mCardModulesAdapter.render( position );
|
||||
}
|
||||
mLastPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,31 +83,27 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
@Override
|
||||
public void onPageScrollStateChanged( int state ) {
|
||||
if ( state == ViewPager.SCROLL_STATE_IDLE ) {
|
||||
if ( mCurrentPosition == 0 ) {
|
||||
mCurrentPosition = mCardModulesAdapter.getCount() - 3;
|
||||
mCardsContainer.setCurrentItem( mCurrentPosition, false );
|
||||
} else if ( mCurrentPosition == mCardModulesAdapter.getCount() - 2 ) {
|
||||
mCurrentPosition = 1;
|
||||
mCardsContainer.setCurrentItem( mCurrentPosition, false );
|
||||
}
|
||||
// if ( mCurrentPosition == 0 ) {
|
||||
// mCurrentPosition = mCardModulesAdapter.getCount() - 3;
|
||||
// mCardsContainer.setCurrentItem( mCurrentPosition, false );
|
||||
// } else if ( mCurrentPosition == mCardModulesAdapter.getCount() - 2 ) {
|
||||
// mCurrentPosition = 1;
|
||||
// mCardsContainer.setCurrentItem( mCurrentPosition, false );
|
||||
// }
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
public int getCurrentPosition() {
|
||||
return mCurrentPosition;
|
||||
}
|
||||
|
||||
public OrientedViewPager getCardsContainer() {
|
||||
return mCardsContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate( @Nullable Bundle savedInstanceState ) {
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
mMogoModuleHandler = new MogoModulesManager( this );
|
||||
|
||||
mMogoSocketManager = ( IMogoSocketManager ) ARouter.getInstance().build( MogoServicePaths.PATH_SOCKET_MANAGER ).navigation();
|
||||
mMogoSocketManager.init( getApplicationContext(), AppConstants.SOCKET_APP_ID );
|
||||
|
||||
mMogoModuleHandler.onMapLoadedCallback( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -140,9 +130,9 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
private void loadModules() {
|
||||
|
||||
List< IMogoModuleProvider > providers = mMogoModuleHandler.loadCards();
|
||||
List< IMogoModuleProvider > providers = mMogoModuleHandler.loadCardsModule();
|
||||
mCardModulesAdapter = new CardModulesAdapter( this, providers );
|
||||
mCardsContainer.setOffscreenPageLimit( providers.size() + 2 );
|
||||
mCardsContainer.setOffscreenPageLimit( providers.size() );
|
||||
mCardsContainer.setPageTransformer( true, new VerticalStackTransformer( this ) );
|
||||
mCardsContainer.setAdapter( mCardModulesAdapter );
|
||||
mCardsContainer.setCurrentItem( mCurrentPosition );
|
||||
@@ -182,5 +172,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoModuleHandler.destroy();
|
||||
mMogoModuleHandler = null;
|
||||
}
|
||||
mMogoSocketManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.mogo.module.main.cards;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -30,18 +28,10 @@ public class CardModulesAdapter extends FragmentStatePagerAdapter {
|
||||
private final MainActivity mActivity;
|
||||
private List< IMogoModuleProvider > mProviders;
|
||||
|
||||
private PlaceholderFragmentProvider mLastPH;
|
||||
private PlaceholderFragmentProvider mFirstPH;
|
||||
private PlaceholderFragmentProvider mPH;
|
||||
|
||||
|
||||
public CardModulesAdapter( @NonNull MainActivity fragmentActivity, List< IMogoModuleProvider > providers ) {
|
||||
super( fragmentActivity.getSupportFragmentManager() );
|
||||
mActivity = fragmentActivity;
|
||||
this.mProviders = new ArrayList<>( providers );
|
||||
this.mProviders.add( 0, mLastPH = new PlaceholderFragmentProvider() );
|
||||
this.mProviders.add( mFirstPH = new PlaceholderFragmentProvider() );
|
||||
this.mProviders.add( mPH = new PlaceholderFragmentProvider() );
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -52,11 +42,6 @@ public class CardModulesAdapter extends FragmentStatePagerAdapter {
|
||||
bundle.putInt( "position", factPosition );
|
||||
Logger.d( TAG, "here" );
|
||||
final Fragment f = mProviders.get( factPosition ).createFragment( mActivity, bundle );
|
||||
if ( position == 0 ) {
|
||||
mLastPH.setCopyTarget( f );
|
||||
} else if ( position == getCount() - 2 ) {
|
||||
mFirstPH.setCopyTarget( f );
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
@@ -106,23 +91,8 @@ public class CardModulesAdapter extends FragmentStatePagerAdapter {
|
||||
return currentPosition + offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem( @NonNull ViewGroup container, int position, @NonNull Object object ) {
|
||||
// super.destroyItem( container, position, object );
|
||||
// Logger.d( TAG, "destroy " + object );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void finishUpdate( @NonNull ViewGroup container ) {
|
||||
super.finishUpdate( container );
|
||||
}
|
||||
|
||||
public void render( int position ) {
|
||||
if ( position == 1 ) {
|
||||
mLastPH.renderTargetUI();
|
||||
} else if ( position == getCount() - 2 ) {
|
||||
mFirstPH.renderTargetUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public interface MogoModulesHandler extends IMogoMapListener,
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List< IMogoModuleProvider > loadCards();
|
||||
List< IMogoModuleProvider > loadCardsModule();
|
||||
|
||||
/**
|
||||
* 加载小智语音
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.mogo.map.model.MogoPoi;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.map.navi.MogoNaviInfo;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.main.MainActivity;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
@@ -69,12 +70,12 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< IMogoModuleProvider > loadCards() {
|
||||
final List< String > modulePaths = MogoModulePaths.getModulesPath();
|
||||
public List< IMogoModuleProvider > loadCardsModule() {
|
||||
final List< MogoModule > modules = MogoModulePaths.getModules();
|
||||
final ArrayList< IMogoModuleProvider > providers = new ArrayList<>();
|
||||
if ( modulePaths != null && !modulePaths.isEmpty() ) {
|
||||
for ( String modulePath : modulePaths ) {
|
||||
IMogoModuleProvider provider = load( modulePath );
|
||||
if ( modules != null && !modules.isEmpty() ) {
|
||||
for ( MogoModule module : modules ) {
|
||||
IMogoModuleProvider provider = load( module.getPath() );
|
||||
providers.add( provider );
|
||||
mCardProviders.put( provider.getModuleName(), provider );
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user