Skip to content

Commit 66e4edf

Browse files
authored
misc: fixed linting in lib (#6)
1 parent 5f9c01d commit 66e4edf

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CrashHandler private constructor(
3535
/**
3636
* Builder for the crash handler
3737
*/
38-
class Builder() {
38+
class Builder {
3939
private var application: Application? = null
4040
private var prefs: SharedPreferences? = null
4141
private var prefsKey: String? = null
@@ -49,7 +49,7 @@ class CrashHandler private constructor(
4949
*
5050
* note: you can get the backtrace text by using `intent.getStringExtra("error")`
5151
*
52-
* @param activity the activity class to use
52+
* @param context the context class to use
5353
*/
5454
fun withContext(context: Context): Builder {
5555
this.application = context.applicationContext as Application?
@@ -80,7 +80,6 @@ class CrashHandler private constructor(
8080
return this
8181
}
8282

83-
8483
/**
8584
* the key of the [SharedPreferences] you want to let the library handle
8685
*
@@ -129,11 +128,19 @@ class CrashHandler private constructor(
129128
* build the Crash Handler
130129
*/
131130
fun build(): CrashHandler {
132-
return CrashHandler(application, activity!!, prefs, prefsKey, errorReporterCrashKey, prefix, suffix)
131+
return CrashHandler(
132+
application,
133+
activity!!,
134+
prefs,
135+
prefsKey,
136+
errorReporterCrashKey,
137+
prefix,
138+
suffix
139+
)
133140
}
134141
}
135142

136-
private var oldHandler: Thread.UncaughtExceptionHandler? = null
143+
private var oldHandler: Thread.UncaughtExceptionHandler? = null
137144

138145
fun setup() {
139146
if (application != null) {
@@ -180,16 +187,19 @@ class CrashHandler private constructor(
180187

181188
// add device informations
182189
val deviceToReport =
183-
if (Build.DEVICE.contains(Build.MANUFACTURER)) Build.DEVICE else "${Build.MANUFACTURER} ${Build.DEVICE}"
184-
data += "\n\non $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})"
190+
if (Build.DEVICE.contains(Build.MANUFACTURER)) {
191+
Build.DEVICE
192+
} else {
193+
"${Build.MANUFACTURER} ${Build.DEVICE}"
194+
}
185195

196+
data += "\n\non $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})"
186197

187198
// add the current time to it
188199
data += "\n\nCrash happened at ${Date(now)}"
189200

190201
// if lib as access to the preferences store
191202
if (prefs != null && prefsKey != null) {
192-
193203
// get the last Crash
194204
val lastCrash = prefs.getLong(prefsKey, 0L)
195205

@@ -198,7 +208,6 @@ class CrashHandler private constructor(
198208

199209
// if a crash already happened just before it means the Error Activity crashed lul
200210
if (lastCrash >= now - 1000) {
201-
202211
// log it :D
203212
Log.e(
204213
TAG,
@@ -237,7 +246,12 @@ class CrashHandler private constructor(
237246
val intent = Intent(application, activity)
238247

239248
// add flags so that it don't use the current Application context
240-
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)
249+
intent.addFlags(
250+
Intent.FLAG_ACTIVITY_CLEAR_TASK or
251+
Intent.FLAG_ACTIVITY_NEW_TASK or
252+
Intent.FLAG_ACTIVITY_CLEAR_TOP or
253+
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
254+
)
241255

242256
// add the Data String
243257
intent.putExtra("error", data)
@@ -251,6 +265,4 @@ class CrashHandler private constructor(
251265
exitProcess(10)
252266
}
253267
}
254-
255-
256-
}
268+
}

0 commit comments

Comments
 (0)