From 57911c42d176315f96c56511a51b492c819ddebb Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 26 Apr 2020 22:55:13 -0400 Subject: [PATCH] Copy debug info when tapping version --- .../ui/manga/info/MangaInfoController.kt | 36 ++++--------------- .../tachiyomi/ui/more/AboutController.kt | 20 +++++++++++ .../util/system/ActivityExtensions.kt | 23 ++++++++++++ app/src/main/res/values/strings.xml | 2 +- 4 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/system/ActivityExtensions.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index a8fa4d56c..fe8af18a8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -1,14 +1,11 @@ package eu.kanade.tachiyomi.ui.manga.info -import android.content.ClipData -import android.content.ClipboardManager import android.content.Context import android.content.Intent import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Toast import androidx.core.content.ContextCompat import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.R @@ -33,7 +30,7 @@ import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.webview.WebViewActivity -import eu.kanade.tachiyomi.util.lang.truncateCenter +import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.setChips @@ -107,7 +104,7 @@ class MangaInfoController(private val fromSource: Boolean = false) : binding.mangaFullTitle.longClicks() .onEach { - copyToClipboard(view.context.getString(R.string.title), binding.mangaFullTitle.text.toString()) + activity?.copyToClipboard(view.context.getString(R.string.title), binding.mangaFullTitle.text.toString()) } .launchIn(scope) @@ -119,7 +116,7 @@ class MangaInfoController(private val fromSource: Boolean = false) : binding.mangaArtist.longClicks() .onEach { - copyToClipboard(binding.mangaArtistLabel.text.toString(), binding.mangaArtist.text.toString()) + activity?.copyToClipboard(binding.mangaArtistLabel.text.toString(), binding.mangaArtist.text.toString()) } .launchIn(scope) @@ -131,7 +128,7 @@ class MangaInfoController(private val fromSource: Boolean = false) : binding.mangaAuthor.longClicks() .onEach { - copyToClipboard(binding.mangaAuthor.text.toString(), binding.mangaAuthor.text.toString()) + activity?.copyToClipboard(binding.mangaAuthor.text.toString(), binding.mangaAuthor.text.toString()) } .launchIn(scope) @@ -143,13 +140,13 @@ class MangaInfoController(private val fromSource: Boolean = false) : binding.mangaSummary.longClicks() .onEach { - copyToClipboard(view.context.getString(R.string.description), binding.mangaSummary.text.toString()) + activity?.copyToClipboard(view.context.getString(R.string.description), binding.mangaSummary.text.toString()) } .launchIn(scope) binding.mangaCover.longClicks() .onEach { - copyToClipboard(view.context.getString(R.string.title), presenter.manga.title) + activity?.copyToClipboard(view.context.getString(R.string.title), presenter.manga.title) } .launchIn(scope) } @@ -482,27 +479,6 @@ class MangaInfoController(private val fromSource: Boolean = false) : presenter.moveMangaToCategories(manga, categories) } - /** - * Copies a string to clipboard - * - * @param label Label to show to the user describing the content - * @param content the actual text to copy to the board - */ - private fun copyToClipboard(label: String, content: String) { - if (content.isBlank()) return - - val activity = activity ?: return - val view = view ?: return - - val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - clipboard.setPrimaryClip(ClipData.newPlainText(label, content)) - - activity.toast( - view.context.getString(R.string.copied_to_clipboard, content.truncateCenter(20)), - Toast.LENGTH_SHORT - ) - } - /** * Perform a global search using the provided query. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 4a5faa941..40da897b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.more import android.app.Dialog import android.content.Intent import android.net.Uri +import android.os.Build import android.os.Bundle import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog @@ -23,6 +24,7 @@ import eu.kanade.tachiyomi.util.preference.onClick import eu.kanade.tachiyomi.util.preference.preference import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.titleRes +import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.toast import java.text.DateFormat import java.text.ParseException @@ -55,6 +57,8 @@ class AboutController : SettingsController() { } else { "Stable ${BuildConfig.VERSION_NAME}" } + + onClick { copyDebugInfo() } } preference { titleRes = R.string.build_time @@ -186,6 +190,22 @@ class AboutController : SettingsController() { } } + private fun copyDebugInfo() { + val deviceInfo = + """ + App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR}, ${BuildConfig.COMMIT_SHA}, ${BuildConfig.VERSION_CODE}) + Android version: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT}) + Android build ID: ${Build.DISPLAY} + Device brand: ${Build.BRAND} + Device manufacturer: ${Build.MANUFACTURER} + Device name: ${Build.DEVICE} + Device model: ${Build.MODEL} + Device product name: ${Build.PRODUCT} + """.trimIndent() + + activity?.copyToClipboard("Debug information", deviceInfo) + } + private fun getFormattedBuildTime(): String { return try { val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ActivityExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ActivityExtensions.kt new file mode 100644 index 000000000..04ef89d00 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ActivityExtensions.kt @@ -0,0 +1,23 @@ +package eu.kanade.tachiyomi.util.system + +import android.app.Activity +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.lang.truncateCenter + +/** + * Copies a string to clipboard + * + * @param label Label to show to the user describing the content + * @param content the actual text to copy to the board + */ +fun Activity.copyToClipboard(label: String, content: String) { + if (content.isBlank()) return + + val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + clipboard.setPrimaryClip(ClipData.newPlainText(label, content)) + + toast(getString(R.string.copied_to_clipboard, content.truncateCenter(50))) +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 46105064b..f6f5d2833 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -428,7 +428,7 @@ Show more info Show less info Delete downloaded chapters? - %1$s copied to clipboard + Copied to clipboard:\n%1$s Source not installed: %1$s Add manga to library?