增加设置家和公司的功能
This commit is contained in:
@@ -7,10 +7,14 @@ 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.dao.SearchPoiDao
|
||||
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 io.reactivex.Observable
|
||||
import io.reactivex.ObservableEmitter
|
||||
import io.reactivex.ObservableOnSubscribe
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
@@ -19,17 +23,20 @@ import io.reactivex.schedulers.Schedulers
|
||||
* 2020-01-12.
|
||||
*/
|
||||
object AddressManager {
|
||||
private var homeAddress: SearchPoi? = null
|
||||
private var companyAddress: SearchPoi? = null
|
||||
var homeAddress: SearchPoi? = null
|
||||
var companyAddress: SearchPoi? = null
|
||||
private lateinit var poiDao:SearchPoiDao
|
||||
fun goHome() {
|
||||
if (homeAddress == null) {
|
||||
pushSettingAddress(
|
||||
DataConstants.TYPE_HOME_ADDRESS
|
||||
)
|
||||
} else {
|
||||
var newInstance = ChoosePathFragment.newInstance(EntityConvertUtils.poi2MogoTip(
|
||||
homeAddress
|
||||
).point)
|
||||
var newInstance = ChoosePathFragment.newInstance(
|
||||
EntityConvertUtils.poi2MogoTip(
|
||||
homeAddress
|
||||
).point
|
||||
)
|
||||
SearchServiceHolder.push(
|
||||
newInstance, MogoModulePaths.PATH_FRAGMENT_CHOOSE_PAHT
|
||||
)
|
||||
@@ -43,15 +50,25 @@ object AddressManager {
|
||||
)
|
||||
} else {
|
||||
var newInstance =
|
||||
ChoosePathFragment.newInstance(EntityConvertUtils.poi2MogoTip(
|
||||
companyAddress
|
||||
).point)
|
||||
ChoosePathFragment.newInstance(
|
||||
EntityConvertUtils.poi2MogoTip(
|
||||
companyAddress
|
||||
).point
|
||||
)
|
||||
SearchServiceHolder.push(
|
||||
newInstance, MogoModulePaths.PATH_FRAGMENT_CHOOSE_PAHT
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun hasHome(): Boolean {
|
||||
return homeAddress == null
|
||||
}
|
||||
|
||||
fun hasCompany(): Boolean {
|
||||
return companyAddress == null
|
||||
}
|
||||
|
||||
private fun pushSettingAddress(type: Int) {
|
||||
|
||||
val builder = FragmentDescriptor.Builder()
|
||||
@@ -62,8 +79,10 @@ object AddressManager {
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult") fun init(context: Context) {
|
||||
AppDataBase.getDatabase(context)
|
||||
|
||||
poiDao = AppDataBase.getDatabase(context)
|
||||
.poiDao()
|
||||
poiDao
|
||||
.companyAddress
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@@ -72,8 +91,8 @@ object AddressManager {
|
||||
companyAddress = t1[0]
|
||||
}
|
||||
}
|
||||
AppDataBase.getDatabase(context)
|
||||
.poiDao()
|
||||
|
||||
poiDao
|
||||
.homeAddress
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@@ -91,4 +110,24 @@ object AddressManager {
|
||||
homeAddress = searchPoi
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteHome(){
|
||||
homeAddress=null
|
||||
Observable.create(
|
||||
ObservableOnSubscribe<String> {
|
||||
poiDao.delete(homeAddress)
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
fun deleteCompany(){
|
||||
companyAddress=null
|
||||
Observable.create(
|
||||
ObservableOnSubscribe<String> {
|
||||
poiDao.delete(companyAddress)
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.mogo.map.uicontroller.EnumMapUI
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.manager.AddressManager
|
||||
import com.mogo.module.navi.manager.SettingManager
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
import com.mogo.service.MogoServicePaths
|
||||
@@ -37,6 +38,10 @@ import kotlinx.android.synthetic.main.fragment_navi_setting.rb_navi_no_high_way
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.rg_navi_day_night
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.rg_navi_sound_type
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.sb_navi_volume_progress
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.tv_navi_clear_company_address
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.tv_navi_clear_home_address
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.tv_navi_company_address
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.tv_navi_home_address
|
||||
import java.util.HashMap
|
||||
|
||||
/**
|
||||
@@ -97,7 +102,11 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
iv_back.setOnClickListener {
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
}
|
||||
initViews()
|
||||
initEvent()
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
|
||||
rb_navi_high_way.isChecked = SettingManager.isHighSpeed()
|
||||
rb_navi_jam.isChecked = SettingManager.isCongestion()
|
||||
@@ -113,6 +122,12 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
rb_navi_draft.isChecked = SettingManager.voiceStyle == R.id.rb_navi_draft
|
||||
|
||||
|
||||
updateHome()
|
||||
updateCompany()
|
||||
|
||||
}
|
||||
|
||||
private fun initEvent() {
|
||||
iv_sound_plus.setOnClickListener {
|
||||
sb_navi_volume_progress.progress = ++sb_navi_volume_progress.progress
|
||||
SettingManager.volume = sb_navi_volume_progress.progress
|
||||
@@ -185,5 +200,47 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tv_navi_clear_home_address.setOnClickListener {
|
||||
AddressManager.deleteHome()
|
||||
updateHome()
|
||||
|
||||
}
|
||||
|
||||
tv_navi_clear_company_address.setOnClickListener {
|
||||
AddressManager.deleteCompany()
|
||||
updateCompany()
|
||||
}
|
||||
|
||||
tv_navi_company_address.setOnClickListener {
|
||||
if (!AddressManager.hasCompany()) {
|
||||
AddressManager.goHome()
|
||||
}
|
||||
}
|
||||
|
||||
tv_navi_home_address.setOnClickListener {
|
||||
if (!AddressManager.hasHome()) {
|
||||
AddressManager.goCompany()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateHome() {
|
||||
|
||||
if (AddressManager.hasHome()) {
|
||||
tv_navi_home_address.text = AddressManager.homeAddress?.name
|
||||
tv_navi_clear_home_address.visibility = View.VISIBLE
|
||||
} else {
|
||||
tv_navi_clear_home_address.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCompany() {
|
||||
if (AddressManager.hasCompany()) {
|
||||
tv_navi_company_address.text = AddressManager.companyAddress?.name
|
||||
tv_navi_clear_company_address.visibility = View.VISIBLE
|
||||
} else {
|
||||
tv_navi_clear_company_address.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user