1
0
Fork 0

fixed a Context memory leak

This commit is contained in:
sspanak 2024-08-13 12:17:49 +03:00 committed by Dimo Karaivanov
parent da846c44bc
commit 3f8820f0c4

View file

@ -26,7 +26,6 @@ public class CustomWordsImporter extends AbstractFileProcessor {
private ConsumerCompat<Integer> progressHandler; private ConsumerCompat<Integer> progressHandler;
private ConsumerCompat<String> failureHandler; private ConsumerCompat<String> failureHandler;
private final Context context;
private CustomWordFile file; private CustomWordFile file;
private final Resources resources; private final Resources resources;
private SQLiteOpener sqlite; private SQLiteOpener sqlite;
@ -45,7 +44,6 @@ public class CustomWordsImporter extends AbstractFileProcessor {
private CustomWordsImporter(Context context) { private CustomWordsImporter(Context context) {
super(); super();
this.context = context;
this.resources = context.getResources(); this.resources = context.getResources();
} }
@ -95,7 +93,7 @@ public class CustomWordsImporter extends AbstractFileProcessor {
Timer.start(getClass().getSimpleName()); Timer.start(getClass().getSimpleName());
sendStart(resources.getString(R.string.dictionary_import_running)); sendStart(resources.getString(R.string.dictionary_import_running));
if (isFileValid() && isThereRoomForMoreWords() && insertWords()) { if (isFileValid() && isThereRoomForMoreWords(activity) && insertWords(activity)) {
sendSuccess(); sendSuccess();
Logger.i(getClass().getSimpleName(), "Imported " + file.getName() + " in " + Timer.get(getClass().getSimpleName()) + " ms"); Logger.i(getClass().getSimpleName(), "Imported " + file.getName() + " in " + Timer.get(getClass().getSimpleName()) + " ms");
} else { } else {
@ -104,7 +102,7 @@ public class CustomWordsImporter extends AbstractFileProcessor {
} }
private boolean openDb() { private boolean openDb(Context context) {
sqlite = SQLiteOpener.getInstance(context); sqlite = SQLiteOpener.getInstance(context);
if (sqlite.getDb() != null) { if (sqlite.getDb() != null) {
return true; return true;
@ -116,7 +114,7 @@ public class CustomWordsImporter extends AbstractFileProcessor {
} }
private boolean insertWords() { private boolean insertWords(Context context) {
ReadOps readOps = new ReadOps(); ReadOps readOps = new ReadOps();
int ignoredWords = 0; int ignoredWords = 0;
int lineCount = 1; int lineCount = 1;
@ -130,7 +128,7 @@ public class CustomWordsImporter extends AbstractFileProcessor {
return false; return false;
} }
CustomWord customWord = createCustomWord(line, lineCount); CustomWord customWord = createCustomWord(context, line, lineCount);
if (customWord == null) { if (customWord == null) {
sqlite.failTransaction(); sqlite.failTransaction();
return false; return false;
@ -174,8 +172,8 @@ public class CustomWordsImporter extends AbstractFileProcessor {
} }
private boolean isThereRoomForMoreWords() { private boolean isThereRoomForMoreWords(Context context) {
if (!openDb()) { if (!openDb(context)) {
return false; return false;
} }
@ -198,7 +196,7 @@ public class CustomWordsImporter extends AbstractFileProcessor {
} }
private CustomWord createCustomWord(String line, int lineCount) { private CustomWord createCustomWord(Context context, String line, int lineCount) {
try { try {
return new CustomWord( return new CustomWord(
CustomWordFile.getWord(line), CustomWordFile.getWord(line),