From e3c2af2c59b8c0f58302507c9bca2321bcb32de8 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 7 Jul 2020 09:24:21 +0200 Subject: [PATCH] Code cleaning --- .../src/main/AndroidManifest.xml | 4 ++-- .../AnimatedImageViewHolder.kt | 6 ++--- .../AttachmentSourceProvider.kt | 2 +- .../AttachmentViewerActivity.kt | 11 +++------ .../AttachmentsAdapter.kt | 23 +++++++------------ .../SwipeDirection.kt | 2 +- .../SwipeDirectionDetector.kt | 2 +- .../SwipeToDismissHandler.kt | 5 ++-- .../ZoomableImageViewHolder.kt | 2 +- .../features/media/AttachmentOverlayView.kt | 3 --- .../features/media/ImageContentRenderer.kt | 3 --- .../features/media/RoomAttachmentProvider.kt | 11 ++++----- .../media/VectorAttachmentViewerActivity.kt | 10 ++------ 13 files changed, 28 insertions(+), 56 deletions(-) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/AnimatedImageViewHolder.kt (93%) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/AttachmentSourceProvider.kt (97%) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/AttachmentViewerActivity.kt (98%) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/AttachmentsAdapter.kt (91%) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/SwipeDirection.kt (96%) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/SwipeDirectionDetector.kt (98%) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/SwipeToDismissHandler.kt (96%) rename attachment-viewer/src/main/java/im/vector/riotx/{attachment_viewer => attachmentviewer}/ZoomableImageViewHolder.kt (98%) diff --git a/attachment-viewer/src/main/AndroidManifest.xml b/attachment-viewer/src/main/AndroidManifest.xml index 4a632774f7..4c48526635 100644 --- a/attachment-viewer/src/main/AndroidManifest.xml +++ b/attachment-viewer/src/main/AndroidManifest.xml @@ -1,10 +1,10 @@ + package="im.vector.riotx.attachmentviewer"> diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AnimatedImageViewHolder.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AnimatedImageViewHolder.kt similarity index 93% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AnimatedImageViewHolder.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AnimatedImageViewHolder.kt index 10b3cf8ffc..9f512e78be 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AnimatedImageViewHolder.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AnimatedImageViewHolder.kt @@ -14,11 +14,10 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer import android.graphics.drawable.Animatable import android.graphics.drawable.Drawable -import android.util.Log import android.view.View import android.widget.ImageView import android.widget.LinearLayout @@ -27,7 +26,6 @@ import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import com.bumptech.glide.request.target.CustomViewTarget import com.bumptech.glide.request.transition.Transition -import com.github.chrisbanes.photoview.PhotoView class AnimatedImageViewHolder constructor(itemView: View) : BaseViewHolder(itemView) { @@ -58,7 +56,7 @@ class AnimatedImageViewHolder constructor(itemView: View) : } touchImageView.setImageDrawable(resource) if (resource is Animatable) { - resource.start(); + resource.start() } } } diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentSourceProvider.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentSourceProvider.kt similarity index 97% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentSourceProvider.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentSourceProvider.kt index 7b24f4bb46..9539bf5565 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentSourceProvider.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentSourceProvider.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer import android.content.Context import android.view.View diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentViewerActivity.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentViewerActivity.kt similarity index 98% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentViewerActivity.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentViewerActivity.kt index e26a0cb832..ffd9175fc0 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentViewerActivity.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentViewerActivity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer import android.graphics.Color import android.os.Bundle @@ -120,7 +120,6 @@ abstract class AttachmentViewerActivity : AppCompatActivity() { scaleDetector = createScaleGestureDetector() - ViewCompat.setOnApplyWindowInsetsListener(rootContainer) { _, insets -> overlayView?.updatePadding(top = insets.systemWindowInsetTop) topInset = insets.systemWindowInsetTop @@ -129,7 +128,6 @@ abstract class AttachmentViewerActivity : AppCompatActivity() { } override fun dispatchTouchEvent(ev: MotionEvent): Boolean { - // The zoomable view is configured to disallow interception when image is zoomed // Check if the overlay is visible, and wants to handle the click @@ -137,20 +135,18 @@ abstract class AttachmentViewerActivity : AppCompatActivity() { return true } - Log.v("ATTACHEMENTS", "================\ndispatchTouchEvent $ev") handleUpDownEvent(ev) Log.v("ATTACHEMENTS", "scaleDetector is in progress ${scaleDetector.isInProgress}") Log.v("ATTACHEMENTS", "pointerCount ${ev.pointerCount}") - Log.v("ATTACHEMENTS", "wasScaled ${wasScaled}") + Log.v("ATTACHEMENTS", "wasScaled $wasScaled") if (swipeDirection == null && (scaleDetector.isInProgress || ev.pointerCount > 1 || wasScaled)) { wasScaled = true Log.v("ATTACHEMENTS", "dispatch to pager") return attachmentPager.dispatchTouchEvent(ev) } - Log.v("ATTACHEMENTS", "is current item scaled ${isScaled()}") return (if (isScaled()) super.dispatchTouchEvent(ev) else handleTouchIfNotScaled(ev)).also { Log.v("ATTACHEMENTS", "\n================") @@ -210,8 +206,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity() { } private fun handleTouchIfNotScaled(event: MotionEvent): Boolean { - - Log.v("ATTACHEMENTS", "handleTouchIfNotScaled ${event}") + Log.v("ATTACHEMENTS", "handleTouchIfNotScaled $event") directionDetector.handleTouchEvent(event) return when (swipeDirection) { diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentsAdapter.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentsAdapter.kt similarity index 91% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentsAdapter.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentsAdapter.kt index f762a6ea3e..26577aee32 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/AttachmentsAdapter.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentsAdapter.kt @@ -14,30 +14,27 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView - abstract class BaseViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) { abstract fun bind(attachmentInfo: AttachmentInfo) } - class AttachmentViewHolder constructor(itemView: View) : BaseViewHolder(itemView) { override fun bind(attachmentInfo: AttachmentInfo) { - } } -//class AttachmentsAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) : FragmentStateAdapter(fragmentManager, lifecycle) { +// class AttachmentsAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) : FragmentStateAdapter(fragmentManager, lifecycle) { class AttachmentsAdapter() : RecyclerView.Adapter() { var attachmentSourceProvider: AttachmentSourceProvider? = null @@ -75,7 +72,6 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { is AttachmentInfo.Audio -> TODO() is AttachmentInfo.File -> TODO() } - } override fun getItemCount(): Int { @@ -85,7 +81,7 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { override fun onBindViewHolder(holder: BaseViewHolder, position: Int) { attachmentSourceProvider?.getAttachmentInfoAt(position)?.let { holder.bind(it) - when(it) { + when (it) { is AttachmentInfo.Image -> { attachmentSourceProvider?.loadImage(holder as ZoomableImageViewHolder, it) } @@ -94,7 +90,6 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { } else -> {} } - } } @@ -119,15 +114,13 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { // } // return fragment // } - } - -//private const val ARG_OBJECT = "object" +// private const val ARG_OBJECT = "object" // -//// Instances of this class are fragments representing a single -//// object in our collection. -//class DemoObjectFragment : Fragment() { +// // Instances of this class are fragments representing a single +// // object in our collection. +// class DemoObjectFragment : Fragment() { // // override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // return inflater.inflate(R.layout.view_image_attachment, container, false) @@ -139,4 +132,4 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { // textView.text = getInt(ARG_OBJECT).toString() // } // } -//} +// } diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeDirection.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeDirection.kt similarity index 96% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeDirection.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeDirection.kt index fc54d292c2..e552d55efb 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeDirection.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeDirection.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer sealed class SwipeDirection { object NotDetected : SwipeDirection() diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeDirectionDetector.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeDirectionDetector.kt similarity index 98% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeDirectionDetector.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeDirectionDetector.kt index cce37a6d05..cedbcd0180 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeDirectionDetector.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeDirectionDetector.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer import android.content.Context import android.view.MotionEvent diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeToDismissHandler.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeToDismissHandler.kt similarity index 96% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeToDismissHandler.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeToDismissHandler.kt index 3a317d94e2..e52c72cba0 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/SwipeToDismissHandler.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/SwipeToDismissHandler.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer import android.animation.Animator import android.animation.AnimatorListenerAdapter @@ -100,7 +100,7 @@ class SwipeToDismissHandler( onDismiss() } - //remove the update listener, otherwise it will be saved on the next animation execution: + // remove the update listener, otherwise it will be saved on the next animation execution: swipeView.animate().setUpdateListener(null) }) .start() @@ -112,7 +112,6 @@ internal fun ViewPropertyAnimator.setAnimatorListener( onAnimationStart: ((Animator?) -> Unit)? = null ) = this.setListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { onAnimationEnd?.invoke(animation) } diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/ZoomableImageViewHolder.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/ZoomableImageViewHolder.kt similarity index 98% rename from attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/ZoomableImageViewHolder.kt rename to attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/ZoomableImageViewHolder.kt index 6dd387b870..00a8ad275a 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachment_viewer/ZoomableImageViewHolder.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/ZoomableImageViewHolder.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.riotx.attachment_viewer +package im.vector.riotx.attachmentviewer import android.graphics.drawable.Drawable import android.util.Log diff --git a/vector/src/main/java/im/vector/riotx/features/media/AttachmentOverlayView.kt b/vector/src/main/java/im/vector/riotx/features/media/AttachmentOverlayView.kt index 49930fde76..af6c4991fa 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/AttachmentOverlayView.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/AttachmentOverlayView.kt @@ -23,15 +23,12 @@ import android.view.View import android.widget.ImageView import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.view.updateLayoutParams import im.vector.riotx.R -import im.vector.riotx.attachment_viewer.AttachmentInfo class AttachmentOverlayView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr) { - var onShareCallback: (() -> Unit) ? = null var onBack: (() -> Unit) ? = null diff --git a/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt b/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt index 7cd7ba56e5..bc9c64c801 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt @@ -144,7 +144,6 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder: } fun renderThumbnailDontTransform(data: Data, imageView: ImageView, callback: ((Boolean) -> Unit)? = null) { - // a11y imageView.contentDescription = data.filename @@ -181,8 +180,6 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder: }) .dontTransform() .into(imageView) - - } private fun createGlideRequest(data: Data, mode: Mode, imageView: ImageView, size: Size): GlideRequest { diff --git a/vector/src/main/java/im/vector/riotx/features/media/RoomAttachmentProvider.kt b/vector/src/main/java/im/vector/riotx/features/media/RoomAttachmentProvider.kt index 099d4fed5d..84311c997a 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/RoomAttachmentProvider.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/RoomAttachmentProvider.kt @@ -26,10 +26,10 @@ import im.vector.matrix.android.api.session.room.model.message.MessageWithAttach import im.vector.matrix.android.api.session.room.model.message.getFileUrl import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt -import im.vector.riotx.attachment_viewer.AnimatedImageViewHolder -import im.vector.riotx.attachment_viewer.AttachmentInfo -import im.vector.riotx.attachment_viewer.AttachmentSourceProvider -import im.vector.riotx.attachment_viewer.ZoomableImageViewHolder +import im.vector.riotx.attachmentviewer.AnimatedImageViewHolder +import im.vector.riotx.attachmentviewer.AttachmentInfo +import im.vector.riotx.attachmentviewer.AttachmentSourceProvider +import im.vector.riotx.attachmentviewer.ZoomableImageViewHolder import im.vector.riotx.core.date.VectorDateFormatter import im.vector.riotx.core.extensions.localDateTime import javax.inject.Inject @@ -108,11 +108,10 @@ class RoomAttachmentProvider( val dateString = item.root.localDateTime().let { "${dateFormatter.formatMessageDay(it)} at ${dateFormatter.formatMessageHour(it)} " } - overlayView?.updateWith("${position + 1} of ${attachments.size}","${item.senderInfo.displayName} $dateString" ) + overlayView?.updateWith("${position + 1} of ${attachments.size}", "${item.senderInfo.displayName} $dateString") return overlayView } - // override fun loadImage(holder: ImageViewHolder, info: AttachmentInfo.Image) { // (info.data as? ImageContentRenderer.Data)?.let { // imageContentRenderer.render(it, ImageContentRenderer.Mode.FULL_SIZE, holder.touchImageView) diff --git a/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt index dc37ac6294..57ff8bb05d 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt @@ -29,7 +29,7 @@ import androidx.core.view.isInvisible import androidx.core.view.isVisible import androidx.transition.Transition import im.vector.riotx.R -import im.vector.riotx.attachment_viewer.AttachmentViewerActivity +import im.vector.riotx.attachmentviewer.AttachmentViewerActivity import im.vector.riotx.core.di.* import im.vector.riotx.features.themes.ActivityOtherThemes import im.vector.riotx.features.themes.ThemeUtils @@ -62,7 +62,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), RoomAttachmen private var isAnimatingOut = false override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) Timber.i("onCreate Activity ${this.javaClass.simpleName}") val vectorComponent = getVectorComponent() @@ -81,7 +80,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), RoomAttachmen val index = events.indexOfFirst { it.eventId == args.eventId } initialIndex = index - if (savedInstanceState == null && addTransitionListener()) { args.sharedTransitionName?.let { ViewCompat.setTransitionName(imageTransitionView, it) @@ -110,12 +108,10 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), RoomAttachmen window.statusBarColor = ContextCompat.getColor(this, R.color.black_alpha) window.navigationBarColor = ContextCompat.getColor(this, R.color.black_alpha) - } private fun getOtherThemes() = ActivityOtherThemes.VectorAttachmentsPreview - override fun shouldAnimateDismiss(): Boolean { return currentPosition != initialIndex } @@ -137,7 +133,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), RoomAttachmen transitionImageContainer.isVisible = true } isAnimatingOut = true - ActivityCompat.finishAfterTransition(this); + ActivityCompat.finishAfterTransition(this) } /* ========================================================================================== @@ -180,7 +176,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), RoomAttachmen private fun args() = intent.getParcelableExtra(EXTRA_ARGS) - private fun getVectorComponent(): VectorComponent { return (application as HasVectorInjector).injector() } @@ -205,7 +200,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), RoomAttachmen it.putExtra(EXTRA_ARGS, Args(roomId, eventId, sharedTransitionName)) it.putExtra(EXTRA_IMAGE_DATA, mediaData) } - } override fun onDismissTapped() {