opt
This commit is contained in:
@@ -37,7 +37,6 @@ import com.mogo.utils.network.RetrofitFactory;
|
||||
@Route( path = MogoServicePaths.PATH_SERVICES_NETWORK)
|
||||
public class MogoNetWorkService implements IMogoNetwork {
|
||||
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
MogoInitor.init( context );
|
||||
|
||||
@@ -5,8 +5,14 @@ import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -20,69 +26,134 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class MogoStatusManager implements IMogoStatusManager {
|
||||
|
||||
/**
|
||||
* 小智语音UI
|
||||
* 状态记录
|
||||
*/
|
||||
private static final int UI_VOICE = 1;
|
||||
private static final Map< StatusDescriptor, Boolean > mStatus = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* ADAS UI
|
||||
* 回调集合
|
||||
*/
|
||||
private static final int UI_ADAS = 2;
|
||||
private static final Map< StatusDescriptor, List< IMogoStatusChangedListener > > mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* V2X UI
|
||||
* 状态类型修改记录
|
||||
*/
|
||||
private static final int UI_V2X = 3;
|
||||
|
||||
/**
|
||||
* PUSH UI
|
||||
*/
|
||||
private static final int UI_PUSH = 4;
|
||||
|
||||
private static final Map< Integer, Boolean > mStatus = new ConcurrentHashMap<>();
|
||||
private static final Map< StatusDescriptor, String > mModifier = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean isVoiceShow() {
|
||||
return mStatus.get( UI_VOICE );
|
||||
return get_bool_val( StatusDescriptor.VOICE_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isADASShow() {
|
||||
return mStatus.get( UI_ADAS );
|
||||
return get_bool_val( StatusDescriptor.ADAS_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isV2XShow() {
|
||||
return mStatus.get( UI_V2X );
|
||||
return get_bool_val( StatusDescriptor.V2X_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPushShow() {
|
||||
return mStatus.get( UI_PUSH );
|
||||
return get_bool_val( StatusDescriptor.PUSH_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVoiceUIShow( boolean show ) {
|
||||
mStatus.put( UI_VOICE, show );
|
||||
public boolean isAccOn() {
|
||||
return get_bool_val( StatusDescriptor.ACC_STATUS );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setADASUIShow( boolean show ) {
|
||||
mStatus.put( UI_ADAS, show );
|
||||
public boolean isUserInteracted() {
|
||||
return get_bool_val( StatusDescriptor.USER_INTERACTED );
|
||||
}
|
||||
|
||||
private boolean get_bool_val( StatusDescriptor descriptor ) {
|
||||
Boolean val = mStatus.get( descriptor );
|
||||
return val == null ? false : val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setV2XUIShow( boolean show ) {
|
||||
mStatus.put( UI_V2X, show );
|
||||
public void setVoiceUIShow( String tag, boolean show ) {
|
||||
mStatus.put( StatusDescriptor.VOICE_UI, show );
|
||||
invokeStatusChangedListener( StatusDescriptor.VOICE_UI, show );
|
||||
recorderStatusModifier( tag, StatusDescriptor.VOICE_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPushUIShow( boolean show ) {
|
||||
mStatus.put( UI_PUSH, show );
|
||||
public void setADASUIShow( String tag, boolean show ) {
|
||||
mStatus.put( StatusDescriptor.ADAS_UI, show );
|
||||
invokeStatusChangedListener( StatusDescriptor.ADAS_UI, show );
|
||||
recorderStatusModifier( tag, StatusDescriptor.ADAS_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setV2XUIShow( String tag, boolean show ) {
|
||||
mStatus.put( StatusDescriptor.V2X_UI, show );
|
||||
invokeStatusChangedListener( StatusDescriptor.V2X_UI, show );
|
||||
recorderStatusModifier( tag, StatusDescriptor.V2X_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPushUIShow( String tag, boolean show ) {
|
||||
mStatus.put( StatusDescriptor.PUSH_UI, show );
|
||||
invokeStatusChangedListener( StatusDescriptor.PUSH_UI, show );
|
||||
recorderStatusModifier( tag, StatusDescriptor.PUSH_UI );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccStatus( String tag, boolean isOn ) {
|
||||
mStatus.put( StatusDescriptor.ACC_STATUS, isOn );
|
||||
invokeStatusChangedListener( StatusDescriptor.ACC_STATUS, isOn );
|
||||
recorderStatusModifier( tag, StatusDescriptor.ACC_STATUS );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserInteractionStatus( String tag, boolean interrupt, boolean callback ) {
|
||||
mStatus.put( StatusDescriptor.USER_INTERACTED, interrupt );
|
||||
if ( callback ) {
|
||||
invokeStatusChangedListener( StatusDescriptor.USER_INTERACTED, interrupt );
|
||||
}
|
||||
recorderStatusModifier( tag, StatusDescriptor.USER_INTERACTED );
|
||||
}
|
||||
|
||||
private void invokeStatusChangedListener( StatusDescriptor descriptor, boolean status ) {
|
||||
if ( mListeners.containsKey( descriptor ) ) {
|
||||
Iterator< IMogoStatusChangedListener > iterator = mListeners.get( descriptor ).iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoStatusChangedListener listener = iterator.next();
|
||||
if ( listener != null ) {
|
||||
listener.onStatusChanged( descriptor, status );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recorderStatusModifier( String tag, StatusDescriptor descriptor ) {
|
||||
mModifier.put( descriptor, tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStatusChangedListener( String tag, StatusDescriptor descriptor, IMogoStatusChangedListener listeners ) {
|
||||
if ( listeners == null || descriptor == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !mListeners.containsKey( descriptor ) ) {
|
||||
mListeners.put( descriptor, new ArrayList<>() );
|
||||
}
|
||||
mListeners.get( descriptor ).add( listeners );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterStatusChangedListener( String tag, StatusDescriptor descriptor, IMogoStatusChangedListener listener ) {
|
||||
if ( mListeners.get( descriptor ) != null ) {
|
||||
mListeners.get( descriptor ).remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user