opt
This commit is contained in:
@@ -4,6 +4,8 @@ import com.amap.api.maps.model.CameraPosition;
|
||||
import com.amap.api.services.geocoder.RegeocodeAddress;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,7 +17,34 @@ import java.util.List;
|
||||
*/
|
||||
public class EntityConvertUtils {
|
||||
|
||||
public static List<MogoTip> pois2MogoTips( List< SearchPoi > datums ) {
|
||||
public static ZDPoi mogo2ZD( SearchPoi poi ) {
|
||||
if ( poi == null ) {
|
||||
return null;
|
||||
}
|
||||
ZDPoi zdPoi = new ZDPoi();
|
||||
zdPoi.setAddress( poi.getAddress() );
|
||||
zdPoi.setName( poi.getName() );
|
||||
zdPoi.setLat( poi.getLat() );
|
||||
zdPoi.setLng( poi.getLng() );
|
||||
return zdPoi;
|
||||
}
|
||||
|
||||
public static SearchPoi zd2Mogo( ZDPoi poi, int type ) {
|
||||
if ( poi == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String poiId = type == DataConstants.TYPE_COMPANY_ADDRESS ? DataConstants.POI_ID_COMPANY : DataConstants.POI_ID_HOME;
|
||||
SearchPoi searchPoi = new SearchPoi( poiId,
|
||||
poi.getName(),
|
||||
poi.getAddress(),
|
||||
poi.getLat(),
|
||||
poi.getLng(), "", "", "" );
|
||||
searchPoi.setType( type );
|
||||
return searchPoi;
|
||||
}
|
||||
|
||||
public static List< MogoTip > pois2MogoTips( List< SearchPoi > datums ) {
|
||||
final List< MogoTip > output = new ArrayList<>();
|
||||
if ( datums == null || datums.isEmpty() ) {
|
||||
return output;
|
||||
@@ -65,7 +94,6 @@ public class EntityConvertUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//public static SearchPoi aMapLocation2Poi( AMapLocation location ) {
|
||||
// if ( location == null || location.getErrorCode() != AMapLocation.LOCATION_SUCCESS ) {
|
||||
// return null;
|
||||
@@ -95,16 +123,16 @@ public class EntityConvertUtils {
|
||||
}
|
||||
|
||||
|
||||
public static SearchPoi geoToPoi(double latitude,double longitude,int type) {
|
||||
SearchPoi searchPoi = new SearchPoi(System.currentTimeMillis() + "",
|
||||
null,
|
||||
null,
|
||||
latitude,
|
||||
longitude,
|
||||
null,
|
||||
null,
|
||||
"");
|
||||
searchPoi.setType(type);
|
||||
public static SearchPoi geoToPoi( double latitude, double longitude, int type ) {
|
||||
SearchPoi searchPoi = new SearchPoi( System.currentTimeMillis() + "",
|
||||
null,
|
||||
null,
|
||||
latitude,
|
||||
longitude,
|
||||
null,
|
||||
null,
|
||||
"" );
|
||||
searchPoi.setType( type );
|
||||
return searchPoi;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,4 +233,22 @@ public class SearchPoi implements Parcelable {
|
||||
return new SearchPoi[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SearchPoi{" +
|
||||
"pId='" + pId + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", address='" + address + '\'' +
|
||||
", lat=" + lat +
|
||||
", lng=" + lng +
|
||||
", district='" + district + '\'' +
|
||||
", adCode='" + adCode + '\'' +
|
||||
", typeCode='" + typeCode + '\'' +
|
||||
", province='" + province + '\'' +
|
||||
", city='" + city + '\'' +
|
||||
", type=" + type +
|
||||
", time=" + time +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.mogo.module.navi.bean;
|
||||
|
||||
public class ZDPoi {
|
||||
String name;
|
||||
String address;
|
||||
double lng;
|
||||
double lat;
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setLng(double lng) {
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
public void setLat(double lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ZDPoi() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param lat
|
||||
* @param lng
|
||||
*/
|
||||
public ZDPoi(String name,String address, double lat, double lng) {
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.lat = lat;
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,10 +5,10 @@ import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.gps.simulator.IMogoGpsSimulatorManager;
|
||||
import com.mogo.module.guideshow.provider.IGuideShowProvider;
|
||||
import com.mogo.module.navi.cp.PersonalInfoManagerImpl;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.analytics.IMogoAnalytics;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
@@ -18,6 +18,7 @@ import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
import com.mogo.service.module.IMogoSettingManager;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -27,6 +28,8 @@ import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
*/
|
||||
public class SearchApisHolder {
|
||||
|
||||
private static final String TAG = "SearchApisHolder";
|
||||
|
||||
private static IMogoServiceApis sApis;
|
||||
private static IMogoMapService sMapServiceApis;
|
||||
private static IMogoMapUIController sUiControllerApis;
|
||||
@@ -43,7 +46,10 @@ public class SearchApisHolder {
|
||||
private static IMogoGpsSimulatorManager sGpsSimulatorManager;
|
||||
private static IMogoSearchManager sSearchManager;
|
||||
|
||||
private static PersonalInfoManagerImpl mPersonalInfoManager;
|
||||
|
||||
static {
|
||||
Logger.d( TAG, "static block init." );
|
||||
sApis = ARouter.getInstance().navigation( IMogoServiceApis.class );
|
||||
sMapServiceApis = sApis.getMapServiceApi();
|
||||
sUiControllerApis = sMapServiceApis.getMapUIController();
|
||||
@@ -57,7 +63,7 @@ public class SearchApisHolder {
|
||||
sIntentManager = sApis.getIntentManagerApi();
|
||||
sSettingManager = sApis.getSettingManagerApi();
|
||||
sSearchManager = sApis.getSearchManagerApi();
|
||||
sGpsSimulatorManager = ARouter.getInstance().navigation( IMogoGpsSimulatorManager.class);
|
||||
sGpsSimulatorManager = ARouter.getInstance().navigation( IMogoGpsSimulatorManager.class );
|
||||
sGuideShowApis = ARouter.getInstance().navigation( IGuideShowProvider.class );
|
||||
}
|
||||
|
||||
@@ -120,4 +126,12 @@ public class SearchApisHolder {
|
||||
public static IMogoSearchManager getSearchManager() {
|
||||
return sSearchManager;
|
||||
}
|
||||
|
||||
public static PersonalInfoManagerImpl getPersonalInfoManager() {
|
||||
Logger.d( TAG, "getPersonalInfoManager invoked." );
|
||||
if ( mPersonalInfoManager == null ) {
|
||||
mPersonalInfoManager = new PersonalInfoManagerImpl( AbsMogoApplication.getApp() );
|
||||
}
|
||||
return mPersonalInfoManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,15 @@ import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
import com.mogo.module.navi.database.AppDataBase;
|
||||
import com.mogo.module.navi.manager.AddressManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -41,23 +43,18 @@ public class AddressContentProvider extends ContentProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public Cursor query( @NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable
|
||||
String sortOrder ) {
|
||||
String sortOrder ) {
|
||||
final int code = mMatcher.match( uri );
|
||||
Log.d( TAG, "query code: " + code );
|
||||
final SearchPoi poi = getPoi( code );
|
||||
MatrixCursor
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME,DataConstants.HOME_ADDRESS, DataConstants.HOME_ADDRESS_LATITUDE, DataConstants.HOME_ADDRESS_LONGITUDE} );
|
||||
Logger.d( TAG, "query : %s", poi );
|
||||
MatrixCursor cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME, DataConstants.HOME_ADDRESS, DataConstants.HOME_ADDRESS_LATITUDE, DataConstants.HOME_ADDRESS_LONGITUDE} );
|
||||
if ( code == DataConstants.HOME_ADDRESS_CODE ) {
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME,DataConstants.HOME_ADDRESS, DataConstants.HOME_ADDRESS_LATITUDE, DataConstants.HOME_ADDRESS_LONGITUDE} );
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME, DataConstants.HOME_ADDRESS, DataConstants.HOME_ADDRESS_LATITUDE, DataConstants.HOME_ADDRESS_LONGITUDE} );
|
||||
} else if ( code == DataConstants.COMPANY_ADDRESS_CODE ) {
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.COMPANY_ADDRESS_NAME,DataConstants.COMPANY_ADDRESS, DataConstants.COMPANY_ADDRESS_LATITUDE, DataConstants.COMPANY_ADDRESS_LONGITUDE} );
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.COMPANY_ADDRESS_NAME, DataConstants.COMPANY_ADDRESS, DataConstants.COMPANY_ADDRESS_LATITUDE, DataConstants.COMPANY_ADDRESS_LONGITUDE} );
|
||||
}
|
||||
if ( cursor != null ) {
|
||||
if ( poi == null ) {
|
||||
cursor.addRow( new Object[]{"","", 0, 0} );
|
||||
} else {
|
||||
cursor.addRow( new Object[]{poi.getName(),poi.getAddress(), poi.getLat(), poi.getLng()} );
|
||||
}
|
||||
if ( cursor != null && poi != null ) {
|
||||
cursor.addRow( new Object[]{poi.getName(), poi.getAddress(), poi.getLat(), poi.getLng()} );
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
@@ -69,7 +66,7 @@ public class AddressContentProvider extends ContentProvider {
|
||||
return homeAddressPoi.get( 0 );
|
||||
}
|
||||
} else if ( type == DataConstants.COMPANY_ADDRESS_CODE ) {
|
||||
List< SearchPoi > homeAddressPoi = AppDataBase.getDatabase( getContext()).poiDao().getCompanyAddress().blockingGet();
|
||||
List< SearchPoi > homeAddressPoi = AppDataBase.getDatabase( getContext() ).poiDao().getCompanyAddress().blockingGet();
|
||||
if ( homeAddressPoi != null && homeAddressPoi.size() > 0 ) {
|
||||
return homeAddressPoi.get( 0 );
|
||||
}
|
||||
@@ -87,7 +84,7 @@ public class AddressContentProvider extends ContentProvider {
|
||||
@Override
|
||||
public Uri insert( @NonNull Uri uri, @Nullable ContentValues values ) {
|
||||
final int code = mMatcher.match( uri );
|
||||
Log.d( TAG, "insert code: " + code );
|
||||
Logger.d( TAG, "insert code: " + code );
|
||||
if ( values.size() == 0 ) {
|
||||
return uri;
|
||||
}
|
||||
@@ -109,6 +106,7 @@ public class AddressContentProvider extends ContentProvider {
|
||||
}
|
||||
if ( validateLocation( lat, lng ) ) {
|
||||
sp = new SearchPoi( DataConstants.POI_ID_HOME, poiName, poiAddress, lat, lng, "", "", "" );
|
||||
sp.setType( code );
|
||||
}
|
||||
} else if ( code == DataConstants.COMPANY_ADDRESS_CODE ) {
|
||||
poiName = values.getAsString( DataConstants.COMPANY_ADDRESS_NAME );
|
||||
@@ -123,7 +121,7 @@ public class AddressContentProvider extends ContentProvider {
|
||||
}
|
||||
if ( validateLocation( lat, lng ) ) {
|
||||
sp = new SearchPoi( DataConstants.POI_ID_COMPANY, poiName, poiAddress, lat, lng, "", "", "" );
|
||||
sp.setType(code);
|
||||
sp.setType( code );
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -136,7 +134,7 @@ public class AddressContentProvider extends ContentProvider {
|
||||
|
||||
private boolean validateLocation( double lat, double lng ) {
|
||||
if ( ( lat ) == 0D || ( lng ) == 0D ) {
|
||||
Log.e( TAG, "error location" );
|
||||
Logger.e( TAG, "error location" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -146,14 +144,9 @@ public class AddressContentProvider extends ContentProvider {
|
||||
if ( poi == null ) {
|
||||
return;
|
||||
}
|
||||
List<Long> result = AppDataBase.getDatabase( getContext() ).poiDao().insert( poi );
|
||||
if ( result.get( 0 ).intValue() == -1 ) {
|
||||
Log.e( TAG, "insert error. " );
|
||||
}else {
|
||||
Log.e( TAG, "insert success. " );
|
||||
|
||||
}
|
||||
AddressManager.INSTANCE.insert(poi);
|
||||
Logger.d( TAG, "insert entity: %s", poi );
|
||||
AppDataBase.getDatabase( getContext() ).poiDao().insert( poi );
|
||||
AddressHelper.notifyAddressChanged( poi.getType() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package com.mogo.module.navi.cp;
|
||||
|
||||
import android.content.Context;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -17,20 +12,19 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class AddressHelper {
|
||||
|
||||
private static final String TAG = "AddressHelper";
|
||||
public static void notifyHomeAddressChanged( ) {
|
||||
|
||||
public static void notifyHomeAddressChanged() {
|
||||
AbsMogoApplication.getApp().getContentResolver().notifyChange( DataConstants.CONTENT_HOME_ADDRESS_URI, null );
|
||||
}
|
||||
|
||||
public static void notifyCompanyAddressChanged( ) {
|
||||
|
||||
public static void notifyCompanyAddressChanged() {
|
||||
AbsMogoApplication.getApp().getContentResolver().notifyChange( DataConstants.CONTENT_COMPANY_ADDRESS_URI, null );
|
||||
}
|
||||
|
||||
public static void notifyAddressChanged(
|
||||
int type) {
|
||||
if (type== DataConstants.TYPE_HOME_ADDRESS) {
|
||||
public static void notifyAddressChanged( int type ) {
|
||||
if ( type == DataConstants.TYPE_HOME_ADDRESS ) {
|
||||
notifyHomeAddressChanged();
|
||||
}else {
|
||||
} else if ( type == DataConstants.TYPE_COMPANY_ADDRESS ) {
|
||||
notifyCompanyAddressChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.mogo.module.navi.cp;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.mogo.module.navi.bean.ZDPoi;
|
||||
|
||||
|
||||
/**
|
||||
* 个人信息相关封装
|
||||
* Created by zhangxuri on 2018/10/17.
|
||||
*/
|
||||
|
||||
public abstract class PersonalInfoManager {
|
||||
|
||||
protected final static Object lock = new Object();
|
||||
|
||||
private static final Uri uri = Uri.parse("content://com.zhidao.guide.lock.product.bindstatus/status");
|
||||
|
||||
protected static PersonalInfoManager INSTANCE;
|
||||
|
||||
/**
|
||||
* 实例化对象
|
||||
* @param context 上下文
|
||||
* @return
|
||||
*/
|
||||
public static PersonalInfoManager getInstance(Context context) {
|
||||
PersonalInfoManager client = INSTANCE;
|
||||
if(client == null) {
|
||||
synchronized (lock) {
|
||||
client = INSTANCE;
|
||||
if(client == null) {
|
||||
client = new PersonalInfoManagerImpl(context);
|
||||
INSTANCE = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
public PersonalInfoManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求获取用户信息
|
||||
* @return
|
||||
*//*
|
||||
public UserInfo getUserInfo() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
if (resolver != null){
|
||||
UserInfo userInfo = new UserInfo();
|
||||
Cursor cursor = resolver.query(personlUri, null, null, null, null);
|
||||
if((cursor != null) && cursor.moveToFirst()) {
|
||||
userInfo.setUserId(cursor.getString(cursor.getColumnIndex(USER_ID)));
|
||||
userInfo.setPhone(cursor.getString(cursor.getColumnIndex(PHONE)));
|
||||
userInfo.setDisplayName(cursor.getString(cursor.getColumnIndex(DISPLAY_NAME)));
|
||||
String score = cursor.getString(cursor.getColumnIndex(SCORE));
|
||||
try {
|
||||
userInfo.setScore(Integer.parseInt(score));
|
||||
} catch (NumberFormatException ex) {
|
||||
Log.e("PersonalInfoClient", "getUserInfo: NumberFormatException");
|
||||
}
|
||||
}
|
||||
if(cursor != null){
|
||||
cursor.close();
|
||||
}
|
||||
return userInfo;
|
||||
} else {
|
||||
Log.e("PersonalInfoClient", "resolver == null");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* 获取当前车机绑定状态
|
||||
* @return
|
||||
*/
|
||||
public static boolean isRegister(Context context) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
if (resolver != null) {
|
||||
cursor = resolver.query(uri, null, null, null, null);
|
||||
if ((cursor != null) && cursor.moveToFirst()) {
|
||||
int status = cursor.getInt(cursor.getColumnIndex("lock_status"));
|
||||
return (status == 1);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放资源
|
||||
*/
|
||||
public abstract void release();
|
||||
|
||||
/**
|
||||
* 设置家的地址
|
||||
*/
|
||||
public abstract void setHome( ZDPoi homePoi);
|
||||
|
||||
/**
|
||||
* 设置公司地址
|
||||
*/
|
||||
public abstract void setCompany(ZDPoi companyPoi);
|
||||
|
||||
/**
|
||||
* 获取家的地址
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract ZDPoi getHome();
|
||||
|
||||
public abstract ZDPoi getCompany();
|
||||
|
||||
/**
|
||||
* 添加信息变化监听
|
||||
*
|
||||
* @param listener 监听器
|
||||
*/
|
||||
public abstract void addListener(InfoListener listener);
|
||||
|
||||
/**
|
||||
* 删除信息变化监听
|
||||
*
|
||||
* @param listener 监听器
|
||||
*/
|
||||
public abstract void removeListener(InfoListener listener);
|
||||
|
||||
/**
|
||||
* 常用地址变化监听器
|
||||
*/
|
||||
public interface InfoListener {
|
||||
|
||||
/**
|
||||
* 家地址变化
|
||||
* @param home
|
||||
*/
|
||||
void onHomeChanged( ZDPoi home );
|
||||
|
||||
/**
|
||||
* 公司地址变化
|
||||
* @param company
|
||||
*/
|
||||
void onCompanyChanged( ZDPoi company );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
package com.mogo.module.navi.cp;
|
||||
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.module.navi.bean.ZDPoi;
|
||||
import com.mogo.utils.ThreadPoolService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 个人信息管理
|
||||
*/
|
||||
public class PersonalInfoManagerImpl extends PersonalInfoManager {
|
||||
|
||||
private final String TAG = "PersonalInfoManager";
|
||||
|
||||
private static final Uri personlUri = Uri.parse( "content://com.zhidao.auto.personal.provider/info" );
|
||||
|
||||
private static final Uri COMPANY_ADDRESS_URI = Uri.parse( "content://com.zhidao.auto.personal.provider/companyAddress" );//旧的公司地址
|
||||
|
||||
private static final Uri CONTENT_COMPANY_ADDRESS_URI = Uri.parse( "content://com.zhidao.launcher.provider.personal.info/companyAddress" );//新的公司地址
|
||||
|
||||
private static final Uri HOME_ADDRESS_URI = Uri.parse( "content://com.zhidao.auto.personal.provider/homeAddress" );//旧的家地址
|
||||
|
||||
private static final Uri CONTENT_HOME_ADDRESS_URI = Uri.parse( "content://com.zhidao.launcher.provider.personal.info/homeAddress" );//新的家地址
|
||||
|
||||
//公司地址
|
||||
private static final String COMPANY_ADDRESS = "companyAddress";
|
||||
private static final String COMPANY_ADDRESS_NAME = "companyAddressName";
|
||||
private static final String COMPANY_ADDRESS_LATITUDE = "companyAddressLatitude";
|
||||
private static final String COMPANY_ADDRESS_LONGITUDE = "companyAddressLongitude";
|
||||
|
||||
//家庭地址
|
||||
private static final String HOME_ADDRESS = "homeAddress";
|
||||
private static final String HOME_ADDRESS_NAME = "homeAddressName";
|
||||
private static final String HOME_ADDRESS_LATITUDE = "homeAddressLatitude";
|
||||
private static final String HOME_ADDRESS_LONGITUDE = "homeAddressLongitude";
|
||||
|
||||
private List< InfoListener > mListenerList = new ArrayList<>();
|
||||
private boolean mIsRegister = false;
|
||||
private Handler mHandler = new Handler( Looper.getMainLooper() );
|
||||
private Context mContext;
|
||||
|
||||
public PersonalInfoManagerImpl( Context context ) {
|
||||
this.mContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( InfoListener listener ) {
|
||||
synchronized ( mListenerList ) {
|
||||
if ( listener != null ) {
|
||||
mListenerList.add( listener );
|
||||
}
|
||||
if ( !mIsRegister ) {
|
||||
registerObserver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( InfoListener listener ) {
|
||||
synchronized ( mListenerList ) {
|
||||
if ( listener != null ) {
|
||||
mListenerList.remove( listener );
|
||||
}
|
||||
if ( mListenerList.isEmpty() && mIsRegister ) {
|
||||
unregisterObserver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterObserver() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
if ( resolver == null ) return;
|
||||
if ( mIsRegister ) {
|
||||
resolver.unregisterContentObserver( mContentObserver );
|
||||
mIsRegister = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void registerObserver() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
if ( resolver != null ) {
|
||||
resolver.registerContentObserver( COMPANY_ADDRESS_URI, true, mContentObserver );
|
||||
resolver.registerContentObserver( CONTENT_COMPANY_ADDRESS_URI, true, mContentObserver );
|
||||
resolver.registerContentObserver( HOME_ADDRESS_URI, true, mContentObserver );
|
||||
resolver.registerContentObserver( CONTENT_HOME_ADDRESS_URI, true, mContentObserver );
|
||||
mIsRegister = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompany( ZDPoi companyPoi ) {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
if ( resolver == null ) {
|
||||
return;
|
||||
}
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( COMPANY_ADDRESS, companyPoi.getAddress() );
|
||||
values.put( COMPANY_ADDRESS_NAME, companyPoi.getName() );
|
||||
values.put( COMPANY_ADDRESS_LATITUDE, companyPoi.getLat() );
|
||||
values.put( COMPANY_ADDRESS_LONGITUDE, companyPoi.getLng() );
|
||||
try {
|
||||
resolver.insert( CONTENT_COMPANY_ADDRESS_URI, values );
|
||||
} catch ( IllegalArgumentException ex ) {
|
||||
Log.e( TAG, "setCompany: new url not exits" );
|
||||
try {
|
||||
resolver.insert( COMPANY_ADDRESS_URI, values );
|
||||
} catch ( IllegalArgumentException exception ) {
|
||||
Log.e( TAG, "setCompany: ERROR" );
|
||||
}
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHome( ZDPoi homePoi ) {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
if ( resolver == null ) {
|
||||
return;
|
||||
}
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( HOME_ADDRESS, homePoi.getAddress() );
|
||||
values.put( HOME_ADDRESS_NAME, homePoi.getName() );
|
||||
values.put( HOME_ADDRESS_LATITUDE, homePoi.getLat() );
|
||||
values.put( HOME_ADDRESS_LONGITUDE, homePoi.getLng() );
|
||||
try {
|
||||
resolver.insert( CONTENT_HOME_ADDRESS_URI, values );
|
||||
} catch ( IllegalArgumentException ex ) {
|
||||
try {
|
||||
resolver.insert( HOME_ADDRESS_URI, values );
|
||||
} catch ( IllegalArgumentException exception ) {
|
||||
Log.e( TAG, "setHome: ERROR" );
|
||||
}
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZDPoi getCompany() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
if ( resolver == null ) {
|
||||
return null;
|
||||
}
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = resolver.query( CONTENT_COMPANY_ADDRESS_URI, null, null, null, null );
|
||||
if ( cursor == null ) { //桌面url不存在
|
||||
cursor = resolver.query( COMPANY_ADDRESS_URI, null, null, null, null );
|
||||
}
|
||||
|
||||
if ( cursor == null ) {
|
||||
return null;
|
||||
}
|
||||
ZDPoi poi = new ZDPoi();
|
||||
if ( cursor.moveToFirst() ) {
|
||||
String companyAddress = cursor.getString( cursor.getColumnIndex( COMPANY_ADDRESS ) );
|
||||
String companyAddressName = cursor.getString( cursor.getColumnIndex( COMPANY_ADDRESS_NAME ) );
|
||||
double companyLat = cursor.getDouble( cursor.getColumnIndex( COMPANY_ADDRESS_LATITUDE ) );
|
||||
double companyLng = cursor.getDouble( cursor.getColumnIndex( COMPANY_ADDRESS_LONGITUDE ) );
|
||||
poi.setAddress( companyAddress );
|
||||
poi.setName( companyAddressName );
|
||||
poi.setLat( companyLat );
|
||||
poi.setLng( companyLng );
|
||||
return poi;
|
||||
}
|
||||
} catch ( Exception ex ) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if ( cursor != null ) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZDPoi getHome() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
if ( resolver == null ) {
|
||||
return null;
|
||||
}
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = resolver.query( CONTENT_HOME_ADDRESS_URI, null, null, null, null );
|
||||
if ( cursor == null ) { //桌面url不存在
|
||||
cursor = resolver.query( HOME_ADDRESS_URI, null, null, null, null );
|
||||
}
|
||||
|
||||
if ( cursor == null ) {
|
||||
return null;
|
||||
}
|
||||
ZDPoi poi = new ZDPoi();
|
||||
if ( cursor.moveToFirst() ) {
|
||||
String homeAddress = cursor.getString( cursor.getColumnIndex( HOME_ADDRESS ) );
|
||||
String homeAddressName = cursor.getString( cursor.getColumnIndex( HOME_ADDRESS_NAME ) );
|
||||
double homeAddressLat = cursor.getDouble( cursor.getColumnIndex( HOME_ADDRESS_LATITUDE ) );
|
||||
double homeAddressLng = cursor.getDouble( cursor.getColumnIndex( HOME_ADDRESS_LONGITUDE ) );
|
||||
poi.setAddress( homeAddress );
|
||||
poi.setName( homeAddressName );
|
||||
poi.setLat( homeAddressLat );
|
||||
poi.setLng( homeAddressLng );
|
||||
return poi;
|
||||
}
|
||||
} catch ( Exception ex ) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if ( cursor != null ) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void dispatchPoiEvent( int state, ZDPoi poi ) {
|
||||
synchronized ( mListenerList ) {
|
||||
for ( InfoListener listener : mListenerList ) {
|
||||
if ( state == 0 ) {
|
||||
listener.onHomeChanged( poi );
|
||||
} else {
|
||||
listener.onCompanyChanged( poi );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ContentObserver mContentObserver = new ContentObserver( mHandler ) {
|
||||
@Override
|
||||
public void onChange( boolean selfChange, Uri uri ) {
|
||||
super.onChange( selfChange, uri );
|
||||
int state;
|
||||
if ( uri.equals( HOME_ADDRESS_URI ) || uri.equals( CONTENT_HOME_ADDRESS_URI ) ) {
|
||||
state = 0;
|
||||
} else {
|
||||
state = 1;
|
||||
}
|
||||
ThreadPoolService.execute( () -> {
|
||||
final ZDPoi poi = queryFromDataSource( uri );
|
||||
mHandler.post( () -> {
|
||||
if ( poi != null ) {
|
||||
dispatchPoiEvent( state, poi );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private ZDPoi queryFromDataSource( Uri uri ) {
|
||||
Log.i( TAG, "onChange: uri = " + uri.toString() );
|
||||
Cursor cursor = null;
|
||||
String address;
|
||||
String addressName;
|
||||
double lat;
|
||||
double lng;
|
||||
ZDPoi poi = null;
|
||||
try {
|
||||
cursor = mContext.getContentResolver().query( uri, null, null, null, null );
|
||||
if ( cursor != null && cursor.moveToNext() ) {
|
||||
if ( uri.equals( HOME_ADDRESS_URI ) || uri.equals( CONTENT_HOME_ADDRESS_URI ) ) {
|
||||
address = cursor.getString( cursor.getColumnIndex( HOME_ADDRESS ) );
|
||||
addressName = cursor.getString( cursor.getColumnIndex( HOME_ADDRESS_NAME ) );
|
||||
lat = cursor.getDouble( cursor.getColumnIndex( HOME_ADDRESS_LATITUDE ) );
|
||||
lng = cursor.getDouble( cursor.getColumnIndex( HOME_ADDRESS_LONGITUDE ) );
|
||||
} else {
|
||||
address = cursor.getString( cursor.getColumnIndex( COMPANY_ADDRESS ) );
|
||||
addressName = cursor.getString( cursor.getColumnIndex( COMPANY_ADDRESS_NAME ) );
|
||||
lat = cursor.getDouble( cursor.getColumnIndex( COMPANY_ADDRESS_LATITUDE ) );
|
||||
lng = cursor.getDouble( cursor.getColumnIndex( COMPANY_ADDRESS_LONGITUDE ) );
|
||||
}
|
||||
Log.i( TAG, "onChange: address = " + address + "addressName = " + addressName );
|
||||
Log.i( TAG, "onChange: lat = " + lat + "lng = " + lng );
|
||||
poi = new ZDPoi();
|
||||
poi.setAddress( address );
|
||||
poi.setName( addressName );
|
||||
poi.setLat( lat );
|
||||
poi.setLng( lng );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
Log.e( TAG, "onChange: Exception = " + e.getMessage() );
|
||||
} finally {
|
||||
if ( cursor != null ) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return poi;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
synchronized ( lock ) {
|
||||
this.mListenerList.clear();
|
||||
unregisterObserver();
|
||||
INSTANCE = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,27 +2,20 @@ package com.mogo.module.navi.manager
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy
|
||||
import com.mogo.module.common.map.Scene
|
||||
import android.util.Log
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils
|
||||
import com.mogo.module.navi.bean.SearchPoi
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.bean.ZDPoi
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.cp.AddressHelper
|
||||
import com.mogo.module.navi.cp.PersonalInfoManager
|
||||
import com.mogo.module.navi.dao.SearchPoiDao
|
||||
import com.mogo.module.navi.database.AppDataBase
|
||||
import com.mogo.module.navi.ui.search.CategorySearchFragment
|
||||
import com.mogo.module.navi.ui.search.ChoosePathFragment
|
||||
import com.mogo.module.navi.ui.search.SearchFragment
|
||||
import com.mogo.module.navi.ui.setting.NaviSettingFragment
|
||||
import com.mogo.module.navi.ui.setting.SettingAddressFragment
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor
|
||||
import com.mogo.utils.WorkThreadHandler
|
||||
import com.mogo.utils.logger.Logger
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.ObservableOnSubscribe
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
@@ -47,39 +40,47 @@ object AddressManager {
|
||||
return companyAddress != null
|
||||
}
|
||||
|
||||
private lateinit var context: Context
|
||||
@SuppressLint("CheckResult")
|
||||
fun init(context: Context) {
|
||||
|
||||
this.context = context
|
||||
poiDao = AppDataBase.getDatabase(context).poiDao()
|
||||
poiDao.companyAddress
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { t1, _ ->
|
||||
if (t1.size > 0) {
|
||||
companyAddress = t1[0]
|
||||
}
|
||||
}
|
||||
WorkThreadHandler.getInstance().post {
|
||||
try {
|
||||
var zdCompany = SearchApisHolder.getPersonalInfoManager().company
|
||||
companyAddress = EntityConvertUtils.zd2Mogo(zdCompany, DataConstants.TYPE_COMPANY_ADDRESS)
|
||||
var zdHome = SearchApisHolder.getPersonalInfoManager().home
|
||||
homeAddress = EntityConvertUtils.zd2Mogo(zdHome, DataConstants.TYPE_HOME_ADDRESS)
|
||||
} catch (e: Exception) {
|
||||
Logger.d(TAG, Log.getStackTraceString(e))
|
||||
}
|
||||
}
|
||||
|
||||
poiDao.homeAddress
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { t1, _ ->
|
||||
if (t1.size > 0) {
|
||||
homeAddress = t1[0]
|
||||
}
|
||||
}
|
||||
SearchApisHolder.getPersonalInfoManager().addListener(object : PersonalInfoManager.InfoListener {
|
||||
override fun onCompanyChanged(company: ZDPoi?) {
|
||||
Logger.d(TAG, "company data changed.")
|
||||
companyAddress = EntityConvertUtils.zd2Mogo(company, DataConstants.TYPE_COMPANY_ADDRESS)
|
||||
EventBus.getDefault().post(companyAddress)
|
||||
}
|
||||
|
||||
override fun onHomeChanged(home: ZDPoi?) {
|
||||
Logger.d(TAG, "home data changed.")
|
||||
homeAddress = EntityConvertUtils.zd2Mogo(home, DataConstants.TYPE_HOME_ADDRESS)
|
||||
EventBus.getDefault().post(homeAddress)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun insert(searchPoi: SearchPoi) {
|
||||
|
||||
EventBus.getDefault().post(searchPoi)
|
||||
if (searchPoi.type == DataConstants.TYPE_COMPANY_ADDRESS) {
|
||||
companyAddress = searchPoi
|
||||
} else {
|
||||
homeAddress = searchPoi
|
||||
}
|
||||
Observable.create(
|
||||
ObservableOnSubscribe<String> {
|
||||
if (searchPoi.type == DataConstants.TYPE_COMPANY_ADDRESS) {
|
||||
SearchApisHolder.getPersonalInfoManager().company = EntityConvertUtils.mogo2ZD(searchPoi)
|
||||
} else {
|
||||
SearchApisHolder.getPersonalInfoManager().home = EntityConvertUtils.mogo2ZD(searchPoi)
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
fun deleteHome() {
|
||||
@@ -88,109 +89,20 @@ object AddressManager {
|
||||
poiDao.delete(homeAddress)
|
||||
homeAddress?.name = ""
|
||||
AddressHelper.notifyAddressChanged(1)
|
||||
|
||||
homeAddress = null
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun deleteCompany() {
|
||||
Observable.create(
|
||||
ObservableOnSubscribe<String> {
|
||||
poiDao.delete(companyAddress)
|
||||
companyAddress?.name = ""
|
||||
AddressHelper.notifyAddressChanged(0)
|
||||
|
||||
companyAddress = null
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
/**
|
||||
* 回家
|
||||
*/
|
||||
fun goHome() {
|
||||
if (homeAddress == null) {
|
||||
choosePoint(DataConstants.TYPE_HOME_ADDRESS)
|
||||
} else {
|
||||
calculatePath(EntityConvertUtils.poi2MogoTip(homeAddress).point)
|
||||
}
|
||||
}
|
||||
|
||||
private fun choosePoint(type: Int) {
|
||||
beforePushFragment()
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchApisHolder.getUiControllerApis(), Scene.CHOOSE_POINT)
|
||||
pushFragment(SettingAddressFragment.newInstance(type), AMapConstants.PATH_FRAGMENT_SETTING_HOME, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* 去公司
|
||||
*/
|
||||
fun goCompany() {
|
||||
if (companyAddress == null) {
|
||||
choosePoint(DataConstants.TYPE_COMPANY_ADDRESS)
|
||||
} else {
|
||||
calculatePath(EntityConvertUtils.poi2MogoTip(companyAddress).point)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*/
|
||||
fun goSearch() {
|
||||
beforePushFragment()
|
||||
pushFragment(SearchFragment(), AMapConstants.PATH_FRAGMENT_SEARCH, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* 路径规划
|
||||
*/
|
||||
fun calculatePath(destination: MogoLatLng?) {
|
||||
destination?.let {
|
||||
beforePushFragment()
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchApisHolder.getUiControllerApis(), Scene.CALCULATE_PATH)
|
||||
pushFragment(ChoosePathFragment.newInstance(destination), AMapConstants.PATH_FRAGMENT_CHOOSE_PATH, true)
|
||||
}
|
||||
}
|
||||
|
||||
fun categorySearch(category: String) {
|
||||
beforePushFragment()
|
||||
pushFragment(CategorySearchFragment.newInstance(category), AMapConstants.PATH_FRAGMENT_SEARCH_CATEGORY, true)
|
||||
}
|
||||
|
||||
fun goSettings() {
|
||||
beforePushFragment()
|
||||
pushFragment(NaviSettingFragment(), AMapConstants.PATH_FRAGMENT_NAVI_SETTING, true)
|
||||
}
|
||||
|
||||
private fun beforePushFragment() {
|
||||
closeADAS()
|
||||
if (!SearchApisHolder.getStatusManager().isSearchUIShow) {
|
||||
SearchApisHolder.getStatusManager().setSearchUIShow(TAG, true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun pushFragment(fragment: Fragment, tag: String, notifyMain: Boolean) {
|
||||
SearchApisHolder.getFragmentManager().push(
|
||||
FragmentDescriptor.Builder()
|
||||
.fragment(fragment)
|
||||
.tag(tag)
|
||||
.notifyMainModule(notifyMain)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun closeADAS() {
|
||||
try {
|
||||
SearchApisHolder.getApis().adasControllerApi.closeADAS()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ import com.mogo.service.module.IMogoSearchManager;
|
||||
public class MogoSearchManager implements IMogoSearchManager {
|
||||
@Override
|
||||
public void goHome() {
|
||||
AddressManager.INSTANCE.goHome();
|
||||
MogoSearchManagerImpl.INSTANCE.goHome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goCompany() {
|
||||
AddressManager.INSTANCE.goCompany();
|
||||
MogoSearchManagerImpl.INSTANCE.goCompany();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,22 +29,22 @@ public class MogoSearchManager implements IMogoSearchManager {
|
||||
if ( SearchApisHolder.getNaviApis().isNaviing() ) {
|
||||
return;
|
||||
}
|
||||
AddressManager.INSTANCE.goSearch();
|
||||
MogoSearchManagerImpl.INSTANCE.goSearch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void categorySearch( String keyword ) {
|
||||
AddressManager.INSTANCE.categorySearch( keyword );
|
||||
MogoSearchManagerImpl.INSTANCE.categorySearch( keyword );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculatePath( MogoLatLng destination ) {
|
||||
AddressManager.INSTANCE.calculatePath( destination );
|
||||
MogoSearchManagerImpl.INSTANCE.calculatePath( destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goSettings() {
|
||||
AddressManager.INSTANCE.goSettings();
|
||||
MogoSearchManagerImpl.INSTANCE.goSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.mogo.module.navi.manager
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy
|
||||
import com.mogo.module.common.map.Scene
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.ui.search.CategorySearchFragment
|
||||
import com.mogo.module.navi.ui.search.ChoosePathFragment
|
||||
import com.mogo.module.navi.ui.search.SearchFragment
|
||||
import com.mogo.module.navi.ui.setting.NaviSettingFragment
|
||||
import com.mogo.module.navi.ui.setting.SettingAddressFragment
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-05-25
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
object MogoSearchManagerImpl {
|
||||
|
||||
val TAG: String = "MogoSearchManagerImpl.kt"
|
||||
|
||||
/**
|
||||
* 回家
|
||||
*/
|
||||
fun goHome() {
|
||||
if (!AddressManager.hasHome()) {
|
||||
choosePoint(DataConstants.TYPE_HOME_ADDRESS)
|
||||
} else {
|
||||
calculatePath(EntityConvertUtils.poi2MogoTip(AddressManager.homeAddress).point)
|
||||
}
|
||||
}
|
||||
|
||||
private fun choosePoint(type: Int) {
|
||||
beforePushFragment()
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchApisHolder.getUiControllerApis(), Scene.CHOOSE_POINT)
|
||||
pushFragment(SettingAddressFragment.newInstance(type), AMapConstants.PATH_FRAGMENT_SETTING_HOME, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* 去公司
|
||||
*/
|
||||
fun goCompany() {
|
||||
if (!AddressManager.hasCompany()) {
|
||||
choosePoint(DataConstants.TYPE_COMPANY_ADDRESS)
|
||||
} else {
|
||||
calculatePath(EntityConvertUtils.poi2MogoTip(AddressManager.companyAddress).point)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*/
|
||||
fun goSearch() {
|
||||
beforePushFragment()
|
||||
pushFragment(SearchFragment(), AMapConstants.PATH_FRAGMENT_SEARCH, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* 路径规划
|
||||
*/
|
||||
fun calculatePath(destination: MogoLatLng?) {
|
||||
destination?.let {
|
||||
beforePushFragment()
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchApisHolder.getUiControllerApis(), Scene.CALCULATE_PATH)
|
||||
pushFragment(ChoosePathFragment.newInstance(destination), AMapConstants.PATH_FRAGMENT_CHOOSE_PATH, true)
|
||||
}
|
||||
}
|
||||
|
||||
fun categorySearch(category: String) {
|
||||
beforePushFragment()
|
||||
pushFragment(CategorySearchFragment.newInstance(category), AMapConstants.PATH_FRAGMENT_SEARCH_CATEGORY, true)
|
||||
}
|
||||
|
||||
fun goSettings() {
|
||||
beforePushFragment()
|
||||
pushFragment(NaviSettingFragment(), AMapConstants.PATH_FRAGMENT_NAVI_SETTING, true)
|
||||
}
|
||||
|
||||
private fun beforePushFragment() {
|
||||
closeADAS()
|
||||
if (!SearchApisHolder.getStatusManager().isSearchUIShow) {
|
||||
SearchApisHolder.getStatusManager().setSearchUIShow(TAG, true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun pushFragment(fragment: Fragment, tag: String, notifyMain: Boolean) {
|
||||
SearchApisHolder.getFragmentManager().push(
|
||||
FragmentDescriptor.Builder()
|
||||
.fragment(fragment)
|
||||
.tag(tag)
|
||||
.notifyMainModule(notifyMain)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun closeADAS() {
|
||||
try {
|
||||
SearchApisHolder.getApis().adasControllerApi.closeADAS()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -178,7 +178,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
|
||||
private fun goPath() {
|
||||
mAdapter.currentItem?.let {
|
||||
AddressManager.calculatePath(mAdapter.currentItem.point)
|
||||
SearchApisHolder.getSearchManager().calculatePath(mAdapter.currentItem.point)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,14 +150,14 @@ public class SearchFragment extends BaseSearchFragment
|
||||
findViewById( R.id.tv_navi_company ).setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
AddressManager.INSTANCE.goCompany();
|
||||
SearchApisHolder.getSearchManager().goCompany();
|
||||
}
|
||||
} );
|
||||
|
||||
findViewById( R.id.tv_navi_home ).setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
AddressManager.INSTANCE.goHome();
|
||||
SearchApisHolder.getSearchManager().goHome();
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -184,18 +184,18 @@ public class SearchFragment extends BaseSearchFragment
|
||||
goCategory( tag.getName() );
|
||||
} else {
|
||||
mSearchPresenter.insert( searchPoi );
|
||||
AddressManager.INSTANCE.calculatePath( tag.getPoint() );
|
||||
SearchApisHolder.getSearchManager().calculatePath( tag.getPoint() );
|
||||
}
|
||||
}
|
||||
|
||||
private void goSetting() {
|
||||
SearchApisHolder.getAnalyticsApis().track( "Navigation_button_setting", new HashMap< String, Object >() );
|
||||
AddressManager.INSTANCE.goSettings();
|
||||
SearchApisHolder.getSearchManager().goSettings();
|
||||
}
|
||||
|
||||
private void goHistory( SearchPoi item ) {
|
||||
MogoTip mogoTip = EntityConvertUtils.poi2MogoTip( item );
|
||||
AddressManager.INSTANCE.calculatePath( mogoTip.getPoint() );
|
||||
SearchApisHolder.getSearchManager().calculatePath( mogoTip.getPoint() );
|
||||
}
|
||||
|
||||
private static final String GO_HOME_CMD = "goHome";
|
||||
@@ -341,7 +341,7 @@ public class SearchFragment extends BaseSearchFragment
|
||||
}
|
||||
|
||||
private void goCategory( String text ) {
|
||||
AddressManager.INSTANCE.categorySearch( text );
|
||||
SearchApisHolder.getSearchManager().categorySearch( text );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -414,42 +414,30 @@ public class SearchFragment extends BaseSearchFragment
|
||||
.speakQAndACmd( getString( R.string.notice_clean_history ),
|
||||
new String[]{"确定", "立即清空"}, new String[]{"取消"}, this );
|
||||
break;
|
||||
|
||||
|
||||
case GAS_CMD:
|
||||
|
||||
goCategory( getString( R.string.navi_gas ) );
|
||||
|
||||
break;
|
||||
case GO_COMPANY_CMD:
|
||||
AddressManager.INSTANCE.goCompany();
|
||||
|
||||
SearchApisHolder.getSearchManager().goCompany();
|
||||
break;
|
||||
case GO_HOME_CMD:
|
||||
AddressManager.INSTANCE.goHome();
|
||||
SearchApisHolder.getSearchManager().goHome();
|
||||
break;
|
||||
case NAVI_SETTING_CMD:
|
||||
goSetting();
|
||||
break;
|
||||
|
||||
case PARK_CMD:
|
||||
goCategory( getString( R.string.navi_park ) );
|
||||
|
||||
break;
|
||||
case RESTAURANT_CMD:
|
||||
goCategory( getString( R.string.navi_restrant ) );
|
||||
|
||||
break;
|
||||
|
||||
case TOILET_CMD:
|
||||
goCategory( getString( R.string.navi_toilet ) );
|
||||
break;
|
||||
|
||||
case WASH_CMD:
|
||||
goCategory( getString( R.string.navi_wash ) );
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -22,15 +22,10 @@ import com.mogo.module.navi.bean.SearchPoi
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.cp.AddressHelper
|
||||
import com.mogo.module.navi.database.AppDataBase
|
||||
import com.mogo.module.navi.manager.AddressManager
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
import com.mogo.utils.TipToast
|
||||
import com.mogo.utils.UiThreadHandler
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.ObservableOnSubscribe
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.fragment_setting_address.*
|
||||
|
||||
/**
|
||||
@@ -58,7 +53,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
}
|
||||
|
||||
private val TAG: String = "SettingAddressFragment"
|
||||
private var style: Int = DataConstants.TYPE_HOME_ADDRESS
|
||||
private var type: Int = DataConstants.TYPE_HOME_ADDRESS
|
||||
var addMarker: IMogoMarker? = null
|
||||
|
||||
private lateinit var mGeoSearch: IMogoGeoSearch
|
||||
@@ -71,7 +66,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
tilt: Float,
|
||||
bearing: Float) {
|
||||
super.onMapChanged(latLng, zoom, tilt, bearing)
|
||||
selectPoi = EntityConvertUtils.geoToPoi(latLng?.lat ?: 0.0, latLng?.lng ?: 0.0, style)
|
||||
selectPoi = EntityConvertUtils.geoToPoi(latLng?.lat ?: 0.0, latLng?.lng ?: 0.0, type)
|
||||
var mogoRegeocodeQuery = MogoRegeocodeQuery()
|
||||
mogoRegeocodeQuery.point = latLng
|
||||
mGeoSearch.getFromLocationAsyn(mogoRegeocodeQuery)
|
||||
@@ -91,7 +86,8 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
style = arguments?.getInt(AMapConstants.KEY_SET_HOME_COMPONY) ?: DataConstants.TYPE_HOME_ADDRESS
|
||||
type = arguments?.getInt(AMapConstants.KEY_SET_HOME_COMPONY)
|
||||
?: DataConstants.TYPE_HOME_ADDRESS
|
||||
SearchApisHolder.getRegisterCenterApis().registerMogoMapListener(AMapConstants.PATH_FRAGMENT_SETTING_HOME, mapListener)
|
||||
SearchApisHolder.getUiControllerApis().showMyLocation(false)
|
||||
SearchApisHolder.getMarkerManager().removeMarkers()
|
||||
@@ -105,11 +101,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
}
|
||||
|
||||
fun isHome(): Boolean {
|
||||
return style == DataConstants.TYPE_HOME_ADDRESS
|
||||
}
|
||||
|
||||
fun isCompony(): Boolean {
|
||||
return style == DataConstants.TYPE_COMPANY_ADDRESS
|
||||
return type == DataConstants.TYPE_HOME_ADDRESS
|
||||
}
|
||||
|
||||
override fun onViewCreated(
|
||||
@@ -159,17 +151,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
}
|
||||
|
||||
fun insert(searchPoi: SearchPoi) {
|
||||
|
||||
AddressManager.insert(searchPoi)
|
||||
Observable.create(
|
||||
ObservableOnSubscribe<String> {
|
||||
AppDataBase.getDatabase(activity)
|
||||
.poiDao()
|
||||
.insert(searchPoi)
|
||||
AddressHelper.notifyAddressChanged(searchPoi.type)
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
Reference in New Issue
Block a user