1
1
package fr .free .nrw .commons ;
2
2
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
-
11
3
import android .annotation .SuppressLint ;
4
+ import android .app .Application ;
12
5
import android .app .NotificationChannel ;
13
6
import android .app .NotificationManager ;
14
7
import android .content .Context ;
15
8
import android .database .sqlite .SQLiteDatabase ;
9
+ import android .database .sqlite .SQLiteException ;
16
10
import android .os .Build ;
17
11
import android .os .Process ;
18
12
import android .util .Log ;
13
+
19
14
import androidx .annotation .NonNull ;
20
- import androidx . multidex . MultiDexApplication ;
15
+
21
16
import com .facebook .drawee .backends .pipeline .Fresco ;
22
17
import com .facebook .imagepipeline .core .ImagePipeline ;
23
18
import com .facebook .imagepipeline .core .ImagePipelineConfig ;
24
19
import com .mapbox .mapboxsdk .Mapbox ;
25
20
import com .squareup .leakcanary .LeakCanary ;
26
21
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
+
27
39
import fr .free .nrw .commons .auth .SessionManager ;
28
40
import fr .free .nrw .commons .bookmarks .locations .BookmarkLocationsDao ;
29
41
import fr .free .nrw .commons .bookmarks .pictures .BookmarkPicturesDao ;
30
42
import fr .free .nrw .commons .category .CategoryDao ;
31
43
import fr .free .nrw .commons .concurrency .BackgroundPoolExceptionHandler ;
32
44
import fr .free .nrw .commons .concurrency .ThreadPoolService ;
33
- import fr .free .nrw .commons .contributions .ContributionDao ;
34
45
import fr .free .nrw .commons .data .DBOpenHelper ;
46
+ import fr .free .nrw .commons .db .AppDatabase ;
35
47
import fr .free .nrw .commons .di .ApplicationlessInjection ;
36
48
import fr .free .nrw .commons .kvstore .JsonKvStore ;
37
49
import fr .free .nrw .commons .logging .FileLoggingTree ;
38
50
import fr .free .nrw .commons .logging .LogUtils ;
39
- import fr .free .nrw .commons .media .CustomOkHttpNetworkFetcher ;
40
51
import fr .free .nrw .commons .settings .Prefs ;
41
52
import fr .free .nrw .commons .upload .FileUtils ;
42
53
import fr .free .nrw .commons .utils .ConfigUtils ;
43
- import io .reactivex .Completable ;
44
54
import io .reactivex .android .schedulers .AndroidSchedulers ;
45
55
import io .reactivex .internal .functions .Functions ;
46
56
import io .reactivex .plugins .RxJavaPlugins ;
47
57
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 ;
60
58
import timber .log .Timber ;
61
59
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
+
62
68
@ 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 }
67
73
)
68
74
69
75
@ AcraMailSender (
70
- mailTo = "commons-app-android-private@googlegroups.com"
76
+ mailTo = "commons-app-android-private@googlegroups.com"
71
77
)
72
78
73
79
@ 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
78
84
)
79
85
80
- public class CommonsApplication extends MultiDexApplication {
86
+ public class CommonsApplication extends Application {
87
+ @ Inject SessionManager sessionManager ;
88
+ @ Inject DBOpenHelper dbOpenHelper ;
81
89
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 ;
94
91
95
92
/**
96
93
* Constants begin
@@ -123,7 +120,8 @@ public AppLanguageLookUpTable getLanguageLookUpTable() {
123
120
return languageLookUpTable ;
124
121
}
125
122
126
- @ Inject ContributionDao contributionDao ;
123
+ @ Inject
124
+ AppDatabase appDatabase ;
127
125
128
126
/**
129
127
* Used to declare and initialize various components and dependencies
@@ -137,9 +135,9 @@ public void onCreate() {
137
135
Mapbox .getInstance (this , getString (R .string .mapbox_commons_app_token ));
138
136
139
137
ApplicationlessInjection
140
- .getInstance (this )
141
- .getCommonsApplicationComponent ()
142
- .inject (this );
138
+ .getInstance (this )
139
+ .getCommonsApplicationComponent ()
140
+ .inject (this );
143
141
144
142
AppAdapter .set (new CommonsAppAdapter (sessionManager , defaultPrefs ));
145
143
@@ -157,9 +155,8 @@ public void onCreate() {
157
155
158
156
// Set DownsampleEnabled to True to downsample the image in case it's heavy
159
157
ImagePipelineConfig config = ImagePipelineConfig .newBuilder (this )
160
- .setNetworkFetcher (customOkHttpNetworkFetcher )
161
- .setDownsampleEnabled (true )
162
- .build ();
158
+ .setDownsampleEnabled (true )
159
+ .build ();
163
160
try {
164
161
Fresco .initialize (this , config );
165
162
} catch (Exception e ) {
@@ -192,11 +189,11 @@ private void initTimber() {
192
189
String logFileName = isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs" ;
193
190
String logDirectory = LogUtils .getLogDirectory ();
194
191
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 ());
200
197
201
198
Timber .plant (tree );
202
199
Timber .plant (new Timber .DebugTree ());
@@ -208,10 +205,10 @@ public static boolean isRoboUnitTest() {
208
205
209
206
private ThreadPoolService getFileLoggingThreadPool () {
210
207
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 ();
215
212
}
216
213
217
214
public static void createNotificationChannel (@ NonNull Context context ) {
@@ -220,7 +217,7 @@ public static void createNotificationChannel(@NonNull Context context) {
220
217
NotificationChannel channel = manager .getNotificationChannel (NOTIFICATION_CHANNEL_ID_ALL );
221
218
if (channel == null ) {
222
219
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 );
224
221
manager .createNotificationChannel (channel );
225
222
}
226
223
}
@@ -241,7 +238,7 @@ protected RefWatcher setupLeakCanary() {
241
238
return LeakCanary .install (this );
242
239
}
243
240
244
- /**
241
+ /**
245
242
* Provides a way to get member refWatcher
246
243
*
247
244
* @param context Application context
@@ -272,12 +269,12 @@ public void clearApplicationData(Context context, LogoutListener logoutListener)
272
269
273
270
sessionManager .logout ()
274
271
.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 ();
281
278
}
282
279
))
283
280
.subscribeOn (Schedulers .io ())
@@ -302,7 +299,7 @@ private void updateAllDatabases() {
302
299
303
300
CategoryDao .Table .onDelete (db );
304
301
dbOpenHelper .deleteTable (db ,CONTRIBUTIONS_TABLE );//Delete the contributions table in the existing db on older versions
305
- contributionDao .deleteAll ();
302
+ appDatabase . getContributionDao () .deleteAll ();
306
303
BookmarkPicturesDao .Table .onDelete (db );
307
304
BookmarkLocationsDao .Table .onDelete (db );
308
305
}
0 commit comments