Don't log tryOrNull errors unnecessarily

This commit is contained in:
Moez Bhatti
2018-07-02 18:01:01 -04:00
parent 95b80ad408
commit 9cea675bd8
4 changed files with 10 additions and 7 deletions
@@ -72,10 +72,10 @@ class ExternalBlockingManagerImpl @Inject constructor(
// If either version of Should I Answer? is installed and SIA is enabled, build the
// intent to request a rating
if (prefs.sia.get()) {
intent = tryOrNull {
intent = tryOrNull(false) {
context.packageManager.getApplicationInfo("org.mistergroup.shouldianswerpersonal", 0).enabled
Intent("org.mistergroup.shouldianswerpersonal.PublicService").setPackage("org.mistergroup.shouldianswerpersonal")
} ?: tryOrNull {
} ?: tryOrNull(false) {
context.packageManager.getApplicationInfo("org.mistergroup.muzutozvednout", 0).enabled
Intent("org.mistergroup.muzutozvednout.PublicService").setPackage("org.mistergroup.muzutozvednout")
}
@@ -163,7 +163,7 @@ class SyncRepositoryImpl @Inject constructor(
}
// If we don't have a valid id, return null
val id = tryOrNull { ContentUris.parseId(uri) } ?: return null
val id = tryOrNull(false) { ContentUris.parseId(uri) } ?: return null
// Check if the message already exists, so we can reuse the id
val existingId = Realm.getDefaultInstance().use { realm ->
@@ -20,11 +20,14 @@ package com.moez.QKSMS.util
import timber.log.Timber
fun <T> tryOrNull(body: () -> T?): T? {
fun <T> tryOrNull(logOnError: Boolean = true, body: () -> T?): T? {
return try {
body()
} catch (e: Exception) {
Timber.w(e)
if (logOnError) {
Timber.w(e)
}
null
}
}
@@ -28,11 +28,11 @@ import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.telephony.PhoneNumberUtils
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.RemoteInput
import androidx.core.app.TaskStackBuilder
import android.telephony.PhoneNumberUtils
import com.moez.QKSMS.R
import com.moez.QKSMS.common.util.extensions.dpToPx
import com.moez.QKSMS.extensions.isImage
@@ -165,7 +165,7 @@ class NotificationManagerImpl @Inject constructor(
.load(PhoneNumberUtils.stripSeparators(address))
.submit(64.dpToPx(context), 64.dpToPx(context))
}
?.let { futureGet -> tryOrNull { futureGet.get() } }
?.let { futureGet -> tryOrNull(false) { futureGet.get() } }
when (prefs.notificationPreviews(threadId).get()) {
Preferences.NOTIFICATION_PREVIEWS_ALL -> {