66
66
import static org .acra .ReportField .USER_COMMENT ;
67
67
68
68
@ AcraCore (
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 }
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 }
73
73
)
74
74
75
75
@ AcraMailSender (
76
-
76
+
77
77
)
78
78
79
79
@ AcraDialog (
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
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
84
84
)
85
85
86
86
public class CommonsApplication extends Application {
@@ -135,9 +135,9 @@ public void onCreate() {
135
135
Mapbox .getInstance (this , getString (R .string .mapbox_commons_app_token ));
136
136
137
137
ApplicationlessInjection
138
- .getInstance (this )
139
- .getCommonsApplicationComponent ()
140
- .inject (this );
138
+ .getInstance (this )
139
+ .getCommonsApplicationComponent ()
140
+ .inject (this );
141
141
142
142
AppAdapter .set (new CommonsAppAdapter (sessionManager , defaultPrefs ));
143
143
@@ -155,8 +155,8 @@ public void onCreate() {
155
155
156
156
// Set DownsampleEnabled to True to downsample the image in case it's heavy
157
157
ImagePipelineConfig config = ImagePipelineConfig .newBuilder (this )
158
- .setDownsampleEnabled (true )
159
- .build ();
158
+ .setDownsampleEnabled (true )
159
+ .build ();
160
160
try {
161
161
Fresco .initialize (this , config );
162
162
} catch (Exception e ) {
@@ -185,30 +185,52 @@ public void onCreate() {
185
185
*
186
186
*/
187
187
private void initTimber () {
188
- boolean isBeta = ConfigUtils .isBetaFlavour ();
189
- String logFileName = isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs" ;
190
- String logDirectory = LogUtils .getLogDirectory ();
191
- FileLoggingTree tree = new FileLoggingTree (
192
- Log .VERBOSE ,
193
- logFileName ,
194
- logDirectory ,
195
- 1000 ,
196
- getFileLoggingThreadPool ());
197
-
198
- Timber .plant (tree );
199
- Timber .plant (new Timber .DebugTree ());
188
+ boolean isBeta = ConfigUtils .isBetaFlavour ();
189
+ String logFileName =
190
+ isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs" ;
191
+ String logDirectory = LogUtils .getLogDirectory ();
192
+ //Delete stale logs if they have exceeded the specified size
193
+ deleteStaleLogs (logFileName , logDirectory );
194
+
195
+ FileLoggingTree tree = new FileLoggingTree (
196
+ Log .VERBOSE ,
197
+ logFileName ,
198
+ logDirectory ,
199
+ 1000 ,
200
+ getFileLoggingThreadPool ());
201
+
202
+ Timber .plant (tree );
203
+ Timber .plant (new Timber .DebugTree ());
200
204
}
201
205
206
+ /**
207
+ * Deletes the logs zip file at the specified directory and file locations specified in the
208
+ * params
209
+ *
210
+ * @param logFileName
211
+ * @param logDirectory
212
+ */
213
+ private void deleteStaleLogs (String logFileName , String logDirectory ) {
214
+ try {
215
+ File file = new File (logDirectory + "/zip/" + logFileName + ".zip" );
216
+ if (file .exists () && file .getTotalSpace () > 1000000 ) {// In Kbs
217
+ file .delete ();
218
+ }
219
+ } catch (Exception e ) {
220
+ Timber .e (e );
221
+ }
222
+ }
223
+
202
224
public static boolean isRoboUnitTest () {
203
225
return "robolectric" .equals (Build .FINGERPRINT );
204
226
}
205
227
206
228
private ThreadPoolService getFileLoggingThreadPool () {
207
229
return new ThreadPoolService .Builder ("file-logging-thread" )
208
- .setPriority (Process .THREAD_PRIORITY_LOWEST )
209
- .setPoolSize (1 )
210
- .setExceptionHandler (new BackgroundPoolExceptionHandler ())
211
- .build ();
230
+ .setPriority (Process .THREAD_PRIORITY_LOWEST )
231
+ .setPoolSize (1 )
232
+ .setExceptionHandler (new BackgroundPoolExceptionHandler ())
233
+ .build ();
212
234
}
213
235
214
236
public static void createNotificationChannel (@ NonNull Context context ) {
@@ -217,7 +239,7 @@ public static void createNotificationChannel(@NonNull Context context) {
217
239
NotificationChannel channel = manager .getNotificationChannel (NOTIFICATION_CHANNEL_ID_ALL );
218
240
if (channel == null ) {
219
241
channel = new NotificationChannel (NOTIFICATION_CHANNEL_ID_ALL ,
220
- context .getString (R .string .notifications_channel_name_all ), NotificationManager .IMPORTANCE_DEFAULT );
242
+ context .getString (R .string .notifications_channel_name_all ), NotificationManager .IMPORTANCE_DEFAULT );
221
243
manager .createNotificationChannel (channel );
222
244
}
223
245
}
@@ -238,7 +260,7 @@ protected RefWatcher setupLeakCanary() {
238
260
return LeakCanary .install (this );
239
261
}
240
262
241
- /**
263
+ /**
242
264
* Provides a way to get member refWatcher
243
265
*
244
266
* @param context Application context
@@ -269,12 +291,12 @@ public void clearApplicationData(Context context, LogoutListener logoutListener)
269
291
270
292
sessionManager .logout ()
271
293
.andThen (Completable .fromAction (() ->{
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 ();
294
+ Timber .d ("All accounts have been removed" );
295
+ clearImageCache ();
296
+ //TODO: fix preference manager
297
+ defaultPrefs .clearAll ();
298
+ defaultPrefs .putBoolean ("firstrun" , false );
299
+ updateAllDatabases ();
278
300
}
279
301
))
280
302
.subscribeOn (Schedulers .io ())
0 commit comments