mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Convert handleGeoCoordinates to kotlin
This commit is contained in:
parent
f37501ffde
commit
f8f0a94500
7 changed files with 38 additions and 50 deletions
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.explore.map;
|
|||
|
||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
|
||||
import static fr.free.nrw.commons.utils.GeoCoordinatesKt.handleGeoCoordinates;
|
||||
import static fr.free.nrw.commons.utils.MapUtils.ZOOM_LEVEL;
|
||||
|
||||
import android.Manifest.permission;
|
||||
|
|
@ -36,7 +37,6 @@ import fr.free.nrw.commons.BaseMarker;
|
|||
import fr.free.nrw.commons.MapController;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.utils.GeoCoordinates;
|
||||
import fr.free.nrw.commons.utils.UrlUtils;
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
|
|
@ -640,7 +640,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
|||
*/
|
||||
private void passInfoToSheet(final Place place) {
|
||||
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(
|
||||
view -> GeoCoordinates.handleGeoCoordinates(getActivity(),
|
||||
view -> handleGeoCoordinates(requireActivity(),
|
||||
place.getLocation(), binding.mapView.getZoomLevelDouble()));
|
||||
|
||||
binding.bottomSheetDetailsBinding.commonsButton.setVisibility(
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ import fr.free.nrw.commons.theme.BaseActivity
|
|||
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.Companion.LAST_LOCATION
|
||||
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.Companion.LAST_ZOOM
|
||||
import fr.free.nrw.commons.utils.DialogUtil
|
||||
import fr.free.nrw.commons.utils.GeoCoordinates
|
||||
import fr.free.nrw.commons.utils.MapUtils.ZOOM_LEVEL
|
||||
import fr.free.nrw.commons.utils.handleGeoCoordinates
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
|
||||
|
|
@ -432,8 +432,8 @@ class LocationPickerActivity : BaseActivity(), LocationPermissionCallback {
|
|||
|
||||
position?.let {
|
||||
mapView?.zoomLevelDouble?.let { zoomLevel ->
|
||||
GeoCoordinates.handleGeoCoordinates(this, it, zoomLevel)
|
||||
} ?: GeoCoordinates.handleGeoCoordinates(this, it)
|
||||
handleGeoCoordinates(this, it, zoomLevel)
|
||||
} ?: handleGeoCoordinates(this, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,10 +110,8 @@ import fr.free.nrw.commons.upload.UploadMediaDetail
|
|||
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment
|
||||
import fr.free.nrw.commons.upload.depicts.DepictsFragment
|
||||
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment
|
||||
import fr.free.nrw.commons.utils.ClipboardUtils
|
||||
import fr.free.nrw.commons.utils.DateUtil.getDateStringWithSkeletonPattern
|
||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||
import fr.free.nrw.commons.utils.GeoCoordinates
|
||||
import fr.free.nrw.commons.utils.LangCodeUtils.getLocalizedResources
|
||||
import fr.free.nrw.commons.utils.PermissionUtils.PERMISSIONS_STORAGE
|
||||
import fr.free.nrw.commons.utils.PermissionUtils.checkPermissionsAndPerformAction
|
||||
|
|
@ -123,6 +121,7 @@ import fr.free.nrw.commons.utils.ViewUtil
|
|||
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||
import fr.free.nrw.commons.utils.ViewUtilWrapper
|
||||
import fr.free.nrw.commons.utils.copyToClipboard
|
||||
import fr.free.nrw.commons.utils.handleGeoCoordinates
|
||||
import fr.free.nrw.commons.utils.setUnderlinedText
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage.Revision
|
||||
import io.reactivex.Observable
|
||||
|
|
@ -921,7 +920,7 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
|
|||
|
||||
private fun onMediaDetailCoordinatesClicked() {
|
||||
if (media!!.coordinates != null && activity != null) {
|
||||
GeoCoordinates.handleGeoCoordinates(activity, media!!.coordinates)
|
||||
handleGeoCoordinates(requireContext(), media!!.coordinates!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ import fr.free.nrw.commons.contributions.ContributionController
|
|||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
import fr.free.nrw.commons.utils.ActivityUtils
|
||||
import fr.free.nrw.commons.utils.GeoCoordinates
|
||||
import fr.free.nrw.commons.utils.UrlUtils
|
||||
import fr.free.nrw.commons.utils.handleGeoCoordinates
|
||||
import fr.free.nrw.commons.wikidata.WikidataConstants
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
|
@ -105,7 +105,7 @@ class CommonPlaceClickActions
|
|||
|
||||
fun onDirectionsClicked(): (Place) -> Unit =
|
||||
{
|
||||
GeoCoordinates.handleGeoCoordinates(activity, it.getLocation())
|
||||
handleGeoCoordinates(activity, it.getLocation())
|
||||
}
|
||||
|
||||
private fun storeSharedPrefs(selectedPlace: Place) {
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ import fr.free.nrw.commons.upload.FileUtils
|
|||
import fr.free.nrw.commons.utils.ClipboardUtils
|
||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||
import fr.free.nrw.commons.utils.ExecutorUtils.get
|
||||
import fr.free.nrw.commons.utils.GeoCoordinates
|
||||
import fr.free.nrw.commons.utils.LayoutUtils.getScreenWidth
|
||||
import fr.free.nrw.commons.utils.LayoutUtils.setLayoutHeightAlignedToWidth
|
||||
import fr.free.nrw.commons.utils.MapUtils.defaultLatLng
|
||||
|
|
@ -107,6 +106,7 @@ import fr.free.nrw.commons.utils.SystemThemeUtils
|
|||
import fr.free.nrw.commons.utils.UrlUtils
|
||||
import fr.free.nrw.commons.utils.ViewUtil.showLongToast
|
||||
import fr.free.nrw.commons.utils.copyToClipboard
|
||||
import fr.free.nrw.commons.utils.handleGeoCoordinates
|
||||
import fr.free.nrw.commons.wikidata.WikidataConstants
|
||||
import fr.free.nrw.commons.wikidata.WikidataEditListener
|
||||
import fr.free.nrw.commons.wikidata.WikidataEditListener.WikidataP18EditListener
|
||||
|
|
@ -2854,7 +2854,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
|
||||
R.drawable.ic_directions_black_24dp -> {
|
||||
selectedPlace?.let {
|
||||
GeoCoordinates.handleGeoCoordinates(this.context, it.getLocation())
|
||||
handleGeoCoordinates(requireContext(), it.getLocation())
|
||||
binding?.map?.zoomLevelDouble ?: 0.0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
public final class GeoCoordinates {
|
||||
|
||||
/**
|
||||
* Util function to handle geo coordinates. It no longer depends on google maps and any app
|
||||
* capable of handling the map intent can handle it
|
||||
*
|
||||
* @param context The context for launching intent
|
||||
* @param latLng The latitude and longitude of the location
|
||||
*/
|
||||
public static void handleGeoCoordinates(final Context context, final LatLng latLng) {
|
||||
handleGeoCoordinates(context, latLng, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Util function to handle geo coordinates with specified zoom level. It no longer depends on
|
||||
* google maps and any app capable of handling the map intent can handle it
|
||||
*
|
||||
* @param context The context for launching intent
|
||||
* @param latLng The latitude and longitude of the location
|
||||
* @param zoomLevel The zoom level
|
||||
*/
|
||||
public static void handleGeoCoordinates(final Context context, final LatLng latLng,
|
||||
final double zoomLevel) {
|
||||
final Intent mapIntent = new Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri(zoomLevel));
|
||||
if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
|
||||
context.startActivity(mapIntent);
|
||||
} else {
|
||||
ViewUtil.showShortToast(context, context.getString(R.string.map_application_missing));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||
|
||||
/**
|
||||
* Util function to handle geo coordinates with specified zoom level. It no longer depends on
|
||||
* google maps and any app capable of handling the map intent can handle it
|
||||
*
|
||||
* @param context The context for launching intent
|
||||
* @param latLng The latitude and longitude of the location
|
||||
* @param zoomLevel The zoom level
|
||||
*/
|
||||
fun handleGeoCoordinates(
|
||||
context: Context, latLng: LatLng,
|
||||
zoomLevel: Double = 16.0
|
||||
) {
|
||||
val mapIntent = Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri(zoomLevel))
|
||||
if (mapIntent.resolveActivity(context.packageManager) != null) {
|
||||
context.startActivity(mapIntent)
|
||||
} else {
|
||||
showShortToast(context, context.getString(R.string.map_application_missing))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue