kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix poor handling of single tap touches.
rodzic
6673df2514
commit
957f8754e1
|
@ -17,7 +17,6 @@ import android.view.GestureDetector
|
|||
import android.view.MotionEvent
|
||||
import android.view.ScaleGestureDetector
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.animation.Interpolator
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
|
@ -227,6 +226,8 @@ class StoryViewerPageFragment :
|
|||
)
|
||||
)
|
||||
|
||||
gestureDetector.setOnDoubleTapListener(null)
|
||||
|
||||
val scaleListener = StoryScaleListener(
|
||||
viewModel, sharedViewModel, card
|
||||
)
|
||||
|
@ -248,10 +249,6 @@ class StoryViewerPageFragment :
|
|||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
viewModel.setIsUserTouching(true)
|
||||
} else if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP) {
|
||||
singleTapHandler.onActionUp(event)
|
||||
}
|
||||
|
||||
viewModel.setIsUserTouching(false)
|
||||
|
||||
val canCloseFromHorizontalSlide = requireView().translationX > DimensionUnit.DP.toPixels(56f)
|
||||
|
@ -1074,21 +1071,7 @@ class StoryViewerPageFragment :
|
|||
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) {
|
||||
if (System.currentTimeMillis() - tapStart > ViewConfiguration.getTapTimeout()) {
|
||||
return
|
||||
}
|
||||
|
||||
if (e.x < container.measuredWidth * getLeftBoundary()) {
|
||||
performLeftAction()
|
||||
} else if (e.x > container.measuredWidth - (container.measuredWidth * getRightBoundary())) {
|
||||
|
@ -1213,7 +1196,11 @@ class StoryViewerPageFragment :
|
|||
private val maxSlide = DimensionUnit.DP.toPixels(56f * 2)
|
||||
|
||||
override fun onDown(e: MotionEvent): Boolean {
|
||||
singleTapHandler.onDown()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
singleTapHandler.onActionUp(e)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -1252,7 +1239,6 @@ class StoryViewerPageFragment :
|
|||
|
||||
onContentTranslation(viewToTranslate.translationX, viewToTranslate.translationY)
|
||||
|
||||
singleTapHandler.onGestureHappened()
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -1274,7 +1260,6 @@ class StoryViewerPageFragment :
|
|||
onReplyToPost()
|
||||
}
|
||||
|
||||
singleTapHandler.onGestureHappened()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,9 @@ class StoryImageLoader(
|
|||
fun clear() {
|
||||
GlideApp.with(postImage).clear(postImage)
|
||||
GlideApp.with(blurImage).clear(blurImage)
|
||||
|
||||
postImage.setImageDrawable(null)
|
||||
blurImage.setImageDrawable(null)
|
||||
}
|
||||
|
||||
private fun loadViaCache(cacheValue: StoryCache.StoryCacheValue) {
|
||||
|
|
|
@ -31,6 +31,7 @@ class StoryPostFragment : Fragment(R.layout.stories_post_fragment) {
|
|||
})
|
||||
|
||||
private val binding by ViewBinderDelegate(StoriesPostFragmentBinding::bind) {
|
||||
it.video.cleanup()
|
||||
presentNone()
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,13 @@ class StoryVideoLoader(
|
|||
fun load() {
|
||||
fragment.viewLifecycleOwner.lifecycle.addObserver(this)
|
||||
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() {
|
||||
fragment.viewLifecycleOwner.lifecycle.removeObserver(this)
|
||||
videoPlayer.cleanup()
|
||||
videoPlayer.stop()
|
||||
}
|
||||
|
||||
override fun onResume(lifecycleOwner: LifecycleOwner) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.thoughtcrime.securesms.video;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
@ -25,6 +26,8 @@ import android.widget.FrameLayout;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
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.ExoPlayer;
|
||||
|
@ -35,7 +38,6 @@ import com.google.android.exoplayer2.Tracks;
|
|||
import com.google.android.exoplayer2.source.ClippingMediaSource;
|
||||
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
|
||||
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.PlayerControlView;
|
||||
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.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.mms.VideoSlide;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -80,7 +81,11 @@ public class VideoPlayer extends FrameLayout {
|
|||
public VideoPlayer(Context context, AttributeSet attrs, int 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);
|
||||
|
||||
|
@ -202,6 +207,12 @@ public class VideoPlayer extends FrameLayout {
|
|||
}
|
||||
}
|
||||
|
||||
public void setKeepContentOnPlayerReset(boolean keepContentOnPlayerReset) {
|
||||
if (this.exoView != null) {
|
||||
this.exoView.setKeepContentOnPlayerReset(keepContentOnPlayerReset);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnClickListener(@Nullable OnClickListener l) {
|
||||
if (this.exoView != null) {
|
||||
|
@ -215,11 +226,15 @@ public class VideoPlayer extends FrameLayout {
|
|||
return this.exoControls;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
public void stop() {
|
||||
if (this.exoPlayer != null) {
|
||||
exoPlayer.stop();
|
||||
exoPlayer.clearMediaItems();
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
if (this.exoPlayer != null) {
|
||||
exoView.setPlayer(null);
|
||||
exoControls.setPlayer(null);
|
||||
|
||||
|
@ -319,9 +334,9 @@ public class VideoPlayer extends FrameLayout {
|
|||
|
||||
private @NonNull MediaItem.ClippingConfiguration getClippingConfiguration(long startMs, long endMs) {
|
||||
return startMs != endMs ? new MediaItem.ClippingConfiguration.Builder()
|
||||
.setStartPositionMs(startMs)
|
||||
.setEndPositionMs(endMs)
|
||||
.build()
|
||||
.setStartPositionMs(startMs)
|
||||
.setEndPositionMs(endMs)
|
||||
.build()
|
||||
: MediaItem.ClippingConfiguration.UNSET;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
@ -25,6 +26,7 @@
|
|||
<org.thoughtcrime.securesms.video.VideoPlayer
|
||||
android:id="@+id/video"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
app:playerLayoutId="@layout/story_video_player" />
|
||||
|
||||
</FrameLayout>
|
|
@ -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>
|
|
@ -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>
|
|
@ -293,6 +293,10 @@
|
|||
<attr name="thumbHintBackgroundColor" format="color" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="VideoPlayer">
|
||||
<attr name="playerLayoutId" format="dimension" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="GroupMemberListView">
|
||||
<attr name="maxHeight" />
|
||||
<attr name="selectable" format="boolean" />
|
||||
|
|
Ładowanie…
Reference in New Issue