Skip to content

Commit ba9287f

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/2.7.x-release'
2 parents 165850b + c6f728a commit ba9287f

File tree

7 files changed

+137
-58
lines changed

7 files changed

+137
-58
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Wikimedia Commons for Android
22

3+
## v2.7.0
4+
- New Nearby Places UI with direct uploads (and associated category suggestions)
5+
- Added two-factor authentication login
6+
- Added Notifications activity to display user talk messages
7+
- Added real-time location tracking in Nearby
8+
- Added "rate us", "translate", and FB link in About
9+
- Improvements to UI of navigation drawer, tutorial, media details view, login activity and Settings
10+
- Added option to nominate picture for deletion in media details view
11+
- Too many bug and crash fixes to mention!
12+
313
## v2.6.7
414
- Added null checks to prevent frequent crashes in ModificationsSyncAdapter
515

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ android {
9191

9292
defaultConfig {
9393
applicationId 'fr.free.nrw.commons'
94-
versionCode 82
95-
versionName '2.6.7'
94+
versionCode 83
95+
versionName '2.7.0'
9696
setProperty("archivesBaseName", "app-commons-v$versionName-" + getBranchName())
9797

9898
minSdkVersion project.minSdkVersion

app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ protected void onStart() {
262262
@Override
263263
protected void onStop() {
264264
super.onStop();
265-
locationManager.removeLocationListener(this);
266-
locationManager.unregisterLocationManager();
267265
}
268266

269267
@Override
@@ -292,8 +290,13 @@ public void onPause() {
292290
// to the retained fragment object to perform its own cleanup.
293291
removeMapFragment();
294292
removeListFragment();
295-
unregisterReceiver(broadcastReceiver);
293+
296294
}
295+
unregisterReceiver(broadcastReceiver);
296+
broadcastReceiver = null;
297+
locationManager.removeLocationListener(this);
298+
locationManager.unregisterLocationManager();
299+
297300
}
298301

299302
private void addNetworkBroadcastReceiver() {
@@ -422,6 +425,7 @@ private void removeMapFragment() {
422425
if (nearbyMapFragment != null) {
423426
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
424427
fm.beginTransaction().remove(nearbyMapFragment).commit();
428+
nearbyMapFragment = null;
425429
}
426430
}
427431

@@ -433,6 +437,7 @@ private void removeListFragment() {
433437
if (nearbyListFragment != null) {
434438
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
435439
fm.beginTransaction().remove(nearbyListFragment).commit();
440+
nearbyListFragment = null;
436441
}
437442
}
438443

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

+69-19
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import fr.free.nrw.commons.Utils;
5757
import fr.free.nrw.commons.contributions.ContributionController;
5858
import fr.free.nrw.commons.utils.UriDeserializer;
59+
import fr.free.nrw.commons.utils.ViewUtil;
5960
import timber.log.Timber;
6061

6162
import static android.app.Activity.RESULT_OK;
@@ -106,7 +107,8 @@ public class NearbyMapFragment extends DaggerFragment {
106107
private PolygonOptions currentLocationPolygonOptions;
107108

108109
private boolean isBottomListSheetExpanded;
109-
private final double CAMERA_TARGET_SHIFT_FACTOR = 0.06;
110+
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06;
111+
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
110112

111113
@Inject
112114
@Named("prefs")
@@ -254,13 +256,28 @@ private void updateMapToTrackPosition() {
254256
}
255257

256258
// Make camera to follow user on location change
257-
CameraPosition position = new CameraPosition.Builder()
258-
.target(isBottomListSheetExpanded ?
259-
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR,
260-
curMapBoxLatLng.getLongitude())
261-
: curMapBoxLatLng ) // Sets the new camera position
262-
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
263-
.build();
259+
CameraPosition position ;
260+
if(ViewUtil.isPortrait(getActivity())){
261+
position = new CameraPosition.Builder()
262+
.target(isBottomListSheetExpanded ?
263+
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
264+
curMapBoxLatLng.getLongitude())
265+
: curMapBoxLatLng ) // Sets the new camera position
266+
.zoom(isBottomListSheetExpanded ?
267+
11 // zoom level is fixed to 11 when bottom sheet is expanded
268+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
269+
.build();
270+
}else {
271+
position = new CameraPosition.Builder()
272+
.target(isBottomListSheetExpanded ?
273+
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
274+
curMapBoxLatLng.getLongitude())
275+
: curMapBoxLatLng ) // Sets the new camera position
276+
.zoom(isBottomListSheetExpanded ?
277+
11 // zoom level is fixed to 11 when bottom sheet is expanded
278+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
279+
.build();
280+
}
264281

265282
mapboxMap.animateCamera(CameraUpdateFactory
266283
.newCameraPosition(position), 1000);
@@ -274,12 +291,21 @@ private void updateMapCameraAccordingToBottomSheet(boolean isBottomListSheetExpa
274291
if (mapboxMap != null && curLatLng != null) {
275292
if (isBottomListSheetExpanded) {
276293
// Make camera to follow user on location change
277-
position = new CameraPosition.Builder()
278-
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR,
279-
curLatLng.getLongitude())) // Sets the new camera target above
280-
// current to make it visible when sheet is expanded
281-
.zoom(11) // Same zoom level
282-
.build();
294+
if(ViewUtil.isPortrait(getActivity())) {
295+
position = new CameraPosition.Builder()
296+
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
297+
curLatLng.getLongitude())) // Sets the new camera target above
298+
// current to make it visible when sheet is expanded
299+
.zoom(11) // Fixed zoom level
300+
.build();
301+
} else {
302+
position = new CameraPosition.Builder()
303+
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
304+
curLatLng.getLongitude())) // Sets the new camera target above
305+
// current to make it visible when sheet is expanded
306+
.zoom(11) // Fixed zoom level
307+
.build();
308+
}
283309

284310
} else {
285311
// Make camera to follow user on location change
@@ -345,10 +371,29 @@ private void setListeners() {
345371
fabRecenter.setOnClickListener(view -> {
346372
if (curLatLng != null) {
347373
mapView.getMapAsync(mapboxMap -> {
348-
CameraPosition position = new CameraPosition.Builder()
349-
.target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())) // Sets the new camera position
350-
.zoom(11) // Sets the zoom
351-
.build(); // Creates a CameraPosition from the builder
374+
CameraPosition position;
375+
376+
if(ViewUtil.isPortrait(getActivity())){
377+
position = new CameraPosition.Builder()
378+
.target(isBottomListSheetExpanded ?
379+
new LatLng(curLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
380+
curLatLng.getLongitude())
381+
: new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude(), 0)) // Sets the new camera position
382+
.zoom(isBottomListSheetExpanded ?
383+
11 // zoom level is fixed to 11 when bottom sheet is expanded
384+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
385+
.build();
386+
}else {
387+
position = new CameraPosition.Builder()
388+
.target(isBottomListSheetExpanded ?
389+
new LatLng(curLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
390+
curLatLng.getLongitude())
391+
: new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude(), 0)) // Sets the new camera position
392+
.zoom(isBottomListSheetExpanded ?
393+
11 // zoom level is fixed to 11 when bottom sheet is expanded
394+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
395+
.build();
396+
}
352397

353398
mapboxMap.animateCamera(CameraUpdateFactory
354399
.newCameraPosition(position), 1000);
@@ -535,7 +580,9 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
535580
transparentView.setAlpha(0);
536581
closeFabs(isFabOpen);
537582
hideFAB();
538-
this.getView().requestFocus();
583+
if (this.getView() != null) {
584+
this.getView().requestFocus();
585+
}
539586
break;
540587
}
541588
}
@@ -776,6 +823,9 @@ public void onDestroyView() {
776823
if (mapView != null) {
777824
mapView.onDestroy();
778825
}
826+
selected = null;
827+
currentLocationMarker = null;
828+
779829
super.onDestroyView();
780830
}
781831

app/src/main/java/fr/free/nrw/commons/upload/DetectUnwantedPicturesAsync.java

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package fr.free.nrw.commons.upload;
22

3+
import android.app.Activity;
34
import android.content.Context;
5+
import android.content.Intent;
46
import android.graphics.BitmapRegionDecoder;
57
import android.net.Uri;
68
import android.os.AsyncTask;
9+
import android.support.v7.app.AlertDialog;
710

811
import java.io.IOException;
12+
import java.lang.ref.WeakReference;
913

14+
import fr.free.nrw.commons.R;
15+
import fr.free.nrw.commons.contributions.ContributionsActivity;
1016
import fr.free.nrw.commons.utils.ImageUtils;
1117
import timber.log.Timber;
1218

@@ -21,16 +27,13 @@
2127

2228
public class DetectUnwantedPicturesAsync extends AsyncTask<Void, Void, ImageUtils.Result> {
2329

24-
interface Callback {
25-
void onResult(ImageUtils.Result result);
26-
}
27-
28-
private final Callback callback;
2930
private final String imageMediaFilePath;
31+
public final WeakReference<Activity> activityWeakReference;
3032

31-
DetectUnwantedPicturesAsync(String imageMediaFilePath, Callback callback) {
32-
this.callback = callback;
33+
DetectUnwantedPicturesAsync(WeakReference<Activity> activityWeakReference, String imageMediaFilePath) {
34+
//this.callback = callback;
3335
this.imageMediaFilePath = imageMediaFilePath;
36+
this.activityWeakReference = activityWeakReference;
3437
}
3538

3639
@Override
@@ -53,7 +56,29 @@ protected ImageUtils.Result doInBackground(Void... voids) {
5356
@Override
5457
protected void onPostExecute(ImageUtils.Result result) {
5558
super.onPostExecute(result);
56-
//callback to UI so that it can take necessary decision based on the result obtained
57-
callback.onResult(result);
59+
Activity activity = activityWeakReference.get();
60+
61+
if (result != ImageUtils.Result.IMAGE_OK) {
62+
//show appropriate error message
63+
String errorMessage = result == ImageUtils.Result.IMAGE_DARK ? activity.getString(R.string.upload_image_too_dark) : activity.getString(R.string.upload_image_blurry);
64+
AlertDialog.Builder errorDialogBuilder = new AlertDialog.Builder(activity);
65+
errorDialogBuilder.setMessage(errorMessage);
66+
errorDialogBuilder.setTitle(activity.getString(R.string.warning));
67+
errorDialogBuilder.setPositiveButton(activity.getString(R.string.no), (dialogInterface, i) -> {
68+
//user does not wish to upload the picture, take them back to ContributionsActivity
69+
Intent intent = new Intent(activity, ContributionsActivity.class);
70+
dialogInterface.dismiss();
71+
activity.startActivity(intent);
72+
});
73+
errorDialogBuilder.setNegativeButton(activity.getString(R.string.yes), (dialogInterface, i) -> {
74+
//user wishes to go ahead with the upload of this picture, just dismiss this dialog
75+
dialogInterface.dismiss();
76+
});
77+
78+
AlertDialog errorDialog = errorDialogBuilder.create();
79+
if (!activity.isFinishing()) {
80+
errorDialog.show();
81+
}
82+
}
5883
}
5984
}

app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java

+3-25
Original file line numberDiff line numberDiff line change
@@ -415,31 +415,9 @@ private void performPreUploadProcessingOfFile() {
415415

416416
private void performUnwantedPictureDetectionProcess() {
417417
String imageMediaFilePath = FileUtils.getPath(this,mediaUri);
418-
DetectUnwantedPicturesAsync detectUnwantedPicturesAsync = new DetectUnwantedPicturesAsync(imageMediaFilePath, result -> {
419-
420-
if (result != ImageUtils.Result.IMAGE_OK) {
421-
//show appropriate error message
422-
String errorMessage = result == ImageUtils.Result.IMAGE_DARK ? getString(R.string.upload_image_too_dark) : getString(R.string.upload_image_blurry);
423-
AlertDialog.Builder errorDialogBuilder = new AlertDialog.Builder(this);
424-
errorDialogBuilder.setMessage(errorMessage);
425-
errorDialogBuilder.setTitle(getString(R.string.warning));
426-
errorDialogBuilder.setPositiveButton(getString(R.string.no), (dialogInterface, i) -> {
427-
//user does not wish to upload the picture, take them back to ContributionsActivity
428-
Intent intent = new Intent(ShareActivity.this, ContributionsActivity.class);
429-
dialogInterface.dismiss();
430-
startActivity(intent);
431-
});
432-
errorDialogBuilder.setNegativeButton(getString(R.string.yes), (dialogInterface, i) -> {
433-
//user wishes to go ahead with the upload of this picture, just dismiss this dialog
434-
dialogInterface.dismiss();
435-
});
436-
437-
AlertDialog errorDialog = errorDialogBuilder.create();
438-
if (!isFinishing()) {
439-
errorDialog.show();
440-
}
441-
}
442-
});
418+
DetectUnwantedPicturesAsync detectUnwantedPicturesAsync
419+
= new DetectUnwantedPicturesAsync(new WeakReference<Activity>(this)
420+
, imageMediaFilePath);
443421

444422
detectUnwantedPicturesAsync.execute();
445423
}

app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java

+11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package fr.free.nrw.commons.utils;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.support.design.widget.Snackbar;
6+
import android.view.Display;
57
import android.view.View;
68
import android.widget.Toast;
79

@@ -16,4 +18,13 @@ public static void showLongToast(Context context, String text) {
1618
Toast.LENGTH_LONG).show();
1719
}
1820

21+
public static boolean isPortrait(Context context) {
22+
Display orientation = ((Activity)context).getWindowManager().getDefaultDisplay();
23+
if(orientation.getWidth() < orientation.getHeight()){
24+
return true;
25+
} else {
26+
return false;
27+
}
28+
}
29+
1930
}

0 commit comments

Comments
 (0)