Skip to content

Option to zoom into full covers #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions app/src/main/java/eu/kanade/tachiyomi/ui/manga/FullCoverDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import android.view.animation.DecelerateInterpolator
import androidx.activity.BackEventCompat
import androidx.activity.ComponentDialog
import androidx.activity.OnBackPressedCallback
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams
import androidx.core.animation.addListener
import androidx.core.animation.doOnEnd
import androidx.core.content.ContextCompat
import androidx.core.view.WindowInsetsCompat.Type.systemBars
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.transition.ChangeBounds
import androidx.transition.ChangeImageTransform
Expand Down Expand Up @@ -122,27 +125,26 @@ class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable
lastY = backEvent.touchY
velocityTracker.addMovement(motionEvent)
motionEvent.recycle()
binding.mangaCoverFull.scaleX = 1f - maxProgress * 0.6f
binding.mangaCoverFull.translationX =
binding.mangaCoverZoom.scaleX = 1f - maxProgress * 0.6f
binding.mangaCoverZoom.translationX =
maxProgress * 100f * (if (backEvent.swipeEdge == BackEventCompat.EDGE_LEFT) 1 else -1)
binding.mangaCoverFull.translationY = -maxProgress * 150f
binding.mangaCoverFull.scaleY = 1f - maxProgress * 0.6f
binding.mangaCoverZoom.translationY = -maxProgress * 150f
binding.mangaCoverZoom.scaleY = 1f - maxProgress * 0.6f
}

override fun handleOnBackCancelled() {
binding.mangaCoverFull.scaleX = 1f
binding.mangaCoverFull.translationX = 0f
binding.mangaCoverFull.translationY = 0f
binding.mangaCoverFull.scaleY = 1f
binding.mangaCoverZoom.scaleX = 1f
binding.mangaCoverZoom.translationX = 0f
binding.mangaCoverZoom.translationY = 0f
binding.mangaCoverZoom.scaleY = 1f
}
}
onBackPressedDispatcher.addCallback(backPressedCallback)

binding.touchOutside.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.mangaCoverFull.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
listOf(binding.touchOutside, binding.mangaCoverFull, binding.mangaCoverZoom).forEach {
it.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
}

binding.btnSave.setOnClickListener {
Expand All @@ -159,14 +161,15 @@ class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable
.build()

expandedImageView.setImageDrawable(drawable)
binding.mangaCoverZoom.setImageDrawable(drawable)

val rect = Rect()
thumbView.getGlobalVisibleRect(rect)
val systemInsets = activity?.window?.decorView?.rootWindowInsetsCompat?.getInsets(systemBars())
val topInset = systemInsets?.top ?: 0
val leftInset = systemInsets?.left ?: 0
val rightInset = systemInsets?.right ?: 0
expandedImageView.updateLayoutParams<ConstraintLayout.LayoutParams> {
expandedImageView.updateLayoutParams<LayoutParams> {
height = thumbView.height
width = thumbView.width
topMargin = rect.top - topInset
Expand All @@ -189,15 +192,17 @@ class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
activity?.window?.decorView?.animateBlur(1f, 20f, 50)?.start()
}
expandedImageView.updateLayoutParams<ConstraintLayout.LayoutParams> {
height = 0
width = 0
topMargin = defMargin + 48.dpToPx
marginStart = defMargin
marginEnd = defMargin
bottomMargin = defMargin
horizontalBias = 0.5f
verticalBias = 0.5f
listOf(expandedImageView, binding.mangaCoverZoom).forEach {
it.updateLayoutParams<LayoutParams> {
height = 0
width = 0
topMargin = defMargin + 48.dpToPx
marginStart = defMargin
marginEnd = defMargin
bottomMargin = defMargin
horizontalBias = 0.5f
verticalBias = 0.5f
}
}

// TransitionSet for the full cover because using animation for this SUCKS
Expand Down Expand Up @@ -227,6 +232,12 @@ class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable
}
}
playTogether(radiusAnimator, saveAnimator)
doOnEnd {
if (binding.touchOutside.isClickable) {
binding.mangaCoverFull.isInvisible = true
binding.mangaCoverZoom.isVisible = true
}
}
duration = shortAnimationDuration
interpolator = DecelerateInterpolator()
start()
Expand Down Expand Up @@ -266,14 +277,21 @@ class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable
}
val rect2 = Rect()
thumbView.getGlobalVisibleRect(rect2)
binding.mangaCoverFull.scaleX = binding.mangaCoverZoom.scaleX
binding.mangaCoverFull.translationX = binding.mangaCoverZoom.translationX
binding.mangaCoverFull.translationY = binding.mangaCoverZoom.translationY
binding.mangaCoverFull.scaleY = binding.mangaCoverZoom.scaleY
binding.mangaCoverFull.isVisible = true
binding.mangaCoverZoom.isVisible = false
binding.mangaCoverZoom.isClickable = false
binding.mangaCoverFull.isClickable = false
binding.touchOutside.isClickable = false
val expandedImageView = binding.mangaCoverFull
val systemInsets = activity?.window?.decorView?.rootWindowInsetsCompat?.getInsets(systemBars())
val topInset = systemInsets?.top ?: 0
val leftInset = systemInsets?.left ?: 0
val rightInset = systemInsets?.right ?: 0
expandedImageView.updateLayoutParams<ConstraintLayout.LayoutParams> {
expandedImageView.updateLayoutParams<LayoutParams> {
height = thumbView.height
width = thumbView.width
topMargin = rect2.top - topInset
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/res/layout/full_cover_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/button_container"/>

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/manga_cover_zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:visibility="invisible"
tools:src="@mipmap/ic_launcher"
android:contentDescription="@string/cover_of_image"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/button_container"/>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/button_container"
android:layout_width="0dp"
Expand Down Expand Up @@ -65,4 +84,4 @@
android:text="@string/share"
app:icon="@drawable/ic_share_24dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading