mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Prevent memory leak(s) from QuizChecker. (#2656)
This commit is contained in:
parent
3ceaaa9bb4
commit
8cd87ad148
2 changed files with 11 additions and 13 deletions
|
|
@ -506,6 +506,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
|
|||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
quizChecker.cleanup();
|
||||
locationManager.unregisterLocationManager();
|
||||
// Remove ourself from hashmap to prevent memory leaks
|
||||
locationManager = null;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons.quiz;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -20,8 +19,6 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
|
||||
/**
|
||||
* fetches the number of images uploaded and number of images reverted.
|
||||
* Then it calculates the percentage of the images reverted
|
||||
|
|
@ -37,7 +34,6 @@ public class QuizChecker {
|
|||
private boolean isUploadCountFetched;
|
||||
|
||||
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
public Context context;
|
||||
|
||||
private final SessionManager sessionManager;
|
||||
private final OkHttpJsonApiClient okHttpJsonApiClient;
|
||||
|
|
@ -50,16 +46,13 @@ public class QuizChecker {
|
|||
|
||||
/**
|
||||
* constructor to set the parameters for quiz
|
||||
* @param context context
|
||||
* @param sessionManager
|
||||
* @param okHttpJsonApiClient instance of MediaWikiApi
|
||||
*/
|
||||
@Inject
|
||||
public QuizChecker(Context context,
|
||||
SessionManager sessionManager,
|
||||
public QuizChecker(SessionManager sessionManager,
|
||||
OkHttpJsonApiClient okHttpJsonApiClient,
|
||||
@Named("default_preferences") JsonKvStore revertKvStore) {
|
||||
this.context = context;
|
||||
this.sessionManager = sessionManager;
|
||||
this.okHttpJsonApiClient = okHttpJsonApiClient;
|
||||
this.revertKvStore = revertKvStore;
|
||||
|
|
@ -70,6 +63,10 @@ public class QuizChecker {
|
|||
setRevertCount(activity);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
compositeDisposable.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* to fet the total number of images uploaded
|
||||
*/
|
||||
|
|
@ -151,10 +148,10 @@ public class QuizChecker {
|
|||
@SuppressLint("StringFormatInvalid")
|
||||
private void callQuiz(Activity activity) {
|
||||
DialogUtil.showAlertDialog(activity,
|
||||
context.getResources().getString(R.string.quiz),
|
||||
context.getResources().getString(R.string.quiz_alert_message, REVERT_PERCENTAGE_FOR_MESSAGE),
|
||||
context.getResources().getString(R.string.about_translate_proceed),
|
||||
context.getResources().getString(android.R.string.cancel),
|
||||
activity.getString(R.string.quiz),
|
||||
activity.getString(R.string.quiz_alert_message, REVERT_PERCENTAGE_FOR_MESSAGE),
|
||||
activity.getString(R.string.about_translate_proceed),
|
||||
activity.getString(android.R.string.cancel),
|
||||
() -> startQuizActivity(activity), null);
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +160,7 @@ public class QuizChecker {
|
|||
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, newRevetSharedPrefs);
|
||||
int newUploadCount = totalUploadCount + revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, newUploadCount);
|
||||
Intent i = new Intent(context, WelcomeActivity.class);
|
||||
Intent i = new Intent(activity, WelcomeActivity.class);
|
||||
i.putExtra("isQuiz", true);
|
||||
activity.startActivity(i);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue