From 68286b2accbdfe6fb111f17f38311e41bd4dfdb7 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 19 May 2021 22:55:27 -0400 Subject: [PATCH] Tweak About view, make links actually clickable --- .../tachiyomi/ui/more/AboutController.kt | 43 +++++-------------- .../tachiyomi/ui/more/AboutLinksPreference.kt | 27 ++++++++++++ .../tachiyomi/ui/more/MoreController.kt | 11 ----- .../tachiyomi/ui/more/MoreHeaderPreference.kt | 15 +++++++ 4 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutLinksPreference.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreHeaderPreference.kt 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 c82ef5095c..24b7191113 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 @@ -1,13 +1,9 @@ package eu.kanade.tachiyomi.ui.more import android.app.Dialog -import android.content.Context import android.os.Bundle -import android.util.AttributeSet import androidx.core.os.bundleOf -import androidx.preference.Preference import androidx.preference.PreferenceScreen -import androidx.preference.PreferenceViewHolder import com.afollestad.materialdialogs.MaterialDialog import com.mikepenz.aboutlibraries.LibsBuilder import eu.kanade.tachiyomi.BuildConfig @@ -16,6 +12,7 @@ import eu.kanade.tachiyomi.data.updater.UpdateResult import eu.kanade.tachiyomi.data.updater.UpdaterService import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.openInBrowser import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.util.CrashLogUtil @@ -27,6 +24,7 @@ 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.openInBrowser import eu.kanade.tachiyomi.util.system.toast import timber.log.Timber import java.text.DateFormat @@ -35,7 +33,7 @@ import java.text.SimpleDateFormat import java.util.Locale import java.util.TimeZone -class AboutController : SettingsController() { +class AboutController : SettingsController(), NoToolbarElevationController { private val updateChecker by lazy { GithubUpdateChecker() } @@ -46,6 +44,8 @@ class AboutController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_about + add(MoreHeaderPreference(context)) + add(AboutLinksPreference(context)) preferenceCategory { @@ -58,7 +58,12 @@ class AboutController : SettingsController() { "Stable ${BuildConfig.VERSION_NAME} (${getFormattedBuildTime()})" } - onClick { copyDebugInfo() } + onClick { + activity?.let { + val deviceInfo = CrashLogUtil(it).getDebugInfo() + it.copyToClipboard("Debug information", deviceInfo) + } + } } if (isUpdaterEnabled) { preference { @@ -153,13 +158,6 @@ class AboutController : SettingsController() { } } - private fun copyDebugInfo() { - activity?.let { - val deviceInfo = CrashLogUtil(it).getDebugInfo() - activity?.copyToClipboard("Debug information", deviceInfo) - } - } - private fun getFormattedBuildTime(): String { return try { val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US) @@ -179,22 +177,3 @@ class AboutController : SettingsController() { } } } - -private class AboutLinksPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - Preference(context, attrs) { - - init { - layoutResource = R.layout.pref_about_links - isSelectable = false - } - - override fun onBindViewHolder(holder: PreferenceViewHolder) { - super.onBindViewHolder(holder) - - // holder.findViewById(R.id.btn_website).setOnClickListener { openInBrowser("https://tachiyomi.org") } - // holder.findViewById(R.id.btn_discord).setOnClickListener { openInBrowser("https://discord.gg/tachiyomi") } - // holder.findViewById(R.id.btn_twitter).setOnClickListener { openInBrowser("https://twitter.com/tachiyomiorg") } - // holder.findViewById(R.id.btn_facebook).setOnClickListener { openInBrowser("https://facebook.com/tachiyomiorg") } - // holder.findViewById(R.id.btn_github).setOnClickListener { openInBrowser("https://github.com/tachiyomiorg") } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutLinksPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutLinksPreference.kt new file mode 100644 index 0000000000..02a99e93b1 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutLinksPreference.kt @@ -0,0 +1,27 @@ +package eu.kanade.tachiyomi.ui.more + +import android.content.Context +import android.util.AttributeSet +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.system.openInBrowser + +class AboutLinksPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + Preference(context, attrs) { + + init { + layoutResource = R.layout.pref_about_links + isSelectable = false + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + + holder.findViewById(R.id.btn_website).setOnClickListener { context.openInBrowser("https://tachiyomi.org") } + holder.findViewById(R.id.btn_discord).setOnClickListener { context.openInBrowser("https://discord.gg/tachiyomi") } + holder.findViewById(R.id.btn_twitter).setOnClickListener { context.openInBrowser("https://twitter.com/tachiyomiorg") } + holder.findViewById(R.id.btn_facebook).setOnClickListener { context.openInBrowser("https://facebook.com/tachiyomiorg") } + holder.findViewById(R.id.btn_github).setOnClickListener { context.openInBrowser("https://github.com/tachiyomiorg") } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index c44d844554..d5a0b59bfe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -1,8 +1,6 @@ package eu.kanade.tachiyomi.ui.more -import android.content.Context import android.os.Bundle -import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -168,15 +166,6 @@ class MoreController : return subscribe(onNext).also { untilDestroySubscriptions.add(it) } } - private class MoreHeaderPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - Preference(context, attrs) { - - init { - layoutResource = R.layout.pref_more_header - isSelectable = false - } - } - companion object { const val URL_HELP = "https://tachiyomi.org/help/" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreHeaderPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreHeaderPreference.kt new file mode 100644 index 0000000000..2cef50320c --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreHeaderPreference.kt @@ -0,0 +1,15 @@ +package eu.kanade.tachiyomi.ui.more + +import android.content.Context +import android.util.AttributeSet +import androidx.preference.Preference +import eu.kanade.tachiyomi.R + +class MoreHeaderPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + Preference(context, attrs) { + + init { + layoutResource = R.layout.pref_more_header + isSelectable = false + } +}