diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
3 files changed, 46 insertions, 16 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt index 7c8c1895..dd8cf594 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt @@ -41,28 +41,40 @@ object L : KauLogger("Frost", { } inline fun _i(message: () -> Any?) { - if (BuildConfig.DEBUG) + if (BuildConfig.DEBUG) { i(message) + } } inline fun _d(message: () -> Any?) { - if (BuildConfig.DEBUG) + if (BuildConfig.DEBUG) { d(message) + } } inline fun _e(e: Throwable?, message: () -> Any?) { - if (BuildConfig.DEBUG) + if (BuildConfig.DEBUG) { e(e, message) + } } + var bugsnagInit = false + override fun logImpl(priority: Int, message: String?, t: Throwable?) { - if (BuildConfig.DEBUG) + /* + * Debug flag is constant and should help with optimization + * bugsnagInit is changed per application and helps prevent crashes (if calling pre init) + * analytics is changed by the user, and may be toggled throughout the app + */ + if (BuildConfig.DEBUG || !bugsnagInit || !Prefs.analytics) { super.logImpl(priority, message, t) - else { - if (message != null) + } else { + if (message != null) { Bugsnag.leaveBreadcrumb(message) - if (t != null) + } + if (t != null) { Bugsnag.notify(t) + } } } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index c10a95ce..0885109a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -22,6 +22,8 @@ import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.utils.colorToForeground import ca.allanwang.kau.utils.isColorVisibleOn import ca.allanwang.kau.utils.withAlpha +import com.bugsnag.android.Bugsnag +import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.enums.FACEBOOK_BLUE import com.pitchedapps.frost.enums.FeedSort import com.pitchedapps.frost.enums.MainActivityLayout @@ -41,7 +43,9 @@ object Prefs : KPref() { var prevId: Long by kpref("prev_id", -1L) - var theme: Int by kpref("theme", 0, postSetter = { _: Int -> loader.invalidate() }) + var theme: Int by kpref("theme", 0) { _: Int -> + loader.invalidate() + } var customTextColor: Int by kpref("color_text", 0xffeceff1.toInt()) @@ -153,7 +157,17 @@ object Prefs : KPref() { var verboseLogging: Boolean by kpref("verbose_logging", false) - var analytics: Boolean by kpref("analytics", true) + var analytics: Boolean by kpref("analytics", false) { + if (!BuildConfig.DEBUG) { + if (it) { + Bugsnag.setAutoCaptureSessions(true) + Bugsnag.enableExceptionHandler() + } else { + Bugsnag.setAutoCaptureSessions(false) + Bugsnag.disableExceptionHandler() + } + } + } var biometricsEnabled: Boolean by kpref("biometrics_enabled", false) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index 0574aeae..8544aac3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -137,7 +137,8 @@ private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlay fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl<WebOverlayActivity>(url) -fun Context.launchWebOverlayDesktop(url: String) = launchWebOverlayImpl<WebOverlayDesktopActivity>(url) +fun Context.launchWebOverlayDesktop(url: String) = + launchWebOverlayImpl<WebOverlayDesktopActivity>(url) private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation( this, @@ -154,9 +155,11 @@ fun Context.launchImageActivity(imageUrl: String, text: String? = null, cookie: } fun Activity.launchTabCustomizerActivity() { - startActivityForResult<TabCustomizerActivity>(SettingsActivity.ACTIVITY_REQUEST_TABS, bundleBuilder = { - with(fadeBundle()) - }) + startActivityForResult<TabCustomizerActivity>( + SettingsActivity.ACTIVITY_REQUEST_TABS, + bundleBuilder = { + with(fadeBundle()) + }) } fun WebOverlayActivity.url(): String { @@ -165,11 +168,12 @@ fun WebOverlayActivity.url(): String { fun Activity.setFrostTheme(forceTransparent: Boolean = false) { val isTransparent = - (Color.alpha(Prefs.bgColor) != 255) || (Color.alpha(Prefs.headerColor) != 255) || forceTransparent - if (Prefs.bgColor.isColorDark) + forceTransparent || (Color.alpha(Prefs.bgColor) != 255) || (Color.alpha(Prefs.headerColor) != 255) + if (Prefs.bgColor.isColorDark) { setTheme(if (isTransparent) R.style.FrostTheme_Transparent else R.style.FrostTheme) - else + } else { setTheme(if (isTransparent) R.style.FrostTheme_Light_Transparent else R.style.FrostTheme_Light) + } } class ActivityThemeUtils { |