From 26089140fb58086d6325f6af4b25483560f6dff6 Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX Date: Wed, 20 Sep 2023 10:50:32 -0400 Subject: [PATCH] Deter reporting the same log over and over --- .../tagmo/eightbit/io/Debug.kt | 36 +++++++++++++++---- .../tagmo/nfctech/NfcActivity.kt | 2 +- .../hiddenramblings/tagmo/nfctech/ScanTag.kt | 2 +- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/hiddenramblings/tagmo/eightbit/io/Debug.kt b/app/src/main/java/com/hiddenramblings/tagmo/eightbit/io/Debug.kt index 3e52708e9..8506e4490 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/eightbit/io/Debug.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/eightbit/io/Debug.kt @@ -40,6 +40,8 @@ object Debug { get() = TagMo.appContext private val mPrefs = Preferences(context) + private var lastBugReport = 0L + private val manufacturer: String by lazy { try { @SuppressLint("PrivateApi") @@ -229,7 +231,7 @@ object Debug { } private fun submitLogcat(context: Context, logText: String) { - if (BuildConfig.WEAR_OS) return + lastBugReport = System.currentTimeMillis() val subject = context.getString(R.string.git_issue_title, BuildConfig.COMMIT) val selectionTitle = if (logText.contains("AndroidRuntime")) context.getString(R.string.logcat_crash) @@ -254,15 +256,19 @@ object Debug { } } + private fun setClipboard(context: Context, subject: String, logText: String) { + with (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) { + setPrimaryClip(ClipData.newPlainText(subject, logText)) + } + } + @JvmStatic - fun setClipboardException(context: Context, exception: String?) { + fun clipException(context: Context, exception: String?) { if (BuildConfig.WEAR_OS) return val log = getDeviceProfile(context) log.append(separator).append(separator).append(exception) val subject = context.getString(R.string.git_issue_title, BuildConfig.COMMIT) - with (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) { - setPrimaryClip(ClipData.newPlainText(subject, log.toString())) - } + setClipboard(context, subject, log.toString()) } @JvmStatic @@ -294,9 +300,25 @@ object Debug { log.setLength(0) withContext(Dispatchers.Main) { val subject = context.getString(R.string.git_issue_title, BuildConfig.COMMIT) - with (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) { - setPrimaryClip(ClipData.newPlainText(subject, logText)) + if (System.currentTimeMillis() < lastBugReport + 900000) { + if (context is Activity) { + IconifiedSnackbar(context).buildSnackbar( + R.string.duplicate_reports, + R.drawable.ic_support_required_menu, + Snackbar.LENGTH_LONG + ).also { status -> + status.addCallback(object: Snackbar.Callback() { + override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { + setClipboard(context, subject, logText) + } + }) + status.show() + } + } + return@withContext } + setClipboard(context, subject, logText) + if (BuildConfig.WEAR_OS) return@withContext if (context is Activity) { IconifiedSnackbar(context).buildSnackbar( subject, diff --git a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt index bba5b3b9f..2771ebfc9 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt @@ -606,7 +606,7 @@ class NfcActivity : AppCompatActivity() { e.printStackTrace(PrintWriter(this)) } try { - Debug.setClipboardException(this@NfcActivity, exception.toString()) + Debug.clipException(this@NfcActivity, exception.toString()) } catch (ignored: Exception) { } } diff --git a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/ScanTag.kt b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/ScanTag.kt index e34fe1ca5..fccf02f0b 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/ScanTag.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/ScanTag.kt @@ -179,7 +179,7 @@ class ScanTag { e.printStackTrace(PrintWriter(this)) } try { - Debug.setClipboardException(activity, exception.toString()) + Debug.clipException(activity, exception.toString()) } catch (ignored: Exception) { } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9871147aa..e86dffa57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -488,4 +488,6 @@ GitHub and Google Play builds are now universal.\nPlease click continue to resolve installation conflicts. No statues were harmed in making this product. + + Duplicate bug reports are not required \ No newline at end of file