Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2025 Julius Linus <juliuslinus1@gmail.com>
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package com.nextcloud.talk.fullscreenfile

import android.content.Context
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.ViewConfiguration
import kotlin.math.abs

class FullScreenGestureListener(val context: Context, val callback: () -> Unit) :
GestureDetector.SimpleOnGestureListener() {

private val viewConfig = ViewConfiguration.get(context)
private val minSwipeDistance = viewConfig.scaledTouchSlop
private val minSwipeVelocity = viewConfig.scaledMinimumFlingVelocity

override fun onDown(event: MotionEvent): Boolean = true

override fun onFling(e1: MotionEvent?, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
// Safety check for null start event
if (e1 == null) return false

val deltaX = e2.x - e1.x
val deltaY = e2.y - e1.y

if (abs(deltaY) > abs(deltaX)) { // Intended vertical swipe

if (deltaY > minSwipeDistance && abs(velocityY) > minSwipeVelocity) {
callback()
return true
}
}

return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
*/
package com.nextcloud.talk.fullscreenfile

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.GestureDetector
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -43,6 +45,7 @@ class FullScreenImageActivity : AppCompatActivity() {
private lateinit var windowInsetsController: WindowInsetsControllerCompat
private lateinit var path: String
private var showFullscreen = false
private lateinit var gestureDetector: GestureDetector

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_preview, menu)
Expand Down Expand Up @@ -90,6 +93,7 @@ class FullScreenImageActivity : AppCompatActivity() {
}
}

@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
Expand All @@ -107,10 +111,23 @@ class FullScreenImageActivity : AppCompatActivity() {
binding.photoView.setOnOutsidePhotoTapListener {
toggleFullscreen()
}

binding.gifView.setOnClickListener {
toggleFullscreen()
}

binding.photoView.setOnTouchListener { _, p1 ->
p1?.let {
gestureDetector.onTouchEvent(it)
} ?: false
}

binding.gifView.setOnTouchListener { _, p1 ->
p1?.let {
gestureDetector.onTouchEvent(it)
} ?: false
}

// Enable enlarging the image more than default 3x maximumScale.
// Medium scale adapted to make double-tap behaviour more consistent.
binding.photoView.maximumScale = MAX_SCALE
Expand All @@ -133,6 +150,13 @@ class FullScreenImageActivity : AppCompatActivity() {
binding.photoView.visibility = View.VISIBLE
displayImage(path)
}

gestureDetector = GestureDetector(
this,
FullScreenGestureListener(this) {
onBackPressedDispatcher.onBackPressed()
}
)
}

private fun displayImage(path: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
*/
package com.nextcloud.talk.fullscreenfile

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.GestureDetector
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup.MarginLayoutParams
Expand Down Expand Up @@ -52,6 +54,7 @@ class FullScreenMediaActivity : AppCompatActivity() {
private var playWhenReadyState: Boolean = true
private var playBackPosition: Long = 0L
private lateinit var windowInsetsController: WindowInsetsControllerCompat
private lateinit var gestureDetector: GestureDetector

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_preview, menu)
Expand Down Expand Up @@ -99,6 +102,7 @@ class FullScreenMediaActivity : AppCompatActivity() {
}
}

@SuppressLint("ClickableViewAccessibility")
@OptIn(UnstableApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -122,6 +126,12 @@ class FullScreenMediaActivity : AppCompatActivity() {
binding.playerView.controllerShowTimeoutMs = 0
}

binding.playerView.setOnTouchListener { _, p1 ->
p1?.let {
gestureDetector.onTouchEvent(it)
} ?: false
}

initWindowInsetsController()
applyWindowInsets()

Expand All @@ -134,6 +144,13 @@ class FullScreenMediaActivity : AppCompatActivity() {
}
}
)

gestureDetector = GestureDetector(
this,
FullScreenGestureListener(this) {
onBackPressedDispatcher.onBackPressed()
}
)
}

override fun onStart() {
Expand Down
Loading