This commit is contained in:
wangcongtao
2020-01-02 12:05:52 +08:00
parent 05bd793763
commit aa51e04589
40 changed files with 3941 additions and 3323 deletions

View File

@@ -0,0 +1,42 @@
package com.mogo.module.common;
/**
* @author congtaowang
* @since 2019-12-31
* <p>
* 模块描述信息
*/
public class MogoModule {
/**
* 模块加载路径
*/
private String mPath;
/**
* 模块名称
*/
private String mName;
public MogoModule( String path, String name ) {
this.mPath = path;
this.mName = name;
}
public String getPath() {
return mPath;
}
public void setPath( String path ) {
this.mPath = path;
}
public String getName() {
return mName;
}
public void setName( String name ) {
this.mName = name;
}
}

View File

@@ -16,7 +16,7 @@ import java.util.Vector;
*/
public class MogoModulePaths {
private static List< String > mModulesPath = new ArrayList<>();
private static List< MogoModule > mMogoModules = new ArrayList<>();
/**
* 地图模块 fragment 路径
@@ -33,10 +33,17 @@ public class MogoModulePaths {
if ( TextUtils.isEmpty( path.replace( " ", "" ) ) ) {
throw new IllegalArgumentException( "module path can't be empty or null or blank" );
}
mModulesPath.add( path );
mMogoModules.add( new MogoModule( path, "" ) );
}
public static List< String > getModulesPath() {
return mModulesPath;
public static void addModule( MogoModule module ) {
if ( module == null || TextUtils.isEmpty( module.getPath().replace( " ", "" ) ) ) {
throw new IllegalArgumentException( "module path can't be empty or null or blank" );
}
mMogoModules.add( module );
}
public static List< MogoModule > getModules() {
return mMogoModules;
}
}

View File

@@ -43,6 +43,7 @@ dependencies {
implementation rootProject.ext.dependencies.mogoserviceapi
implementation rootProject.ext.dependencies.mogoservice
implementation rootProject.ext.dependencies.moduleapps
implementation rootProject.ext.dependencies.mogoconnection
} else {
implementation project(":foudations:mogo-utils")
implementation project(":foudations:mogo-commons")
@@ -51,6 +52,7 @@ dependencies {
implementation project(':services:mogo-service-api')
implementation project(':services:mogo-service')
implementation project(':modules:mogo-module-apps')
implementation project(':foudations:mogo-connection')
}
}

View File

@@ -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";
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}
}

View File

@@ -29,7 +29,7 @@ public interface MogoModulesHandler extends IMogoMapListener,
*
* @return
*/
List< IMogoModuleProvider > loadCards();
List< IMogoModuleProvider > loadCardsModule();
/**
* 加载小智语音

View File

@@ -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 );
}

View File

@@ -1,47 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<!-- 小智语音-->
<FrameLayout
android:id="@+id/module_main_id_ai_fragment_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="75dp"
android:background="#f00"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- 卡片-->
<FrameLayout
android:id="@+id/module_main_id_fragment_container"
android:layout_width="300dp"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.mogo.module.main.cards.OrientedViewPager
android:id="@+id/module_main_id_cards_container"
android:layout_width="match_parent"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 卡片-->
<FrameLayout
android:id="@+id/module_main_id_fragment_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_marginBottom="50dp"
android:padding="10dp" />
android:layout_weight="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<!-- <androidx.viewpager2.widget.ViewPager2-->
<!-- android:id="@+id/module_main_id_cards_container"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:clipChildren="false" />-->
<com.mogo.module.main.cards.OrientedViewPager
android:id="@+id/module_main_id_cards_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:padding="10dp" />
</FrameLayout>
</FrameLayout>
<!-- 地图-->
<FrameLayout
android:id="@+id/module_main_id_map_fragment_container"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintLeft_toRightOf="@+id/module_main_id_fragment_container"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- 地图-->
<FrameLayout
android:id="@+id/module_main_id_map_fragment_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
app:layout_constraintLeft_toRightOf="@+id/module_main_id_fragment_container"
app:layout_constraintRight_toRightOf="parent" />
</LinearLayout>
</LinearLayout>

View File

@@ -2,7 +2,6 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00">
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>