From 551e1f1f5715b17bea2f1a0d7b3b3884100e5b16 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Mon, 20 Apr 2020 16:13:49 -0700 Subject: [PATCH] Update dependencies This includes a migration to Firebase Crashlytics with Google Analytics instead of Fabric Crashlytics which has been deprecated and is on the way out. --- app/build.gradle | 10 ++++++---- .../simplemarkdown/MarkdownApplication.kt | 3 +-- .../simplemarkdown/utility/ErrorHandler.kt | 18 ++++++------------ .../view/activity/MainActivity.kt | 12 ++++++++++++ .../view/activity/SupportActivity.kt | 1 + build.gradle | 1 + 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 26996b5..06acb88 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'jacoco' +apply plugin: 'com.google.firebase.crashlytics' def keystoreProperties = new Properties() try { @@ -40,8 +41,8 @@ android { applicationId "com.wbrawner.simplemarkdown" minSdkVersion 21 targetSdkVersion 29 - versionCode 24 - versionName "0.8.2" + versionCode 25 + versionName "0.8.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" buildConfigField "boolean", "ENABLE_CUSTOM_CSS", "false" } @@ -96,9 +97,10 @@ dependencies { implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' implementation 'com.commonsware.cwac:anddown:0.3.0' - implementation 'com.google.firebase:firebase-core:17.3.0' implementation 'com.android.billingclient:billing:2.2.0' - implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' + implementation 'com.google.firebase:firebase-core:17.3.0' + implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta04' + implementation 'com.google.firebase:firebase-analytics:17.3.0' implementation "androidx.core:core-ktx:1.2.0" implementation 'androidx.browser:browser:1.2.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/MarkdownApplication.kt b/app/src/main/java/com/wbrawner/simplemarkdown/MarkdownApplication.kt index 169640c..9de53cc 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/MarkdownApplication.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/MarkdownApplication.kt @@ -14,12 +14,11 @@ class MarkdownApplication : Application() { if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder() .detectAll() - .penaltyDeath() + .penaltyLog() .build()) StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() - .penaltyDeath() .build()) } super.onCreate() diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/utility/ErrorHandler.kt b/app/src/main/java/com/wbrawner/simplemarkdown/utility/ErrorHandler.kt index 63f5e43..4ee20dd 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/utility/ErrorHandler.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/utility/ErrorHandler.kt @@ -1,24 +1,19 @@ package com.wbrawner.simplemarkdown.utility -import android.content.Context import android.util.Log -import com.crashlytics.android.Crashlytics +import com.google.firebase.crashlytics.FirebaseCrashlytics import com.wbrawner.simplemarkdown.BuildConfig -import io.fabric.sdk.android.Fabric -import java.util.concurrent.atomic.AtomicBoolean interface ErrorHandler { - fun init(context: Context) + fun enable(enable: Boolean) fun reportException(t: Throwable, message: String? = null) } class CrashlyticsErrorHandler : ErrorHandler { - private val isInitialized = AtomicBoolean(false) + private val crashlytics = FirebaseCrashlytics.getInstance() - override fun init(context: Context) { - if (!isInitialized.getAndSet(true)) { - Fabric.with(context, Crashlytics()) - } + override fun enable(enable: Boolean) { + crashlytics.setCrashlyticsCollectionEnabled(enable) } override fun reportException(t: Throwable, message: String?) { @@ -27,7 +22,6 @@ class CrashlyticsErrorHandler : ErrorHandler { Log.e("CrashlyticsErrorHandler", "Caught exception: $message", t) return } - if (!isInitialized.get()) return - Crashlytics.logException(t) + crashlytics.recordException(t) } } \ No newline at end of file diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt index 78a6825..ba7a2ba 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt @@ -20,6 +20,7 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.lifecycle.Observer import androidx.preference.PreferenceManager +import com.wbrawner.simplemarkdown.MarkdownApplication import com.wbrawner.simplemarkdown.R import com.wbrawner.simplemarkdown.utility.hideKeyboard import com.wbrawner.simplemarkdown.view.adapter.EditPagerAdapter @@ -69,6 +70,17 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes } } + override fun onStart() { + super.onStart() + launch { + withContext(Dispatchers.IO) { + val enableErrorReports = PreferenceManager.getDefaultSharedPreferences(this@MainActivity) + .getBoolean(getString(R.string.error_reports_enabled), true) + (application as MarkdownApplication).errorHandler.enable(enableErrorReports) + } + } + } + override fun onUserLeaveHint() { super.onUserLeaveHint() launch { diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SupportActivity.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SupportActivity.kt index 282227d..45fa84c 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SupportActivity.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SupportActivity.kt @@ -33,6 +33,7 @@ class SupportActivity : AppCompatActivity(), BillingClientStateListener, Purchas supportActionBar?.setDisplayHomeAsUpEnabled(true) billingClient = BillingClient.newBuilder(applicationContext) .setListener(this) + .enablePendingPurchases() .build() billingClient.startConnection(this) githubButton.setOnClickListener { diff --git a/build.gradle b/build.gradle index 239791a..f3727a0 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.6.3' classpath 'com.google.gms:google-services:4.3.3' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta04' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }