mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Migrated
This commit is contained in:
parent
f049cc868f
commit
b884074ad2
1 changed files with 55 additions and 61 deletions
|
|
@ -50,6 +50,7 @@ import com.jakewharton.rxbinding2.view.RxView
|
||||||
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
|
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
|
||||||
import fr.free.nrw.commons.CommonsApplication
|
import fr.free.nrw.commons.CommonsApplication
|
||||||
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
|
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
|
||||||
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.Utils
|
import fr.free.nrw.commons.Utils
|
||||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||||
import fr.free.nrw.commons.contributions.ContributionController
|
import fr.free.nrw.commons.contributions.ContributionController
|
||||||
|
|
@ -683,40 +684,38 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
||||||
|
|
||||||
private fun locationPermissionGranted() {
|
private fun locationPermissionGranted() {
|
||||||
isPermissionDenied = false
|
isPermissionDenied = false
|
||||||
applicationKvStore!!.putBoolean("doNotAskForLocationPermission", false)
|
applicationKvStore.putBoolean("doNotAskForLocationPermission", false)
|
||||||
lastKnownLocation = locationManager!!.getLastLocation()
|
lastKnownLocation = locationManager.getLastLocation()
|
||||||
val target = lastKnownLocation
|
val target = lastKnownLocation
|
||||||
if (lastKnownLocation != null) {
|
|
||||||
val targetP = GeoPoint(target!!.latitude, target.longitude)
|
if (target != null) {
|
||||||
|
val targetP = GeoPoint(target.latitude, target.longitude)
|
||||||
mapCenter = targetP
|
mapCenter = targetP
|
||||||
binding!!.map.controller.setCenter(targetP)
|
binding?.map?.controller?.setCenter(targetP)
|
||||||
recenterMarkerToPosition(targetP)
|
recenterMarkerToPosition(targetP)
|
||||||
if (!isCameFromExploreMap()) {
|
if (!isCameFromExploreMap()) {
|
||||||
moveCameraToPosition(targetP);
|
moveCameraToPosition(targetP)
|
||||||
}
|
}
|
||||||
} else if (locationManager!!.isGPSProviderEnabled()
|
} else if (locationManager.isGPSProviderEnabled() || locationManager.isNetworkProviderEnabled()) {
|
||||||
|| locationManager!!.isNetworkProviderEnabled()
|
locationManager.requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER)
|
||||||
) {
|
locationManager.requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER)
|
||||||
locationManager!!.requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER)
|
|
||||||
locationManager!!.requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER)
|
|
||||||
setProgressBarVisibility(true)
|
setProgressBarVisibility(true)
|
||||||
} else {
|
} else {
|
||||||
locationPermissionsHelper!!.showLocationOffDialog(
|
activity?.let { locationPermissionsHelper?.showLocationOffDialog(it, R.string.ask_to_turn_location_on_text) }
|
||||||
requireActivity(),
|
|
||||||
fr.free.nrw.commons.R.string.ask_to_turn_location_on_text
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
presenter!!.onMapReady()
|
|
||||||
|
presenter?.onMapReady()
|
||||||
registerUnregisterLocationListener(false)
|
registerUnregisterLocationListener(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
binding!!.map.onResume()
|
binding?.map?.onResume()
|
||||||
presenter!!.attachView(this)
|
presenter?.attachView(this)
|
||||||
registerNetworkReceiver()
|
registerNetworkReceiver()
|
||||||
if (isResumed && (activity as MainActivity).activeFragment == ActiveFragment.NEARBY) {
|
|
||||||
if (locationPermissionsHelper!!.checkLocationPermission(requireActivity())) {
|
if (isResumed && (activity as? MainActivity)?.activeFragment == ActiveFragment.NEARBY) {
|
||||||
|
if (activity?.let { locationPermissionsHelper?.checkLocationPermission(it) } == true) {
|
||||||
locationPermissionGranted()
|
locationPermissionGranted()
|
||||||
} else {
|
} else {
|
||||||
startMapWithoutPermission()
|
startMapWithoutPermission()
|
||||||
|
|
@ -2456,49 +2455,44 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
||||||
* @param geoPoint The GeoPoint representing the new center position of the map.
|
* @param geoPoint The GeoPoint representing the new center position of the map.
|
||||||
*/
|
*/
|
||||||
private fun recenterMarkerToPosition(geoPoint: GeoPoint?) {
|
private fun recenterMarkerToPosition(geoPoint: GeoPoint?) {
|
||||||
if (geoPoint != null) {
|
geoPoint?.let {
|
||||||
binding!!.map.controller.setCenter(geoPoint)
|
binding?.map?.controller?.setCenter(it)
|
||||||
val overlays = binding!!.map.overlays
|
val overlays = binding?.map?.overlays ?: return@let
|
||||||
for (i in overlays.indices) {
|
|
||||||
if (overlays[i] is Marker) {
|
// Remove markers and disks using index-based removal
|
||||||
binding!!.map.overlays.removeAt(i)
|
var i = 0
|
||||||
} else if (overlays[i] is ScaleDiskOverlay) {
|
while (i < overlays.size) {
|
||||||
binding!!.map.overlays.removeAt(i)
|
when (overlays[i]) {
|
||||||
|
is Marker, is ScaleDiskOverlay -> overlays.removeAt(i)
|
||||||
|
else -> i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val diskOverlay =
|
|
||||||
ScaleDiskOverlay(
|
// Add disk overlay
|
||||||
this.context,
|
ScaleDiskOverlay(context, it, 2000, UnitOfMeasure.foot).apply {
|
||||||
geoPoint, 2000, UnitOfMeasure.foot
|
setCirclePaint2(Paint().apply {
|
||||||
)
|
color = Color.rgb(128, 128, 128)
|
||||||
val circlePaint = Paint()
|
style = Paint.Style.STROKE
|
||||||
circlePaint.color = Color.rgb(128, 128, 128)
|
strokeWidth = 2f
|
||||||
circlePaint.style = Paint.Style.STROKE
|
})
|
||||||
circlePaint.strokeWidth = 2f
|
setCirclePaint1(Paint().apply {
|
||||||
diskOverlay.setCirclePaint2(circlePaint)
|
color = Color.argb(40, 128, 128, 128)
|
||||||
val diskPaint = Paint()
|
style = Paint.Style.FILL_AND_STROKE
|
||||||
diskPaint.color = Color.argb(40, 128, 128, 128)
|
})
|
||||||
diskPaint.style = Paint.Style.FILL_AND_STROKE
|
setDisplaySizeMin(900)
|
||||||
diskOverlay.setCirclePaint1(diskPaint)
|
setDisplaySizeMax(1700)
|
||||||
diskOverlay.setDisplaySizeMin(900)
|
overlays.add(this)
|
||||||
diskOverlay.setDisplaySizeMax(1700)
|
}
|
||||||
binding!!.map.overlays.add(diskOverlay)
|
|
||||||
val startMarker = Marker(
|
// Add marker
|
||||||
binding!!.map
|
Marker(binding?.map).apply {
|
||||||
)
|
position = it
|
||||||
startMarker.position = geoPoint
|
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||||
startMarker.setAnchor(
|
icon = ContextCompat.getDrawable(context, R.drawable.current_location_marker)
|
||||||
Marker.ANCHOR_CENTER,
|
title = "Your Location"
|
||||||
Marker.ANCHOR_BOTTOM
|
textLabelFontSize = 24
|
||||||
)
|
overlays.add(this)
|
||||||
startMarker.icon =
|
}
|
||||||
ContextCompat.getDrawable(
|
|
||||||
this.requireContext(),
|
|
||||||
fr.free.nrw.commons.R.drawable.current_location_marker
|
|
||||||
)
|
|
||||||
startMarker.title = "Your Location"
|
|
||||||
startMarker.textLabelFontSize = 24
|
|
||||||
binding!!.map.overlays.add(startMarker)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue