Truly binded all library views

This commit is contained in:
Jays2Kings 2021-03-29 03:15:03 -04:00
parent 0a36245177
commit e2362a2f72
8 changed files with 69 additions and 48 deletions

View File

@ -7,8 +7,6 @@ import android.view.MotionEvent
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import eu.kanade.tachiyomi.util.view.hide import eu.kanade.tachiyomi.util.view.hide
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import kotlinx.android.synthetic.main.filter_bottom_sheet.*
import kotlinx.android.synthetic.main.library_list_controller.*
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.sign import kotlin.math.sign
@ -27,7 +25,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
): Boolean { ): Boolean {
val distance = ((e1?.rawX ?: 0f) - (e2?.rawX ?: 0f)) / 50 val distance = ((e1?.rawX ?: 0f) - (e2?.rawX ?: 0f)) / 50
val poa = 1.7f val poa = 1.7f
controller.category_hopper_frame.translationX = abs(distance).pow(poa) * -sign(distance) controller.binding.categoryHopperFrame.translationX = abs(distance).pow(poa) * -sign(distance)
return super.onScroll(e1, e2, distanceX, distanceY) return super.onScroll(e1, e2, distanceX, distanceY)
} }
@ -45,10 +43,11 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
var result = false var result = false
val diffY = e2.y - e1.y val diffY = e2.y - e1.y
val diffX = e2.x - e1.x val diffX = e2.x - e1.x
val animator = controller.category_hopper_frame.animate().setDuration(150L) val hopperFrame = controller.binding.categoryHopperFrame
val animator = controller.binding.categoryHopperFrame.animate().setDuration(150L)
animator.translationX(0f) animator.translationX(0f)
animator.withEndAction { animator.withEndAction {
controller.category_hopper_frame.translationX = 0f hopperFrame.translationX = 0f
} }
if (abs(diffX) <= abs(diffY) && if (abs(diffX) <= abs(diffY) &&
abs(diffY) > SWIPE_THRESHOLD && abs(diffY) > SWIPE_THRESHOLD &&
@ -63,13 +62,13 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
abs(diffX) > SWIPE_THRESHOLD * 5 && abs(diffX) > SWIPE_THRESHOLD * 5 &&
abs(velocityX) > SWIPE_VELOCITY_THRESHOLD abs(velocityX) > SWIPE_VELOCITY_THRESHOLD
) { ) {
val hopperGravity = (controller.category_hopper_frame.layoutParams as CoordinatorLayout.LayoutParams).gravity val hopperGravity = (controller.binding.categoryHopperFrame.layoutParams as CoordinatorLayout.LayoutParams).gravity
if (diffX <= 0) { if (diffX <= 0) {
animator.translationX( animator.translationX(
if (hopperGravity == Gravity.TOP or Gravity.LEFT) 0f if (hopperGravity == Gravity.TOP or Gravity.LEFT) 0f
else (-(controller.view!!.width - controller.category_hopper_frame.width) / 2).toFloat() else (-(controller.view!!.width - controller.binding.categoryHopperFrame.width) / 2).toFloat()
).withEndAction { ).withEndAction {
controller.category_hopper_frame?.updateLayoutParams<CoordinatorLayout.LayoutParams> { hopperFrame.updateLayoutParams<CoordinatorLayout.LayoutParams> {
gravity = gravity =
Gravity.TOP or ( Gravity.TOP or (
if (gravity == Gravity.TOP or Gravity.RIGHT) { if (gravity == Gravity.TOP or Gravity.RIGHT) {
@ -86,9 +85,9 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
} else { } else {
animator.translationX( animator.translationX(
if (hopperGravity == Gravity.TOP or Gravity.RIGHT) 0f if (hopperGravity == Gravity.TOP or Gravity.RIGHT) 0f
else ((controller.view!!.width - controller.category_hopper_frame.width) / 2).toFloat() else ((controller.view!!.width - hopperFrame.width) / 2).toFloat()
).withEndAction { ).withEndAction {
controller.category_hopper_frame?.updateLayoutParams<CoordinatorLayout.LayoutParams> { hopperFrame.updateLayoutParams<CoordinatorLayout.LayoutParams> {
gravity = gravity =
Gravity.TOP or ( Gravity.TOP or (
if (gravity == Gravity.TOP or Gravity.LEFT) { if (gravity == Gravity.TOP or Gravity.LEFT) {
@ -114,7 +113,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
controller.preferences.shownHopperSwipeTutorial().set(true) controller.preferences.shownHopperSwipeTutorial().set(true)
} }
controller.hopperGravity = controller.preferences.hopperGravity().get() controller.hopperGravity = controller.preferences.hopperGravity().get()
controller.category_hopper_frame?.translationX = 0f controller.binding.categoryHopperFrame.translationX = 0f
} }
private companion object { private companion object {

View File

@ -1,9 +1,9 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.view.View import android.view.View
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import kotlinx.android.synthetic.main.manga_grid_item.*
/** /**
* Generic class used to hold the displayed data of a manga in the library. * Generic class used to hold the displayed data of a manga in the library.
@ -44,7 +44,7 @@ abstract class LibraryHolder(
} }
fun setReadingButton(item: LibraryItem) { fun setReadingButton(item: LibraryItem) {
play_layout?.visibility = if (item.manga.unread > 0 && item.unreadType > 0 && !item.hideReadingButton) { itemView.findViewById<View>(R.id.play_layout)?.visibility = if (item.manga.unread > 0 && item.unreadType > 0 && !item.hideReadingButton) {
View.VISIBLE View.VISIBLE
} else View.GONE } else View.GONE
} }

View File

@ -17,11 +17,11 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.databinding.MangaGridItemBinding
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.manga_grid_item.view.*
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -62,40 +62,41 @@ class LibraryItem(
LibraryListHolder(view, adapter as LibraryCategoryAdapter) LibraryListHolder(view, adapter as LibraryCategoryAdapter)
} else { } else {
view.apply { view.apply {
val binding = MangaGridItemBinding.bind(this)
val coverHeight = (parent.itemWidth / 3f * 4f).toInt() val coverHeight = (parent.itemWidth / 3f * 4f).toInt()
if (libraryLayout == 1) { if (libraryLayout == 1) {
gradient.layoutParams = FrameLayout.LayoutParams( binding.gradient.layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT,
(coverHeight * 0.66f).toInt(), (coverHeight * 0.66f).toInt(),
Gravity.BOTTOM Gravity.BOTTOM
) )
card.updateLayoutParams<ConstraintLayout.LayoutParams> { binding.card.updateLayoutParams<ConstraintLayout.LayoutParams> {
bottomMargin = 6.dpToPx bottomMargin = 6.dpToPx
} }
} else if (libraryLayout == 2) { } else if (libraryLayout == 2) {
constraint_layout.background = ContextCompat.getDrawable( binding.constraintLayout.background = ContextCompat.getDrawable(
context, context,
R.drawable.library_item_selector R.drawable.library_item_selector
) )
} }
if (isFixedSize) { if (isFixedSize) {
constraint_layout.layoutParams = FrameLayout.LayoutParams( binding.constraintLayout.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT ViewGroup.LayoutParams.WRAP_CONTENT
) )
cover_thumbnail.maxHeight = Int.MAX_VALUE binding.coverThumbnail.maxHeight = Int.MAX_VALUE
cover_thumbnail.minimumHeight = 0 binding.coverThumbnail.minimumHeight = 0
constraint_layout.minHeight = 0 binding.constraintLayout.minHeight = 0
cover_thumbnail.scaleType = ImageView.ScaleType.CENTER_CROP binding.coverThumbnail.scaleType = ImageView.ScaleType.CENTER_CROP
cover_thumbnail.adjustViewBounds = false binding.coverThumbnail.adjustViewBounds = false
cover_thumbnail.layoutParams = FrameLayout.LayoutParams( binding.coverThumbnail.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
(parent.itemWidth / 3f * 3.7f).toInt() (parent.itemWidth / 3f * 3.7f).toInt()
) )
} else { } else {
constraint_layout.minHeight = coverHeight binding.constraintLayout.minHeight = coverHeight
cover_thumbnail.minimumHeight = (parent.itemWidth / 3f * 3.6f).toInt() binding.coverThumbnail.minimumHeight = (parent.itemWidth / 3f * 3.6f).toInt()
cover_thumbnail.maxHeight = (parent.itemWidth / 3f * 6f).toInt() binding.coverThumbnail.maxHeight = (parent.itemWidth / 3f * 6f).toInt()
} }
} }
LibraryGridHolder( LibraryGridHolder(

View File

@ -8,9 +8,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.MaterialTextButtonBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import kotlinx.android.synthetic.main.material_text_button.*
class SearchGlobalItem : AbstractFlexibleItem<SearchGlobalItem.Holder>() { class SearchGlobalItem : AbstractFlexibleItem<SearchGlobalItem.Holder>() {
@ -62,18 +62,19 @@ class SearchGlobalItem : AbstractFlexibleItem<SearchGlobalItem.Holder>() {
class Holder(val view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) : class Holder(val view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) :
BaseFlexibleViewHolder(view, adapter, true) { BaseFlexibleViewHolder(view, adapter, true) {
private val binding = MaterialTextButtonBinding.bind(view)
init { init {
button.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.button.updateLayoutParams<ViewGroup.MarginLayoutParams> {
width = MATCH_PARENT width = MATCH_PARENT
} }
button.setOnClickListener { binding.button.setOnClickListener {
val query = (adapter.getItem(flexibleAdapterPosition) as SearchGlobalItem).string val query = (adapter.getItem(flexibleAdapterPosition) as SearchGlobalItem).string
(adapter as? LibraryCategoryAdapter)?.libraryListener?.globalSearch(query) (adapter as? LibraryCategoryAdapter)?.libraryListener?.globalSearch(query)
} }
} }
fun bind(string: String) { fun bind(string: String) {
button.text = view.context.getString(R.string.search_globally, string) binding.button.text = view.context.getString(R.string.search_globally, string)
} }
override fun onLongClick(view: View?): Boolean { override fun onLongClick(view: View?): Boolean {

View File

@ -5,7 +5,6 @@ import android.util.AttributeSet
import eu.kanade.tachiyomi.databinding.LibraryBadgesLayoutBinding import eu.kanade.tachiyomi.databinding.LibraryBadgesLayoutBinding
import eu.kanade.tachiyomi.util.bindToPreference import eu.kanade.tachiyomi.util.bindToPreference
import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView
import kotlinx.android.synthetic.main.library_badges_layout.view.*
class LibraryBadgesView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class LibraryBadgesView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
BaseLibraryDisplayView<LibraryBadgesLayoutBinding>(context, attrs) { BaseLibraryDisplayView<LibraryBadgesLayoutBinding>(context, attrs) {

View File

@ -242,20 +242,20 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
} }
private fun createTags() { private fun createTags() {
downloaded = inflate(R.layout.filter_buttons) as FilterTagGroup downloaded = inflate(R.layout.filter_tag_group) as FilterTagGroup
downloaded.setup(this, R.string.downloaded, R.string.not_downloaded) downloaded.setup(this, R.string.downloaded, R.string.not_downloaded)
completed = inflate(R.layout.filter_buttons) as FilterTagGroup completed = inflate(R.layout.filter_tag_group) as FilterTagGroup
completed.setup(this, R.string.completed, R.string.ongoing) completed.setup(this, R.string.completed, R.string.ongoing)
unreadProgress = inflate(R.layout.filter_buttons) as FilterTagGroup unreadProgress = inflate(R.layout.filter_tag_group) as FilterTagGroup
unreadProgress.setup(this, R.string.not_started, R.string.in_progress) unreadProgress.setup(this, R.string.not_started, R.string.in_progress)
unread = inflate(R.layout.filter_buttons) as FilterTagGroup unread = inflate(R.layout.filter_tag_group) as FilterTagGroup
unread.setup(this, R.string.unread, R.string.read) unread.setup(this, R.string.unread, R.string.read)
if (hasTracking) { if (hasTracking) {
tracked = inflate(R.layout.filter_buttons) as FilterTagGroup tracked = inflate(R.layout.filter_tag_group) as FilterTagGroup
tracked?.setup(this, R.string.tracked, R.string.not_tracked) tracked?.setup(this, R.string.tracked, R.string.not_tracked)
} }
@ -278,7 +278,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
if (libraryManga.any { it.mangaType() == Manga.TYPE_COMIC }) types.add(R.string.comic) if (libraryManga.any { it.mangaType() == Manga.TYPE_COMIC }) types.add(R.string.comic)
if (types.isNotEmpty()) { if (types.isNotEmpty()) {
launchUI { launchUI {
val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup val mangaType = inflate(R.layout.filter_tag_group) as FilterTagGroup
mangaType.setup( mangaType.setup(
this@FilterBottomSheet, this@FilterBottomSheet,
R.string.manga, R.string.manga,
@ -319,7 +319,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
if (loggedServices.size > 1) { if (loggedServices.size > 1) {
val serviceNames = loggedServices.map { context.getString(it.nameRes()) } val serviceNames = loggedServices.map { context.getString(it.nameRes()) }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
trackers = inflate(R.layout.filter_buttons) as FilterTagGroup trackers = inflate(R.layout.filter_tag_group) as FilterTagGroup
trackers?.setup( trackers?.setup(
this@FilterBottomSheet, this@FilterBottomSheet,
serviceNames.first(), serviceNames.first(),

View File

@ -8,12 +8,12 @@ import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import com.f2prateek.rx.preferences.Preference import com.f2prateek.rx.preferences.Preference
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.databinding.FilterTagGroupBinding
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.util.view.visibleIf import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.filter_buttons.view.*
class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout
(context, attrs) { (context, attrs) {
@ -25,26 +25,47 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
private var root: ViewGroup? = null private var root: ViewGroup? = null
private val buttons by lazy { arrayOf(firstButton, secondButton, thirdButton, fourthButton) } private val buttons by lazy {
private val separators by lazy { arrayOf(separator1, separator2, separator3) } arrayOf(
binding.firstButton,
binding.secondButton,
binding.thirdButton,
binding.fourthButton
)
}
private val separators by lazy {
arrayOf(
binding.separator1,
binding.separator2,
binding.separator3
)
}
override fun isActivated(): Boolean { override fun isActivated(): Boolean {
return buttons.any { it.isActivated } return buttons.any { it.isActivated }
} }
lateinit var binding: FilterTagGroupBinding
override fun onFinishInflate() {
super.onFinishInflate()
binding = FilterTagGroupBinding.bind(this)
}
fun nameOf(index: Int): String? = buttons.getOrNull(index)?.text as? String fun nameOf(index: Int): String? = buttons.getOrNull(index)?.text as? String
fun setup(root: ViewGroup, firstText: Int, vararg extra: Int?) { fun setup(root: ViewGroup, firstText: Int, vararg extra: Int?) {
val text1 = context.getString(firstText) val text1 = context.getString(firstText)
val strings = extra.mapNotNull { if (it != null) context.getString(it) else null } val strings = extra.mapNotNull { if (it != null) context.getString(it) else null }
setup(root, text1, extra = *strings.toTypedArray()) setup(root, text1, extra = strings.toTypedArray())
} }
fun setup(root: ViewGroup, firstText: String, vararg extra: String?) { fun setup(root: ViewGroup, firstText: String, vararg extra: String?) {
listener = root as? FilterTagGroupListener listener = root as? FilterTagGroupListener
(layoutParams as? MarginLayoutParams)?.rightMargin = 5.dpToPx (layoutParams as? MarginLayoutParams)?.rightMargin = 5.dpToPx
(layoutParams as? MarginLayoutParams)?.leftMargin = 5.dpToPx (layoutParams as? MarginLayoutParams)?.leftMargin = 5.dpToPx
firstButton.text = firstText binding.firstButton.text = firstText
val extras = (extra.toList() + listOf<String?>(null, null, null)).take(separators.size) val extras = (extra.toList() + listOf<String?>(null, null, null)).take(separators.size)
extras.forEachIndexed { index, text -> extras.forEachIndexed { index, text ->
buttons[index + 1].text = text buttons[index + 1].text = text
@ -96,12 +117,12 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
) )
} }
if (itemCount == 1) { if (itemCount == 1) {
firstButton.isActivated = !firstButton.isActivated binding.firstButton.isActivated = !binding.firstButton.isActivated
firstButton.setTextColor( binding.firstButton.setTextColor(
if (firstButton.isActivated) Color.WHITE else context if (binding.firstButton.isActivated) Color.WHITE else context
.getResourceColor(android.R.attr.textColorPrimary) .getResourceColor(android.R.attr.textColorPrimary)
) )
listener?.onFilterClicked(this, if (firstButton.isActivated) index else -1, callBack) listener?.onFilterClicked(this, if (binding.firstButton.isActivated) index else -1, callBack)
return return
} }
val mainButton = buttons[index] val mainButton = buttons[index]