1. 车聊聊电话和音乐浮窗的互斥

2. 添加模块资源释放回调
This commit is contained in:
wangcongtao
2020-09-24 16:59:17 +08:00
parent 87bc02aeda
commit d33741db28
13 changed files with 139 additions and 32 deletions

View File

@@ -133,7 +133,7 @@ targetSdkVersion : 22,
jetbrainsannotationsjava5 : "org.jetbrains:annotations-java5:15.0",
// 统一登录
accountsdk : "com.zhidao.accountservice:account-sdk:1.0.14",
accountsdk : "com.zhidao.accountservice:account-sdk:1.0.11",
// crash
crashSdk : "com.zhidaoauto.crash.log:library:1.0.5",
kotlinstdlibjdk7 : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${kotlin_version}",

View File

@@ -357,5 +357,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
AIAssist.getInstance( this ).release();
mServiceApis.getOnlineCarPanelApi().clear();
ContextHolderUtil.releaseContext();
MogoModulesManager.getInstance().onDestroy();
}
}

View File

@@ -77,4 +77,9 @@ public interface MogoModulesHandler {
* @param containerId
*/
void loadSplashModule(int containerId);
/**
* 释放各个模块资源
*/
void onDestroy();
}

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.idst.nls.internal.utils.L;
import com.mogo.module.common.MogoModule;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.module.extensions.ExtensionsModuleConst;
@@ -16,6 +17,7 @@ import com.mogo.utils.ResourcesHelper;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -131,25 +133,25 @@ public class MogoModulesManager implements MogoModulesHandler {
}
@Override
public void loadEventPanelModule(int containerId) {
public void loadEventPanelModule( int containerId ) {
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance()
.build(MogoServicePaths.PATH_EVENT_PANEL)
.build( MogoServicePaths.PATH_EVENT_PANEL )
.navigation( getContext() );
addFragment( provider, containerId );
}
@Override
public void loadLeftPanelModule(int containerId) {
public void loadLeftPanelModule( int containerId ) {
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance()
.build(MogoServicePaths.PATH_LEFT_PANEL)
.build( MogoServicePaths.PATH_LEFT_PANEL )
.navigation( getContext() );
addFragment( provider, containerId );
}
@Override
public void loadSplashModule(int containerId) {
public void loadSplashModule( int containerId ) {
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance()
.build(MogoServicePaths.PATH_SPLASH)
.build( MogoServicePaths.PATH_SPLASH )
.navigation( getContext() );
addFragment( provider, containerId );
}
@@ -188,4 +190,25 @@ public class MogoModulesManager implements MogoModulesHandler {
.replace( containerId, fragment, provider.getModuleName() )
.commitAllowingStateLoss();
}
@Override
public void onDestroy() {
if ( mModuleNameProviders != null ) {
Collection< IMogoModuleProvider > modules = mModuleNameProviders.values();
if ( modules != null ) {
for ( IMogoModuleProvider module : modules ) {
try {
Logger.d( TAG, "destroy module: " + module.getModuleName() );
module.onDestroy();
} catch ( Exception e ) {
Logger.e( TAG, e, "onDestroy" );
}
}
}
mModuleNameProviders.clear();
}
if ( mModuleProviders != null ) {
mModuleProviders.clear();
}
}
}

View File

@@ -47,6 +47,8 @@ dependencies {
implementation "com.mogo.tencent.wecarflow:mogo-wecarflow:+@aar"
implementation "com.mogo.kwmusic:mogo-kwmusic:+"
implementation rootProject.ext.dependencies.carcallprovider
if (Boolean.valueOf(RELEASE)) {
implementation rootProject.ext.dependencies.mogomap
implementation rootProject.ext.dependencies.mogoutils

View File

@@ -20,7 +20,7 @@ import com.mogo.service.module.ModuleType;
public class MediaCardViewProvider implements IMogoModuleProvider {
private static final String TAG = "MediaCardViewProvider";
private MediaWindow2 mediaWindow2;
@Override
public Fragment createFragment( Context context, Bundle data ) {
@@ -33,7 +33,7 @@ public class MediaCardViewProvider implements IMogoModuleProvider {
@Override
public void init( Context context ) {
ServiceMediaHandler.init( context );
MediaWindow2 mediaWindow2 = new MediaWindow2();
mediaWindow2 = new MediaWindow2();
mediaWindow2.initMedia(context);
}
@@ -88,4 +88,12 @@ public class MediaCardViewProvider implements IMogoModuleProvider {
public String getAppName() {
return "";
}
@Override
public void onDestroy() {
if ( mediaWindow2 != null ) {
mediaWindow2.onDestroy();
}
mediaWindow2 = null;
}
}

View File

@@ -11,6 +11,7 @@ import com.mogo.map.navi.IMogoNavi;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant;
import com.mogo.module.authorize.authprovider.module.IMogoAuthorizeModuleManager;
import com.mogo.module.carchattingprovider.ICarsChattingProvider;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.adas.IMogoADASController;
import com.mogo.service.analytics.IMogoAnalytics;
@@ -53,6 +54,8 @@ public class ServiceMediaHandler {
private static IMogoAuthorizeModuleManager mMogoAuthorizeModuleManager;
private static IMogoMarkerService sMarkerService;
private static ICarsChattingProvider sCarsChattingProvider;
public static void init(Context context) {
mApis = (MogoServiceApis) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context);
mMapService = mApis.getMapServiceApi();
@@ -73,6 +76,8 @@ public class ServiceMediaHandler {
mMogoADASController = mApis.getAdasControllerApi();
mMogoAuthorizeModuleManager = (IMogoAuthorizeModuleManager) ARouter.getInstance().build(AuthorizeConstant.PROVIDER_MODULE).navigation(context);
sMarkerService = mApis.getMarkerService();
sCarsChattingProvider = ARouter.getInstance().navigation( ICarsChattingProvider.class );
}
public static IMogoADASController getMogoADASController(){
@@ -157,6 +162,10 @@ public class ServiceMediaHandler {
return mMogoDataManager;
}
public static MogoServiceApis getApis() {
return mApis;
}
/**
* 这个注册的第一个参数是模块名称,目的是只给当前显示的卡片分发事件
* @return
@@ -183,6 +192,11 @@ public class ServiceMediaHandler {
return sMarkerService;
}
public static ICarsChattingProvider getCarsChattingApis() {
isApisNull( sCarsChattingProvider );
return sCarsChattingProvider;
}
public static void isApisNull( Object object){
if (isObjStaticNull(object)){
init(AbsMogoApplication.getApp());

View File

@@ -12,11 +12,13 @@ import android.widget.TextView;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.voice.AIAssist;
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
import com.mogo.module.carchattingprovider.ICallProviderResponse;
import com.mogo.module.common.glide.SkinAbleBitmapTarget;
import com.mogo.module.media.MediaConstants;
import com.mogo.module.media.R;
import com.mogo.module.media.ServiceMediaHandler;
import com.mogo.module.media.constants.MusicConstant;
import com.mogo.module.media.listener.CallProviderResponseAdapter;
import com.mogo.module.media.listener.NoDoubleClickListener;
import com.mogo.module.media.model.MediaInfoData;
import com.mogo.module.media.presenter.BaseMediaPresenter;
@@ -25,6 +27,7 @@ import com.mogo.module.media.presenter.PresenterFactory;
import com.mogo.module.media.utils.Utils;
import com.mogo.module.media.view.IMusicView;
import com.mogo.module.media.widget.AnimCircleImageView;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.StatusDescriptor;
import com.mogo.utils.WindowUtils;
import com.mogo.utils.glide.GlideApp;
@@ -38,7 +41,7 @@ import com.tencent.wecarflow.flowoutside.sdk.FlowPlayControl;
*
* @author tongchenfei
*/
public class MediaWindow2 implements IMusicView {
public class MediaWindow2 implements IMusicView , IMogoStatusChangedListener {
public static final String TAG = MediaWindow2.class.getName();
private Context mContext;
@@ -58,6 +61,9 @@ public class MediaWindow2 implements IMusicView {
private boolean mHasAddWindow = false;
private boolean mTwoChange = false;
private boolean isFirstPlay = false;
private boolean mIsCallChatWindowVisible;
private ICallProviderResponse mCallProviderResponse;
public void initMedia(Context context) {
mContext = context;
@@ -76,14 +82,34 @@ public class MediaWindow2 implements IMusicView {
});
}
ServiceMediaHandler.getIMogoStatusManager().registerStatusChangedListener(MediaConstants.MODULE_TYPE, StatusDescriptor.ACC_STATUS, (descriptor, isTrue) -> {
if (descriptor == StatusDescriptor.ACC_STATUS&&!isTrue) {
ServiceMediaHandler.getMogoWindowManager().removeView(mWindowView);
mHasAddWindow = false;
}
});
ServiceMediaHandler.getIMogoStatusManager().registerStatusChangedListener(MediaConstants.MODULE_TYPE, StatusDescriptor.ACC_STATUS, this);
isFirstPlay = true;
// 车聊聊才是王
mCallProviderResponse = new CallProviderResponseAdapter(){
@Override
public void callWindowStatus( boolean b ) {
Logger.d( TAG, "callWindowStatus: "+ b);
mIsCallChatWindowVisible = b;
if ( !mHasAddWindow || mWindowView == null ) {
return;
}
if ( mIsCallChatWindowVisible ) {
mWindowView.setVisibility(View.GONE );
} else {
mWindowView.setVisibility(View.VISIBLE);
}
}
};
ServiceMediaHandler.getCarsChattingApis().registerCallWindowStatusListener( MediaConstants.MODULE_TYPE, mContext, mCallProviderResponse);
isFirstPlay = true;
}
@Override
public void onStatusChanged( StatusDescriptor descriptor, boolean isTrue ) {
if (descriptor == StatusDescriptor.ACC_STATUS&&!isTrue) {
ServiceMediaHandler.getMogoWindowManager().removeView(mWindowView);
mHasAddWindow = false;
}
}
private void addWindowView() {
@@ -93,16 +119,10 @@ public class MediaWindow2 implements IMusicView {
return;
}
if(!ServiceMediaHandler.getIMogoStatusManager().isMainPageOnResume()){
Log.d(TAG, "not in front");
return;
}
if (!mHasAddWindow) {
mHasAddWindow = true;
mWindowView =
LayoutInflater.from(mContext).inflate(R.layout.module_media_music_window_alert_layout, null);
mWindowView.setVisibility(View.VISIBLE);
mCircleImg = mWindowView.findViewById(R.id.window_circle_img);
mScrollText = mWindowView.findViewById(R.id.window_scroll_txt);
mWindowPlayPause = mWindowView.findViewById(R.id.window_play_pause);
@@ -158,6 +178,12 @@ public class MediaWindow2 implements IMusicView {
}
}
});
if ( mIsCallChatWindowVisible ) {
mWindowView.setVisibility(View.GONE);
} else {
mWindowView.setVisibility(View.VISIBLE);
}
}
}
@@ -305,4 +331,10 @@ public class MediaWindow2 implements IMusicView {
mWindowView.setVisibility(View.GONE);
}
}
public void onDestroy(){
Logger.d(TAG, "onDestroy");
ServiceMediaHandler.getCarsChattingApis().unRegisterCallWindowStatusListener( MediaConstants.MODULE_TYPE, mContext);
ServiceMediaHandler.getIMogoStatusManager().unregisterStatusChangedListener(MediaConstants.MODULE_TYPE, StatusDescriptor.ACC_STATUS,this);
}
}

View File

@@ -100,4 +100,9 @@ public class MogoServiceProvider implements IMogoModuleProvider {
MogoServices.getInstance().init( AbsMogoApplication.getApp() );
}, 5_000L );
}
@Override
public void onDestroy() {
MogoServices.getInstance().destroy();
}
}

View File

@@ -20,6 +20,7 @@ import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.storage.SpStorage;
import com.mogo.commons.voice.AIAssist;
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
import com.mogo.map.IDestroyable;
import com.mogo.map.MogoLatLng;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.map.location.IMogoLocationListener;
@@ -95,7 +96,8 @@ public class MogoServices implements IMogoMapListener,
IMogoAimlessModeListener,
IMogoVoiceCmdCallBack,
FragmentStackTransactionListener,
IMogoCarLocationChangedListener2 {
IMogoCarLocationChangedListener2,
IDestroyable {
private boolean mInternalUnWakeupRegisterStatus = false;
@@ -1021,4 +1023,9 @@ public class MogoServices implements IMogoMapListener,
}
}
@Override
public void destroy() {
Logger.d( TAG, "MogoServices do nothings." );
}
}

View File

@@ -189,12 +189,15 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
// 在线车辆点击使用infoWindow
if ( TextUtils.equals( mogoMarker.getOwner(), ModuleNames.CARD_TYPE_USER_DATA ) ) {
if ( !mogoMarker.isDestroyed() ) {
try {
MarkerOnlineCar onlineCar = ( MarkerOnlineCar ) ( ( MarkerShowEntity ) mogoMarker.getObject() ).getBindObj();
CallChatApi.getInstance().showUserWindow( mContext, onlineCar );
} catch ( Exception e ) {
Logger.e( TAG, e, "openMarker" );
}
mogoMarker.setInfoWindowAdapter( UserDataMarkerInfoWindowAdapter.getInstance( mContext ) );
mogoMarker.showInfoWindow();
Logger.d( TAG, "打开info window" );
// try {
// MarkerOnlineCar onlineCar = ( MarkerOnlineCar ) ( ( MarkerShowEntity ) mogoMarker.getObject() ).getBindObj();
// CallChatApi.getInstance().showUserWindow( mContext, onlineCar );
// } catch ( Exception e ) {
// Logger.e( TAG, e, "openMarker" );
// }
}
} else {
Object object = mogoMarker.getObject();
@@ -225,7 +228,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
}
// 在线车辆点击使用infoWindow
if ( TextUtils.equals( mogoMarker.getOwner(), ModuleNames.CARD_TYPE_USER_DATA ) ) {
// mogoMarker.hideInfoWindow();
mogoMarker.hideInfoWindow();
Logger.d( TAG, "关闭info window" );
} else {
Object object = mogoMarker.getObject();

View File

@@ -2,6 +2,7 @@ package com.mogo.service.module;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
@@ -13,6 +14,8 @@ import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.navi.IMogoNaviListener;
import java.util.logging.Logger;
/**
* @author congtaowang
* @since 2019-12-24
@@ -128,4 +131,8 @@ public interface IMogoModuleProvider extends IProvider {
default String getAppName() {
return "";
}
default void onDestroy(){
Log.d( "IMogoModuleProvider", "onDestroy" );
}
}

View File

@@ -2,7 +2,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient android:centerX="0.5" android:angle="0" android:endColor="#11ffffff" android:startColor="#ffffff" android:type="linear" />
<gradient android:centerX="0.5" android:centerY="0.5" android:angle="0" android:endColor="#00ffffff" android:startColor="#ffffff" android:type="linear" />
</shape>
</item>
</selector>