mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Adding animation for expanding and collapsing manga descriptions
This commit is contained in:
parent
e90c512831
commit
d1189e546e
2 changed files with 32 additions and 8 deletions
|
@ -6,7 +6,6 @@ import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
|
|
@ -18,6 +18,7 @@ import androidx.core.graphics.drawable.toDrawable
|
||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||||
import coil.request.CachePolicy
|
import coil.request.CachePolicy
|
||||||
import eu.kanade.tachiyomi.util.system.isInNightMode
|
import eu.kanade.tachiyomi.util.system.isInNightMode
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
|
@ -72,12 +73,14 @@ class MangaHeaderHolder(
|
||||||
topView.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
topView.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||||
height = adapter.delegate.topCoverHeight()
|
height = adapter.delegate.topCoverHeight()
|
||||||
}
|
}
|
||||||
moreButton.setOnClickListener { expandDesc() }
|
moreButton.setOnClickListener {
|
||||||
|
expandDesc(true)
|
||||||
|
}
|
||||||
mangaSummary.setOnClickListener {
|
mangaSummary.setOnClickListener {
|
||||||
if (moreButton.isVisible) {
|
if (moreButton.isVisible) {
|
||||||
expandDesc()
|
expandDesc(true)
|
||||||
} else if (!hadSelection) {
|
} else if (!hadSelection) {
|
||||||
collapseDesc()
|
collapseDesc(true)
|
||||||
} else {
|
} else {
|
||||||
hadSelection = false
|
hadSelection = false
|
||||||
}
|
}
|
||||||
|
@ -106,7 +109,9 @@ class MangaHeaderHolder(
|
||||||
if (!itemView.resources.isLTR) {
|
if (!itemView.resources.isLTR) {
|
||||||
moreBgGradient.rotation = 180f
|
moreBgGradient.rotation = 180f
|
||||||
}
|
}
|
||||||
lessButton.setOnClickListener { collapseDesc() }
|
lessButton.setOnClickListener {
|
||||||
|
collapseDesc(true)
|
||||||
|
}
|
||||||
|
|
||||||
webviewButton.setOnClickListener { adapter.delegate.openInWebView() }
|
webviewButton.setOnClickListener { adapter.delegate.openInWebView() }
|
||||||
shareButton.setOnClickListener { adapter.delegate.prepareToShareManga() }
|
shareButton.setOnClickListener { adapter.delegate.prepareToShareManga() }
|
||||||
|
@ -151,7 +156,7 @@ class MangaHeaderHolder(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun expandDesc() {
|
private fun expandDesc(animated: Boolean = false) {
|
||||||
binding ?: return
|
binding ?: return
|
||||||
if (binding.moreButton.visibility == View.VISIBLE || isTablet) {
|
if (binding.moreButton.visibility == View.VISIBLE || isTablet) {
|
||||||
binding.mangaSummary.maxLines = Integer.MAX_VALUE
|
binding.mangaSummary.maxLines = Integer.MAX_VALUE
|
||||||
|
@ -160,22 +165,42 @@ class MangaHeaderHolder(
|
||||||
binding.mangaGenresTags.isVisible = true
|
binding.mangaGenresTags.isVisible = true
|
||||||
binding.lessButton.isVisible = !isTablet
|
binding.lessButton.isVisible = !isTablet
|
||||||
binding.moreButtonGroup.isVisible = false
|
binding.moreButtonGroup.isVisible = false
|
||||||
|
if (animated) {
|
||||||
|
val animVector = AnimatedVectorDrawableCompat.create(binding.root.context, R.drawable.anim_expand_more_to_less)
|
||||||
|
binding.lessButton.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, animVector, null)
|
||||||
|
animVector?.start()
|
||||||
|
}
|
||||||
binding.title.maxLines = Integer.MAX_VALUE
|
binding.title.maxLines = Integer.MAX_VALUE
|
||||||
binding.mangaAuthor.maxLines = Integer.MAX_VALUE
|
binding.mangaAuthor.maxLines = Integer.MAX_VALUE
|
||||||
binding.mangaSummary.requestFocus()
|
binding.mangaSummary.requestFocus()
|
||||||
|
if (animated) {
|
||||||
|
val transition = androidx.transition.Slide()
|
||||||
|
transition.duration = binding.root.resources.getInteger(
|
||||||
|
android.R.integer.config_shortAnimTime
|
||||||
|
).toLong()
|
||||||
|
androidx.transition.TransitionManager.beginDelayedTransition(
|
||||||
|
adapter.controller.binding.recycler,
|
||||||
|
transition
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collapseDesc() {
|
private fun collapseDesc(animated: Boolean = false) {
|
||||||
binding ?: return
|
binding ?: return
|
||||||
if (isTablet) return
|
if (isTablet) return
|
||||||
|
binding.moreButtonGroup.isVisible = !isTablet
|
||||||
|
if (animated) {
|
||||||
|
val animVector = AnimatedVectorDrawableCompat.create(binding.root.context, R.drawable.anim_expand_less_to_more)
|
||||||
|
binding.moreButton.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, animVector, null)
|
||||||
|
animVector?.start()
|
||||||
|
}
|
||||||
binding.mangaSummary.setTextIsSelectable(false)
|
binding.mangaSummary.setTextIsSelectable(false)
|
||||||
binding.mangaSummary.isClickable = true
|
binding.mangaSummary.isClickable = true
|
||||||
binding.mangaSummary.maxLines = 3
|
binding.mangaSummary.maxLines = 3
|
||||||
setDescription()
|
setDescription()
|
||||||
binding.mangaGenresTags.isVisible = isTablet
|
binding.mangaGenresTags.isVisible = isTablet
|
||||||
binding.lessButton.isVisible = false
|
binding.lessButton.isVisible = false
|
||||||
binding.moreButtonGroup.isVisible = !isTablet
|
|
||||||
binding.title.maxLines = 4
|
binding.title.maxLines = 4
|
||||||
binding.mangaAuthor.maxLines = 2
|
binding.mangaAuthor.maxLines = 2
|
||||||
adapter.recyclerView.post {
|
adapter.recyclerView.post {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue