Fix poor handling of single tap touches.

fork-5.53.8
Alex Hart 2022-10-14 10:31:55 -03:00
rodzic 6673df2514
commit 957f8754e1
9 zmienionych plików z 82 dodań i 31 usunięć

Wyświetl plik

@ -17,7 +17,6 @@ import android.view.GestureDetector
import android.view.MotionEvent import android.view.MotionEvent
import android.view.ScaleGestureDetector import android.view.ScaleGestureDetector
import android.view.View import android.view.View
import android.view.ViewConfiguration
import android.view.animation.Interpolator import android.view.animation.Interpolator
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.TextView import android.widget.TextView
@ -227,6 +226,8 @@ class StoryViewerPageFragment :
) )
) )
gestureDetector.setOnDoubleTapListener(null)
val scaleListener = StoryScaleListener( val scaleListener = StoryScaleListener(
viewModel, sharedViewModel, card viewModel, sharedViewModel, card
) )
@ -248,10 +249,6 @@ class StoryViewerPageFragment :
if (event.actionMasked == MotionEvent.ACTION_DOWN) { if (event.actionMasked == MotionEvent.ACTION_DOWN) {
viewModel.setIsUserTouching(true) viewModel.setIsUserTouching(true)
} else if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) { } else if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
if (event.actionMasked == MotionEvent.ACTION_UP) {
singleTapHandler.onActionUp(event)
}
viewModel.setIsUserTouching(false) viewModel.setIsUserTouching(false)
val canCloseFromHorizontalSlide = requireView().translationX > DimensionUnit.DP.toPixels(56f) val canCloseFromHorizontalSlide = requireView().translationX > DimensionUnit.DP.toPixels(56f)
@ -1074,21 +1071,7 @@ class StoryViewerPageFragment :
private const val BOUNDARY_PREV = 1f - BOUNDARY_NEXT private const val BOUNDARY_PREV = 1f - BOUNDARY_NEXT
} }
private var tapStart: Long = 0L
fun onGestureHappened() {
tapStart = 0L
}
fun onDown() {
tapStart = System.currentTimeMillis()
}
fun onActionUp(e: MotionEvent) { fun onActionUp(e: MotionEvent) {
if (System.currentTimeMillis() - tapStart > ViewConfiguration.getTapTimeout()) {
return
}
if (e.x < container.measuredWidth * getLeftBoundary()) { if (e.x < container.measuredWidth * getLeftBoundary()) {
performLeftAction() performLeftAction()
} else if (e.x > container.measuredWidth - (container.measuredWidth * getRightBoundary())) { } else if (e.x > container.measuredWidth - (container.measuredWidth * getRightBoundary())) {
@ -1213,7 +1196,11 @@ class StoryViewerPageFragment :
private val maxSlide = DimensionUnit.DP.toPixels(56f * 2) private val maxSlide = DimensionUnit.DP.toPixels(56f * 2)
override fun onDown(e: MotionEvent): Boolean { override fun onDown(e: MotionEvent): Boolean {
singleTapHandler.onDown() return true
}
override fun onSingleTapUp(e: MotionEvent): Boolean {
singleTapHandler.onActionUp(e)
return true return true
} }
@ -1252,7 +1239,6 @@ class StoryViewerPageFragment :
onContentTranslation(viewToTranslate.translationX, viewToTranslate.translationY) onContentTranslation(viewToTranslate.translationX, viewToTranslate.translationY)
singleTapHandler.onGestureHappened()
return true return true
} }
@ -1274,7 +1260,6 @@ class StoryViewerPageFragment :
onReplyToPost() onReplyToPost()
} }
singleTapHandler.onGestureHappened()
return true return true
} }
} }

Wyświetl plik

@ -73,6 +73,9 @@ class StoryImageLoader(
fun clear() { fun clear() {
GlideApp.with(postImage).clear(postImage) GlideApp.with(postImage).clear(postImage)
GlideApp.with(blurImage).clear(blurImage) GlideApp.with(blurImage).clear(blurImage)
postImage.setImageDrawable(null)
blurImage.setImageDrawable(null)
} }
private fun loadViaCache(cacheValue: StoryCache.StoryCacheValue) { private fun loadViaCache(cacheValue: StoryCache.StoryCacheValue) {

Wyświetl plik

@ -31,6 +31,7 @@ class StoryPostFragment : Fragment(R.layout.stories_post_fragment) {
}) })
private val binding by ViewBinderDelegate(StoriesPostFragmentBinding::bind) { private val binding by ViewBinderDelegate(StoriesPostFragmentBinding::bind) {
it.video.cleanup()
presentNone() presentNone()
} }

Wyświetl plik

@ -23,11 +23,13 @@ class StoryVideoLoader(
fun load() { fun load() {
fragment.viewLifecycleOwner.lifecycle.addObserver(this) fragment.viewLifecycleOwner.lifecycle.addObserver(this)
videoPlayer.setVideoSource(VideoSlide(fragment.requireContext(), videoPost.videoUri, videoPost.size, false), true, TAG, videoPost.clipStart.inWholeMilliseconds, videoPost.clipEnd.inWholeMilliseconds) videoPlayer.setVideoSource(VideoSlide(fragment.requireContext(), videoPost.videoUri, videoPost.size, false), true, TAG, videoPost.clipStart.inWholeMilliseconds, videoPost.clipEnd.inWholeMilliseconds)
videoPlayer.hideControls()
videoPlayer.setKeepContentOnPlayerReset(false)
} }
fun clear() { fun clear() {
fragment.viewLifecycleOwner.lifecycle.removeObserver(this) fragment.viewLifecycleOwner.lifecycle.removeObserver(this)
videoPlayer.cleanup() videoPlayer.stop()
} }
override fun onResume(lifecycleOwner: LifecycleOwner) { override fun onResume(lifecycleOwner: LifecycleOwner) {

Wyświetl plik

@ -17,6 +17,7 @@
package org.thoughtcrime.securesms.video; package org.thoughtcrime.securesms.video;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
@ -25,6 +26,8 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.res.TypedArrayKt;
import androidx.core.content.res.TypedArrayUtils;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
@ -35,7 +38,6 @@ import com.google.android.exoplayer2.Tracks;
import com.google.android.exoplayer2.source.ClippingMediaSource; import com.google.android.exoplayer2.source.ClippingMediaSource;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory; import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.PlayerControlView; import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.ui.PlayerView;
@ -44,7 +46,6 @@ import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.mms.VideoSlide; import org.thoughtcrime.securesms.mms.VideoSlide;
import org.thoughtcrime.securesms.util.MediaUtil;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -80,7 +81,11 @@ public class VideoPlayer extends FrameLayout {
public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) { public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
inflate(context, R.layout.video_player, this); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.VideoPlayer);
int videPlayerLayout = typedArray.getResourceId(R.styleable.VideoPlayer_playerLayoutId, R.layout.video_player);
typedArray.recycle();
inflate(context, videPlayerLayout, this);
this.mediaSourceFactory = new DefaultMediaSourceFactory(context); this.mediaSourceFactory = new DefaultMediaSourceFactory(context);
@ -202,6 +207,12 @@ public class VideoPlayer extends FrameLayout {
} }
} }
public void setKeepContentOnPlayerReset(boolean keepContentOnPlayerReset) {
if (this.exoView != null) {
this.exoView.setKeepContentOnPlayerReset(keepContentOnPlayerReset);
}
}
@Override @Override
public void setOnClickListener(@Nullable OnClickListener l) { public void setOnClickListener(@Nullable OnClickListener l) {
if (this.exoView != null) { if (this.exoView != null) {
@ -215,11 +226,15 @@ public class VideoPlayer extends FrameLayout {
return this.exoControls; return this.exoControls;
} }
public void cleanup() { public void stop() {
if (this.exoPlayer != null) { if (this.exoPlayer != null) {
exoPlayer.stop(); exoPlayer.stop();
exoPlayer.clearMediaItems(); exoPlayer.clearMediaItems();
}
}
public void cleanup() {
if (this.exoPlayer != null) {
exoView.setPlayer(null); exoView.setPlayer(null);
exoControls.setPlayer(null); exoControls.setPlayer(null);
@ -319,9 +334,9 @@ public class VideoPlayer extends FrameLayout {
private @NonNull MediaItem.ClippingConfiguration getClippingConfiguration(long startMs, long endMs) { private @NonNull MediaItem.ClippingConfiguration getClippingConfiguration(long startMs, long endMs) {
return startMs != endMs ? new MediaItem.ClippingConfiguration.Builder() return startMs != endMs ? new MediaItem.ClippingConfiguration.Builder()
.setStartPositionMs(startMs) .setStartPositionMs(startMs)
.setEndPositionMs(endMs) .setEndPositionMs(endMs)
.build() .build()
: MediaItem.ClippingConfiguration.UNSET; : MediaItem.ClippingConfiguration.UNSET;
} }

Wyświetl plik

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -25,6 +26,7 @@
<org.thoughtcrime.securesms.video.VideoPlayer <org.thoughtcrime.securesms.video.VideoPlayer
android:id="@+id/video" android:id="@+id/video"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
app:playerLayoutId="@layout/story_video_player" />
</FrameLayout> </FrameLayout>

Wyświetl plik

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:viewBindingIgnore="true">
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout
android:id="@+id/exo_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
<View
android:id="@+id/exo_shutter"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

Wyświetl plik

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:viewBindingIgnore="true">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
app:player_layout_id="@layout/story_exoplayer_layout"
app:shutter_background_color="@color/core_black"
app:surface_type="texture_view" />
</FrameLayout>

Wyświetl plik

@ -293,6 +293,10 @@
<attr name="thumbHintBackgroundColor" format="color" /> <attr name="thumbHintBackgroundColor" format="color" />
</declare-styleable> </declare-styleable>
<declare-styleable name="VideoPlayer">
<attr name="playerLayoutId" format="dimension" />
</declare-styleable>
<declare-styleable name="GroupMemberListView"> <declare-styleable name="GroupMemberListView">
<attr name="maxHeight" /> <attr name="maxHeight" />
<attr name="selectable" format="boolean" /> <attr name="selectable" format="boolean" />