From 66e4edf5c9739b01cc36df87a9d48ba75e9833fc Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 14 Mar 2023 16:05:58 +0100 Subject: [PATCH] misc: fixed linting in lib (#6) --- .../com/dzeio/crashhandler/CrashHandler.kt | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt b/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt index e0d40d9..d638b6c 100644 --- a/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt +++ b/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt @@ -35,7 +35,7 @@ class CrashHandler private constructor( /** * Builder for the crash handler */ - class Builder() { + class Builder { private var application: Application? = null private var prefs: SharedPreferences? = null private var prefsKey: String? = null @@ -49,7 +49,7 @@ class CrashHandler private constructor( * * note: you can get the backtrace text by using `intent.getStringExtra("error")` * - * @param activity the activity class to use + * @param context the context class to use */ fun withContext(context: Context): Builder { this.application = context.applicationContext as Application? @@ -80,7 +80,6 @@ class CrashHandler private constructor( return this } - /** * the key of the [SharedPreferences] you want to let the library handle * @@ -129,11 +128,19 @@ class CrashHandler private constructor( * build the Crash Handler */ fun build(): CrashHandler { - return CrashHandler(application, activity!!, prefs, prefsKey, errorReporterCrashKey, prefix, suffix) + return CrashHandler( + application, + activity!!, + prefs, + prefsKey, + errorReporterCrashKey, + prefix, + suffix + ) } } - private var oldHandler: Thread.UncaughtExceptionHandler? = null + private var oldHandler: Thread.UncaughtExceptionHandler? = null fun setup() { if (application != null) { @@ -180,16 +187,19 @@ class CrashHandler private constructor( // add device informations val deviceToReport = - if (Build.DEVICE.contains(Build.MANUFACTURER)) Build.DEVICE else "${Build.MANUFACTURER} ${Build.DEVICE}" - data += "\n\non $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})" + if (Build.DEVICE.contains(Build.MANUFACTURER)) { + Build.DEVICE + } else { + "${Build.MANUFACTURER} ${Build.DEVICE}" + } + data += "\n\non $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})" // add the current time to it data += "\n\nCrash happened at ${Date(now)}" // if lib as access to the preferences store if (prefs != null && prefsKey != null) { - // get the last Crash val lastCrash = prefs.getLong(prefsKey, 0L) @@ -198,7 +208,6 @@ class CrashHandler private constructor( // if a crash already happened just before it means the Error Activity crashed lul if (lastCrash >= now - 1000) { - // log it :D Log.e( TAG, @@ -237,7 +246,12 @@ class CrashHandler private constructor( val intent = Intent(application, activity) // add flags so that it don't use the current Application context - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) + intent.addFlags( + Intent.FLAG_ACTIVITY_CLEAR_TASK or + Intent.FLAG_ACTIVITY_NEW_TASK or + Intent.FLAG_ACTIVITY_CLEAR_TOP or + Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS + ) // add the Data String intent.putExtra("error", data) @@ -251,6 +265,4 @@ class CrashHandler private constructor( exitProcess(10) } } - - -} \ No newline at end of file +}