63
63
import timber .log .Timber ;
64
64
65
65
@ AcraCore (
66
- buildConfigClass = BuildConfig .class ,
67
- resReportSendSuccessToast = R .string .crash_dialog_ok_toast ,
68
- reportFormat = StringFormat .KEY_VALUE_LIST ,
69
- reportContent = {USER_COMMENT , APP_VERSION_CODE , APP_VERSION_NAME , ANDROID_VERSION , PHONE_MODEL , STACK_TRACE }
66
+ buildConfigClass = BuildConfig .class ,
67
+ resReportSendSuccessToast = R .string .crash_dialog_ok_toast ,
68
+ reportFormat = StringFormat .KEY_VALUE_LIST ,
69
+ reportContent = {USER_COMMENT , APP_VERSION_CODE , APP_VERSION_NAME , ANDROID_VERSION , PHONE_MODEL ,
70
+ STACK_TRACE }
70
71
)
71
72
72
73
@ AcraMailSender (
73
- mailTo = "commons-app-android-private@googlegroups.com" ,
74
- reportAsFile = false
74
+ mailTo = "commons-app-android-private@googlegroups.com" ,
75
+ reportAsFile = false
75
76
)
76
77
77
78
@ AcraDialog (
78
- resTheme = R .style .Theme_AppCompat_Dialog ,
79
- resText = R .string .crash_dialog_text ,
80
- resTitle = R .string .crash_dialog_title ,
81
- resCommentPrompt = R .string .crash_dialog_comment_prompt
79
+ resTheme = R .style .Theme_AppCompat_Dialog ,
80
+ resText = R .string .crash_dialog_text ,
81
+ resTitle = R .string .crash_dialog_title ,
82
+ resCommentPrompt = R .string .crash_dialog_comment_prompt
82
83
)
83
84
84
85
public class CommonsApplication extends MultiDexApplication {
85
86
86
- public static final String IS_LIMITED_CONNECTION_MODE_ENABLED = "is_limited_connection_mode_enabled" ;
87
- @ Inject
88
- SessionManager sessionManager ;
89
- @ Inject
90
- DBOpenHelper dbOpenHelper ;
87
+ public static final String IS_LIMITED_CONNECTION_MODE_ENABLED = "is_limited_connection_mode_enabled" ;
88
+ @ Inject
89
+ SessionManager sessionManager ;
90
+ @ Inject
91
+ DBOpenHelper dbOpenHelper ;
91
92
92
- @ Inject
93
- @ Named ("default_preferences" )
94
- JsonKvStore defaultPrefs ;
93
+ @ Inject
94
+ @ Named ("default_preferences" )
95
+ JsonKvStore defaultPrefs ;
95
96
96
- @ Inject
97
- CustomOkHttpNetworkFetcher customOkHttpNetworkFetcher ;
97
+ @ Inject
98
+ CustomOkHttpNetworkFetcher customOkHttpNetworkFetcher ;
98
99
99
100
/**
100
101
* Constants begin
@@ -118,23 +119,26 @@ public class CommonsApplication extends MultiDexApplication {
118
119
private RefWatcher refWatcher ;
119
120
120
121
private static CommonsApplication INSTANCE ;
122
+
121
123
public static CommonsApplication getInstance () {
122
124
return INSTANCE ;
123
125
}
124
126
125
127
private AppLanguageLookUpTable languageLookUpTable ;
128
+
126
129
public AppLanguageLookUpTable getLanguageLookUpTable () {
127
130
return languageLookUpTable ;
128
131
}
129
132
130
- @ Inject ContributionDao contributionDao ;
133
+ @ Inject
134
+ ContributionDao contributionDao ;
131
135
132
- /**
133
- * In memory list of contributios whose uploads ahve been paused by the user
134
- */
135
- public static Map <String , Boolean > pauseUploads = new HashMap <>();
136
+ /**
137
+ * In memory list of contributios whose uploads ahve been paused by the user
138
+ */
139
+ public static Map <String , Boolean > pauseUploads = new HashMap <>();
136
140
137
- /**
141
+ /**
138
142
* Used to declare and initialize various components and dependencies
139
143
*/
140
144
@ Override
@@ -146,15 +150,14 @@ public void onCreate() {
146
150
Mapbox .getInstance (this , getString (R .string .mapbox_commons_app_token ));
147
151
148
152
ApplicationlessInjection
149
- .getInstance (this )
150
- .getCommonsApplicationComponent ()
151
- .inject (this );
153
+ .getInstance (this )
154
+ .getCommonsApplicationComponent ()
155
+ .inject (this );
152
156
153
157
AppAdapter .set (new CommonsAppAdapter (sessionManager , defaultPrefs ));
154
158
155
159
initTimber ();
156
160
157
-
158
161
if (!defaultPrefs .getBoolean ("has_user_manually_removed_location" )) {
159
162
Set <String > defaultExifTagsSet = defaultPrefs .getStringSet (Prefs .MANAGED_EXIF_TAGS );
160
163
if (null == defaultExifTagsSet ) {
@@ -166,9 +169,9 @@ public void onCreate() {
166
169
167
170
// Set DownsampleEnabled to True to downsample the image in case it's heavy
168
171
ImagePipelineConfig config = ImagePipelineConfig .newBuilder (this )
169
- .setNetworkFetcher (customOkHttpNetworkFetcher )
170
- .setDownsampleEnabled (true )
171
- .build ();
172
+ .setNetworkFetcher (customOkHttpNetworkFetcher )
173
+ .setDownsampleEnabled (true )
174
+ .build ();
172
175
try {
173
176
Fresco .initialize (this , config );
174
177
} catch (Exception e ) {
@@ -192,77 +195,80 @@ public void onCreate() {
192
195
}
193
196
194
197
/**
195
- * Plants debug and file logging tree.
196
- * Timber lets you plant your own logging trees.
197
- *
198
+ * Plants debug and file logging tree. Timber lets you plant your own logging trees.
198
199
*/
199
200
private void initTimber () {
200
- boolean isBeta = ConfigUtils .isBetaFlavour ();
201
- String logFileName =
202
- isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs" ;
203
- String logDirectory = LogUtils .getLogDirectory ();
204
- //Delete stale logs if they have exceeded the specified size
205
- deleteStaleLogs (logFileName , logDirectory );
206
-
207
- FileLoggingTree tree = new FileLoggingTree (
208
- Log .VERBOSE ,
209
- logFileName ,
210
- logDirectory ,
211
- 1000 ,
212
- getFileLoggingThreadPool ());
213
-
214
- Timber .plant (tree );
215
- Timber .plant (new Timber .DebugTree ());
201
+ boolean isBeta = ConfigUtils .isBetaFlavour ();
202
+ String logFileName =
203
+ isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs" ;
204
+ String logDirectory = LogUtils .getLogDirectory ();
205
+ //Delete stale logs if they have exceeded the specified size
206
+ deleteStaleLogs (logFileName , logDirectory );
207
+
208
+ FileLoggingTree tree = new FileLoggingTree (
209
+ Log .VERBOSE ,
210
+ logFileName ,
211
+ logDirectory ,
212
+ 1000 ,
213
+ getFileLoggingThreadPool ());
214
+
215
+ Timber .plant (tree );
216
+ Timber .plant (new Timber .DebugTree ());
216
217
}
217
218
218
- /**
219
- * Deletes the logs zip file at the specified directory and file locations specified in the
220
- * params
221
- *
222
- * @param logFileName
223
- * @param logDirectory
224
- */
225
- private void deleteStaleLogs (String logFileName , String logDirectory ) {
226
- try {
227
- File file = new File (logDirectory + "/zip/" + logFileName + ".zip" );
228
- if (file .exists () && file .getTotalSpace () > 1000000 ) {// In Kbs
229
- file .delete ();
230
- }
231
- } catch (Exception e ) {
232
- Timber .e (e );
219
+ /**
220
+ * Deletes the logs zip file at the specified directory and file locations specified in the
221
+ * params
222
+ *
223
+ * @param logFileName
224
+ * @param logDirectory
225
+ */
226
+ private void deleteStaleLogs (String logFileName , String logDirectory ) {
227
+ try {
228
+ File file = new File (logDirectory + "/zip/" + logFileName + ".zip" );
229
+ if (file .exists () && file .getTotalSpace () > 1000000 ) {// In Kbs
230
+ file .delete ();
231
+ }
232
+ } catch (Exception e ) {
233
+ Timber .e (e );
234
+ }
233
235
}
234
- }
235
236
236
237
public static boolean isRoboUnitTest () {
237
238
return "robolectric" .equals (Build .FINGERPRINT );
238
239
}
239
240
240
241
private ThreadPoolService getFileLoggingThreadPool () {
241
242
return new ThreadPoolService .Builder ("file-logging-thread" )
242
- .setPriority (Process .THREAD_PRIORITY_LOWEST )
243
- .setPoolSize (1 )
244
- .setExceptionHandler (new BackgroundPoolExceptionHandler ())
245
- .build ();
243
+ .setPriority (Process .THREAD_PRIORITY_LOWEST )
244
+ .setPoolSize (1 )
245
+ .setExceptionHandler (new BackgroundPoolExceptionHandler ())
246
+ .build ();
246
247
}
247
248
248
249
public static void createNotificationChannel (@ NonNull Context context ) {
249
250
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
250
- NotificationManager manager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
251
- NotificationChannel channel = manager .getNotificationChannel (NOTIFICATION_CHANNEL_ID_ALL );
251
+ NotificationManager manager = (NotificationManager ) context
252
+ .getSystemService (Context .NOTIFICATION_SERVICE );
253
+ NotificationChannel channel = manager
254
+ .getNotificationChannel (NOTIFICATION_CHANNEL_ID_ALL );
252
255
if (channel == null ) {
253
256
channel = new NotificationChannel (NOTIFICATION_CHANNEL_ID_ALL ,
254
- context .getString (R .string .notifications_channel_name_all ), NotificationManager .IMPORTANCE_DEFAULT );
257
+ context .getString (R .string .notifications_channel_name_all ),
258
+ NotificationManager .IMPORTANCE_DEFAULT );
255
259
manager .createNotificationChannel (channel );
256
260
}
257
261
}
258
262
}
259
263
260
264
public String getUserAgent () {
261
- return "Commons/" + ConfigUtils .getVersionNameWithSha (this ) + " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build .VERSION .RELEASE ;
265
+ return "Commons/" + ConfigUtils .getVersionNameWithSha (this )
266
+ + " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build .VERSION .RELEASE ;
262
267
}
263
268
264
269
/**
265
270
* Helps in setting up LeakCanary library
271
+ *
266
272
* @return instance of LeakCanary
267
273
*/
268
274
protected RefWatcher setupLeakCanary () {
@@ -272,7 +278,7 @@ protected RefWatcher setupLeakCanary() {
272
278
return LeakCanary .install (this );
273
279
}
274
280
275
- /**
281
+ /**
276
282
* Provides a way to get member refWatcher
277
283
*
278
284
* @param context Application context
@@ -285,7 +291,8 @@ public static RefWatcher getRefWatcher(Context context) {
285
291
286
292
/**
287
293
* clears data of current application
288
- * @param context Application context
294
+ *
295
+ * @param context Application context
289
296
* @param logoutListener Implementation of interface LogoutListener
290
297
*/
291
298
@ SuppressLint ("CheckResult" )
@@ -302,13 +309,13 @@ public void clearApplicationData(Context context, LogoutListener logoutListener)
302
309
}
303
310
304
311
sessionManager .logout ()
305
- .andThen (Completable .fromAction (() ->{
306
- Timber .d ("All accounts have been removed" );
307
- clearImageCache ();
308
- //TODO: fix preference manager
309
- defaultPrefs .clearAll ();
310
- defaultPrefs .putBoolean ("firstrun" , false );
311
- updateAllDatabases ();
312
+ .andThen (Completable .fromAction (() -> {
313
+ Timber .d ("All accounts have been removed" );
314
+ clearImageCache ();
315
+ //TODO: fix preference manager
316
+ defaultPrefs .clearAll ();
317
+ defaultPrefs .putBoolean ("firstrun" , false );
318
+ updateAllDatabases ();
312
319
}
313
320
))
314
321
.subscribeOn (Schedulers .io ())
@@ -332,12 +339,13 @@ private void updateAllDatabases() {
332
339
SQLiteDatabase db = dbOpenHelper .getWritableDatabase ();
333
340
334
341
CategoryDao .Table .onDelete (db );
335
- dbOpenHelper .deleteTable (db ,CONTRIBUTIONS_TABLE );//Delete the contributions table in the existing db on older versions
342
+ dbOpenHelper .deleteTable (db ,
343
+ CONTRIBUTIONS_TABLE );//Delete the contributions table in the existing db on older versions
336
344
337
345
try {
338
- contributionDao .deleteAll ();
346
+ contributionDao .deleteAll ();
339
347
} catch (SQLiteException e ) {
340
- Timber .e (e );
348
+ Timber .e (e );
341
349
}
342
350
BookmarkPicturesDao .Table .onDelete (db );
343
351
BookmarkLocationsDao .Table .onDelete (db );
@@ -348,6 +356,7 @@ private void updateAllDatabases() {
348
356
* Interface used to get log-out events
349
357
*/
350
358
public interface LogoutListener {
359
+
351
360
void onLogoutComplete ();
352
361
}
353
362
}
0 commit comments