家和公司设置问题

This commit is contained in:
zhangyuanzhen
2020-04-03 16:08:01 +08:00
parent 45d5995634
commit 97a8174e86
4 changed files with 22 additions and 21 deletions

View File

@@ -1,6 +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 org.jetbrains.annotations.NotNull;
@@ -14,27 +15,21 @@ import org.jetbrains.annotations.Nullable;
*/
public class AddressHelper {
public static void notifyHomeAddressChanged( Context context ) {
if ( context == null ) {
return;
}
context.getContentResolver().notifyChange( DataConstants.CONTENT_HOME_ADDRESS_URI, null );
public static void notifyHomeAddressChanged( ) {
AbsMogoApplication.getApp().getContentResolver().notifyChange( DataConstants.CONTENT_HOME_ADDRESS_URI, null );
}
public static void notifyCompanyAddressChanged( Context context ) {
if ( context == null ) {
return;
}
context.getContentResolver().notifyChange( DataConstants.CONTENT_COMPANY_ADDRESS_URI, null );
public static void notifyCompanyAddressChanged( ) {
AbsMogoApplication.getApp().getContentResolver().notifyChange( DataConstants.CONTENT_COMPANY_ADDRESS_URI, null );
}
public static void notifyAddressChanged(@Nullable Context context,
public static void notifyAddressChanged(
@NotNull SearchPoi searchPoi) {
if (searchPoi.getType()== DataConstants.TYPE_HOME_ADDRESS) {
notifyHomeAddressChanged(context);
notifyHomeAddressChanged();
}else {
notifyCompanyAddressChanged(context);
notifyCompanyAddressChanged();
}
}
}

View File

@@ -13,6 +13,7 @@ import com.mogo.module.navi.database.AppDataBase
import com.mogo.module.navi.ui.search.ChoosePathFragment
import com.mogo.module.navi.ui.setting.SettingAddressFragment
import com.mogo.service.fragmentmanager.FragmentDescriptor
import com.mogo.utils.UiThreadHandler
import io.reactivex.Observable
import io.reactivex.ObservableEmitter
import io.reactivex.ObservableOnSubscribe
@@ -24,6 +25,7 @@ import org.greenrobot.eventbus.EventBus
* @author zyz
* 2020-01-12.
*/
@SuppressLint("StaticFieldLeak")
object AddressManager {
var homeAddress: SearchPoi? = null
var companyAddress: SearchPoi? = null
@@ -60,6 +62,7 @@ object AddressManager {
SearchServiceHolder.push(
newInstance, MogoModulePaths.PATH_FRAGMENT_CHOOSE_PAHT
)
}
}
@@ -80,8 +83,10 @@ object AddressManager {
SearchServiceHolder.fragmentManager.push(build)
}
private lateinit var context: Context
@SuppressLint("CheckResult") fun init(context: Context) {
this.context=context
poiDao = AppDataBase.getDatabase(context)
.poiDao()
poiDao
@@ -120,7 +125,7 @@ object AddressManager {
ObservableOnSubscribe<String> {
poiDao.delete(homeAddress)
homeAddress?.name=""
AddressHelper.notifyAddressChanged(context, homeAddress!!)
AddressHelper.notifyAddressChanged( homeAddress!!)
homeAddress=null
})
@@ -135,7 +140,7 @@ object AddressManager {
ObservableOnSubscribe<String> {
poiDao.delete(companyAddress)
companyAddress?.name=""
AddressHelper.notifyAddressChanged(context, companyAddress!!)
AddressHelper.notifyAddressChanged( companyAddress!!)
companyAddress=null
})

View File

@@ -300,9 +300,7 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
}
UiThreadHandler.postDelayed(Runnable {
AddressHelper.notifyAddressChanged(activity, searchPoi)
}, 100)
}
override fun onDestroyView() {

View File

@@ -159,6 +159,9 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
.windowCenterLocation
moveMapToCenter()
UiThreadHandler.postDelayed({
if (!isAdded) {
return@postDelayed
}
var decodeResource = BitmapFactory.decodeResource(resources, R.mipmap.icon_choose_position2)
val options = MogoMarkerOptions()
.icon(decodeResource)
@@ -180,10 +183,10 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
AddressManager.insert(searchPoi)
Observable.create(
ObservableOnSubscribe<String> {
AppDataBase.getDatabase(context)
AppDataBase.getDatabase(activity)
.poiDao()
.insert(searchPoi)
AddressHelper.notifyAddressChanged(searchPoi)
})
.subscribeOn(Schedulers.io())
.subscribe()