From ae23f1ba59150d105bda559d30ff2890e5f47dde Mon Sep 17 00:00:00 2001 From: Adolfo Santiago Date: Sat, 16 Mar 2024 16:39:19 +0100 Subject: [PATCH] Formatting classes --- .../tusky/fragment/ViewImageFragment.kt | 2 ++ .../tusky/fragment/ViewMediaFragment.kt | 16 ++++++++++++++-- .../tusky/fragment/ViewVideoFragment.kt | 2 ++ .../com/keylesspalace/tusky/util/MediaUtils.kt | 11 +++++++---- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt b/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt index 15edc703..c14778ea 100644 --- a/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt +++ b/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt @@ -123,10 +123,12 @@ class ViewImageFragment : ViewMediaFragment() { swipeStartedWithOneFinger = true lastY = event.rawY } + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { onGestureEnd() swipeStartedWithOneFinger = false } + MotionEvent.ACTION_MOVE -> { if (swipeStartedWithOneFinger && ( diff --git a/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.kt b/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.kt index 31d7bb19..3a57ed95 100644 --- a/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.kt +++ b/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.kt @@ -17,6 +17,8 @@ package com.keylesspalace.tusky.fragment import android.os.Bundle import android.text.TextUtils +import androidx.annotation.OptIn +import androidx.media3.common.util.UnstableApi import com.keylesspalace.tusky.ViewMediaActivity import com.keylesspalace.tusky.entity.Attachment @@ -46,8 +48,12 @@ abstract class ViewMediaFragment : BaseFragment() { @JvmStatic protected val ARG_AVATAR_URL = "avatarUrl" + @OptIn(UnstableApi::class) @JvmStatic - fun newInstance(attachment: Attachment, shouldStartPostponedTransition: Boolean): ViewMediaFragment { + fun newInstance( + attachment: Attachment, + shouldStartPostponedTransition: Boolean + ): ViewMediaFragment { val arguments = Bundle(2) arguments.putParcelable(ARG_ATTACHMENT, attachment) arguments.putBoolean(ARG_START_POSTPONED_TRANSITION, shouldStartPostponedTransition) @@ -57,6 +63,7 @@ abstract class ViewMediaFragment : BaseFragment() { Attachment.Type.VIDEO, Attachment.Type.GIFV, Attachment.Type.AUDIO -> ViewVideoFragment() + else -> ViewImageFragment() // it probably won't show anything, but its better than crashing } fragment.arguments = arguments @@ -82,7 +89,12 @@ abstract class ViewMediaFragment : BaseFragment() { showingDescription = !TextUtils.isEmpty(description) isDescriptionVisible = showingDescription - setupMediaView(url, previewUrl, description, showingDescription && mediaActivity.isToolbarVisible) + setupMediaView( + url, + previewUrl, + description, + showingDescription && mediaActivity.isToolbarVisible + ) toolbarVisibiltyDisposable = (activity as ViewMediaActivity) .addToolbarVisibilityListener { isVisible -> diff --git a/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt b/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt index c595432e..21dc1d6d 100644 --- a/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt +++ b/husky/app/src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt @@ -234,12 +234,14 @@ class ViewVideoFragment : ViewMediaFragment() { Player.STATE_BUFFERING -> { binding.progressBar.visibility = View.VISIBLE } + Player.STATE_READY, Player.STATE_ENDED -> { binding.progressBar.visibility = View.GONE binding.videoControls.show() binding.videoControls.visibility = View.VISIBLE } + else -> Unit } } diff --git a/husky/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.kt b/husky/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.kt index 464fd423..8aba1d84 100644 --- a/husky/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.kt +++ b/husky/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.kt @@ -159,15 +159,18 @@ fun reorientBitmap(bitmap: Bitmap?, orientation: Int): Bitmap? { matrix.setRotate(180.0f) matrix.postScale(-1.0f, 1.0f) } + ExifInterface.ORIENTATION_TRANSPOSE -> { matrix.setRotate(90.0f) matrix.postScale(-1.0f, 1.0f) } + ExifInterface.ORIENTATION_ROTATE_90 -> matrix.setRotate(90.0f) ExifInterface.ORIENTATION_TRANSVERSE -> { matrix.setRotate(-90.0f) matrix.postScale(-1.0f, 1.0f) } + ExifInterface.ORIENTATION_ROTATE_270 -> matrix.setRotate(-90.0f) else -> return bitmap } @@ -251,9 +254,9 @@ fun deleteStaleCachedMedia(mediaDirectory: File?) { fun getTemporaryMediaFilename(extension: String): String { return "${MEDIA_TEMP_PREFIX}_${ - SimpleDateFormat( - "yyyyMMdd_HHmmss", - Locale.US - ).format(Date()) + SimpleDateFormat( + "yyyyMMdd_HHmmss", + Locale.US + ).format(Date()) }.$extension" }