Skip to content

Commit

Permalink
Fix: save lastKnowLocation in ViewModel to keep showing distance in l…
Browse files Browse the repository at this point in the history
…ist in Places (#4445)

* Fix: save lastKnowLocation in ViewModel to keep showing distance in list

* Fix lint
  • Loading branch information
cooltey authored Feb 6, 2024
1 parent 1cc53a1 commit a16e662
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/org/wikipedia/places/PlacesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,9 @@ class PlacesFragment : Fragment(), LinkPreviewDialog.LoadPageCallback, LinkPrevi
if (haveLocationPermissions()) {
binding.viewButtonsGroup.check(R.id.mapViewButton)
mapboxMap?.let {
val currentLocation = it.locationComponent.lastKnownLocation
viewModel.lastKnownLocation = it.locationComponent.lastKnownLocation
var currentLatLngLoc: LatLng? = null
currentLocation?.let { loc -> currentLatLngLoc = LatLng(loc.latitude, loc.longitude) }
viewModel.lastKnownLocation?.let { loc -> currentLatLngLoc = LatLng(loc.latitude, loc.longitude) }
val location = preferredLocation?.let { loc -> LatLng(loc.latitude, loc.longitude) }
val targetLocation = location ?: currentLatLngLoc
targetLocation?.let { target ->
Expand Down Expand Up @@ -767,7 +767,7 @@ class PlacesFragment : Fragment(), LinkPreviewDialog.LoadPageCallback, LinkPrevi
}

override fun onBindViewHolder(holder: RecyclerViewItemHolder, position: Int) {
holder.bindItem(nearbyPages[position], mapboxMap?.locationComponent?.lastKnownLocation)
holder.bindItem(nearbyPages[position], viewModel.lastKnownLocation)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PlacesFragmentViewModel(bundle: Bundle) : ViewModel() {
var location: Location? = bundle.parcelable(PlacesActivity.EXTRA_LOCATION)
var highlightedPageTitle: PageTitle? = bundle.parcelable(Constants.ARG_TITLE)

var lastKnownLocation: Location? = null
val nearbyPagesLiveData = MutableLiveData<Resource<List<NearbyPage>>>()

fun fetchNearbyPages(latitude: Double, longitude: Double, radius: Int, maxResults: Int) {
Expand Down

0 comments on commit a16e662

Please sign in to comment.