1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-15 03:07:29 +00:00

Convert CrashReporter to kotlin

This commit is contained in:
Ammar Githam 2021-07-11 21:24:35 +09:00
parent aee3fad59c
commit a3383ab477
3 changed files with 31 additions and 38 deletions

View File

@ -42,8 +42,7 @@ class InstaGrabberApplication : Application() {
private fun setupCrashReporter() { private fun setupCrashReporter() {
if (BuildConfig.DEBUG) return if (BuildConfig.DEBUG) return
CrashReporter.get(this).start() CrashReporter.getInstance(this).start()
// logCollector = new LogCollector(this);
} }
private fun setupCloseGuard() { private fun setupCloseGuard() {

View File

@ -25,7 +25,7 @@ fun showUpdateDialog(
mainThread.execute { mainThread.execute {
MaterialAlertDialogBuilder(context).apply { MaterialAlertDialogBuilder(context).apply {
setTitle(context.getString(R.string.update_available, version)) setTitle(context.getString(R.string.update_available, version))
setNeutralButton(R.string.skip_update) { dialog: DialogInterface, which: Int -> setNeutralButton(R.string.skip_update) { dialog: DialogInterface, _: Int ->
Utils.settingsHelper.putString(Constants.SKIPPED_VERSION, version) Utils.settingsHelper.putString(Constants.SKIPPED_VERSION, version)
dialog.dismiss() dialog.dismiss()
} }

View File

@ -1,46 +1,40 @@
package awaisomereport; package awaisomereport
import android.app.Application; import android.app.Application
import androidx.annotation.NonNull; class CrashReporter private constructor(application: Application) : Thread.UncaughtExceptionHandler {
public final class CrashReporter implements Thread.UncaughtExceptionHandler { private val crashHandler: CrashHandler?
private static final String TAG = CrashReporter.class.getSimpleName(); private var startAttempted = false
private var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
private static CrashReporter reporterInstance; init {
crashHandler = CrashHandler(application)
// private final File crashLogsZip;
private final CrashHandler crashHandler;
private boolean startAttempted = false;
private Thread.UncaughtExceptionHandler defaultEH;
public static CrashReporter get(final Application application) {
if (reporterInstance == null) {
reporterInstance = new CrashReporter(application);
}
return reporterInstance;
} }
private CrashReporter(@NonNull final Application application) { fun start() {
crashHandler = new CrashHandler(application); if (startAttempted) return
// this.crashLogsZip = new File(application.getExternalCacheDir(), "crash_logs.zip"); defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(this)
startAttempted = true
} }
public void start() { override fun uncaughtException(t: Thread, exception: Throwable) {
if (!startAttempted) {
defaultEH = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
startAttempted = true;
}
}
@Override
public void uncaughtException(@NonNull final Thread t, @NonNull final Throwable exception) {
if (crashHandler == null) { if (crashHandler == null) {
defaultEH.uncaughtException(t, exception); defaultExceptionHandler?.uncaughtException(t, exception)
return; return
}
crashHandler.uncaughtException(t, exception, defaultExceptionHandler ?: return)
}
companion object {
@Volatile
private var INSTANCE: CrashReporter? = null
fun getInstance(application: Application): CrashReporter {
return INSTANCE ?: synchronized(this) {
CrashReporter(application).also { INSTANCE = it }
}
} }
crashHandler.uncaughtException(t, exception, defaultEH);
} }
} }