Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* SPDX-FileCopyrightText: 2021 Andy Scherzinger <[email protected]>
* SPDX-FileCopyrightText: 2021 Marcel Hibbe <[email protected]>
* SPDX-FileCopyrightText: 2021 Dariusz Olszewski <[email protected]>
* SPDX-FileCopyrightText: 2026 Enrique López-Mañas <[email protected]>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.fullscreenfile

import android.content.Intent
import android.os.Bundle
import android.util.Log
import com.nextcloud.talk.ui.SwipeToCloseLayout
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -133,6 +135,12 @@ class FullScreenImageActivity : AppCompatActivity() {
binding.photoView.visibility = View.VISIBLE
displayImage(path)
}

binding.swipeToCloseLayout.setOnSwipeToCloseListener(object : SwipeToCloseLayout.OnSwipeToCloseListener {
override fun onSwipeToClose() {
finish()
}
})
}

private fun displayImage(path: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* SPDX-FileCopyrightText: 2023 Parneet Singh <[email protected]>
* SPDX-FileCopyrightText: 2021 Andy Scherzinger <[email protected]>
* SPDX-FileCopyrightText: 2021 Marcel Hibbe <[email protected]>
* SPDX-FileCopyrightText: 2026 Enrique López-Mañas <[email protected]>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.fullscreenfile
Expand Down Expand Up @@ -39,6 +40,7 @@ import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.databinding.ActivityFullScreenMediaBinding
import com.nextcloud.talk.ui.SwipeToCloseLayout
import com.nextcloud.talk.ui.dialog.SaveToStorageDialogFragment
import com.nextcloud.talk.utils.Mimetype.VIDEO_PREFIX_GENERIC
import java.io.File
Expand Down Expand Up @@ -135,6 +137,12 @@ class FullScreenMediaActivity : AppCompatActivity() {
}
}
)

binding.swipeToCloseLayout.setOnSwipeToCloseListener(object : SwipeToCloseLayout.OnSwipeToCloseListener {
override fun onSwipeToClose() {
finish()
}
})
}

override fun onStart() {
Expand Down
92 changes: 92 additions & 0 deletions app/src/main/java/com/nextcloud/talk/ui/SwipeToCloseLayout.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2026 Enrique López-Mañas <[email protected]>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.ui

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout
import androidx.customview.widget.ViewDragHelper
import kotlin.math.abs

class SwipeToCloseLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

private var dragHelper: ViewDragHelper
private var swipeListener: OnSwipeToCloseListener? = null

interface OnSwipeToCloseListener {
fun onSwipeToClose()
}

init {
dragHelper = ViewDragHelper.create(this, 1.0f, DragCallback())
}

fun setOnSwipeToCloseListener(listener: OnSwipeToCloseListener) {
this.swipeListener = listener
}

override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
val action = ev.actionMasked
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
dragHelper.cancel()
return false
}
return dragHelper.shouldInterceptTouchEvent(ev)
}

override fun onTouchEvent(ev: MotionEvent): Boolean {
dragHelper.processTouchEvent(ev)
return true
}

private inner class DragCallback : ViewDragHelper.Callback() {
override fun tryCaptureView(child: View, pointerId: Int): Boolean {
return true // Capture any child view
}

override fun getViewVerticalDragRange(child: View): Int {
return height
}

override fun clampViewPositionVertical(child: View, therapeutic: Int, dy: Int): Int {
return therapeutic
}

override fun onViewReleased(releasedChild: View, xvel: Float, yvel: Float) {
val totalDragDistance = abs(releasedChild.top)
if (totalDragDistance > height * DRAG_THRESHOLD || abs(yvel) > dragHelper.minVelocity) {
swipeListener?.onSwipeToClose()
} else {
dragHelper.settleCapturedViewAt(0, 0)
invalidate()
}
}

override fun onViewPositionChanged(changedView: View, left: Int, top: Int, dx: Int, dy: Int) {
val progress = 1f - (abs(top).toFloat() / height)
alpha = progress.coerceIn(MIN_ALPHA, MAX_ALPHA)
}
}

override fun computeScroll() {
if (dragHelper.continueSettling(true)) {
postInvalidateOnAnimation()
}
}

companion object {
private const val DRAG_THRESHOLD = 0.3f
private const val MIN_ALPHA = 0.5f
private const val MAX_ALPHA = 1.0f
}
}
7 changes: 4 additions & 3 deletions app/src/main/res/layout/activity_full_screen_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
~ SPDX-FileCopyrightText: 2021 Andy Scherzinger <[email protected]>
~ SPDX-FileCopyrightText: 2021 Marcel Hibbe <[email protected]>
~ SPDX-FileCopyrightText: 2021 Dariusz Olszewski <[email protected]>
~ SPDX-FileCopyrightText: 2026 Enrique López-Mañas <[email protected]>
~ SPDX-License-Identifier: GPL-3.0-or-later
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.nextcloud.talk.ui.SwipeToCloseLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image_wrapper_view"
android:id="@+id/swipe_to_close_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fullscreenfile.FullScreenImageActivity">
Expand All @@ -35,4 +36,4 @@
android:layout_height="match_parent"
android:visibility="invisible" />

</FrameLayout>
</com.nextcloud.talk.ui.SwipeToCloseLayout>
6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_full_screen_media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
~
~ SPDX-FileCopyrightText: 2021 Andy Scherzinger <[email protected]>
~ SPDX-FileCopyrightText: 2021 Marcel Hibbe <[email protected]>
~ SPDX-FileCopyrightText: 2026 Enrique López-Mañas <[email protected]>
~ SPDX-License-Identifier: GPL-3.0-or-later
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.nextcloud.talk.ui.SwipeToCloseLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_to_close_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fullscreenfile.FullScreenMediaActivity">
Expand All @@ -28,4 +30,4 @@
app:show_buffering="when_playing"
app:show_shuffle_button="true" />

</FrameLayout>
</com.nextcloud.talk.ui.SwipeToCloseLayout>
Loading