mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 05:43:55 +01:00
Fix memory leak(s). (#2674)
This commit is contained in:
parent
d1ae88ca8b
commit
351109440f
6 changed files with 24 additions and 37 deletions
|
|
@ -87,6 +87,7 @@ public class ContributionsFragment
|
|||
@Inject NearbyController nearbyController;
|
||||
@Inject OkHttpJsonApiClient okHttpJsonApiClient;
|
||||
@Inject CampaignsPresenter presenter;
|
||||
@Inject LocationServiceManager locationManager;
|
||||
|
||||
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
|
||||
private UploadService uploadService;
|
||||
|
|
@ -105,8 +106,6 @@ public class ContributionsFragment
|
|||
private LatLng curLatLng;
|
||||
|
||||
private boolean firstLocationUpdate = true;
|
||||
public LocationServiceManager locationManager;
|
||||
|
||||
private boolean isFragmentAttachedBefore = false;
|
||||
private View checkBoxView;
|
||||
private CheckBox checkBox;
|
||||
|
|
@ -496,7 +495,6 @@ public class ContributionsFragment
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
locationManager = new LocationServiceManager(getActivity());
|
||||
|
||||
firstLocationUpdate = true;
|
||||
locationManager.addLocationListener(this);
|
||||
|
|
@ -546,7 +544,7 @@ public class ContributionsFragment
|
|||
|
||||
private void checkLocationPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (locationManager.isLocationPermissionGranted()) {
|
||||
if (locationManager.isLocationPermissionGranted(requireContext())) {
|
||||
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.NO_PERMISSION_NEEDED;
|
||||
locationManager.registerLocationManager();
|
||||
} else {
|
||||
|
|
@ -638,8 +636,6 @@ public class ContributionsFragment
|
|||
getChildFragmentManager().removeOnBackStackChangedListener(this);
|
||||
locationManager.unregisterLocationManager();
|
||||
locationManager.removeLocationListener(this);
|
||||
// Try to prevent a possible NPE
|
||||
locationManager.context = null;
|
||||
super.onDestroy();
|
||||
|
||||
if (isUploadServiceConnected) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package fr.free.nrw.commons.contributions;
|
|||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.cursoradapter.widget.CursorAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -20,14 +22,12 @@ class ContributionsListAdapter extends CursorAdapter {
|
|||
|
||||
private final ContributionDao contributionDao;
|
||||
private UploadService uploadService;
|
||||
private Context context;
|
||||
|
||||
public ContributionsListAdapter(Context context,
|
||||
Cursor c,
|
||||
int flags,
|
||||
ContributionDao contributionDao) {
|
||||
super(context, c, flags);
|
||||
this.context = context;
|
||||
this.contributionDao = contributionDao;
|
||||
}
|
||||
|
||||
|
|
@ -53,12 +53,12 @@ class ContributionsListAdapter extends CursorAdapter {
|
|||
new DisplayableContribution.ContributionActions() {
|
||||
@Override
|
||||
public void retryUpload() {
|
||||
ContributionsListAdapter.this.retryUpload(contribution);
|
||||
ContributionsListAdapter.this.retryUpload(view.getContext(), contribution);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUpload() {
|
||||
ContributionsListAdapter.this.deleteUpload(contribution);
|
||||
ContributionsListAdapter.this.deleteUpload(view.getContext(), contribution);
|
||||
}
|
||||
});
|
||||
views.bindModel(context, displayableContribution);
|
||||
|
|
@ -68,7 +68,7 @@ class ContributionsListAdapter extends CursorAdapter {
|
|||
* Retry upload when it is failed
|
||||
* @param contribution contribution to be retried
|
||||
*/
|
||||
private void retryUpload(Contribution contribution) {
|
||||
private void retryUpload(@NonNull Context context, Contribution contribution) {
|
||||
if (NetworkUtils.isInternetConnectionEstablished(context)) {
|
||||
if (contribution.getState() == STATE_FAILED
|
||||
&& uploadService!= null) {
|
||||
|
|
@ -87,7 +87,7 @@ class ContributionsListAdapter extends CursorAdapter {
|
|||
* Delete a failed upload attempt
|
||||
* @param contribution contribution to be deleted
|
||||
*/
|
||||
private void deleteUpload(Contribution contribution) {
|
||||
private void deleteUpload(@NonNull Context context, Contribution contribution) {
|
||||
if (NetworkUtils.isInternetConnectionEstablished(context)) {
|
||||
if (contribution.getState() == STATE_FAILED) {
|
||||
Timber.d("Deleting failed contrib %s", contribution.toString());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue