Skip to content

Commit

Permalink
Reformats project kotlin files
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdecanini committed Apr 9, 2022
1 parent 624f0a3 commit 1c2b55d
Show file tree
Hide file tree
Showing 2,337 changed files with 44,991 additions and 41,920 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.view.View
import im.vector.lib.attachmentviewer.databinding.ItemAnimatedImageAttachmentBinding

class AnimatedImageViewHolder constructor(itemView: View) :
BaseViewHolder(itemView) {
BaseViewHolder(itemView) {

val views = ItemAnimatedImageAttachmentBinding.bind(itemView)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ sealed class AttachmentInfo(open val uid: String) {
data class Image(override val uid: String, val url: String, val data: Any?) : AttachmentInfo(uid)
data class AnimatedImage(override val uid: String, val url: String, val data: Any?) : AttachmentInfo(uid)
data class Video(override val uid: String, val url: String, val data: Any, val thumbnail: Image?) : AttachmentInfo(uid)
// data class Audio(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid)
// data class File(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid)
// data class Audio(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid)
// data class File(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid)
}

interface AttachmentSourceProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
private var isSwipeToDismissAllowed: Boolean = true
private var isOverlayWasClicked = false

// private val shouldDismissToBottom: Boolean
// get() = e == null
// || !externalTransitionImageView.isRectVisible
// || !isAtStartPosition
// private val shouldDismissToBottom: Boolean
// get() = e == null
// || !externalTransitionImageView.isRectVisible
// || !isAtStartPosition

private var isImagePagerIdle = true

Expand Down Expand Up @@ -204,13 +204,13 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
// Log.v("ATTACHEMENTS", "wasScaled $wasScaled")
if (swipeDirection == null && (scaleDetector.isInProgress || ev.pointerCount > 1 || wasScaled)) {
wasScaled = true
// Log.v("ATTACHEMENTS", "dispatch to pager")
// Log.v("ATTACHEMENTS", "dispatch to pager")
return views.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================")
// Log.v("ATTACHEMENTS", "\n================")
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
}

private fun handleEventActionUp(event: MotionEvent) {
// wasDoubleTapped = false
// wasDoubleTapped = false
swipeDismissHandler.onTouch(views.rootContainer, event)
views.attachmentPager.dispatchTouchEvent(event)
isOverlayWasClicked = dispatchOverlayTouch(event)
Expand Down Expand Up @@ -267,19 +267,19 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
}

private fun handleTouchIfNotScaled(event: MotionEvent): Boolean {
// Log.v("ATTACHEMENTS", "handleTouchIfNotScaled $event")
// Log.v("ATTACHEMENTS", "handleTouchIfNotScaled $event")
directionDetector.handleTouchEvent(event)

return when (swipeDirection) {
SwipeDirection.Up, SwipeDirection.Down -> {
SwipeDirection.Up, SwipeDirection.Down -> {
if (isSwipeToDismissAllowed && !wasScaled && isImagePagerIdle) {
swipeDismissHandler.onTouch(views.rootContainer, event)
} else true
}
SwipeDirection.Left, SwipeDirection.Right -> {
views.attachmentPager.dispatchTouchEvent(event)
}
else -> true
else -> true
}
}

Expand All @@ -291,40 +291,40 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
}

private fun dispatchOverlayTouch(event: MotionEvent): Boolean =
overlayView
?.let { it.isVisible && it.dispatchTouchEvent(event) }
?: false
overlayView
?.let { it.isVisible && it.dispatchTouchEvent(event) }
?: false

private fun calculateTranslationAlpha(translationY: Float, translationLimit: Int): Float =
1.0f - 1.0f / translationLimit.toFloat() / 4f * abs(translationY)
1.0f - 1.0f / translationLimit.toFloat() / 4f * abs(translationY)

private fun createSwipeToDismissHandler(): SwipeToDismissHandler =
SwipeToDismissHandler(
swipeView = views.dismissContainer,
shouldAnimateDismiss = { shouldAnimateDismiss() },
onDismiss = { animateClose() },
onSwipeViewMove = ::handleSwipeViewMove
)
SwipeToDismissHandler(
swipeView = views.dismissContainer,
shouldAnimateDismiss = { shouldAnimateDismiss() },
onDismiss = { animateClose() },
onSwipeViewMove = ::handleSwipeViewMove
)

private fun createSwipeDirectionDetector() =
SwipeDirectionDetector(this) { swipeDirection = it }
SwipeDirectionDetector(this) { swipeDirection = it }

private fun createScaleGestureDetector() =
ScaleGestureDetector(this, ScaleGestureDetector.SimpleOnScaleGestureListener())
ScaleGestureDetector(this, ScaleGestureDetector.SimpleOnScaleGestureListener())

private fun createGestureDetector() =
GestureDetectorCompat(this, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (isImagePagerIdle) {
handleSingleTap(e, isOverlayWasClicked)
}
return false
GestureDetectorCompat(this, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (isImagePagerIdle) {
handleSingleTap(e, isOverlayWasClicked)
}
return false
}

override fun onDoubleTap(e: MotionEvent?): Boolean {
return super.onDoubleTap(e)
}
})
override fun onDoubleTap(e: MotionEvent?): Boolean {
return super.onDoubleTap(e)
}
})

override fun onEvent(event: AttachmentEvents) {
if (overlayView is AttachmentEventListener) {
Expand All @@ -341,7 +341,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi

fun handle(commands: AttachmentCommands) {
(attachmentsAdapter.recyclerView?.findViewHolderForAdapterPosition(currentPosition) as? BaseViewHolder)
?.handleCommand(commands)
?.handleCommand(commands)
}

@Suppress("DEPRECATION")
Expand Down Expand Up @@ -380,7 +380,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
}

// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
// except for the ones that make the content appear under the system bars.
@Suppress("DEPRECATION")
private fun showSystemUI() {
systemUiVisibility = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ class AttachmentsAdapter : RecyclerView.Adapter<BaseViewHolder>() {
val inflater = LayoutInflater.from(parent.context)
val itemView = inflater.inflate(viewType, parent, false)
return when (viewType) {
R.layout.item_image_attachment -> ZoomableImageViewHolder(itemView)
R.layout.item_image_attachment -> ZoomableImageViewHolder(itemView)
R.layout.item_animated_image_attachment -> AnimatedImageViewHolder(itemView)
R.layout.item_video_attachment -> VideoViewHolder(itemView)
else -> UnsupportedViewHolder(itemView)
R.layout.item_video_attachment -> VideoViewHolder(itemView)
else -> UnsupportedViewHolder(itemView)
}
}

override fun getItemViewType(position: Int): Int {
val info = attachmentSourceProvider!!.getAttachmentInfoAt(position)
return when (info) {
is AttachmentInfo.Image -> R.layout.item_image_attachment
is AttachmentInfo.Video -> R.layout.item_video_attachment
is AttachmentInfo.Image -> R.layout.item_image_attachment
is AttachmentInfo.Video -> R.layout.item_video_attachment
is AttachmentInfo.AnimatedImage -> R.layout.item_animated_image_attachment
// is AttachmentInfo.Audio -> TODO()
// is AttachmentInfo.File -> TODO()
// is AttachmentInfo.Audio -> TODO()
// is AttachmentInfo.File -> TODO()
}
}

Expand All @@ -68,17 +68,17 @@ class AttachmentsAdapter : RecyclerView.Adapter<BaseViewHolder>() {
attachmentSourceProvider?.getAttachmentInfoAt(position)?.let {
holder.bind(it)
when (it) {
is AttachmentInfo.Image -> {
is AttachmentInfo.Image -> {
attachmentSourceProvider?.loadImage((holder as ZoomableImageViewHolder).target, it)
}
is AttachmentInfo.AnimatedImage -> {
attachmentSourceProvider?.loadImage((holder as AnimatedImageViewHolder).target, it)
}
is AttachmentInfo.Video -> {
is AttachmentInfo.Video -> {
attachmentSourceProvider?.loadVideo((holder as VideoViewHolder).target, it)
}
// else -> {
// // }
// else -> {
// // }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.view.View
import androidx.recyclerview.widget.RecyclerView

abstract class BaseViewHolder constructor(itemView: View) :
RecyclerView.ViewHolder(itemView) {
RecyclerView.ViewHolder(itemView) {

open fun onRecycled() {
boundResourceUid = null
Expand All @@ -42,4 +42,4 @@ abstract class BaseViewHolder constructor(itemView: View) :
}

class UnsupportedViewHolder constructor(itemView: View) :
BaseViewHolder(itemView)
BaseViewHolder(itemView)
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ sealed class SwipeDirection {
companion object {
fun fromAngle(angle: Double): SwipeDirection {
return when (angle) {
in 0.0..45.0 -> Right
in 45.0..135.0 -> Up
in 0.0..45.0 -> Right
in 45.0..135.0 -> Up
in 135.0..225.0 -> Left
in 225.0..315.0 -> Down
in 315.0..360.0 -> Right
else -> NotDetected
else -> NotDetected
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import android.view.MotionEvent
import kotlin.math.sqrt

class SwipeDirectionDetector(
context: Context,
private val onDirectionDetected: (SwipeDirection) -> Unit
context: Context,
private val onDirectionDetected: (SwipeDirection) -> Unit
) {

private val touchSlop: Int = android.view.ViewConfiguration.get(context).scaledTouchSlop
Expand All @@ -33,7 +33,7 @@ class SwipeDirectionDetector(

fun handleTouchEvent(event: MotionEvent) {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
MotionEvent.ACTION_DOWN -> {
startX = event.x
startY = event.y
}
Expand All @@ -45,7 +45,7 @@ class SwipeDirectionDetector(
startX = startY
isDetected = false
}
MotionEvent.ACTION_MOVE -> if (!isDetected && getEventDistance(event) > touchSlop) {
MotionEvent.ACTION_MOVE -> if (!isDetected && getEventDistance(event) > touchSlop) {
isDetected = true
onDirectionDetected(getDirection(startX, startY, event.x, event.y))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import android.view.ViewPropertyAnimator
import android.view.animation.AccelerateInterpolator

class SwipeToDismissHandler(
private val swipeView: View,
private val onDismiss: () -> Unit,
private val onSwipeViewMove: (translationY: Float, translationLimit: Int) -> Unit,
private val shouldAnimateDismiss: () -> Boolean
private val swipeView: View,
private val onDismiss: () -> Unit,
private val onSwipeViewMove: (translationY: Float, translationLimit: Int) -> Unit,
private val shouldAnimateDismiss: () -> Boolean
) : View.OnTouchListener {

companion object {
Expand All @@ -44,7 +44,7 @@ class SwipeToDismissHandler(
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
MotionEvent.ACTION_DOWN -> {
if (swipeView.hitRect.contains(event.x.toInt(), event.y.toInt())) {
isTracking = true
}
Expand All @@ -58,15 +58,15 @@ class SwipeToDismissHandler(
}
return true
}
MotionEvent.ACTION_MOVE -> {
MotionEvent.ACTION_MOVE -> {
if (isTracking) {
val translationY = event.y - startY
swipeView.translationY = translationY
onSwipeViewMove(translationY, translationLimit)
}
return true
}
else -> {
else -> {
return false
}
}
Expand All @@ -79,8 +79,8 @@ class SwipeToDismissHandler(
private fun onTrackingEnd(parentHeight: Int) {
val animateTo = when {
swipeView.translationY < -translationLimit -> -parentHeight.toFloat()
swipeView.translationY > translationLimit -> parentHeight.toFloat()
else -> 0f
swipeView.translationY > translationLimit -> parentHeight.toFloat()
else -> 0f
}

if (animateTo != 0f && !shouldAnimateDismiss()) {
Expand All @@ -92,35 +92,35 @@ class SwipeToDismissHandler(

private fun animateTranslation(translationTo: Float) {
swipeView.animate()
.translationY(translationTo)
.setDuration(ANIMATION_DURATION)
.setInterpolator(AccelerateInterpolator())
.setUpdateListener { onSwipeViewMove(swipeView.translationY, translationLimit) }
.setAnimatorListener(onAnimationEnd = {
if (translationTo != 0f) {
onDismiss()
}
.translationY(translationTo)
.setDuration(ANIMATION_DURATION)
.setInterpolator(AccelerateInterpolator())
.setUpdateListener { onSwipeViewMove(swipeView.translationY, translationLimit) }
.setAnimatorListener(onAnimationEnd = {
if (translationTo != 0f) {
onDismiss()
}

// remove the update listener, otherwise it will be saved on the next animation execution:
swipeView.animate().setUpdateListener(null)
})
.start()
// remove the update listener, otherwise it will be saved on the next animation execution:
swipeView.animate().setUpdateListener(null)
})
.start()
}
}

internal fun ViewPropertyAnimator.setAnimatorListener(
onAnimationEnd: ((Animator?) -> Unit)? = null,
onAnimationStart: ((Animator?) -> Unit)? = null
onAnimationEnd: ((Animator?) -> Unit)? = null,
onAnimationStart: ((Animator?) -> Unit)? = null
) = this.setListener(
object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
onAnimationEnd?.invoke(animation)
}
object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
onAnimationEnd?.invoke(animation)
}

override fun onAnimationStart(animation: Animator?) {
onAnimationStart?.invoke(animation)
}
})
override fun onAnimationStart(animation: Animator?) {
onAnimationStart?.invoke(animation)
}
})

internal val View?.hitRect: Rect
get() = Rect().also { this?.getHitRect(it) }
Loading

0 comments on commit 1c2b55d

Please sign in to comment.