mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Merge remote-tracking branch 'refs/remotes/commons-app/master' into display_toast
# Conflicts: # app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java
This commit is contained in:
commit
485a0a1bc3
5 changed files with 62 additions and 4 deletions
|
|
@ -1,11 +1,18 @@
|
||||||
package fr.free.nrw.commons.nearby;
|
package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
@ -25,6 +32,7 @@ import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
import fr.free.nrw.commons.utils.UriSerializer;
|
import fr.free.nrw.commons.utils.UriSerializer;
|
||||||
|
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -49,6 +57,7 @@ public class NearbyActivity extends BaseActivity {
|
||||||
if (getSupportActionBar() != null) {
|
if (getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
checkGps();
|
||||||
bundle = new Bundle();
|
bundle = new Bundle();
|
||||||
locationManager = new LocationServiceManager(this);
|
locationManager = new LocationServiceManager(this);
|
||||||
locationManager.registerLocationManager();
|
locationManager.registerLocationManager();
|
||||||
|
|
@ -85,6 +94,44 @@ public class NearbyActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void checkGps() {
|
||||||
|
LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
|
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||||
|
Timber.d("GPS is not enabled");
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||||
|
alertDialogBuilder.setMessage(R.string.gps_disabled)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(R.string.enable_gps,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
Intent callGPSSettingIntent = new Intent(
|
||||||
|
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||||
|
Timber.d("Loaded settings page");
|
||||||
|
startActivityForResult(callGPSSettingIntent, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertDialogBuilder.setNegativeButton("Cancel",
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog alert = alertDialogBuilder.create();
|
||||||
|
alert.show();
|
||||||
|
} else {
|
||||||
|
Timber.d("GPS is enabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == 1) {
|
||||||
|
Timber.d("User is back from Settings page");
|
||||||
|
refreshView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void showMapView() {
|
private void showMapView() {
|
||||||
if (!isMapViewActive) {
|
if (!isMapViewActive) {
|
||||||
isMapViewActive = true;
|
isMapViewActive = true;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.drawable.Icon;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||||
|
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
@ -13,6 +15,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
@ -86,13 +89,17 @@ public class NearbyController {
|
||||||
*/
|
*/
|
||||||
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
|
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
|
||||||
LatLng curLatLng,
|
LatLng curLatLng,
|
||||||
List<Place> placeList) {
|
List<Place> placeList,
|
||||||
|
Context context) {
|
||||||
List<NearbyBaseMarker> baseMarkerOptionses = new ArrayList<>();
|
List<NearbyBaseMarker> baseMarkerOptionses = new ArrayList<>();
|
||||||
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
|
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
|
||||||
for (Place place: placeList) {
|
for (Place place: placeList) {
|
||||||
String distance = formatDistanceBetween(curLatLng, place.location);
|
String distance = formatDistanceBetween(curLatLng, place.location);
|
||||||
place.setDistance(distance);
|
place.setDistance(distance);
|
||||||
|
|
||||||
|
Icon icon = IconFactory.getInstance(context)
|
||||||
|
.fromResource(R.drawable.custom_map_marker);
|
||||||
|
|
||||||
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
|
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
|
||||||
nearbyBaseMarker.title(place.name);
|
nearbyBaseMarker.title(place.name);
|
||||||
nearbyBaseMarker.position(
|
nearbyBaseMarker.position(
|
||||||
|
|
@ -100,6 +107,7 @@ public class NearbyController {
|
||||||
place.location.latitude,
|
place.location.latitude,
|
||||||
place.location.longitude));
|
place.location.longitude));
|
||||||
nearbyBaseMarker.place(place);
|
nearbyBaseMarker.place(place);
|
||||||
|
nearbyBaseMarker.icon(icon);
|
||||||
|
|
||||||
baseMarkerOptionses.add(nearbyBaseMarker);
|
baseMarkerOptionses.add(nearbyBaseMarker);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,9 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
||||||
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
|
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
|
||||||
curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
|
curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
|
||||||
baseMarkerOptionses = NearbyController
|
baseMarkerOptionses = NearbyController
|
||||||
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, placeList);
|
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng,
|
||||||
|
placeList,
|
||||||
|
getActivity());
|
||||||
}
|
}
|
||||||
Mapbox.getInstance(getActivity(),
|
Mapbox.getInstance(getActivity(),
|
||||||
getString(R.string.mapbox_commons_app_token));
|
getString(R.string.mapbox_commons_app_token));
|
||||||
|
|
|
||||||
BIN
app/src/main/res/drawable-mdpi/custom_map_marker.png
Normal file
BIN
app/src/main/res/drawable-mdpi/custom_map_marker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 993 B |
|
|
@ -51,6 +51,8 @@
|
||||||
<string name="categories_search_text_hint">Search categories</string>
|
<string name="categories_search_text_hint">Search categories</string>
|
||||||
<string name="menu_save_categories">Save</string>
|
<string name="menu_save_categories">Save</string>
|
||||||
<string name="refresh_button">Refresh</string>
|
<string name="refresh_button">Refresh</string>
|
||||||
|
<string name="gps_disabled">GPS is disabled in your device. Would you like to enable it?</string>
|
||||||
|
<string name="enable_gps">Enable GPS</string>
|
||||||
<string name="contributions_subtitle_zero">No uploads yet</string>
|
<string name="contributions_subtitle_zero">No uploads yet</string>
|
||||||
<plurals name="contributions_subtitle">
|
<plurals name="contributions_subtitle">
|
||||||
<!--zero is not used in english. Category mentioned here for easy reference in future-->
|
<!--zero is not used in english. Category mentioned here for easy reference in future-->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue