diff --git a/app/src/google/java/net/vonforst/evmap/adapter/DonationAdapter.kt b/app/src/google/java/net/vonforst/evmap/adapter/DonationAdapter.kt index 1a4b27ec..72a85818 100644 --- a/app/src/google/java/net/vonforst/evmap/adapter/DonationAdapter.kt +++ b/app/src/google/java/net/vonforst/evmap/adapter/DonationAdapter.kt @@ -19,7 +19,7 @@ class DonationAdapter : DataBindingAdapter() { override fun bind(holder: ViewHolder, item: DonationItem) { super.bind(holder, item) val binding = holder.binding as ItemDonationBinding - binding.textView15.text = item.product.title - binding.textView21.text = item.product.oneTimePurchaseOfferDetails?.formattedPrice + binding.txtName.text = item.product.title + binding.txtPrice.text = item.product.oneTimePurchaseOfferDetails?.formattedPrice } } \ No newline at end of file diff --git a/app/src/google/java/net/vonforst/evmap/fragment/DonateFragment.kt b/app/src/google/java/net/vonforst/evmap/fragment/DonateFragment.kt index 8393567a..7b7fca43 100644 --- a/app/src/google/java/net/vonforst/evmap/fragment/DonateFragment.kt +++ b/app/src/google/java/net/vonforst/evmap/fragment/DonateFragment.kt @@ -20,6 +20,7 @@ import net.vonforst.evmap.adapter.SingleViewAdapter import net.vonforst.evmap.databinding.FragmentDonateBinding import net.vonforst.evmap.databinding.FragmentDonateHeaderBinding import net.vonforst.evmap.databinding.FragmentDonateReferralBinding +import net.vonforst.evmap.ui.goneUnless import net.vonforst.evmap.viewmodel.DonateViewModel import net.vonforst.evmap.viewmodel.Status @@ -73,11 +74,7 @@ class DonateFragment : DonateFragmentBase() { vm.products.observe(viewLifecycleOwner) { donationAdapter.submitList(it.data) - binding.progressBar3.visibility = if (it.status == Status.LOADING) { - View.VISIBLE - } else { - View.GONE - } + binding.progressBar.visibility = goneUnless(it.status == Status.LOADING) } vm.purchaseSuccessful.observe(viewLifecycleOwner) { diff --git a/app/src/google/res/layout/fragment_donate.xml b/app/src/google/res/layout/fragment_donate.xml index 791c10d8..5c6962c3 100644 --- a/app/src/google/res/layout/fragment_donate.xml +++ b/app/src/google/res/layout/fragment_donate.xml @@ -34,7 +34,7 @@ tools:listitem="@layout/fragment_donate_preview" /> () { binding.root.isClickable = item.clickable applySelectableItemBackground(binding.root, item.clickable) - binding.imageView3.setImageResource(item.icon) - binding.imageView3.contentDescription = + binding.imgIcon.setImageResource(item.icon) + binding.imgIcon.contentDescription = binding.root.context.getString(item.contentDescription) binding.txtTariff.text = item.text binding.txtProvider.text = item.detailText - goneUnless(binding.txtProvider, item.detailText != null) + binding.txtProvider.visibility = goneUnless(item.detailText != null) setLinkify( binding.txtProvider, if (item.links) Linkify.WEB_URLS or Linkify.PHONE_NUMBERS else 0, @@ -106,7 +106,7 @@ class DetailsAdapter : DataBindingAdapter() { binding.txtTariff.text = item.text binding.txtProvider.text = item.detailText - goneUnless(binding.txtProvider, item.detailText != null) + binding.txtProvider.visibility = goneUnless(item.detailText != null) setLinkify( binding.txtProvider, if (item.links) Linkify.WEB_URLS or Linkify.PHONE_NUMBERS else 0, @@ -166,12 +166,12 @@ class DetailsAdapter : DataBindingAdapter() { dayOfWeek: DayOfWeek?, hours: OpeningHoursDays ) { - include.textView24.text = if (dayOfWeek != null) { + include.txtDay.text = if (dayOfWeek != null) { dayOfWeek.getDisplayName(TextStyle.FULL, Locale.getDefault()) } else { include.root.context.getString(R.string.holiday) } - include.textView25.text = hours.getHoursForDayOfWeek(dayOfWeek)?.toString() + include.txtHours.text = hours.getHoursForDayOfWeek(dayOfWeek)?.toString() ?: include.root.context.getString(R.string.closed_unfmt) } } diff --git a/app/src/main/java/net/vonforst/evmap/adapter/FavoritesAdapter.kt b/app/src/main/java/net/vonforst/evmap/adapter/FavoritesAdapter.kt index 24a4788a..f8eb9da1 100644 --- a/app/src/main/java/net/vonforst/evmap/adapter/FavoritesAdapter.kt +++ b/app/src/main/java/net/vonforst/evmap/adapter/FavoritesAdapter.kt @@ -45,29 +45,29 @@ class FavoritesAdapter(val onDelete: (FavoritesViewModel.FavoritesListItem) -> U val context = binding.root.context val locale = Locale.getDefault() - binding.textView15.text = item.charger.name - binding.textView2.text = item.charger.address?.toString() - invisibleUnless(binding.textView2, item.charger.address != null) + binding.txtName.text = item.charger.name + binding.txtAddress.text = item.charger.address?.toString() + binding.txtAddress.visibility = invisibleUnless(item.charger.address != null) binding.txtConnectors.text = item.charger.formatChargepoints(context.stringProvider(), locale) - binding.textView16.text = distance(item.distance, context) - goneUnless(binding.textView16, item.distance != null) + binding.txtDistance.text = distance(item.distance, context) + binding.txtDistance.visibility = goneUnless(item.distance != null) val availableData = item.available.data if (availableData != null) { - binding.textView7.text = String.format( + binding.txtStatus.text = String.format( locale, "%s/%d", availabilityText(availableData), item.total ) - binding.textView7.backgroundTintList = + binding.txtStatus.backgroundTintList = ColorStateList.valueOf(availabilityColor(availableData, context)) } - invisibleUnless(binding.textView7, item.available.status == Status.SUCCESS) - goneUnless(binding.progressBar4, item.available.status == Status.LOADING) + binding.txtStatus.visibility = invisibleUnless(item.available.status == Status.SUCCESS) + binding.progressBar.visibility = goneUnless(item.available.status == Status.LOADING) binding.foreground.translationX = 0f binding.btnDelete.setOnClickListener { diff --git a/app/src/main/java/net/vonforst/evmap/adapter/FilterProfilesAdapter.kt b/app/src/main/java/net/vonforst/evmap/adapter/FilterProfilesAdapter.kt index cca6b46b..f4feaa17 100644 --- a/app/src/main/java/net/vonforst/evmap/adapter/FilterProfilesAdapter.kt +++ b/app/src/main/java/net/vonforst/evmap/adapter/FilterProfilesAdapter.kt @@ -34,7 +34,7 @@ class FilterProfilesAdapter( super.bind(holder, item) val binding = holder.binding as ItemFilterProfileBinding - binding.textView9.text = item.name + binding.txtName.text = item.name binding.handle.setOnTouchListener { _, event -> if (event?.action == MotionEvent.ACTION_DOWN) { dragHelper.startDrag(holder) diff --git a/app/src/main/java/net/vonforst/evmap/adapter/FiltersAdapter.kt b/app/src/main/java/net/vonforst/evmap/adapter/FiltersAdapter.kt index d8d22c6a..6835e4b5 100644 --- a/app/src/main/java/net/vonforst/evmap/adapter/FiltersAdapter.kt +++ b/app/src/main/java/net/vonforst/evmap/adapter/FiltersAdapter.kt @@ -109,10 +109,10 @@ class FiltersAdapter : DataBindingAdapter>() { ) { val filter = item.filter as BooleanFilter val value = item.value as BooleanFilterValue - binding.textView17.text = filter.name - binding.switch1.setOnCheckedChangeListener(null) - binding.switch1.isChecked = value.value - binding.switch1.setOnCheckedChangeListener { _: CompoundButton, isChecked: Boolean -> + binding.txtName.text = filter.name + binding.toggle.setOnCheckedChangeListener(null) + binding.toggle.isChecked = value.value + binding.toggle.setOnCheckedChangeListener { _: CompoundButton, isChecked: Boolean -> value.value = isChecked } } @@ -123,7 +123,7 @@ class FiltersAdapter : DataBindingAdapter>() { value: MultipleChoiceFilterValue ) { val inflater = LayoutInflater.from(binding.root.context) - binding.textView17.text = filter.name + binding.txtName.text = filter.name value.values.toList().forEach { if (it !in filter.choices.keys) value.values.remove(it) @@ -231,8 +231,8 @@ class FiltersAdapter : DataBindingAdapter>() { value.values = filter.choices.keys.toMutableSet() } - binding.textView17.text = filter.name - binding.textView26.text = binding.root.context.getString( + binding.txtName.text = filter.name + binding.txtDetail.text = binding.root.context.getString( if (value.all) { R.string.all_selected } else { @@ -251,7 +251,7 @@ class FiltersAdapter : DataBindingAdapter>() { dialog.okListener = { selected -> value.values = selected.toMutableSet() value.all = value.values == filter.choices.keys - binding.textView26.text = binding.root.context.getString( + binding.txtDetail.text = binding.root.context.getString( if (value.all) { R.string.all_selected } else { @@ -269,7 +269,7 @@ class FiltersAdapter : DataBindingAdapter>() { filter: SliderFilter, value: SliderFilterValue ) { - binding.textView17.text = filter.name + binding.txtName.text = filter.name val progress = max(filter.inverseMapping(value.value) - filter.min, 0) binding.seekBar.max = filter.max - filter.min binding.seekBar.setOnSeekBarChangeListener(null) @@ -278,8 +278,7 @@ class FiltersAdapter : DataBindingAdapter>() { binding.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - val mapped = filter.mapping(progress + filter.min) - value.value = mapped + value.value = filter.mapping(progress + filter.min) updateSliderValueText(binding, filter, progress) } @@ -294,7 +293,7 @@ class FiltersAdapter : DataBindingAdapter>() { progress: Int ) { val mappedValue = filter.mapping(progress + filter.min) - binding.textView18.text = if (filter.unit.isNullOrBlank()) { + binding.txtValue.text = if (filter.unit.isNullOrBlank()) { mappedValue.toString() } else { "$mappedValue ${filter.unit}" diff --git a/app/src/main/java/net/vonforst/evmap/adapter/PlaceAutocompleteAdapter.kt b/app/src/main/java/net/vonforst/evmap/adapter/PlaceAutocompleteAdapter.kt index 691e1265..46b97d39 100644 --- a/app/src/main/java/net/vonforst/evmap/adapter/PlaceAutocompleteAdapter.kt +++ b/app/src/main/java/net/vonforst/evmap/adapter/PlaceAutocompleteAdapter.kt @@ -118,7 +118,7 @@ class PlaceAutocompleteAdapter(val context: Context, val location: LiveData adapter.submitList(items) val isEmpty = items.isNullOrEmpty() - binding.animationView.visibility = if (isEmpty) View.VISIBLE else View.GONE - binding.textView19.visibility = if (isEmpty) View.VISIBLE else View.GONE + binding.animationView.visibility = goneUnless(isEmpty) + binding.txtEmptyState.visibility = goneUnless(isEmpty) } createTouchHelper().attachToRecyclerView(binding.favsList) diff --git a/app/src/main/java/net/vonforst/evmap/fragment/FilterProfilesFragment.kt b/app/src/main/java/net/vonforst/evmap/fragment/FilterProfilesFragment.kt index d8a4c5c3..a872692a 100644 --- a/app/src/main/java/net/vonforst/evmap/fragment/FilterProfilesFragment.kt +++ b/app/src/main/java/net/vonforst/evmap/fragment/FilterProfilesFragment.kt @@ -31,6 +31,7 @@ import net.vonforst.evmap.adapter.FilterProfilesAdapter import net.vonforst.evmap.databinding.FragmentFilterProfilesBinding import net.vonforst.evmap.databinding.ItemFilterProfileBinding import net.vonforst.evmap.storage.FilterProfile +import net.vonforst.evmap.ui.goneUnless import net.vonforst.evmap.ui.showEditTextDialog import net.vonforst.evmap.viewmodel.FilterProfilesViewModel import net.vonforst.evmap.viewmodel.viewModelFactory @@ -223,8 +224,7 @@ class FilterProfilesFragment : Fragment() { vm.filterProfiles.observe(viewLifecycleOwner) { profiles -> adapter.submitList(profiles) - binding.textView19.visibility = - if (profiles.isNullOrEmpty()) View.VISIBLE else View.GONE + binding.txtEmptyState.visibility = goneUnless(profiles.isNullOrEmpty()) } touchHelper.attachToRecyclerView(binding.filterProfilesList) diff --git a/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt b/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt index 9605a643..a93a6503 100644 --- a/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt +++ b/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt @@ -115,6 +115,8 @@ import net.vonforst.evmap.ui.availabilityColor import net.vonforst.evmap.ui.availabilityText import net.vonforst.evmap.ui.distance import net.vonforst.evmap.ui.flatten +import net.vonforst.evmap.ui.goneUnless +import net.vonforst.evmap.ui.invisibleUnless import net.vonforst.evmap.ui.isFabActive import net.vonforst.evmap.ui.setTouchModal import net.vonforst.evmap.utils.boundingBox @@ -449,19 +451,15 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { binding.fabLayers.setOnClickListener { openLayersMenu() } - binding.layers.rbStandard.setOnClickListener { - vm.setMapType(AnyMap.Type.NORMAL) - } - binding.layers.rbSatellite.setOnClickListener { - vm.setMapType(AnyMap.Type.HYBRID) - } - binding.layers.rbTerrain.setOnClickListener { - vm.setMapType(AnyMap.Type.TERRAIN) + binding.layers.radioGroup.setOnCheckedChangeListener { group, i -> + when (i) { + R.id.rbStandard -> vm.setMapType(AnyMap.Type.NORMAL) + R.id.rbSatellite -> vm.setMapType(AnyMap.Type.HYBRID) + R.id.rbTerrain -> vm.setMapType(AnyMap.Type.TERRAIN) + } } binding.layers.cbTraffic.setOnCheckedChangeListener { _, isChecked -> - if (vm.mapTrafficEnabled.value != isChecked) { - vm.mapTrafficEnabled.value = isChecked - } + vm.mapTrafficEnabled.value = isChecked } binding.layers.btnClose.setOnClickListener { closeLayersMenu() @@ -648,16 +646,11 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { } private fun updateClearSearchVisibility() { - binding.clearSearch.visibility = if (binding.search.text.isNullOrEmpty()) { - View.INVISIBLE - } else { - View.VISIBLE - } + binding.clearSearch.visibility = invisibleUnless(!binding.search.text.isNullOrEmpty()) } private fun updateChargepointsUi(res: Resource>) { - binding.progressBar2.visibility = - if (res.status == Status.LOADING) View.VISIBLE else View.GONE + binding.progressBar2.visibility = goneUnless(res.status == Status.LOADING) binding.progressBar2.isIndeterminate = res.progress == null binding.progressBar2.progress = ((res.progress ?: 0f) * 100f).toInt().coerceIn(0, 100) binding.search.hint = if (res.progress != null) { @@ -670,8 +663,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { private fun updateGallery(photos: List?) { val galleryAdapter = binding.gallery.adapter as? GalleryAdapter ?: return galleryAdapter.submitList(photos) - binding.galleryPlaceholder.visibility = - if (photos.isNullOrEmpty()) View.VISIBLE else View.INVISIBLE + binding.galleryPlaceholder.visibility = invisibleUnless(photos.isNullOrEmpty()) } private fun renderDetailView() { @@ -693,21 +685,21 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { txtName.text = charger?.name txtName.maxLines = if (expanded) 3 else 1 - textView2.text = charger?.address?.toString() ?: charger?.coordinates?.formatDMS() - textView2.visibility = if (charger != null) View.VISIBLE else View.INVISIBLE + txtAddress.text = charger?.address?.toString() ?: charger?.coordinates?.formatDMS() + txtAddress.visibility = invisibleUnless(charger != null) txtDistance.text = distance(distanceMeters, context) txtConnectors.text = charger?.formatChargepoints(context.stringProvider(), Locale.getDefault()) val hasConnectors = charger?.chargepointsMerged?.isNotEmpty() == true - connectors.visibility = if (hasConnectors) View.VISIBLE else View.GONE - textView7.visibility = if (hasConnectors) View.VISIBLE else View.GONE - textView13.visibility = if (hasConnectors) View.VISIBLE else View.GONE - btnRefreshLiveData.visibility = if (hasConnectors) View.VISIBLE else View.GONE + connectors.visibility = goneUnless(hasConnectors) + txtConnectorsHeading.visibility = goneUnless(hasConnectors) + txtRealtimeDesc.visibility = goneUnless(hasConnectors) + btnRefreshLiveData.visibility = goneUnless(hasConnectors) btnRefreshLiveData.isEnabled = availability?.status != Status.LOADING - val realtimeText = when { + txtRealtimeDesc.text = when { availability?.status == Status.SUCCESS -> getString( R.string.realtime_data_source, availability.data?.source.orEmpty() @@ -717,15 +709,10 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { availability?.message == "not signed in" -> getString(R.string.realtime_data_login_needed) else -> getString(R.string.realtime_data_unavailable) } - textView13.text = realtimeText - btnLogin.visibility = if ( + btnLogin.visibility = goneUnless( hasConnectors && availability?.status == Status.ERROR && availability.message == "not signed in" - ) { - View.VISIBLE - } else { - View.GONE - } + ) val flattenedAvailability = flatten(filteredAvailability?.data?.status?.values) if (flattenedAvailability != null && !expanded) { @@ -756,15 +743,15 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { val amenities = charger?.amenities val hasAmenities = !amenities.isNullOrBlank() - textView12.visibility = if (hasAmenities) View.VISIBLE else View.GONE - textView11.visibility = if (hasAmenities) View.VISIBLE else View.GONE - textView11.text = amenities + txtAmenitiesHeading.visibility = goneUnless(hasAmenities) + txtAmenities.visibility = goneUnless(hasAmenities) + txtAmenities.text = amenities val generalInformation = charger?.generalInformation val hasGeneralInformation = !generalInformation.isNullOrBlank() - textView10.visibility = if (hasGeneralInformation) View.VISIBLE else View.GONE - textView4.visibility = if (hasGeneralInformation) View.VISIBLE else View.GONE - textView4.text = generalInformation + txtGeneralInformationHeading.visibility = goneUnless(hasGeneralInformation) + txtGeneralInformation.visibility = goneUnless(hasGeneralInformation) + txtGeneralInformation.text = generalInformation sourceButton.text = getString(R.string.source, apiName) @@ -772,50 +759,45 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { val hasChargerWebsite = charger?.chargerUrl != null val hasExternalLinks = charger != null && (hasChargeprice || hasChargerWebsite) - buttonsScroller.visibility = if (hasExternalLinks) View.VISIBLE else View.GONE - divider3.visibility = if (hasExternalLinks) View.VISIBLE else View.GONE - btnChargeprice.visibility = if (hasChargeprice) View.VISIBLE else View.GONE - btnChargerWebsite.visibility = if (hasChargerWebsite) View.VISIBLE else View.GONE + buttonsScroller.visibility = goneUnless(hasExternalLinks) + divider3.visibility = goneUnless(hasExternalLinks) + btnChargeprice.visibility = goneUnless(hasChargeprice) + btnChargerWebsite.visibility = goneUnless(hasChargerWebsite) val hasPredictionGraph = predictionData?.predictionGraph != null val isPredictionPercentage = predictionData?.isPercentage == true val predictionDescription = predictionData?.description val showPredictionInfo = hasPredictionGraph && !isPredictionPercentage - textView8.visibility = if (hasPredictionGraph) View.VISIBLE else View.GONE - textView8.text = if (isPredictionPercentage) { + txtPredictionHeading.visibility = goneUnless(hasPredictionGraph) + txtPredictionHeading.text = if (isPredictionPercentage) { getString(R.string.average_utilization) } else { getString(R.string.utilization_prediction) } - prediction.visibility = if (hasPredictionGraph) View.VISIBLE else View.GONE + prediction.visibility = goneUnless(hasPredictionGraph) prediction.data = predictionData?.predictionGraph prediction.maxValue = predictionData?.maxValue prediction.isPercentage = isPredictionPercentage - textView29.text = predictionDescription - textView29.visibility = - if (showPredictionInfo && !predictionDescription.isNullOrBlank()) { - View.VISIBLE - } else { - View.GONE - } - btnPredictionHelp.visibility = if (showPredictionInfo) View.VISIBLE else View.GONE - imgPredictionSource.visibility = if (showPredictionInfo) View.VISIBLE else View.GONE - divider1.visibility = if (hasPredictionGraph) View.VISIBLE else View.GONE + txtPredictionDescription.text = predictionDescription + txtPredictionDescription.visibility = + goneUnless(showPredictionInfo && !predictionDescription.isNullOrBlank()) + btnPredictionHelp.visibility = goneUnless(showPredictionInfo) + imgPredictionSource.visibility = goneUnless(showPredictionInfo) + divider1.visibility = goneUnless(hasPredictionGraph) - imgVerified.visibility = if (charger?.verified == true) View.VISIBLE else View.GONE + imgVerified.visibility = goneUnless(charger?.verified == true) TooltipCompat.setTooltipText(imgVerified, getString(R.string.verified_desc, apiName)) - imgFaultReport.visibility = - if (charger?.faultReport != null) View.VISIBLE else View.GONE + imgFaultReport.visibility = goneUnless(charger?.faultReport != null) TooltipCompat.setTooltipText(imgFaultReport, getString(R.string.fault_report)) val timeRetrieved = charger?.timeRetrieved val showTimeRetrieved = timeRetrieved != null && Duration.between(timeRetrieved, Instant.now()) > Duration.ofHours(1) - txtTimeRetrieved.visibility = if (showTimeRetrieved) View.VISIBLE else View.GONE + txtTimeRetrieved.visibility = goneUnless(showTimeRetrieved) val shownTimeRetrieved = if (showTimeRetrieved) timeRetrieved else null if (shownTimeRetrieved != null) { txtTimeRetrieved.text = getString( @@ -831,7 +813,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { } val license = charger?.license - txtLicense.visibility = if (license.isNullOrBlank()) View.GONE else View.VISIBLE + txtLicense.visibility = goneUnless(!license.isNullOrBlank()) txtLicense.text = license } } @@ -1027,13 +1009,12 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { isFabActive(binding.fabLocate, it == true) } vm.bottomSheetState.observe(viewLifecycleOwner) { - binding.navBarScrim.visibility = - if (it == STATE_COLLAPSED) View.VISIBLE else View.INVISIBLE + binding.navBarScrim.visibility = invisibleUnless(it == STATE_COLLAPSED) } vm.layersMenuOpen.observe(viewLifecycleOwner) { open -> HideOnScrollFabBehavior.from(binding.fabLayers)?.hidden = open - binding.fabLayers.visibility = if (open) View.INVISIBLE else View.VISIBLE - binding.layersSheet.visibility = if (open) View.VISIBLE else View.INVISIBLE + binding.fabLayers.visibility = invisibleUnless(!open) + binding.layersSheet.visibility = invisibleUnless(open) updateBackPressedCallback() } vm.mapType.observe(viewLifecycleOwner) { @@ -1056,13 +1037,12 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { } } vm.mapTrafficSupported.observe(viewLifecycleOwner) { supported -> - val visibility = if (supported) View.VISIBLE else View.GONE + val visibility = goneUnless(supported) binding.layers.textView23.visibility = visibility binding.layers.cbTraffic.visibility = visibility } vm.selectedChargepoint.observe(viewLifecycleOwner) { - binding.detailView.connectorDetailsCard.visibility = - if (it != null) View.VISIBLE else View.INVISIBLE + binding.detailView.connectorDetailsCard.visibility = invisibleUnless(it != null) if (it != null) { detailsDialog.setData(it, vm.availability.value?.data) } @@ -1543,7 +1523,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider { if (filterBadge != null) { // set up badge showing number of active filters vm.filtersCount.observe(viewLifecycleOwner) { - filterBadge.visibility = if (it > 0) View.VISIBLE else View.GONE + filterBadge.visibility = goneUnless(it > 0) filterBadge.text = it.toString() } } diff --git a/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt b/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt index c679ec1b..864291df 100644 --- a/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt +++ b/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt @@ -17,13 +17,9 @@ import net.vonforst.evmap.meterPerFt import net.vonforst.evmap.shouldUseImperialUnits import java.time.Instant -fun goneUnless(view: View, visible: Boolean) { - view.visibility = if (visible) View.VISIBLE else View.GONE -} +fun goneUnless(visible: Boolean): Int = if (visible) View.VISIBLE else View.GONE -fun invisibleUnless(view: View, visible: Boolean) { - view.visibility = if (visible) View.VISIBLE else View.INVISIBLE -} +fun invisibleUnless(visible: Boolean): Int = if (visible) View.VISIBLE else View.INVISIBLE fun isFabActive(view: FloatingActionButton, isColored: Boolean) { view.imageTintList = activeTint(view.context, isColored) diff --git a/app/src/main/res/layout/detail_view.xml b/app/src/main/res/layout/detail_view.xml index 3f663b65..f9d995b3 100644 --- a/app/src/main/res/layout/detail_view.xml +++ b/app/src/main/res/layout/detail_view.xml @@ -34,7 +34,7 @@ tools:text="Parkhaus" /> + app:layout_constraintTop_toBottomOf="@+id/txtAmenities" /> + app:layout_constraintTop_toBottomOf="@+id/txtRealtimeDesc" />