修复UI问题

This commit is contained in:
zhangyuanzhen
2020-02-14 14:33:05 +08:00
parent b6718f7d9d
commit a2b94a97ad
13 changed files with 322 additions and 88 deletions

View File

@@ -46,17 +46,17 @@ public class AddressContentProvider extends ContentProvider {
Log.d( TAG, "query code: " + code );
final SearchPoi poi = getPoi( code );
MatrixCursor
cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME, 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} );
if ( code == DataConstants.HOME_ADDRESS_CODE ) {
cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME, 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_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} );
cursor.addRow( new Object[]{"","", 0, 0} );
} else {
cursor.addRow( new Object[]{poi.getName(), poi.getLat(), poi.getLng()} );
cursor.addRow( new Object[]{poi.getName(),poi.getAddress(), poi.getLat(), poi.getLng()} );
}
}
return cursor;

View File

@@ -0,0 +1,91 @@
package com.mogo.module.navi.dialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.module.navi.R;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.map.IMogoMapService;
/**
* @author lixiaopeng
* @description 通用分享dialog
* @since 2020-01-10
*/
public class NoticeDialog extends Dialog implements View.OnClickListener {
private final String content;
private final String positive;
private TextView txtOk;
private Context mContext;
private View tvCancel;
private View.OnClickListener onClickListener;
private TextView tvContent;
public NoticeDialog(@NonNull Context context,String content,String positive) {
super(context, R.style.Theme_AppCompat_Dialog);
this.mContext = context;
this.content=content;
this.positive=positive;
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
}
//public NoticeDialog(@NonNull Context context, int themeResId) {
// super(context, R.style.Theme_AppCompat_Dialog);
//}
public void setOnClickListener(View.OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initView();
setContent(content);
setPositiveButton(positive);
initListener();
}
private void initView() {
setContentView(R.layout.dialog_common_notice);
txtOk = findViewById(R.id.tv_dialog_ok);
tvCancel = findViewById(R.id.tv_dialog_cancel);
tvContent = findViewById(R.id.tv_dialog_content);
}
private void initListener() {
txtOk.setOnClickListener(this);
tvCancel.setOnClickListener(this);
}
@Override
public void onClick(View view) {
int id = view.getId();
if (onClickListener != null) {
onClickListener.onClick(view);
}
dismiss();
}
public void setContent(String s) {
if (tvContent != null) {
tvContent.setText(s);
}
}
public void setPositiveButton(String str) {
if (txtOk != null) {
txtOk.setText(str);
}
}
}

View File

@@ -10,6 +10,9 @@ import com.mogo.module.common.MogoModulePaths
import com.mogo.module.navi.constants.SearchServiceHolder
import com.mogo.module.navi.ui.search.ChoosePathFragment
import com.mogo.utils.logger.Logger
import androidx.core.content.ContextCompat.startActivity
/**
*@author zyz
@@ -33,6 +36,8 @@ object NaviManager {
val lat = intent.getDoubleExtra("LAT", 0.0)
val lon = intent.getDoubleExtra("LON", 0.0)
showHome()
var newInstance =
ChoosePathFragment.newInstance(
MogoLatLng(lat,lon)
@@ -42,9 +47,20 @@ object NaviManager {
)
}else if (key_type == 10021) {
SearchServiceHolder.getNavi().stopNavi()
}else if (key_type == 20009) {
showHome()
SearchServiceHolder.fragmentManager
.clearAll()
}
}
}
private fun showHome() {
val intent = Intent(Intent.ACTION_MAIN)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.addCategory(Intent.CATEGORY_HOME)
context.startActivity(intent)
}
}
val inputFilter = IntentFilter()
inputFilter.addAction(AUTONAVI_STANDARD_BROADCAST_RECV)

View File

@@ -3,6 +3,7 @@ package com.mogo.module.navi.ui.search;
import android.app.AlertDialog;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
@@ -19,11 +20,13 @@ import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
import com.mogo.map.search.poisearch.MogoPoiResult;
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
import com.mogo.module.common.TextWatcherAdapter;
import com.mogo.module.navi.R;
import com.mogo.module.navi.bean.EntityConvertUtils;
import com.mogo.module.navi.bean.SearchPoi;
import com.mogo.module.navi.constants.DataConstants;
import com.mogo.module.navi.constants.SearchServiceHolder;
import com.mogo.module.navi.database.AppDataBase;
import com.mogo.module.navi.dialog.NoticeDialog;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.map.IMogoMapService;
import io.reactivex.Observable;
@@ -46,25 +49,25 @@ import java.util.List;
* <p>
* 搜搜页逻辑处理
*/
public class SearchPresenter extends Presenter< SearchView >
{
public class SearchPresenter extends Presenter<SearchView> {
private CompositeDisposable mCompositeDisposable;
private IMogoMapService mMapService;
private IMogoMapService mMapService;
public SearchPresenter( SearchView view ) {
super( view );
public SearchPresenter(SearchView view) {
super(view);
mCompositeDisposable = new CompositeDisposable();
}
@Override
public void onCreate( @NonNull LifecycleOwner owner ) {
super.onCreate( owner );
attachSearchBoxTextWatcher( mView.getSearchBox() );
mMapService = (IMogoMapService) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( getContext() );
public void onCreate(@NonNull LifecycleOwner owner) {
super.onCreate(owner);
attachSearchBoxTextWatcher(mView.getSearchBox());
mMapService = (IMogoMapService) ARouter.getInstance()
.build(MogoServicePaths.PATH_SERVICES_MAP)
.navigation(getContext());
loadHistories();
}
}
private void loadHistories() {
Disposable subscribe =
@@ -82,8 +85,8 @@ public class SearchPresenter extends Presenter< SearchView >
addDisposable(subscribe);
}
private void attachSearchBoxTextWatcher( EditText editText ) {
if ( editText == null ) {
private void attachSearchBoxTextWatcher(EditText editText) {
if (editText == null) {
return;
}
editText.addTextChangedListener(watcherAdapter);
@@ -91,14 +94,14 @@ public class SearchPresenter extends Presenter< SearchView >
private final TextWatcherAdapter watcherAdapter = new TextWatcherAdapter() {
@Override
public void afterTextChanged( Editable s ) {
public void afterTextChanged(Editable s) {
// 避免 disable 设置内容时触发
final String input = s.toString();
startSearchPoiByInput( input );
startSearchPoiByInput(input);
}
};
public void startSearchPoiByInput( String keyword ) {
public void startSearchPoiByInput(String keyword) {
MogoInputtipsQuery mogoInputtipsQuery = new MogoInputtipsQuery();
mogoInputtipsQuery.setKeyword(keyword);
@@ -111,59 +114,70 @@ public class SearchPresenter extends Presenter< SearchView >
inputtipsSearch.setInputtipsListener(new IMogoInputtipsListener() {
@Override public void onGetInputtips(List<MogoTip> result) {
mView.renderSearchPoiResult(result,false);
mView.renderSearchPoiResult(result, false);
}
});
inputtipsSearch.requestInputtipsAsyn();
}
/**
* 缓存搜索到的导航地址
*
* @param tip
* @return
*/
public Single cacheSelectPoiItem( MogoTip tip ) {
return Single.create( emitter -> {
SearchPoi poi = EntityConvertUtils.tipToPoi( tip );
public Single cacheSelectPoiItem(MogoTip tip) {
return Single.create(emitter -> {
SearchPoi poi = EntityConvertUtils.tipToPoi(tip);
//ignore insert result
final List<Long> output = AppDataBase.getDatabase( getContext() ).poiDao().insert( poi );
emitter.onSuccess( output );
} ).subscribeOn( Schedulers.io() ).observeOn( AndroidSchedulers.mainThread() );
final List<Long> output = AppDataBase.getDatabase(getContext()).poiDao().insert(poi);
emitter.onSuccess(output);
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
}
public void addDisposable( Disposable disposable ) {
mCompositeDisposable.add( disposable );
public void addDisposable(Disposable disposable) {
mCompositeDisposable.add(disposable);
}
public void deleteAllCachedPoi() {
new AlertDialog.Builder( getContext() )
.setMessage( "清空历史记录?" )
.setPositiveButton( "立即清空", ( dlg, which ) -> {
dlg.dismiss();
//new AlertDialog.Builder( getContext() )
// .setMessage( "清空历史记录?" )
// .setPositiveButton( "立即清空", ( dlg, which ) -> {
// dlg.dismiss();
// deleteAllCachedPoiImpl();
// } )
// .setNegativeButton( "取消", ( dlg, which ) -> {
// dlg.dismiss();
// } )
// .create()
// .show();
NoticeDialog noticeDialog = new NoticeDialog(getContext(),"清空历史记录?","立即清空");
//noticeDialog.setContent("清空历史记录?");
//noticeDialog.setPositiveButton("立即清空");
noticeDialog.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
if (v.getId() == R.id.tv_dialog_ok) {
deleteAllCachedPoiImpl();
} )
.setNegativeButton( "取消", ( dlg, which ) -> {
dlg.dismiss();
} )
.create()
.show();
}
}
});
noticeDialog.show();
}
private void deleteAllCachedPoiImpl() {
final Disposable disposable = AppDataBase.getDatabase( getContext() )
.poiDao()
.getAll()
.map( input -> {
return AppDataBase.getDatabase( getContext() ).poiDao().deleteAll( input );
} )
.subscribeOn( Schedulers.io() )
.observeOn( AndroidSchedulers.mainThread() )
.subscribe( count -> {
mView.showHistory( null );
} );
mCompositeDisposable.add( disposable );
final Disposable disposable = AppDataBase.getDatabase(getContext())
.poiDao()
.getAll()
.map(input -> {
return AppDataBase.getDatabase(getContext()).poiDao().deleteAll(input);
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(count -> {
mView.showHistory(null);
});
mCompositeDisposable.add(disposable);
}
//
///**
@@ -197,9 +211,9 @@ public class SearchPresenter extends Presenter< SearchView >
//
//
private void emitterCommonAddress( SingleEmitter<List<Long>> emitter, SearchPoi poi ) {
private void emitterCommonAddress(SingleEmitter<List<Long>> emitter, SearchPoi poi) {
String poiId = null;
switch ( mView.getSearchType() ) {
switch (mView.getSearchType()) {
case SearchConstants.SEARCH_TYPE_MULTI_HOME:
poiId = DataConstants.POI_ID_HOME;
break;
@@ -207,20 +221,20 @@ public class SearchPresenter extends Presenter< SearchView >
poiId = DataConstants.POI_ID_COMPANY;
break;
}
if ( TextUtils.isEmpty( poiId ) ) {
emitter.onError( new IllegalArgumentException( "设置类型错误,请重试" ) );
if (TextUtils.isEmpty(poiId)) {
emitter.onError(new IllegalArgumentException("设置类型错误,请重试"));
return;
}
if ( poi == null ) {
emitter.onError( new IllegalArgumentException( "位置类型转换错误,请重试" ) );
if (poi == null) {
emitter.onError(new IllegalArgumentException("位置类型转换错误,请重试"));
return;
}
poi.setpId( poiId );
poi.setType( mView.getSearchType() );
poi.setpId(poiId);
poi.setType(mView.getSearchType());
//ignore insert result
final List<Long> output = AppDataBase.getDatabase( getContext() ).poiDao().insert( poi );
final List<Long> output = AppDataBase.getDatabase(getContext()).poiDao().insert(poi);
notifyAIAssistCommonAddressChanged();
emitter.onSuccess( output );
emitter.onSuccess(output);
}
private void notifyAIAssistCommonAddressChanged() {
@@ -232,12 +246,11 @@ public class SearchPresenter extends Presenter< SearchView >
//}
}
public void navi2Positon(){
public void navi2Positon() {
//mMapService.getNavi(getContext()).naviTo();
}
public void insert(SearchPoi searchPoi){
public void insert(SearchPoi searchPoi) {
Observable.create(new ObservableOnSubscribe<String>() {
@Override public void subscribe(ObservableEmitter<String> emitter) throws Exception {
AppDataBase.getDatabase(getContext()).poiDao().insert(searchPoi);
@@ -245,23 +258,21 @@ public class SearchPresenter extends Presenter< SearchView >
}).subscribeOn(Schedulers.io()).subscribe();
}
public void clearHistory(List<SearchPoi> list){
Observable.create(new ObservableOnSubscribe<String>() {
@Override public void subscribe(ObservableEmitter<String> emitter) throws Exception {
AppDataBase.getDatabase(getContext()).poiDao().deleteAll(list);
}
}).subscribeOn(Schedulers.io()).subscribe();
}
public void clearHistory(List<SearchPoi> list) {
Observable.create(new ObservableOnSubscribe<String>() {
@Override public void subscribe(ObservableEmitter<String> emitter) throws Exception {
AppDataBase.getDatabase(getContext()).poiDao().deleteAll(list);
}
}).subscribeOn(Schedulers.io()).subscribe();
}
@Override
public void onDestroy( @NonNull LifecycleOwner owner ) {
super.onDestroy( owner );
if ( mView.getSearchBox() != null ) {
mView.getSearchBox().removeTextChangedListener( watcherAdapter );
public void onDestroy(@NonNull LifecycleOwner owner) {
super.onDestroy(owner);
if (mView.getSearchBox() != null) {
mView.getSearchBox().removeTextChangedListener(watcherAdapter);
}
if ( mCompositeDisposable != null && !mCompositeDisposable.isDisposed() ) {
if (mCompositeDisposable != null && !mCompositeDisposable.isDisposed()) {
mCompositeDisposable.dispose();
mCompositeDisposable = null;
}

View File

@@ -31,9 +31,9 @@ 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.et_navi_search
import kotlinx.android.synthetic.main.fragment_setting_address.iv_navi_back
import kotlinx.android.synthetic.main.fragment_setting_address.tv_set_as_home
import kotlinx.android.synthetic.main.include_search_bar.et_navi_search
import kotlinx.android.synthetic.main.include_search_bar.iv_navi_back
/**
* @author zyz