Merge remote-tracking branch 'refs/remotes/commons-app/2.7.x-release' into 2.7.x-release-fork

This commit is contained in:
misaochan 2018-04-14 19:13:02 +10:00
commit ce5467c6ea
4 changed files with 28 additions and 18 deletions

View file

@ -474,17 +474,17 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::populatePlaces); .subscribe(this::populatePlaces);
nearbyMapFragment.setArguments(bundle); nearbyMapFragment.setBundleForUpdtes(bundle);
nearbyMapFragment.updateMapSignificantly(); nearbyMapFragment.updateMapSignificantly();
updateListFragment(); updateListFragment();
return; return;
} }
if (isSlightUpdate) { if (isSlightUpdate) {
nearbyMapFragment.setArguments(bundle); nearbyMapFragment.setBundleForUpdtes(bundle);
nearbyMapFragment.updateMapSlightly(); nearbyMapFragment.updateMapSlightly();
} else { } else {
nearbyMapFragment.setArguments(bundle); nearbyMapFragment.setBundleForUpdtes(bundle);
nearbyMapFragment.updateMapSignificantly(); nearbyMapFragment.updateMapSignificantly();
updateListFragment(); updateListFragment();
} }
@ -498,7 +498,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
} }
private void updateListFragment() { private void updateListFragment() {
nearbyListFragment.setArguments(bundle); nearbyListFragment.setBundleForUpdates(bundle);
nearbyListFragment.updateNearbyListSignificantly(); nearbyListFragment.updateNearbyListSignificantly();
} }

View file

@ -33,6 +33,8 @@ import static android.app.Activity.RESULT_OK;
import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class NearbyListFragment extends DaggerFragment { public class NearbyListFragment extends DaggerFragment {
private Bundle bundleForUpdates; // Carry information from activity about changed nearby places and current location
private static final Type LIST_TYPE = new TypeToken<List<Place>>() { private static final Type LIST_TYPE = new TypeToken<List<Place>>() {
}.getType(); }.getType();
private static final Type CUR_LAT_LNG_TYPE = new TypeToken<LatLng>() { private static final Type CUR_LAT_LNG_TYPE = new TypeToken<LatLng>() {
@ -80,8 +82,7 @@ public class NearbyListFragment extends DaggerFragment {
} }
public void updateNearbyListSignificantly() { public void updateNearbyListSignificantly() {
Bundle bundle = this.getArguments(); adapterFactory.updateAdapterData(getPlaceListFromBundle(bundleForUpdates),
adapterFactory.updateAdapterData(getPlaceListFromBundle(bundle),
(RVRendererAdapter<Place>) recyclerView.getAdapter()); (RVRendererAdapter<Place>) recyclerView.getAdapter());
} }
@ -140,4 +141,8 @@ public class NearbyListFragment extends DaggerFragment {
} }
} }
public void setBundleForUpdates(Bundle bundleForUpdates) {
this.bundleForUpdates = bundleForUpdates;
}
} }

View file

@ -110,6 +110,8 @@ public class NearbyMapFragment extends DaggerFragment {
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06; private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06;
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04; private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location
@Inject @Inject
@Named("prefs") @Named("prefs")
SharedPreferences prefs; SharedPreferences prefs;
@ -191,14 +193,12 @@ public class NearbyMapFragment extends DaggerFragment {
} }
public void updateMapSlightly() { public void updateMapSlightly() {
// Get arguments from bundle for new location
Bundle bundle = this.getArguments();
if (mapboxMap != null) { if (mapboxMap != null) {
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer()) .registerTypeAdapter(Uri.class, new UriDeserializer())
.create(); .create();
if (bundle != null) { if (bundleForUpdtes != null) {
String gsonLatLng = bundle.getString("CurLatLng"); String gsonLatLng = bundleForUpdtes.getString("CurLatLng");
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);
} }
@ -208,17 +208,15 @@ public class NearbyMapFragment extends DaggerFragment {
} }
public void updateMapSignificantly() { public void updateMapSignificantly() {
Bundle bundle = this.getArguments();
if (mapboxMap != null) { if (mapboxMap != null) {
if (bundle != null) { if (bundleForUpdtes != null) {
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer()) .registerTypeAdapter(Uri.class, new UriDeserializer())
.create(); .create();
String gsonPlaceList = bundle.getString("PlaceList"); String gsonPlaceList = bundleForUpdtes.getString("PlaceList");
String gsonLatLng = bundle.getString("CurLatLng"); String gsonLatLng = bundleForUpdtes.getString("CurLatLng");
String gsonBoundaryCoordinates = bundle.getString("BoundaryCoord"); String gsonBoundaryCoordinates = bundleForUpdtes.getString("BoundaryCoord");
Type listType = new TypeToken<List<Place>>() {}.getType(); Type listType = new TypeToken<List<Place>>() {}.getType();
List<Place> placeList = gson.fromJson(gsonPlaceList, listType); List<Place> placeList = gson.fromJson(gsonPlaceList, listType);
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType(); Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
@ -456,6 +454,8 @@ public class NearbyMapFragment extends DaggerFragment {
private void setupMapView(Bundle savedInstanceState) { private void setupMapView(Bundle savedInstanceState) {
MapboxMapOptions options = new MapboxMapOptions() MapboxMapOptions options = new MapboxMapOptions()
.compassGravity(Gravity.BOTTOM | Gravity.LEFT)
.compassMargins(new int[]{12, 0, 0, 24})
.styleUrl(Style.OUTDOORS) .styleUrl(Style.OUTDOORS)
.logoEnabled(false) .logoEnabled(false)
.attributionEnabled(false) .attributionEnabled(false)
@ -771,7 +771,7 @@ public class NearbyMapFragment extends DaggerFragment {
} }
} }
private void closeFabs ( boolean isFabOpen){ private void closeFabs ( boolean isFabOpen){
if (isFabOpen) { if (isFabOpen) {
fabPlus.startAnimation(rotate_backward); fabPlus.startAnimation(rotate_backward);
fabCamera.startAnimation(fab_close); fabCamera.startAnimation(fab_close);
@ -782,6 +782,11 @@ public class NearbyMapFragment extends DaggerFragment {
} }
} }
public void setBundleForUpdtes(Bundle bundleForUpdtes) {
this.bundleForUpdtes = bundleForUpdtes;
}
@Override @Override
public void onStart() { public void onStart() {
if (mapView != null) { if (mapView != null) {

View file

@ -9,7 +9,7 @@ public class NetworkUtils {
public static boolean isInternetConnectionEstablished(Context context) { public static boolean isInternetConnectionEstablished(Context context) {
ConnectivityManager cm = ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); (ConnectivityManager)context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null && return activeNetwork != null &&