Replace AboutLibraries activity with custom controller

This commit is contained in:
arkon 2021-08-07 11:32:44 -04:00
parent 9b00e91773
commit 1d10d29fa9
16 changed files with 193 additions and 17 deletions

View File

@ -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")

View File

@ -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) :

View File

@ -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())
}
}

View File

@ -0,0 +1,6 @@
package eu.kanade.tachiyomi.ui.more.licenses
import eu.davidea.flexibleadapter.FlexibleAdapter
class LicensesAdapter(controller: LicensesController) :
FlexibleAdapter<LicensesItem>(null, controller, true)

View File

@ -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<LicensesControllerBinding>(),
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)
}
}
}

View File

@ -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 }
}
}

View File

@ -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<LicensesHolder>() {
override fun getLayoutRes(): Int {
return R.layout.licenses_item
}
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): LicensesHolder {
return LicensesHolder(view, adapter)
}
override fun bindViewHolder(
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
holder: LicensesHolder,
position: Int,
payloads: List<Any?>?
) {
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()
}
}

View File

@ -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

View File

@ -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.

View File

@ -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.
*/

View File

@ -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) :

View File

@ -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,

View File

@ -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) {

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/licenses_item" />

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_selector_background"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/name"
style="@style/TextAppearance.Regular.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Library name" />
<TextView
android:id="@+id/artifact_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="artifact:id:1.0" />
<TextView
android:id="@+id/license"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Apache Version 2.0" />
</LinearLayout>

View File

@ -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">
<ImageView
android:id="@+id/thumbnail"