aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/AdBlocker.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt54
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IabBinder.kt12
7 files changed, 67 insertions, 28 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/AdBlocker.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/AdBlocker.kt
index be71a913..20041370 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/AdBlocker.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/AdBlocker.kt
@@ -25,7 +25,7 @@ open class AdBlocker(val assetPath: String) {
doAsync {
val content = context.assets.open(assetPath).bufferedReader().use { it.readLines().filter { !it.startsWith("#") } }
data.addAll(content)
- L.i("Initialized adblock for $assetPath with ${data.size} hosts")
+ L.i { "Initialized adblock for $assetPath with ${data.size} hosts" }
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt
index a530df32..928f90d3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt
@@ -67,8 +67,8 @@ class AnimatedVectorDelegate(
override fun animateToggle() = animateImpl(!atStart)
private fun animateImpl(toStart: Boolean) {
- if ((atStart == toStart)) return L.d("AVD already at ${if (toStart) "start" else "end"}")
- if (avd == null) return L.d("AVD null resource")//no longer using animated vector; do not modify
+ if ((atStart == toStart)) return L.d { "AVD already at ${if (toStart) "start" else "end"}" }
+ if (avd == null) return L.d { "AVD null resource" }//no longer using animated vector; do not modify
avd?.stop()
view.setImageResource(if (toStart) avdEnd else avdStart)
animatedVectorListener?.invoke(avd!!, !toStart)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
index aab79e00..16b1d149 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
@@ -37,10 +37,10 @@ fun Context.frostDownload(uri: Uri?,
mimeType: String? = null,
contentLength: Long = 0L) {
uri ?: return
- L.d("Received download request", "Download $uri")
+ L.d { "Received download request" }
if (uri.scheme != "http" && uri.scheme != "https") {
toast(R.string.error_invalid_download)
- return L.e(string(R.string.error_invalid_download), uri.toString())
+ return L.e { "Invalid download $uri" }
}
if (!isAppEnabled(DOWNLOAD_MANAGER_PACKAGE)) {
materialDialogThemed {
@@ -70,7 +70,7 @@ fun Context.frostDownload(uri: Uri?,
dm.enqueue(request)
} catch (e: Exception) {
toast(R.string.error_generic)
- L.e(e, "Download")
+ L.e(e) { "Download" }
}
}
}
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 d5c1a6fb..b4bed5e1 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
@@ -1,6 +1,6 @@
package com.pitchedapps.frost.utils
-import ca.allanwang.kau.logging.KauLogger
+import android.util.Log
import com.crashlytics.android.Crashlytics
import com.pitchedapps.frost.BuildConfig
@@ -15,15 +15,55 @@ import com.pitchedapps.frost.BuildConfig
* Debug and Error logs must not reveal person info
* Person info logs can be marked as info or verbose
*/
-object L : KauLogger("Frost") {
+object L {
- override fun logImpl(priority: Int, message: String?, privateMessage: String?, t: Throwable?) {
+ const val TAG = "Frost"
+
+ inline fun v(message: () -> Any?) {
+ if (BuildConfig.DEBUG)
+ logImpl(Log.VERBOSE, message)
+ }
+
+ inline fun i(message: () -> Any?) {
+ logImpl(Log.INFO, message)
+ }
+
+ inline fun _i(message: () -> Any?) {
+ if (BuildConfig.DEBUG)
+ logImpl(Log.INFO, message)
+ }
+
+ inline fun d(message: () -> Any?) {
+ if (BuildConfig.DEBUG || Prefs.verboseLogging)
+ logImpl(Log.DEBUG, message)
+ }
+
+ inline fun _d(message: () -> Any?) {
+ if (BuildConfig.DEBUG)
+ logImpl(Log.DEBUG, message)
+ }
+
+ inline fun e(t: Throwable? = null, message: () -> Any?) {
+ logImpl(Log.ERROR, message, t)
+ }
+
+ fun eThrow(message: Any) {
+ val msg = message.toString()
+ logImpl(Log.ERROR, { msg }, Throwable(msg))
+ }
+
+ inline fun logImpl(priority: Int, message: () -> Any?, t: Throwable? = null) {
+ val msg = message()?.toString()
if (BuildConfig.DEBUG) {
- super.logImpl(priority, message, privateMessage, t)
+ if (t != null)
+ Log.e(TAG, msg, t)
+ else
+ Log.println(priority, TAG, msg ?: "null")
} else {
- if (message != null)
- Crashlytics.log(priority, "Frost", message)
- if (t != null) Crashlytics.logException(t)
+ if (msg != null)
+ Crashlytics.log(priority, TAG, msg)
+ if (t != null)
+ Crashlytics.logException(t)
}
}
} \ No newline at end of file
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 592dd4fc..72b2324a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -67,8 +67,7 @@ fun Activity.cookies(): ArrayList<CookieModel> {
*/
fun Context.launchWebOverlay(url: String, clazz: Class<out WebOverlayActivityBase> = WebOverlayActivity::class.java) {
val argUrl = url.formattedFbUrl
- L.v("Launch received", url)
- L.i("Launch web overlay", argUrl)
+ L.v { "Launch received: $url\nLaunch web overlay: $argUrl" }
if (argUrl.isFacebookUrl && argUrl.contains("/logout.php"))
FbCookie.logout(this)
else if (!(Prefs.linksInDefaultApp && resolveActivityForUri(Uri.parse(argUrl))))
@@ -162,7 +161,7 @@ fun frostAnswersCustom(name: String, vararg events: Pair<String, Any>) {
*/
fun Throwable?.logFrostAnswers(text: String) {
val msg = if (this == null) text else "$text: $message"
- L.e(msg)
+ L.e { msg }
frostAnswersCustom("Errors", "text" to text, "message" to (this?.message ?: "NA"))
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt
index 71c6df36..15d707a9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt
@@ -15,7 +15,7 @@ import com.pitchedapps.frost.utils.*
*/
private fun playStoreLog(text: String) {
- L.e(Throwable(text), "IAB Play Store Exception")
+ L.e(Throwable(text)) { "IAB Play Store Exception" }
}
/**
@@ -30,7 +30,7 @@ private fun Activity.playRestart() {
fun Activity?.playStoreNoLongerPro() {
Prefs.pro = false
- L.d("IAB No longer pro")
+ L.d { "IAB No longer pro" }
frostAnswers {
logPurchase(PurchaseEvent()
.putCustomAttribute("result", "no longer pro")
@@ -49,7 +49,7 @@ fun Activity?.playStoreNoLongerPro() {
fun Activity?.playStoreFoundPro() {
Prefs.pro = true
- L.d("Found pro")
+ L.d { "Found pro" }
if (this == null) return
materialDialogThemed {
title(R.string.found_pro)
@@ -62,7 +62,7 @@ fun Activity?.playStoreFoundPro() {
}
fun Activity.playStorePurchaseUnsupported() {
- L.d("Play store not found")
+ L.d { "Play store not found" }
materialDialogThemed {
title(R.string.uh_oh)
content(R.string.play_store_unsupported)
@@ -75,7 +75,7 @@ fun Activity.playStorePurchaseUnsupported() {
}
fun Activity.playStorePurchasedSuccessfully(key: String) {
- L.d("Play store purchased $key successfully")
+ L.d { "Play store purchased $key successfully" }
materialDialogThemed {
title(R.string.play_thank_you)
content(R.string.play_purchased_pro)
@@ -86,7 +86,7 @@ fun Activity.playStorePurchasedSuccessfully(key: String) {
}
fun Activity.purchaseRestored() {
- L.d("Purchase restored")
+ L.d { "Purchase restored" }
materialDialogThemed {
title(R.string.play_thank_you)
content(R.string.purchases_restored_with_pro)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IabBinder.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IabBinder.kt
index 64fc9cb8..00f99878 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IabBinder.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IabBinder.kt
@@ -58,13 +58,13 @@ abstract class IabBinder : FrostBilling {
bp = null
}
- override fun onBillingInitialized() = L.i("IAB initialized")
+ override fun onBillingInitialized() = L.i { "IAB initialized" }
- override fun onPurchaseHistoryRestored() = L.d("IAB restored")
+ override fun onPurchaseHistoryRestored() = L.d { "IAB restored" }
override fun onProductPurchased(productId: String, details: TransactionDetails?) {
bp.doAsync {
- L.i("IAB $productId purchased")
+ L.i { "IAB $productId purchased" }
val listing = weakRef.get()?.getPurchaseListingDetails(productId) ?: return@doAsync
val currency = try {
Currency.getInstance(listing.currency)
@@ -127,7 +127,7 @@ class IabSettings : IabBinder() {
override fun onBillingError(errorCode: Int, error: Throwable?) {
super.onBillingError(errorCode, error)
- L.e("Billing error $errorCode ${error?.message}")
+ L.e { "Billing error $errorCode ${error?.message}" }
}
/**
@@ -136,7 +136,7 @@ class IabSettings : IabBinder() {
override fun restorePurchases() {
bp.doAsync {
val load = weakRef.get()?.loadOwnedPurchasesFromGoogle() ?: return@doAsync
- L.d("IAB settings load from google $load")
+ L.d { "IAB settings load from google $load" }
uiThread {
if (!(weakRef.get()?.isPurchased(FROST_PRO) ?: return@uiThread)) {
if (Prefs.pro) activity.playStoreNoLongerPro()
@@ -174,7 +174,7 @@ class IabMain : IabBinder() {
restored = true
bp.doAsync {
val load = weakRef.get()?.loadOwnedPurchasesFromGoogle() ?: false
- L.d("IAB main load from google $load")
+ L.d { "IAB main load from google $load" }
onComplete {
if (!(weakRef.get()?.isPurchased(FROST_PRO) ?: false)) {
if (Prefs.pro) activity.playStoreNoLongerPro()