Skip to content

Commit

Permalink
Deter reporting the same log over and over
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Sep 20, 2023
1 parent 1cfa319 commit 2608914
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
36 changes: 29 additions & 7 deletions app/src/main/java/com/hiddenramblings/tagmo/eightbit/io/Debug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class ScanTag {
e.printStackTrace(PrintWriter(this))
}
try {
Debug.setClipboardException(activity, exception.toString())
Debug.clipException(activity, exception.toString())
} catch (ignored: Exception) { }
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,6 @@
<string name="conversion_message">GitHub and Google Play builds are now universal.\nPlease click continue to resolve installation conflicts.</string>

<string name="disclaimer_general">No statues were harmed in making this product.</string>

<string name="duplicate_reports">Duplicate bug reports are not required</string>
</resources>

0 comments on commit 2608914

Please sign in to comment.