dev
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package com.mogo.module.apps;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-06
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AppNavigatorFragment extends MvpFragment< IView, Presenter< IView > > implements IView {
|
||||
|
||||
private View mNavigation;
|
||||
private View mMusic;
|
||||
private View mChat;
|
||||
private View mApps;
|
||||
|
||||
private IMogoCardManager mCardManager;
|
||||
|
||||
private AppsFragment mAppsFragment;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.module_apps_fragment_apps_navigator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
mCardManager = ( IMogoCardManager ) ARouter.getInstance().build( MogoServicePaths.PATH_CARD_MANAGER ).navigation( getContext() );
|
||||
|
||||
mNavigation = findViewById( R.id.module_apps_id_navigation );
|
||||
mMusic = findViewById( R.id.module_apps_id_music );
|
||||
mChat = findViewById( R.id.module_apps_id_chat );
|
||||
mApps = findViewById( R.id.module_apps_id_apps );
|
||||
mNavigation.setOnClickListener( view -> {
|
||||
mCardManager.switch2( "CARD_TYPE_NAVIGATION" );
|
||||
} );
|
||||
mMusic.setOnClickListener( view -> {
|
||||
mCardManager.switch2( "CARD_TYPE_SHARE_MUSIC" );
|
||||
} );
|
||||
mChat.setOnClickListener( view -> {
|
||||
mCardManager.switch2( "CARD_TYPE_CARS_CHATTING" );
|
||||
} );
|
||||
mApps.setOnClickListener( view -> {
|
||||
new AppsFragment().show( getChildFragmentManager(), AppsFragment.TAG );
|
||||
} );
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Presenter< IView > createPresenter() {
|
||||
return new Presenter< IView >( this ) {
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.mogo.module.apps;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -10,8 +12,11 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.mogo.commons.mvp.MvpDialogFragment;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.module.apps.model.AppInfo;
|
||||
import com.mogo.utils.BitmapHelper;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,9 +26,11 @@ import java.util.List;
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AppsFragment extends MvpFragment< AppsView, AppsPresenter > implements AppsView {
|
||||
public class AppsFragment extends MvpDialogFragment< AppsView, AppsPresenter > implements AppsView {
|
||||
|
||||
private BottomSheetBehavior mBottomSheetBehavior;
|
||||
public static final String TAG = "AppsFragment";
|
||||
|
||||
// private BottomSheetBehavior mBottomSheetBehavior;
|
||||
private RecyclerView mAppsList;
|
||||
private AppsAdapter mAppsAdapter;
|
||||
|
||||
@@ -35,22 +42,36 @@ public class AppsFragment extends MvpFragment< AppsView, AppsPresenter > impleme
|
||||
@Override
|
||||
protected void initViews() {
|
||||
mAppsList = findViewById( R.id.module_apps_id_apps );
|
||||
mAppsList.setLayoutManager( new GridLayoutManager( getContext(), 3 ) );
|
||||
|
||||
mBottomSheetBehavior = BottomSheetBehavior.from( mAppsList );
|
||||
mBottomSheetBehavior.setSkipCollapsed( true );
|
||||
mBottomSheetBehavior.setBottomSheetCallback( new BottomSheetBehavior.BottomSheetCallback() {
|
||||
@Override
|
||||
public void onStateChanged( @NonNull View bottomSheet, int newState ) {
|
||||
mAppsList.setLayoutManager( new GridLayoutManager( getContext(), 8 ) );
|
||||
// mBottomSheetBehavior = BottomSheetBehavior.from( mAppsList );
|
||||
// mBottomSheetBehavior.setSkipCollapsed( true );
|
||||
// mBottomSheetBehavior.setBottomSheetCallback( new BottomSheetBehavior.BottomSheetCallback() {
|
||||
// @Override
|
||||
// public void onStateChanged( @NonNull View bottomSheet, int newState ) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onSlide( @NonNull View bottomSheet, float slideOffset ) {
|
||||
//
|
||||
// }
|
||||
// } );
|
||||
// mBottomSheetBehavior.setState( BottomSheetBehavior.STATE_COLLAPSED );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
super.onStart();
|
||||
final Dialog dialog = getDialog();
|
||||
if ( dialog != null ) {
|
||||
if ( dialog.getWindow() != null ) {
|
||||
final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
|
||||
params.width = WindowUtils.getScreenWidth( getContext() );
|
||||
params.height = WindowUtils.getScreenHeight( getContext() );
|
||||
dialog.getWindow().setAttributes( params );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlide( @NonNull View bottomSheet, float slideOffset ) {
|
||||
|
||||
}
|
||||
} );
|
||||
mBottomSheetBehavior.setState( BottomSheetBehavior.STATE_COLLAPSED );
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -76,11 +97,9 @@ public class AppsFragment extends MvpFragment< AppsView, AppsPresenter > impleme
|
||||
}
|
||||
|
||||
private void bindListener() {
|
||||
mAppsAdapter.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
AppInfo tag = (AppInfo) v.getTag();
|
||||
|
||||
}
|
||||
});
|
||||
mAppsAdapter.setOnClickListener( view -> {
|
||||
AppInfo app = ( AppInfo ) view.getTag();
|
||||
mPresenter.launch( app );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ import com.mogo.service.module.ModuleType;
|
||||
@Route( path = MogoModulePaths.PATH_MODULE_APPS )
|
||||
public class AppsFragmentProvider implements IMogoModuleProvider {
|
||||
|
||||
private AppsFragment mAppsFragment;
|
||||
private AppNavigatorFragment mAppsFragment;
|
||||
|
||||
@Override
|
||||
public Fragment createFragment( Context context, Bundle data ) {
|
||||
mAppsFragment = new AppsFragment();
|
||||
mAppsFragment = new AppNavigatorFragment();
|
||||
mAppsFragment.setArguments( data );
|
||||
return mAppsFragment;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.module.apps;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -83,4 +84,17 @@ public class AppsPresenter extends Presenter< AppsView > {
|
||||
return appInfos;
|
||||
}
|
||||
|
||||
public void launch( AppInfo appInfo ) {
|
||||
if ( appInfo == null ) {
|
||||
return;
|
||||
}
|
||||
Intent intent = getContext().getPackageManager().getLaunchIntentForPackage( appInfo.getPackageName() );
|
||||
if ( intent == null ) {
|
||||
Logger.e( TAG, "can't launch app: %s", appInfo.toString() );
|
||||
return;
|
||||
}
|
||||
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
getContext().startActivity( intent );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,4 +43,14 @@ public class AppInfo {
|
||||
public Drawable getIcon() {
|
||||
return mIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AppInfo{" +
|
||||
"mName='" + mName + '\'' +
|
||||
", mPackageName='" + mPackageName + '\'' +
|
||||
", mVersionName='" + mVersionName + '\'' +
|
||||
", mVersionCode=" + mVersionCode +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user