From 1d10d29fa94f3c22a6e59861c4e1951cdd11dd18 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 7 Aug 2021 11:32:44 -0400 Subject: [PATCH] Replace AboutLibraries activity with custom controller --- app/build.gradle.kts | 2 +- .../ui/manga/chapter/ChapterDownloadView.kt | 2 +- .../tachiyomi/ui/more/AboutController.kt | 11 +--- .../ui/more/licenses/LicensesAdapter.kt | 6 ++ .../ui/more/licenses/LicensesController.kt | 63 +++++++++++++++++++ .../ui/more/licenses/LicensesHolder.kt | 21 +++++++ .../ui/more/licenses/LicensesItem.kt | 41 ++++++++++++ .../tachiyomi/ui/reader/ReaderActivity.kt | 2 +- .../tachiyomi/ui/reader/ReaderSeekBar.kt | 2 +- .../util/system/ContextExtensions.kt | 14 +++++ .../eu/kanade/tachiyomi/widget/EmptyView.kt | 2 +- .../widget/ThemedSwipeRefreshLayout.kt | 2 +- .../materialdialogs/QuadStateTextView.kt | 2 +- .../main/res/layout/licenses_controller.xml | 7 +++ app/src/main/res/layout/licenses_item.xml | 30 +++++++++ app/src/main/res/layout/source_list_item.xml | 3 +- 16 files changed, 193 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesAdapter.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesHolder.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesItem.kt create mode 100644 app/src/main/res/layout/licenses_controller.xml create mode 100644 app/src/main/res/layout/licenses_item.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3a8aad39d..3485ca4b1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -253,7 +253,7 @@ dependencies { "standardImplementation"("com.google.firebase:firebase-analytics:19.0.0") // Licenses - implementation("com.mikepenz:aboutlibraries:${BuildPluginsVersion.ABOUTLIB_PLUGIN}") + implementation("com.mikepenz:aboutlibraries-core:${BuildPluginsVersion.ABOUTLIB_PLUGIN}") // Tests testImplementation("junit:junit:4.13.2") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDownloadView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDownloadView.kt index 25049319d..9c294a9bc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDownloadView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDownloadView.kt @@ -7,11 +7,11 @@ import android.view.LayoutInflater import android.widget.FrameLayout import androidx.core.view.isVisible import com.google.android.material.progressindicator.BaseProgressIndicator -import com.mikepenz.aboutlibraries.util.getThemeColor import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.databinding.ChapterDownloadViewBinding import eu.kanade.tachiyomi.util.system.dpToPx +import eu.kanade.tachiyomi.util.system.getThemeColor import eu.kanade.tachiyomi.util.view.setVectorCompat class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : 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 a1fe18be5..09abe7672 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 @@ -5,7 +5,6 @@ import android.os.Bundle import androidx.core.os.bundleOf import androidx.preference.PreferenceScreen import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.mikepenz.aboutlibraries.LibsBuilder import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.updater.GithubUpdateChecker @@ -14,6 +13,8 @@ import eu.kanade.tachiyomi.data.updater.UpdaterService 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.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.more.licenses.LicensesController import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.util.CrashLogUtil import eu.kanade.tachiyomi.util.lang.launchNow @@ -84,13 +85,7 @@ class AboutController : SettingsController(), NoToolbarElevationController { key = "pref_about_licenses" titleRes = R.string.licenses onClick { - LibsBuilder() - .withActivityTitle(activity!!.getString(R.string.licenses)) - .withAboutIconShown(false) - .withAboutVersionShown(false) - .withLicenseShown(true) - .withEdgeToEdge(true) - .start(activity!!) + router.pushController(LicensesController().withFadeTransaction()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesAdapter.kt new file mode 100644 index 000000000..09f748bdc --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesAdapter.kt @@ -0,0 +1,6 @@ +package eu.kanade.tachiyomi.ui.more.licenses + +import eu.davidea.flexibleadapter.FlexibleAdapter + +class LicensesAdapter(controller: LicensesController) : + FlexibleAdapter(null, controller, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt new file mode 100644 index 000000000..ba0261529 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt @@ -0,0 +1,63 @@ +package eu.kanade.tachiyomi.ui.more.licenses + +import android.view.LayoutInflater +import android.view.View +import androidx.recyclerview.widget.LinearLayoutManager +import com.mikepenz.aboutlibraries.Libs +import dev.chrisbanes.insetter.applyInsetter +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.databinding.LicensesControllerBinding +import eu.kanade.tachiyomi.ui.base.controller.BaseController +import eu.kanade.tachiyomi.util.system.openInBrowser + +class LicensesController : + BaseController(), + FlexibleAdapter.OnItemClickListener { + + private var adapter: LicensesAdapter? = null + + override fun getTitle(): String? { + return resources?.getString(R.string.licenses) + } + + override fun createBinding(inflater: LayoutInflater) = LicensesControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } + + binding.recycler.layoutManager = LinearLayoutManager(view.context) + adapter = LicensesAdapter(this) + binding.recycler.adapter = adapter + + val licenseItems = Libs(view.context).libraries + .sortedBy { it.libraryName.lowercase() } + .map { LicensesItem(it) } + adapter?.updateDataSet(licenseItems) + } + + override fun onDestroyView(view: View) { + adapter = null + super.onDestroyView(view) + } + + override fun onItemClick(view: View, position: Int): Boolean { + val adapter = adapter ?: return false + + val item = adapter.getItem(position) ?: return false + openLicenseWebsite(item) + return true + } + + private fun openLicenseWebsite(item: LicensesItem) { + val website = item.library.libraryWebsite + if (website.isNotEmpty()) { + activity?.openInBrowser(website) + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesHolder.kt new file mode 100644 index 000000000..b48d9b6bd --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesHolder.kt @@ -0,0 +1,21 @@ +package eu.kanade.tachiyomi.ui.more.licenses + +import android.annotation.SuppressLint +import android.view.View +import com.mikepenz.aboutlibraries.entity.Library +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.viewholders.FlexibleViewHolder +import eu.kanade.tachiyomi.databinding.LicensesItemBinding + +class LicensesHolder(view: View, adapter: FlexibleAdapter<*>) : + FlexibleViewHolder(view, adapter) { + + private val binding = LicensesItemBinding.bind(view) + + @SuppressLint("SetTextI18n") + fun bind(library: Library) { + binding.name.text = "${library.libraryName} ${library.libraryVersion}" + binding.artifactId.text = library.libraryArtifactId + binding.license.text = library.licenses?.joinToString { it.licenseName } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesItem.kt new file mode 100644 index 000000000..2325e5d9d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesItem.kt @@ -0,0 +1,41 @@ +package eu.kanade.tachiyomi.ui.more.licenses + +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import com.mikepenz.aboutlibraries.entity.Library +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.AbstractFlexibleItem +import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.R + +class LicensesItem(val library: Library) : AbstractFlexibleItem() { + + override fun getLayoutRes(): Int { + return R.layout.licenses_item + } + + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): LicensesHolder { + return LicensesHolder(view, adapter) + } + + override fun bindViewHolder( + adapter: FlexibleAdapter>, + holder: LicensesHolder, + position: Int, + payloads: List? + ) { + holder.bind(library) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other is LicensesItem) { + return library.hashCode() == other.hashCode() + } + return false + } + + override fun hashCode(): Int { + return library.hashCode() + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 4c13ecee4..45c059bbe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -35,7 +35,6 @@ import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.shape.MaterialShapeDrawable -import com.mikepenz.aboutlibraries.util.getThemeColor import dev.chrisbanes.insetter.applyInsetter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter @@ -62,6 +61,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.GLUtil +import eu.kanade.tachiyomi.util.system.getThemeColor import eu.kanade.tachiyomi.util.system.hasDisplayCutout import eu.kanade.tachiyomi.util.system.isNightMode import eu.kanade.tachiyomi.util.system.toast diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSeekBar.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSeekBar.kt index a1e08f4fa..4ecc3dc53 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSeekBar.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSeekBar.kt @@ -6,8 +6,8 @@ import android.graphics.Canvas import android.util.AttributeSet import android.view.MotionEvent import androidx.appcompat.widget.AppCompatSeekBar -import com.mikepenz.aboutlibraries.util.getThemeColor import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.system.getThemeColor /** * Seekbar to show current chapter progress. diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 95cb979f2..e346172eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -18,6 +18,7 @@ import android.net.ConnectivityManager import android.net.Uri import android.os.Build import android.os.PowerManager +import android.util.TypedValue import android.view.Display import android.view.View import android.view.WindowManager @@ -140,6 +141,19 @@ fun Context.hasPermission(permission: String) = ContextCompat.checkSelfPermissio return color } +@ColorInt fun Context.getThemeColor(attr: Int): Int { + val tv = TypedValue() + return if (this.theme.resolveAttribute(attr, tv, true)) { + if (tv.resourceId != 0) { + ContextCompat.getColor(this, tv.resourceId) + } else { + tv.data + } + } else { + 0 + } +} + /** * Converts to dp. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt index fb0ff44fd..9086752a4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt @@ -11,9 +11,9 @@ import androidx.annotation.StringRes import androidx.appcompat.view.ContextThemeWrapper import androidx.core.view.isVisible import com.google.android.material.button.MaterialButton -import com.mikepenz.aboutlibraries.util.getThemeColor import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.CommonViewEmptyBinding +import eu.kanade.tachiyomi.util.system.getThemeColor import kotlin.random.Random class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ThemedSwipeRefreshLayout.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ThemedSwipeRefreshLayout.kt index 81e1fcef8..e0bde8512 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ThemedSwipeRefreshLayout.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ThemedSwipeRefreshLayout.kt @@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.widget import android.content.Context import android.util.AttributeSet import androidx.swiperefreshlayout.widget.SwipeRefreshLayout -import com.mikepenz.aboutlibraries.util.getThemeColor import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.system.getThemeColor class ThemedSwipeRefreshLayout @JvmOverloads constructor( context: Context, diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateTextView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateTextView.kt index cb52fa17d..6dc81be15 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateTextView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateTextView.kt @@ -4,8 +4,8 @@ import android.content.Context import android.content.res.ColorStateList import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView -import com.mikepenz.aboutlibraries.util.getThemeColor import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.system.getThemeColor class QuadStateTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : AppCompatTextView(context, attrs) { diff --git a/app/src/main/res/layout/licenses_controller.xml b/app/src/main/res/layout/licenses_controller.xml new file mode 100644 index 000000000..56f53173f --- /dev/null +++ b/app/src/main/res/layout/licenses_controller.xml @@ -0,0 +1,7 @@ + + diff --git a/app/src/main/res/layout/licenses_item.xml b/app/src/main/res/layout/licenses_item.xml new file mode 100644 index 000000000..3f697f2e6 --- /dev/null +++ b/app/src/main/res/layout/licenses_item.xml @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/source_list_item.xml b/app/src/main/res/layout/source_list_item.xml index 1ad672622..9b9848a7b 100644 --- a/app/src/main/res/layout/source_list_item.xml +++ b/app/src/main/res/layout/source_list_item.xml @@ -6,8 +6,7 @@ android:layout_height="56dp" android:layout_gravity="center_vertical" android:background="@drawable/list_item_selector_background" - android:paddingStart="8dp" - android:paddingEnd="8dp"> + android:paddingHorizontal="8dp">