From 955f3922d1e2318ec4b4c4c7c787b3050c6da58d Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Thu, 20 Jan 2022 21:23:24 -0500 Subject: [PATCH] Shorten log recording entries --- app/build.gradle | 4 ++-- app/src/main/java/io/heckel/ntfy/db/Database.kt | 2 +- app/src/main/java/io/heckel/ntfy/log/Log.kt | 6 +++--- app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt | 8 ++++++++ app/src/main/res/values/strings.xml | 3 ++- app/src/play/java/io/heckel/ntfy/util/RateHelper.kt | 1 + 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d652514..a794e8f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,7 +70,7 @@ dependencies { // WorkManager implementation "androidx.work:work-runtime-ktx:2.6.0" - implementation 'androidx.preference:preference:1.1.1' + implementation 'androidx.preference:preference-ktx:1.1.1' // Room (SQLite) def roomVersion = "2.3.0" @@ -81,7 +81,7 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp:4.9.3' // Firebase, sigh ... (only Google Play) - playImplementation 'com.google.firebase:firebase-messaging:22.0.0' + playImplementation 'com.google.firebase:firebase-messaging:23.0.0' // RecyclerView implementation "androidx.recyclerview:recyclerview:$rootProject.recyclerViewVersion" diff --git a/app/src/main/java/io/heckel/ntfy/db/Database.kt b/app/src/main/java/io/heckel/ntfy/db/Database.kt index 94aa942..d062d1d 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Database.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Database.kt @@ -288,7 +288,7 @@ interface LogDao { @Insert suspend fun insert(entry: LogEntry) - @Query("DELETE FROM log WHERE id NOT IN (SELECT id FROM log ORDER BY id DESC LIMIT :keepCount)") + @Query("DELETE FROM log WHERE id NOT IN (SELECT id FROM log ORDER BY timestamp DESC, id DESC LIMIT :keepCount)") suspend fun prune(keepCount: Int) @Query("SELECT * FROM log ORDER BY timestamp ASC, id ASC") diff --git a/app/src/main/java/io/heckel/ntfy/log/Log.kt b/app/src/main/java/io/heckel/ntfy/log/Log.kt index 651c486..25937d8 100644 --- a/app/src/main/java/io/heckel/ntfy/log/Log.kt +++ b/app/src/main/java/io/heckel/ntfy/log/Log.kt @@ -40,7 +40,7 @@ class Log(private val logsDao: LogDao) { private fun prependDeviceInfo(s: String): String { return """ - This is a log of the ntfy Android app. The log shows up to 5,000 lines. + This is a log of the ntfy Android app. The log shows up to 2,000 lines. Server URLs (aside from ntfy.sh) and topics have been replaced with fruits 🍌🥝🍋🥥🥑🍊🍎🍑. Device info: @@ -94,7 +94,7 @@ class Log(private val logsDao: LogDao) { android.util.Log.ERROR -> "E" else -> "?" } - val tag = e.tag.format("%-23s") + val tag = e.tag.format("%23s") val prefix = "${e.timestamp} $date $level $tag" val message = if (e.exception != null) { "${e.message}\nException:\n${e.exception}" @@ -116,7 +116,7 @@ class Log(private val logsDao: LogDao) { companion object { private const val TAG = "NtfyLog" private const val PRUNE_EVERY = 100 - private const val ENTRIES_MAX = 5000 + private const val ENTRIES_MAX = 2000 private val IGNORE_TERMS = listOf("ntfy.sh") private val REPLACE_TERMS = listOf( "banana", "kiwi", "lemon", "coconut", "avocado", "orange", "apple", "peach" diff --git a/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt index 4699bf4..e8631fa 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt @@ -398,6 +398,13 @@ class SettingsActivity : AppCompatActivity() { lifecycleScope.launch(Dispatchers.IO) { Log.d(TAG, "Uploading log to $EXPORT_LOGS_UPLOAD_URL ...") val log = Log.getFormatted() + if (log.length > EXPORT_LOGS_UPLOAD_NOTIFY_SIZE_THRESHOLD) { + requireActivity().runOnUiThread { + Toast + .makeText(context, getString(R.string.settings_advanced_export_logs_uploading), Toast.LENGTH_SHORT) + .show() + } + } val gson = Gson() val request = Request.Builder() .url(EXPORT_LOGS_UPLOAD_URL) @@ -477,5 +484,6 @@ class SettingsActivity : AppCompatActivity() { private const val EXPORT_LOGS_COPY = "copy" private const val EXPORT_LOGS_UPLOAD = "upload" private const val EXPORT_LOGS_UPLOAD_URL = "https://nopaste.net/?f=json" // Run by binwiederhier; see https://github.com/binwiederhier/pcopy + private const val EXPORT_LOGS_UPLOAD_NOTIFY_SIZE_THRESHOLD = 100 * 1024 // Show "Uploading ..." if log larger than X } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 33bf4eb..5cac011 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -250,7 +250,7 @@ Apps cannot receive notifications as broadcasts RecordLogs Record logs - Logs are currently being recorded to your device. Up to 5,000 log lines are stored. + Logs are currently being recorded to your device. Up to 2,000 log lines are stored. Enable log recording, so you can share the logs later. This is useful for diagnosing issues. ExportLogs Copy/upload logs @@ -258,6 +258,7 @@ Copy to clipboard Upload to nopaste.net Logs copied to clipboard + Uploading log … URL copied to clipboard Error uploading logs: %1$s ClearLogs diff --git a/app/src/play/java/io/heckel/ntfy/util/RateHelper.kt b/app/src/play/java/io/heckel/ntfy/util/RateHelper.kt index 5a388f8..dfcca8b 100644 --- a/app/src/play/java/io/heckel/ntfy/util/RateHelper.kt +++ b/app/src/play/java/io/heckel/ntfy/util/RateHelper.kt @@ -2,6 +2,7 @@ package io.heckel.ntfy.util import android.app.Activity import com.google.android.play.core.review.ReviewManagerFactory +import io.heckel.ntfy.log.Log // Open the in-app rate dialog, see https://developer.android.com/guide/playcore/in-app-review/kotlin-java fun rateApp(activity: Activity) {