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
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
quizChecker.cleanup();
|
||||||
locationManager.unregisterLocationManager();
|
locationManager.unregisterLocationManager();
|
||||||
// Remove ourself from hashmap to prevent memory leaks
|
// Remove ourself from hashmap to prevent memory leaks
|
||||||
locationManager = null;
|
locationManager = null;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons.quiz;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -20,8 +19,6 @@ import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches the number of images uploaded and number of images reverted.
|
* fetches the number of images uploaded and number of images reverted.
|
||||||
* Then it calculates the percentage of the images reverted
|
* Then it calculates the percentage of the images reverted
|
||||||
|
|
@ -37,7 +34,6 @@ public class QuizChecker {
|
||||||
private boolean isUploadCountFetched;
|
private boolean isUploadCountFetched;
|
||||||
|
|
||||||
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||||
public Context context;
|
|
||||||
|
|
||||||
private final SessionManager sessionManager;
|
private final SessionManager sessionManager;
|
||||||
private final OkHttpJsonApiClient okHttpJsonApiClient;
|
private final OkHttpJsonApiClient okHttpJsonApiClient;
|
||||||
|
|
@ -50,16 +46,13 @@ public class QuizChecker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor to set the parameters for quiz
|
* constructor to set the parameters for quiz
|
||||||
* @param context context
|
|
||||||
* @param sessionManager
|
* @param sessionManager
|
||||||
* @param okHttpJsonApiClient instance of MediaWikiApi
|
* @param okHttpJsonApiClient instance of MediaWikiApi
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public QuizChecker(Context context,
|
public QuizChecker(SessionManager sessionManager,
|
||||||
SessionManager sessionManager,
|
|
||||||
OkHttpJsonApiClient okHttpJsonApiClient,
|
OkHttpJsonApiClient okHttpJsonApiClient,
|
||||||
@Named("default_preferences") JsonKvStore revertKvStore) {
|
@Named("default_preferences") JsonKvStore revertKvStore) {
|
||||||
this.context = context;
|
|
||||||
this.sessionManager = sessionManager;
|
this.sessionManager = sessionManager;
|
||||||
this.okHttpJsonApiClient = okHttpJsonApiClient;
|
this.okHttpJsonApiClient = okHttpJsonApiClient;
|
||||||
this.revertKvStore = revertKvStore;
|
this.revertKvStore = revertKvStore;
|
||||||
|
|
@ -70,6 +63,10 @@ public class QuizChecker {
|
||||||
setRevertCount(activity);
|
setRevertCount(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanup() {
|
||||||
|
compositeDisposable.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* to fet the total number of images uploaded
|
* to fet the total number of images uploaded
|
||||||
*/
|
*/
|
||||||
|
|
@ -151,10 +148,10 @@ public class QuizChecker {
|
||||||
@SuppressLint("StringFormatInvalid")
|
@SuppressLint("StringFormatInvalid")
|
||||||
private void callQuiz(Activity activity) {
|
private void callQuiz(Activity activity) {
|
||||||
DialogUtil.showAlertDialog(activity,
|
DialogUtil.showAlertDialog(activity,
|
||||||
context.getResources().getString(R.string.quiz),
|
activity.getString(R.string.quiz),
|
||||||
context.getResources().getString(R.string.quiz_alert_message, REVERT_PERCENTAGE_FOR_MESSAGE),
|
activity.getString(R.string.quiz_alert_message, REVERT_PERCENTAGE_FOR_MESSAGE),
|
||||||
context.getResources().getString(R.string.about_translate_proceed),
|
activity.getString(R.string.about_translate_proceed),
|
||||||
context.getResources().getString(android.R.string.cancel),
|
activity.getString(android.R.string.cancel),
|
||||||
() -> startQuizActivity(activity), null);
|
() -> startQuizActivity(activity), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,7 +160,7 @@ public class QuizChecker {
|
||||||
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, newRevetSharedPrefs);
|
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, newRevetSharedPrefs);
|
||||||
int newUploadCount = totalUploadCount + revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
|
int newUploadCount = totalUploadCount + revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||||
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, newUploadCount);
|
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, newUploadCount);
|
||||||
Intent i = new Intent(context, WelcomeActivity.class);
|
Intent i = new Intent(activity, WelcomeActivity.class);
|
||||||
i.putExtra("isQuiz", true);
|
i.putExtra("isQuiz", true);
|
||||||
activity.startActivity(i);
|
activity.startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue