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 eu.kanade.tachiyomi.util.view.hide
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.pow
import kotlin.math.sign
@ -27,7 +25,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
): Boolean {
val distance = ((e1?.rawX ?: 0f) - (e2?.rawX ?: 0f)) / 50
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)
}
@ -45,10 +43,11 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
var result = false
val diffY = e2.y - e1.y
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.withEndAction {
controller.category_hopper_frame.translationX = 0f
hopperFrame.translationX = 0f
}
if (abs(diffX) <= abs(diffY) &&
abs(diffY) > SWIPE_THRESHOLD &&
@ -63,13 +62,13 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
abs(diffX) > SWIPE_THRESHOLD * 5 &&
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) {
animator.translationX(
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 {
controller.category_hopper_frame?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
hopperFrame.updateLayoutParams<CoordinatorLayout.LayoutParams> {
gravity =
Gravity.TOP or (
if (gravity == Gravity.TOP or Gravity.RIGHT) {
@ -86,9 +85,9 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
} else {
animator.translationX(
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 {
controller.category_hopper_frame?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
hopperFrame.updateLayoutParams<CoordinatorLayout.LayoutParams> {
gravity =
Gravity.TOP or (
if (gravity == Gravity.TOP or Gravity.LEFT) {
@ -114,7 +113,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
controller.preferences.shownHopperSwipeTutorial().set(true)
}
controller.hopperGravity = controller.preferences.hopperGravity().get()
controller.category_hopper_frame?.translationX = 0f
controller.binding.categoryHopperFrame.translationX = 0f
}
private companion object {

View File

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

View File

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

View File

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

View File

@ -242,20 +242,20 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
}
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)
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)
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)
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)
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)
}
@ -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 (types.isNotEmpty()) {
launchUI {
val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup
val mangaType = inflate(R.layout.filter_tag_group) as FilterTagGroup
mangaType.setup(
this@FilterBottomSheet,
R.string.manga,
@ -319,7 +319,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
if (loggedServices.size > 1) {
val serviceNames = loggedServices.map { context.getString(it.nameRes()) }
withContext(Dispatchers.Main) {
trackers = inflate(R.layout.filter_buttons) as FilterTagGroup
trackers = inflate(R.layout.filter_tag_group) as FilterTagGroup
trackers?.setup(
this@FilterBottomSheet,
serviceNames.first(),

View File

@ -8,12 +8,12 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import com.f2prateek.rx.preferences.Preference
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.getResourceColor
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible
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
(context, attrs) {
@ -25,26 +25,47 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
private var root: ViewGroup? = null
private val buttons by lazy { arrayOf(firstButton, secondButton, thirdButton, fourthButton) }
private val separators by lazy { arrayOf(separator1, separator2, separator3) }
private val buttons by lazy {
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 {
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 setup(root: ViewGroup, firstText: Int, vararg extra: Int?) {
val text1 = context.getString(firstText)
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?) {
listener = root as? FilterTagGroupListener
(layoutParams as? MarginLayoutParams)?.rightMargin = 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)
extras.forEachIndexed { index, text ->
buttons[index + 1].text = text
@ -96,12 +117,12 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
)
}
if (itemCount == 1) {
firstButton.isActivated = !firstButton.isActivated
firstButton.setTextColor(
if (firstButton.isActivated) Color.WHITE else context
binding.firstButton.isActivated = !binding.firstButton.isActivated
binding.firstButton.setTextColor(
if (binding.firstButton.isActivated) Color.WHITE else context
.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
}
val mainButton = buttons[index]