Skip to content

Commit f6251d1

Browse files
* fixed logout problem fixed logout problem fixed logout problem fixed logout problem fixed logout problem * added error handling on logout Co-authored-by: gouri-panda <gouripanda4@gmail.com>
1 parent ceb03a9 commit f6251d1

File tree

1 file changed

+68
-71
lines changed

1 file changed

+68
-71
lines changed

app/src/main/java/fr/free/nrw/commons/CommonsApplication.java

+68-71
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,93 @@
11
package fr.free.nrw.commons;
22

3-
import static fr.free.nrw.commons.data.DBOpenHelper.CONTRIBUTIONS_TABLE;
4-
import static org.acra.ReportField.ANDROID_VERSION;
5-
import static org.acra.ReportField.APP_VERSION_CODE;
6-
import static org.acra.ReportField.APP_VERSION_NAME;
7-
import static org.acra.ReportField.PHONE_MODEL;
8-
import static org.acra.ReportField.STACK_TRACE;
9-
import static org.acra.ReportField.USER_COMMENT;
10-
113
import android.annotation.SuppressLint;
4+
import android.app.Application;
125
import android.app.NotificationChannel;
136
import android.app.NotificationManager;
147
import android.content.Context;
158
import android.database.sqlite.SQLiteDatabase;
9+
import android.database.sqlite.SQLiteException;
1610
import android.os.Build;
1711
import android.os.Process;
1812
import android.util.Log;
13+
1914
import androidx.annotation.NonNull;
20-
import androidx.multidex.MultiDexApplication;
15+
2116
import com.facebook.drawee.backends.pipeline.Fresco;
2217
import com.facebook.imagepipeline.core.ImagePipeline;
2318
import com.facebook.imagepipeline.core.ImagePipelineConfig;
2419
import com.mapbox.mapboxsdk.Mapbox;
2520
import com.squareup.leakcanary.LeakCanary;
2621
import com.squareup.leakcanary.RefWatcher;
22+
23+
import io.reactivex.Completable;
24+
import org.acra.ACRA;
25+
import org.acra.annotation.AcraCore;
26+
import org.acra.annotation.AcraDialog;
27+
import org.acra.annotation.AcraMailSender;
28+
import org.acra.data.StringFormat;
29+
import org.wikipedia.AppAdapter;
30+
import org.wikipedia.language.AppLanguageLookUpTable;
31+
32+
import java.io.File;
33+
import java.util.HashSet;
34+
import java.util.Set;
35+
36+
import javax.inject.Inject;
37+
import javax.inject.Named;
38+
2739
import fr.free.nrw.commons.auth.SessionManager;
2840
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
2941
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao;
3042
import fr.free.nrw.commons.category.CategoryDao;
3143
import fr.free.nrw.commons.concurrency.BackgroundPoolExceptionHandler;
3244
import fr.free.nrw.commons.concurrency.ThreadPoolService;
33-
import fr.free.nrw.commons.contributions.ContributionDao;
3445
import fr.free.nrw.commons.data.DBOpenHelper;
46+
import fr.free.nrw.commons.db.AppDatabase;
3547
import fr.free.nrw.commons.di.ApplicationlessInjection;
3648
import fr.free.nrw.commons.kvstore.JsonKvStore;
3749
import fr.free.nrw.commons.logging.FileLoggingTree;
3850
import fr.free.nrw.commons.logging.LogUtils;
39-
import fr.free.nrw.commons.media.CustomOkHttpNetworkFetcher;
4051
import fr.free.nrw.commons.settings.Prefs;
4152
import fr.free.nrw.commons.upload.FileUtils;
4253
import fr.free.nrw.commons.utils.ConfigUtils;
43-
import io.reactivex.Completable;
4454
import io.reactivex.android.schedulers.AndroidSchedulers;
4555
import io.reactivex.internal.functions.Functions;
4656
import io.reactivex.plugins.RxJavaPlugins;
4757
import io.reactivex.schedulers.Schedulers;
48-
import java.io.File;
49-
import java.util.HashSet;
50-
import java.util.Set;
51-
import javax.inject.Inject;
52-
import javax.inject.Named;
53-
import org.acra.ACRA;
54-
import org.acra.annotation.AcraCore;
55-
import org.acra.annotation.AcraDialog;
56-
import org.acra.annotation.AcraMailSender;
57-
import org.acra.data.StringFormat;
58-
import org.wikipedia.AppAdapter;
59-
import org.wikipedia.language.AppLanguageLookUpTable;
6058
import timber.log.Timber;
6159

60+
import static fr.free.nrw.commons.data.DBOpenHelper.CONTRIBUTIONS_TABLE;
61+
import static org.acra.ReportField.ANDROID_VERSION;
62+
import static org.acra.ReportField.APP_VERSION_CODE;
63+
import static org.acra.ReportField.APP_VERSION_NAME;
64+
import static org.acra.ReportField.PHONE_MODEL;
65+
import static org.acra.ReportField.STACK_TRACE;
66+
import static org.acra.ReportField.USER_COMMENT;
67+
6268
@AcraCore(
63-
buildConfigClass = BuildConfig.class,
64-
resReportSendSuccessToast = R.string.crash_dialog_ok_toast,
65-
reportFormat = StringFormat.KEY_VALUE_LIST,
66-
reportContent = {USER_COMMENT, APP_VERSION_CODE, APP_VERSION_NAME, ANDROID_VERSION, PHONE_MODEL, STACK_TRACE}
69+
buildConfigClass = BuildConfig.class,
70+
resReportSendSuccessToast = R.string.crash_dialog_ok_toast,
71+
reportFormat = StringFormat.KEY_VALUE_LIST,
72+
reportContent = {USER_COMMENT, APP_VERSION_CODE, APP_VERSION_NAME, ANDROID_VERSION, PHONE_MODEL, STACK_TRACE}
6773
)
6874

6975
@AcraMailSender(
70-
mailTo = "commons-app-android-private@googlegroups.com"
76+
mailTo = "commons-app-android-private@googlegroups.com"
7177
)
7278

7379
@AcraDialog(
74-
resTheme = R.style.Theme_AppCompat_Dialog,
75-
resText = R.string.crash_dialog_text,
76-
resTitle = R.string.crash_dialog_title,
77-
resCommentPrompt = R.string.crash_dialog_comment_prompt
80+
resTheme = R.style.Theme_AppCompat_Dialog,
81+
resText = R.string.crash_dialog_text,
82+
resTitle = R.string.crash_dialog_title,
83+
resCommentPrompt = R.string.crash_dialog_comment_prompt
7884
)
7985

80-
public class CommonsApplication extends MultiDexApplication {
86+
public class CommonsApplication extends Application {
87+
@Inject SessionManager sessionManager;
88+
@Inject DBOpenHelper dbOpenHelper;
8189

82-
public static final String IS_LIMITED_CONNECTION_MODE_ENABLED = "is_limited_connection_mode_enabled";
83-
@Inject
84-
SessionManager sessionManager;
85-
@Inject
86-
DBOpenHelper dbOpenHelper;
87-
88-
@Inject
89-
@Named("default_preferences")
90-
JsonKvStore defaultPrefs;
91-
92-
@Inject
93-
CustomOkHttpNetworkFetcher customOkHttpNetworkFetcher;
90+
@Inject @Named("default_preferences") JsonKvStore defaultPrefs;
9491

9592
/**
9693
* Constants begin
@@ -123,7 +120,8 @@ public AppLanguageLookUpTable getLanguageLookUpTable() {
123120
return languageLookUpTable;
124121
}
125122

126-
@Inject ContributionDao contributionDao;
123+
@Inject
124+
AppDatabase appDatabase;
127125

128126
/**
129127
* Used to declare and initialize various components and dependencies
@@ -137,9 +135,9 @@ public void onCreate() {
137135
Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token));
138136

139137
ApplicationlessInjection
140-
.getInstance(this)
141-
.getCommonsApplicationComponent()
142-
.inject(this);
138+
.getInstance(this)
139+
.getCommonsApplicationComponent()
140+
.inject(this);
143141

144142
AppAdapter.set(new CommonsAppAdapter(sessionManager, defaultPrefs));
145143

@@ -157,9 +155,8 @@ public void onCreate() {
157155

158156
// Set DownsampleEnabled to True to downsample the image in case it's heavy
159157
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
160-
.setNetworkFetcher(customOkHttpNetworkFetcher)
161-
.setDownsampleEnabled(true)
162-
.build();
158+
.setDownsampleEnabled(true)
159+
.build();
163160
try {
164161
Fresco.initialize(this, config);
165162
} catch (Exception e) {
@@ -192,11 +189,11 @@ private void initTimber() {
192189
String logFileName = isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs";
193190
String logDirectory = LogUtils.getLogDirectory();
194191
FileLoggingTree tree = new FileLoggingTree(
195-
Log.VERBOSE,
196-
logFileName,
197-
logDirectory,
198-
1000,
199-
getFileLoggingThreadPool());
192+
Log.VERBOSE,
193+
logFileName,
194+
logDirectory,
195+
1000,
196+
getFileLoggingThreadPool());
200197

201198
Timber.plant(tree);
202199
Timber.plant(new Timber.DebugTree());
@@ -208,10 +205,10 @@ public static boolean isRoboUnitTest() {
208205

209206
private ThreadPoolService getFileLoggingThreadPool() {
210207
return new ThreadPoolService.Builder("file-logging-thread")
211-
.setPriority(Process.THREAD_PRIORITY_LOWEST)
212-
.setPoolSize(1)
213-
.setExceptionHandler(new BackgroundPoolExceptionHandler())
214-
.build();
208+
.setPriority(Process.THREAD_PRIORITY_LOWEST)
209+
.setPoolSize(1)
210+
.setExceptionHandler(new BackgroundPoolExceptionHandler())
211+
.build();
215212
}
216213

217214
public static void createNotificationChannel(@NonNull Context context) {
@@ -220,7 +217,7 @@ public static void createNotificationChannel(@NonNull Context context) {
220217
NotificationChannel channel = manager.getNotificationChannel(NOTIFICATION_CHANNEL_ID_ALL);
221218
if (channel == null) {
222219
channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID_ALL,
223-
context.getString(R.string.notifications_channel_name_all), NotificationManager.IMPORTANCE_DEFAULT);
220+
context.getString(R.string.notifications_channel_name_all), NotificationManager.IMPORTANCE_DEFAULT);
224221
manager.createNotificationChannel(channel);
225222
}
226223
}
@@ -241,7 +238,7 @@ protected RefWatcher setupLeakCanary() {
241238
return LeakCanary.install(this);
242239
}
243240

244-
/**
241+
/**
245242
* Provides a way to get member refWatcher
246243
*
247244
* @param context Application context
@@ -272,12 +269,12 @@ public void clearApplicationData(Context context, LogoutListener logoutListener)
272269

273270
sessionManager.logout()
274271
.andThen(Completable.fromAction(() ->{
275-
Timber.d("All accounts have been removed");
276-
clearImageCache();
277-
//TODO: fix preference manager
278-
defaultPrefs.clearAll();
279-
defaultPrefs.putBoolean("firstrun", false);
280-
updateAllDatabases();
272+
Timber.d("All accounts have been removed");
273+
clearImageCache();
274+
//TODO: fix preference manager
275+
defaultPrefs.clearAll();
276+
defaultPrefs.putBoolean("firstrun", false);
277+
updateAllDatabases();
281278
}
282279
))
283280
.subscribeOn(Schedulers.io())
@@ -302,7 +299,7 @@ private void updateAllDatabases() {
302299

303300
CategoryDao.Table.onDelete(db);
304301
dbOpenHelper.deleteTable(db,CONTRIBUTIONS_TABLE);//Delete the contributions table in the existing db on older versions
305-
contributionDao.deleteAll();
302+
appDatabase.getContributionDao().deleteAll();
306303
BookmarkPicturesDao.Table.onDelete(db);
307304
BookmarkLocationsDao.Table.onDelete(db);
308305
}

0 commit comments

Comments
 (0)