From 1b4d9fc4e94eaa9d2575ffcf04811f8a23915b44 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 23 Apr 2022 10:52:19 -0400 Subject: [PATCH] Migrate open source licenses screen to Compose --- app/build.gradle.kts | 4 +- .../ui/base/controller/ComposeController.kt | 24 ++++++ .../tachiyomi/ui/more/AboutController.kt | 1 - .../tachiyomi/ui/more/LicensesController.kt | 35 +++++++++ .../ui/more/licenses/LicensesAdapter.kt | 6 -- .../ui/more/licenses/LicensesController.kt | 75 ------------------- .../ui/more/licenses/LicensesHolder.kt | 21 ------ .../ui/more/licenses/LicensesItem.kt | 41 ---------- .../main/res/layout/licenses_controller.xml | 21 ------ app/src/main/res/layout/licenses_item.xml | 34 --------- build.gradle.kts | 2 +- gradle/libs.versions.toml | 6 +- 12 files changed, 64 insertions(+), 206 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/LicensesController.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesAdapter.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesHolder.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesItem.kt delete mode 100644 app/src/main/res/layout/licenses_controller.xml delete mode 100644 app/src/main/res/layout/licenses_item.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 075367387..7578d6bea 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -239,6 +239,7 @@ dependencies { } implementation(libs.insetter) implementation(libs.markwon) + implementation(libs.aboutLibraries.compose) // Conductor implementation(libs.bundles.conductor) @@ -253,9 +254,6 @@ dependencies { implementation(libs.acra.http) "standardImplementation"(libs.firebase.analytics) - // Licenses - implementation(libs.aboutlibraries.core) - // Shizuku implementation(libs.bundles.shizuku) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt index 24c6719a6..9f24590eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt @@ -7,6 +7,9 @@ import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.databinding.ComposeControllerBinding import nucleus.presenter.Presenter +/** + * Compose controller with a Nucleus presenter. + */ abstract class ComposeController

> : NucleusController() { override fun createBinding(inflater: LayoutInflater): ComposeControllerBinding = @@ -24,3 +27,24 @@ abstract class ComposeController

> : NucleusController() { + + override fun createBinding(inflater: LayoutInflater): ComposeControllerBinding = + ComposeControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + + binding.root.setContent { + TachiyomiTheme { + ComposeContent() + } + } + } + + @Composable abstract fun ComposeContent() +} 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 f2d42c376..f9b96a0e0 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 @@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.data.updater.RELEASE_URL import eu.kanade.tachiyomi.ui.base.controller.NoAppBarElevationController 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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/LicensesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/LicensesController.kt new file mode 100644 index 000000000..cf1661d6a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/LicensesController.kt @@ -0,0 +1,35 @@ +package eu.kanade.tachiyomi.ui.more + +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.contentColorFor +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.input.nestedscroll.nestedScroll +import androidx.compose.ui.platform.rememberNestedScrollInteropConnection +import com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer +import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults.libraryColors +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.base.controller.BasicComposeController + +class LicensesController : BasicComposeController() { + + override fun getTitle() = resources?.getString(R.string.licenses) + + @Composable + override fun ComposeContent() { + val nestedScrollInterop = rememberNestedScrollInteropConnection(binding.root) + + LibrariesContainer( + modifier = Modifier + .fillMaxSize() + .nestedScroll(nestedScrollInterop), + colors = libraryColors( + backgroundColor = MaterialTheme.colorScheme.background, + contentColor = contentColorFor(MaterialTheme.colorScheme.background), + badgeBackgroundColor = MaterialTheme.colorScheme.primary, + badgeContentColor = contentColorFor(MaterialTheme.colorScheme.primary), + ), + ) + } +} 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 deleted file mode 100644 index 09f748bdc..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesAdapter.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index e235c27ad..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt +++ /dev/null @@ -1,75 +0,0 @@ -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.lang.launchUI -import eu.kanade.tachiyomi.util.lang.withIOContext -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.progress.applyInsetter { - type(navigationBars = true) { - padding() - } - } - - binding.recycler.layoutManager = LinearLayoutManager(view.context) - adapter = LicensesAdapter(this) - binding.recycler.adapter = adapter - - viewScope.launchUI { - val licenseItems = withIOContext { - Libs(view.context).libraries - .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.libraryName })) - .map { LicensesItem(it) } - } - binding.progress.hide() - 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 deleted file mode 100644 index b48d9b6bd..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesHolder.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index fc5a02722..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesItem.kt +++ /dev/null @@ -1,41 +0,0 @@ -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/res/layout/licenses_controller.xml b/app/src/main/res/layout/licenses_controller.xml deleted file mode 100644 index 0ae6429e9..000000000 --- a/app/src/main/res/layout/licenses_controller.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/licenses_item.xml b/app/src/main/res/layout/licenses_item.xml deleted file mode 100644 index 5cb22d156..000000000 --- a/app/src/main/res/layout/licenses_item.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - diff --git a/build.gradle.kts b/build.gradle.kts index efb20b7e9..ee9c89fcf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ buildscript { dependencies { classpath(libs.android.shortcut.gradle) classpath(libs.google.services.gradle) - classpath(libs.aboutlibraries.gradle) + classpath(libs.aboutLibraries.gradle) classpath(kotlinx.serialization.gradle) classpath("com.squareup.sqldelight:gradle-plugin:1.5.3") } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3f332967a..1726326a1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -aboutlib_version = "8.9.4" +aboutlib_version = "10.1.0" okhttp_version = "4.9.3" nucleus_version = "3.0.0" coil_version = "2.0.0-rc03" @@ -83,8 +83,8 @@ logcat = "com.squareup.logcat:logcat:0.1" acra-http = "ch.acra:acra-http:5.9.1" firebase-analytics = "com.google.firebase:firebase-analytics-ktx:20.0.2" -aboutlibraries-core = { module = "com.mikepenz:aboutlibraries-core", version.ref = "aboutlib_version" } -aboutlibraries-gradle = { module = "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin", version.ref = "aboutlib_version" } +aboutLibraries-gradle = { module = "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin", version.ref = "aboutlib_version" } +aboutLibraries-compose = { module = "com.mikepenz:aboutlibraries-compose", version.ref ="aboutlib_version" } shizuku-api = { module = "dev.rikka.shizuku:api", version.ref = "shizuku_version" } shizuku-provider = { module = "dev.rikka.shizuku:provider", version.ref = "shizuku_version" }