Ensure MP4 Gif vertical position updates as content slides.

This commit is contained in:
Alex Hart 2021-10-25 15:23:15 -03:00 committed by GitHub
parent 8f007a23cd
commit 5113f8b203
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 13 deletions

View file

@ -101,6 +101,7 @@ import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
import org.thoughtcrime.securesms.database.model.ReactionRecord;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.giph.mp4.GiphyMp4ItemDecoration;
import org.thoughtcrime.securesms.giph.mp4.GiphyMp4Playable;
import org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackController;
import org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicy;
@ -366,6 +367,7 @@ public class ConversationFragment extends LoggingFragment implements Multiselect
GiphyMp4ProjectionRecycler callback = new GiphyMp4ProjectionRecycler(holders);
GiphyMp4PlaybackController.attach(list, callback, maxPlayback);
list.addItemDecoration(new GiphyMp4ItemDecoration(callback), 0);
return callback;
}

View file

@ -1715,10 +1715,12 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
public @NonNull Projection getGiphyMp4PlayableProjection(@NonNull ViewGroup recyclerView) {
if (mediaThumbnailStub != null && mediaThumbnailStub.isResolvable()) {
return Projection.relativeToParent(recyclerView, mediaThumbnailStub.require(), mediaThumbnailStub.require().getCorners())
.translateY(getTranslationY())
.translateX(bodyBubble.getTranslationX())
.translateX(getTranslationX());
} else {
return Projection.relativeToParent(recyclerView, bodyBubble, bodyBubbleCorners)
.translateY(getTranslationY())
.translateX(bodyBubble.getTranslationX())
.translateX(getTranslationX());
}

View file

@ -0,0 +1,16 @@
package org.thoughtcrime.securesms.giph.mp4
import android.graphics.Canvas
import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView
/**
* Decoration that will make the video display params update on each recycler redraw.
*/
class GiphyMp4ItemDecoration(val callback: GiphyMp4PlaybackController.Callback) : RecyclerView.ItemDecoration() {
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
parent.children.map { parent.getChildViewHolder(it) }.filterIsInstance(GiphyMp4Playable::class.java).forEach {
callback.updateVideoDisplayPositionAndSize(parent, it)
}
}
}

View file

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.giph.mp4;
import android.graphics.Canvas;
import android.view.View;
import androidx.annotation.NonNull;
@ -43,16 +44,12 @@ public final class GiphyMp4PlaybackController extends RecyclerView.OnScrollListe
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
enqueuePlaybackUpdate(recyclerView);
performPlaybackUpdate(recyclerView);
}
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
RecyclerView recyclerView = (RecyclerView) v;
enqueuePlaybackUpdate(recyclerView);
}
private void enqueuePlaybackUpdate(@NonNull RecyclerView recyclerView) {
performPlaybackUpdate(recyclerView);
}
@ -126,8 +123,9 @@ public final class GiphyMp4PlaybackController extends RecyclerView.OnScrollListe
}
}
interface Callback {
public interface Callback {
void update(@NonNull RecyclerView recyclerView, @NonNull List<GiphyMp4Playable> holders, @NonNull Set<Integer> playbackSet);
void updateVideoDisplayPositionAndSize(@NonNull RecyclerView recyclerView, @NonNull GiphyMp4Playable holder);
}
@VisibleForTesting

View file

@ -50,6 +50,7 @@ public final class GiphyMp4ProjectionRecycler implements GiphyMp4PlaybackControl
}
}
@Override
public void updateVideoDisplayPositionAndSize(@NonNull RecyclerView recyclerView, @NonNull GiphyMp4Playable holder) {
GiphyMp4ProjectionPlayerHolder playerHolder = getCurrentHolder(holder.getAdapterPosition());
if (playerHolder != null) {
@ -57,13 +58,6 @@ public final class GiphyMp4ProjectionRecycler implements GiphyMp4PlaybackControl
}
}
public @Nullable View getVideoPlayerAtAdapterPosition(int adapterPosition) {
GiphyMp4ProjectionPlayerHolder holder = getCurrentHolder(adapterPosition);
if (holder != null) return holder.getContainer();
else return null;
}
private void stopAndReleaseAssignedVideos(@NonNull Set<Integer> playbackSet) {
List<Integer> markedForDeletion = new ArrayList<>(playing.size());
for (int i = 0; i < playing.size(); i++) {