mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Convert MapController to kotlin along with fixing nullability in a few places
This commit is contained in:
parent
ca89b656e8
commit
890050d913
5 changed files with 69 additions and 45 deletions
|
|
@ -1,30 +0,0 @@
|
||||||
package fr.free.nrw.commons;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class MapController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We pass this variable as a group of placeList and boundaryCoordinates
|
|
||||||
*/
|
|
||||||
public class NearbyPlacesInfo {
|
|
||||||
public List<Place> placeList; // List of nearby places
|
|
||||||
public LatLng[] boundaryCoordinates; // Corners of nearby area
|
|
||||||
public LatLng currentLatLng; // Current location when this places are populated
|
|
||||||
public LatLng searchLatLng; // Search location for finding this places
|
|
||||||
public List<Media> mediaList; // Search location for finding this places
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We pass this variable as a group of placeList and boundaryCoordinates
|
|
||||||
*/
|
|
||||||
public class ExplorePlacesInfo {
|
|
||||||
public List<Place> explorePlaceList; // List of nearby places
|
|
||||||
public LatLng[] boundaryCoordinates; // Corners of nearby area
|
|
||||||
public LatLng currentLatLng; // Current location when this places are populated
|
|
||||||
public LatLng searchLatLng; // Search location for finding this places
|
|
||||||
public List<Media> mediaList; // Search location for finding this places
|
|
||||||
}
|
|
||||||
}
|
|
||||||
46
app/src/main/java/fr/free/nrw/commons/MapController.kt
Normal file
46
app/src/main/java/fr/free/nrw/commons/MapController.kt
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
package fr.free.nrw.commons
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.location.LatLng
|
||||||
|
import fr.free.nrw.commons.nearby.Place
|
||||||
|
|
||||||
|
abstract class MapController {
|
||||||
|
/**
|
||||||
|
* We pass this variable as a group of placeList and boundaryCoordinates
|
||||||
|
*/
|
||||||
|
inner class NearbyPlacesInfo {
|
||||||
|
@JvmField
|
||||||
|
var placeList: List<Place> = emptyList() // List of nearby places
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var boundaryCoordinates: Array<LatLng> = emptyArray() // Corners of nearby area
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var currentLatLng: LatLng? = null // Current location when this places are populated
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var searchLatLng: LatLng? = null // Search location for finding this places
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var mediaList: List<Media>? = null // Search location for finding this places
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We pass this variable as a group of placeList and boundaryCoordinates
|
||||||
|
*/
|
||||||
|
inner class ExplorePlacesInfo {
|
||||||
|
@JvmField
|
||||||
|
var explorePlaceList: List<Place> = emptyList() // List of nearby places
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var boundaryCoordinates: Array<LatLng> = emptyArray() // Corners of nearby area
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var currentLatLng: LatLng? = null // Current location when this places are populated
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var searchLatLng: LatLng? = null // Search location for finding this places
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
var mediaList: List<Media> = emptyList() // Search location for finding this places
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package fr.free.nrw.commons.explore.map;
|
package fr.free.nrw.commons.explore.map;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import fr.free.nrw.commons.Media;
|
import fr.free.nrw.commons.Media;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
import fr.free.nrw.commons.media.MediaClient;
|
import fr.free.nrw.commons.media.MediaClient;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
@ -23,6 +25,7 @@ public class ExploreMapCalls {
|
||||||
* @param currentLatLng coordinates of search location
|
* @param currentLatLng coordinates of search location
|
||||||
* @return list of places obtained
|
* @return list of places obtained
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
List<Media> callCommonsQuery(final LatLng currentLatLng) {
|
List<Media> callCommonsQuery(final LatLng currentLatLng) {
|
||||||
String coordinates = currentLatLng.getLatitude() + "|" + currentLatLng.getLongitude();
|
String coordinates = currentLatLng.getLatitude() + "|" + currentLatLng.getLongitude();
|
||||||
return mediaClient.getMediaListFromGeoSearch(coordinates).blockingGet();
|
return mediaClient.getMediaListFromGeoSearch(coordinates).blockingGet();
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import fr.free.nrw.commons.explore.map.ExploreMapController.NearbyBaseMarkerThum
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType;
|
import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType;
|
||||||
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -182,7 +183,7 @@ public class ExploreMapPresenter
|
||||||
exploreMapController
|
exploreMapController
|
||||||
.loadAttractionsFromLocationToBaseMarkerOptions(explorePlacesInfo.currentLatLng,
|
.loadAttractionsFromLocationToBaseMarkerOptions(explorePlacesInfo.currentLatLng,
|
||||||
// Curlatlang will be used to calculate distances
|
// Curlatlang will be used to calculate distances
|
||||||
explorePlacesInfo.explorePlaceList,
|
(List<Place>) explorePlacesInfo.explorePlaceList,
|
||||||
exploreMapFragmentView.getContext(),
|
exploreMapFragmentView.getContext(),
|
||||||
this,
|
this,
|
||||||
explorePlacesInfo);
|
explorePlacesInfo);
|
||||||
|
|
@ -230,11 +231,7 @@ public class ExploreMapPresenter
|
||||||
mylocation.setLongitude(exploreMapFragmentView.getLastMapFocus().getLongitude());
|
mylocation.setLongitude(exploreMapFragmentView.getLastMapFocus().getLongitude());
|
||||||
Float distance = mylocation.distanceTo(dest_location);
|
Float distance = mylocation.distanceTo(dest_location);
|
||||||
|
|
||||||
if (distance > 2000.0 * 3 / 4) {
|
return !(distance > 2000.0 * 3 / 4);
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
package fr.free.nrw.commons.nearby;
|
package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import fr.free.nrw.commons.nearby.model.NearbyQueryParams;
|
import fr.free.nrw.commons.nearby.model.NearbyQueryParams;
|
||||||
|
import fr.free.nrw.commons.nearby.model.NearbyQueryParams.Radial;
|
||||||
|
import fr.free.nrw.commons.nearby.model.NearbyQueryParams.Rectangular;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -46,13 +50,14 @@ public class NearbyPlaces {
|
||||||
* @param customQuery
|
* @param customQuery
|
||||||
* @return list of places obtained
|
* @return list of places obtained
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
List<Place> radiusExpander(final LatLng currentLatLng, final String lang,
|
List<Place> radiusExpander(final LatLng currentLatLng, final String lang,
|
||||||
final boolean returnClosestResult, @Nullable final String customQuery) throws Exception {
|
final boolean returnClosestResult, @Nullable final String customQuery) throws Exception {
|
||||||
|
|
||||||
final int minResults;
|
final int minResults;
|
||||||
final double maxRadius;
|
final double maxRadius;
|
||||||
|
|
||||||
List<Place> places = Collections.emptyList();
|
List<Place> places = emptyList();
|
||||||
|
|
||||||
// If returnClosestResult is true, then this means that we are trying to get closest point
|
// If returnClosestResult is true, then this means that we are trying to get closest point
|
||||||
// to use in cardView in Contributions fragment
|
// to use in cardView in Contributions fragment
|
||||||
|
|
@ -113,6 +118,7 @@ public class NearbyPlaces {
|
||||||
* @return A list of places obtained from the Wikidata query.
|
* @return A list of places obtained from the Wikidata query.
|
||||||
* @throws Exception If an error occurs during the retrieval process.
|
* @throws Exception If an error occurs during the retrieval process.
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public List<Place> getFromWikidataQuery(
|
public List<Place> getFromWikidataQuery(
|
||||||
final fr.free.nrw.commons.location.LatLng centerPoint,
|
final fr.free.nrw.commons.location.LatLng centerPoint,
|
||||||
final fr.free.nrw.commons.location.LatLng screenTopRight,
|
final fr.free.nrw.commons.location.LatLng screenTopRight,
|
||||||
|
|
@ -120,11 +126,11 @@ public class NearbyPlaces {
|
||||||
final boolean shouldQueryForMonuments,
|
final boolean shouldQueryForMonuments,
|
||||||
@Nullable final String customQuery) throws Exception {
|
@Nullable final String customQuery) throws Exception {
|
||||||
if (customQuery != null) {
|
if (customQuery != null) {
|
||||||
return okHttpJsonApiClient
|
final List<Place> nearbyPlaces = okHttpJsonApiClient.getNearbyPlaces(
|
||||||
.getNearbyPlaces(
|
new Rectangular(screenTopRight, screenBottomLeft), lang,
|
||||||
new NearbyQueryParams.Rectangular(screenTopRight, screenBottomLeft), lang,
|
|
||||||
shouldQueryForMonuments,
|
shouldQueryForMonuments,
|
||||||
customQuery);
|
customQuery);
|
||||||
|
return nearbyPlaces != null ? nearbyPlaces : emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
final int lowerLimit = 1000, upperLimit = 1500;
|
final int lowerLimit = 1000, upperLimit = 1500;
|
||||||
|
|
@ -141,9 +147,10 @@ public class NearbyPlaces {
|
||||||
final int itemCount = okHttpJsonApiClient.getNearbyItemCount(
|
final int itemCount = okHttpJsonApiClient.getNearbyItemCount(
|
||||||
new NearbyQueryParams.Rectangular(screenTopRight, screenBottomLeft));
|
new NearbyQueryParams.Rectangular(screenTopRight, screenBottomLeft));
|
||||||
if (itemCount < upperLimit) {
|
if (itemCount < upperLimit) {
|
||||||
return okHttpJsonApiClient.getNearbyPlaces(
|
final List<Place> nearbyPlaces = okHttpJsonApiClient.getNearbyPlaces(
|
||||||
new NearbyQueryParams.Rectangular(screenTopRight, screenBottomLeft), lang,
|
new Rectangular(screenTopRight, screenBottomLeft), lang,
|
||||||
shouldQueryForMonuments, null);
|
shouldQueryForMonuments, null);
|
||||||
|
return nearbyPlaces != null ? nearbyPlaces : emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,9 +182,10 @@ public class NearbyPlaces {
|
||||||
maxRadius = targetRadius - 1;
|
maxRadius = targetRadius - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return okHttpJsonApiClient.getNearbyPlaces(
|
final List<Place> nearbyPlaces = okHttpJsonApiClient.getNearbyPlaces(
|
||||||
new NearbyQueryParams.Radial(centerPoint, targetRadius / 100f), lang, shouldQueryForMonuments,
|
new Radial(centerPoint, targetRadius / 100f), lang, shouldQueryForMonuments,
|
||||||
null);
|
null);
|
||||||
|
return nearbyPlaces != null ? nearbyPlaces : emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue