mirror of
https://github.com/ev-map/EVMap.git
synced 2026-05-19 12:26:20 -04:00
@@ -251,8 +251,11 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
|
||||
binding.detailAppBar.toolbar.inflateMenu(R.menu.detail)
|
||||
favToggle = binding.detailAppBar.toolbar.menu.findItem(R.id.menu_fav)
|
||||
binding.detailAppBar.toolbar.menu.findItem(R.id.menu_edit).title =
|
||||
getString(R.string.edit_at_datasource, vm.apiName)
|
||||
|
||||
vm.apiName.observe(viewLifecycleOwner) {
|
||||
binding.detailAppBar.toolbar.menu.findItem(R.id.menu_edit).title =
|
||||
getString(R.string.edit_at_datasource, it)
|
||||
}
|
||||
|
||||
binding.detailView.topPart.doOnNextLayout {
|
||||
bottomSheetBehavior.peekHeight = binding.detailView.topPart.bottom
|
||||
@@ -433,6 +436,12 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_reload -> {
|
||||
vm.reloadChargerDetails()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
@@ -1332,17 +1341,16 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
).show()
|
||||
true
|
||||
}
|
||||
|
||||
val reloadItem = menu.findItem(R.id.menu_reload)
|
||||
reloadItem.setOnMenuItemClickListener {
|
||||
vm.reloadChargepoints(true)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||
return false
|
||||
override fun onMenuItemSelected(menuItem: MenuItem) = when (menuItem.itemId) {
|
||||
R.id.menu_reload -> {
|
||||
vm.reloadChargepoints(true)
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
|
||||
override fun getRootView(): View {
|
||||
|
||||
@@ -310,7 +310,8 @@ class ChargeLocationsRepository(
|
||||
}
|
||||
|
||||
fun getChargepointDetail(
|
||||
id: Long
|
||||
id: Long,
|
||||
overrideCache: Boolean = false
|
||||
): LiveData<Resource<ChargeLocation>> {
|
||||
val dbResult = chargeLocationsDao.getChargeLocationById(
|
||||
id,
|
||||
@@ -326,7 +327,11 @@ class ChargeLocationsRepository(
|
||||
chargeLocationsDao.insert(result.data!!)
|
||||
}
|
||||
}
|
||||
return PreferCacheLiveData(dbResult, apiResult, cacheSoftLimit)
|
||||
return if (overrideCache) {
|
||||
apiResult
|
||||
} else {
|
||||
PreferCacheLiveData(dbResult, apiResult, cacheSoftLimit)
|
||||
}
|
||||
}
|
||||
|
||||
fun getFilters(sp: StringProvider) = MediatorLiveData<List<Filter<FilterValue>>>().apply {
|
||||
|
||||
@@ -163,9 +163,13 @@ class MapViewModel(application: Application, private val state: SavedStateHandle
|
||||
val chargerSparse: MutableLiveData<ChargeLocation?> by lazy {
|
||||
state.getLiveData("chargerSparse")
|
||||
}
|
||||
private val triggerChargerDetailsRefresh = MutableLiveData(false)
|
||||
val chargerDetails: LiveData<Resource<ChargeLocation>> = chargerSparse.switchMap { charger ->
|
||||
charger?.id?.let {
|
||||
repo.getChargepointDetail(it)
|
||||
triggerChargerDetailsRefresh.value = false
|
||||
triggerChargerDetailsRefresh.switchMap { overrideCache ->
|
||||
charger?.id?.let {
|
||||
repo.getChargepointDetail(it, overrideCache)
|
||||
}
|
||||
}
|
||||
}.apply {
|
||||
observeForever { chargerDetail ->
|
||||
@@ -207,7 +211,7 @@ class MapViewModel(application: Application, private val state: SavedStateHandle
|
||||
val location: MutableLiveData<LatLng> by lazy {
|
||||
MutableLiveData<LatLng>()
|
||||
}
|
||||
private val triggerAvailabilityRefresh = MutableLiveData<Boolean>(true)
|
||||
private val triggerAvailabilityRefresh = MutableLiveData(true)
|
||||
val availability: LiveData<Resource<ChargeLocationStatus>> by lazy {
|
||||
chargerSparse.switchMap { charger ->
|
||||
charger?.let {
|
||||
@@ -602,6 +606,10 @@ class MapViewModel(application: Application, private val state: SavedStateHandle
|
||||
triggerAvailabilityRefresh.value = true
|
||||
}
|
||||
|
||||
fun reloadChargerDetails() {
|
||||
triggerChargerDetailsRefresh.value = true
|
||||
}
|
||||
|
||||
fun loadChargerById(chargerId: Long) {
|
||||
chargerSparse.value = null
|
||||
repo.getChargepointDetail(chargerId).observeForever { response ->
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_edit"
|
||||
android:icon="@drawable/ic_edit"
|
||||
android:title="@string/edit_at_datasource"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_share"
|
||||
android:icon="@drawable/ic_share"
|
||||
@@ -19,4 +13,13 @@
|
||||
android:icon="@drawable/ic_fav_no"
|
||||
android:title="@string/fav_add"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_edit"
|
||||
android:icon="@drawable/ic_edit"
|
||||
android:title="@string/edit_at_datasource" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_reload"
|
||||
android:title="@string/reload" />
|
||||
</menu>
|
||||
Reference in New Issue
Block a user