Merge pull request #1390 from commons-app/fixNearbyLeaks

Fix nearby leaks, at least some ot them
This commit is contained in:
neslihanturan 2018-03-30 12:36:41 +03:00 committed by GitHub
commit 09763f942f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 37 deletions

View file

@ -262,8 +262,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
locationManager.removeLocationListener(this);
locationManager.unregisterLocationManager();
} }
@Override @Override
@ -292,8 +290,13 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
// to the retained fragment object to perform its own cleanup. // to the retained fragment object to perform its own cleanup.
removeMapFragment(); removeMapFragment();
removeListFragment(); removeListFragment();
unregisterReceiver(broadcastReceiver);
} }
unregisterReceiver(broadcastReceiver);
broadcastReceiver = null;
locationManager.removeLocationListener(this);
locationManager.unregisterLocationManager();
} }
private void addNetworkBroadcastReceiver() { private void addNetworkBroadcastReceiver() {
@ -422,6 +425,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
if (nearbyMapFragment != null) { if (nearbyMapFragment != null) {
android.support.v4.app.FragmentManager fm = getSupportFragmentManager(); android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().remove(nearbyMapFragment).commit(); fm.beginTransaction().remove(nearbyMapFragment).commit();
nearbyMapFragment = null;
} }
} }
@ -433,6 +437,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
if (nearbyListFragment != null) { if (nearbyListFragment != null) {
android.support.v4.app.FragmentManager fm = getSupportFragmentManager(); android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().remove(nearbyListFragment).commit(); fm.beginTransaction().remove(nearbyListFragment).commit();
nearbyListFragment = null;
} }
} }

View file

@ -823,6 +823,9 @@ public class NearbyMapFragment extends DaggerFragment {
if (mapView != null) { if (mapView != null) {
mapView.onDestroy(); mapView.onDestroy();
} }
selected = null;
currentLocationMarker = null;
super.onDestroyView(); super.onDestroyView();
} }

View file

@ -1,12 +1,18 @@
package fr.free.nrw.commons.upload; package fr.free.nrw.commons.upload;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapRegionDecoder; import android.graphics.BitmapRegionDecoder;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.WeakReference;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionsActivity;
import fr.free.nrw.commons.utils.ImageUtils; import fr.free.nrw.commons.utils.ImageUtils;
import timber.log.Timber; import timber.log.Timber;
@ -21,16 +27,13 @@ import timber.log.Timber;
public class DetectUnwantedPicturesAsync extends AsyncTask<Void, Void, ImageUtils.Result> { public class DetectUnwantedPicturesAsync extends AsyncTask<Void, Void, ImageUtils.Result> {
interface Callback {
void onResult(ImageUtils.Result result);
}
private final Callback callback;
private final String imageMediaFilePath; private final String imageMediaFilePath;
public final WeakReference<Activity> activityWeakReference;
DetectUnwantedPicturesAsync(String imageMediaFilePath, Callback callback) { DetectUnwantedPicturesAsync(WeakReference<Activity> activityWeakReference, String imageMediaFilePath) {
this.callback = callback; //this.callback = callback;
this.imageMediaFilePath = imageMediaFilePath; this.imageMediaFilePath = imageMediaFilePath;
this.activityWeakReference = activityWeakReference;
} }
@Override @Override
@ -53,7 +56,29 @@ public class DetectUnwantedPicturesAsync extends AsyncTask<Void, Void, ImageUtil
@Override @Override
protected void onPostExecute(ImageUtils.Result result) { protected void onPostExecute(ImageUtils.Result result) {
super.onPostExecute(result); super.onPostExecute(result);
//callback to UI so that it can take necessary decision based on the result obtained Activity activity = activityWeakReference.get();
callback.onResult(result);
if (result != ImageUtils.Result.IMAGE_OK) {
//show appropriate error message
String errorMessage = result == ImageUtils.Result.IMAGE_DARK ? activity.getString(R.string.upload_image_too_dark) : activity.getString(R.string.upload_image_blurry);
AlertDialog.Builder errorDialogBuilder = new AlertDialog.Builder(activity);
errorDialogBuilder.setMessage(errorMessage);
errorDialogBuilder.setTitle(activity.getString(R.string.warning));
errorDialogBuilder.setPositiveButton(activity.getString(R.string.no), (dialogInterface, i) -> {
//user does not wish to upload the picture, take them back to ContributionsActivity
Intent intent = new Intent(activity, ContributionsActivity.class);
dialogInterface.dismiss();
activity.startActivity(intent);
});
errorDialogBuilder.setNegativeButton(activity.getString(R.string.yes), (dialogInterface, i) -> {
//user wishes to go ahead with the upload of this picture, just dismiss this dialog
dialogInterface.dismiss();
});
AlertDialog errorDialog = errorDialogBuilder.create();
if (!activity.isFinishing()) {
errorDialog.show();
}
}
} }
} }

View file

@ -415,31 +415,9 @@ public class ShareActivity
private void performUnwantedPictureDetectionProcess() { private void performUnwantedPictureDetectionProcess() {
String imageMediaFilePath = FileUtils.getPath(this,mediaUri); String imageMediaFilePath = FileUtils.getPath(this,mediaUri);
DetectUnwantedPicturesAsync detectUnwantedPicturesAsync = new DetectUnwantedPicturesAsync(imageMediaFilePath, result -> { DetectUnwantedPicturesAsync detectUnwantedPicturesAsync
= new DetectUnwantedPicturesAsync(new WeakReference<Activity>(this)
if (result != ImageUtils.Result.IMAGE_OK) { , imageMediaFilePath);
//show appropriate error message
String errorMessage = result == ImageUtils.Result.IMAGE_DARK ? getString(R.string.upload_image_too_dark) : getString(R.string.upload_image_blurry);
AlertDialog.Builder errorDialogBuilder = new AlertDialog.Builder(this);
errorDialogBuilder.setMessage(errorMessage);
errorDialogBuilder.setTitle(getString(R.string.warning));
errorDialogBuilder.setPositiveButton(getString(R.string.no), (dialogInterface, i) -> {
//user does not wish to upload the picture, take them back to ContributionsActivity
Intent intent = new Intent(ShareActivity.this, ContributionsActivity.class);
dialogInterface.dismiss();
startActivity(intent);
});
errorDialogBuilder.setNegativeButton(getString(R.string.yes), (dialogInterface, i) -> {
//user wishes to go ahead with the upload of this picture, just dismiss this dialog
dialogInterface.dismiss();
});
AlertDialog errorDialog = errorDialogBuilder.create();
if (!isFinishing()) {
errorDialog.show();
}
}
});
detectUnwantedPicturesAsync.execute(); detectUnwantedPicturesAsync.execute();
} }