mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Hoist video editor state out of VideoEditorFragment.
This commit is contained in:
committed by
Alex Hart
parent
619038f27d
commit
ccc9752485
@@ -51,7 +51,8 @@ public final class VideoThumbnailsRangeSelectorView extends VideoThumbnailsView
|
||||
private long downMax;
|
||||
private Thumb dragThumb;
|
||||
private Thumb lastDragThumb;
|
||||
private OnRangeChangeListener onRangeChangeListener;
|
||||
private PositionDragListener playerOnRangeChangeListener;
|
||||
private RangeDragListener editorOnRangeChangeListener;
|
||||
@Px private int thumbSizePixels;
|
||||
@Px private int thumbTouchRadius;
|
||||
@ColorInt private int thumbColor;
|
||||
@@ -109,15 +110,7 @@ public final class VideoThumbnailsRangeSelectorView extends VideoThumbnailsView
|
||||
|
||||
@Override
|
||||
protected void afterDurationChange(long duration) {
|
||||
super.afterDurationChange(duration);
|
||||
|
||||
if (maxValue != null && duration < maxValue) {
|
||||
maxValue = duration;
|
||||
}
|
||||
|
||||
if (minValue != null && duration < minValue) {
|
||||
minValue = duration;
|
||||
}
|
||||
maxValue = duration;
|
||||
|
||||
if (duration > 0) {
|
||||
if (externalMaxValue != null) {
|
||||
@@ -131,15 +124,21 @@ public final class VideoThumbnailsRangeSelectorView extends VideoThumbnailsView
|
||||
}
|
||||
}
|
||||
|
||||
if (onRangeChangeListener != null) {
|
||||
onRangeChangeListener.onRangeDragEnd(getMinValue(), getMaxValue(), getDuration(), Thumb.MIN);
|
||||
}
|
||||
onRangeDrag(getMinValue(), getMaxValue(), duration, true);
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setOnRangeChangeListener(OnRangeChangeListener onRangeChangeListener) {
|
||||
this.onRangeChangeListener = onRangeChangeListener;
|
||||
public void registerPlayerOnRangeChangeListener(PositionDragListener playerOnRangeChangeListener) {
|
||||
this.playerOnRangeChangeListener = playerOnRangeChangeListener;
|
||||
}
|
||||
|
||||
public void registerEditorOnRangeChangeListener(RangeDragListener editorOnRangeChangeListener) {
|
||||
this.editorOnRangeChangeListener = editorOnRangeChangeListener;
|
||||
}
|
||||
|
||||
public void unregisterPlayerOnRangeChangeListener() {
|
||||
this.playerOnRangeChangeListener = null;
|
||||
}
|
||||
|
||||
public void setActualPosition(long position) {
|
||||
@@ -349,22 +348,22 @@ public final class VideoThumbnailsRangeSelectorView extends VideoThumbnailsView
|
||||
changed = setMaxValue(downMax + delta);
|
||||
break;
|
||||
}
|
||||
if (changed && onRangeChangeListener != null) {
|
||||
if (changed) {
|
||||
if (dragThumb == Thumb.POSITION) {
|
||||
onRangeChangeListener.onPositionDrag(dragPosition);
|
||||
onPositionDrag(dragPosition);
|
||||
} else {
|
||||
onRangeChangeListener.onRangeDrag(getMinValue(), getMaxValue(), getDuration(), dragThumb);
|
||||
onRangeDrag(getMinValue(), getMaxValue(), getDuration(), false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionMasked == MotionEvent.ACTION_UP) {
|
||||
if (onRangeChangeListener != null) {
|
||||
if (editorOnRangeChangeListener != null) {
|
||||
if (dragThumb == Thumb.POSITION) {
|
||||
onRangeChangeListener.onEndPositionDrag(dragPosition);
|
||||
onEndPositionDrag(dragPosition);
|
||||
} else {
|
||||
onRangeChangeListener.onRangeDragEnd(getMinValue(), getMaxValue(), getDuration(), dragThumb);
|
||||
onRangeDrag(getMinValue(), getMaxValue(), getDuration(), true);
|
||||
}
|
||||
lastDragThumb = dragThumb;
|
||||
dragEndTimeMs = System.currentTimeMillis();
|
||||
@@ -418,20 +417,36 @@ public final class VideoThumbnailsRangeSelectorView extends VideoThumbnailsView
|
||||
maximumSelectableRangeMicros = timeUnit.toMicros(t);
|
||||
}
|
||||
|
||||
private void onPositionDrag(long position) {
|
||||
if (playerOnRangeChangeListener != null) {
|
||||
playerOnRangeChangeListener.onPositionDrag(position);
|
||||
}
|
||||
}
|
||||
|
||||
private void onEndPositionDrag(long position) {
|
||||
if (playerOnRangeChangeListener != null) {
|
||||
playerOnRangeChangeListener.onEndPositionDrag(position);
|
||||
}
|
||||
}
|
||||
|
||||
private void onRangeDrag(long minValue, long maxValue, long duration, boolean end) {
|
||||
if (editorOnRangeChangeListener != null) {
|
||||
editorOnRangeChangeListener.onRangeDrag(minValue, maxValue, duration, end);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Thumb {
|
||||
MIN,
|
||||
MAX,
|
||||
POSITION
|
||||
}
|
||||
|
||||
public interface OnRangeChangeListener {
|
||||
|
||||
public interface PositionDragListener {
|
||||
void onPositionDrag(long position);
|
||||
|
||||
void onEndPositionDrag(long position);
|
||||
}
|
||||
|
||||
void onRangeDrag(long minValue, long maxValue, long duration, Thumb thumb);
|
||||
|
||||
void onRangeDragEnd(long minValue, long maxValue, long duration, Thumb thumb);
|
||||
public interface RangeDragListener {
|
||||
void onRangeDrag(long minValue, long maxValue, long duration, boolean start);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -16,6 +17,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.media.DecryptableUriMediaInput;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.video.interfaces.MediaInput;
|
||||
|
||||
@@ -26,11 +28,13 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RequiresApi(api = 23)
|
||||
public class VideoThumbnailsView extends View {
|
||||
abstract public class VideoThumbnailsView extends View {
|
||||
|
||||
private static final String TAG = Log.tag(VideoThumbnailsView.class);
|
||||
private static final int CORNER_RADIUS = ViewUtil.dpToPx(8);
|
||||
|
||||
protected Uri currentUri;
|
||||
|
||||
private MediaInput input;
|
||||
private volatile ArrayList<Bitmap> thumbnails;
|
||||
private AsyncTask<Void, Bitmap, Void> thumbnailsTask;
|
||||
@@ -55,12 +59,13 @@ public class VideoThumbnailsView extends View {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void setInput(@NonNull MediaInput input) {
|
||||
if (this.input != null && input.hasSameInput(this.input)) {
|
||||
public void setInput(@NonNull Uri uri) throws IOException {
|
||||
if (uri.equals(this.currentUri)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.input = input;
|
||||
this.currentUri = uri;
|
||||
this.input = DecryptableUriMediaInput.createForUri(getContext(), uri);
|
||||
this.thumbnails = null;
|
||||
if (thumbnailsTask != null) {
|
||||
thumbnailsTask.cancel(true);
|
||||
@@ -163,15 +168,14 @@ public class VideoThumbnailsView extends View {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDuration(long duration) {
|
||||
private void setDuration(long duration) {
|
||||
if (this.duration != duration) {
|
||||
this.duration = duration;
|
||||
afterDurationChange(duration);
|
||||
}
|
||||
}
|
||||
|
||||
protected void afterDurationChange(long duration) {
|
||||
}
|
||||
abstract void afterDurationChange(long duration);
|
||||
|
||||
public long getDuration() {
|
||||
return duration;
|
||||
@@ -241,14 +245,10 @@ public class VideoThumbnailsView extends View {
|
||||
VideoThumbnailsView view = viewReference.get();
|
||||
List<Bitmap> thumbnails = view != null ? view.thumbnails : null;
|
||||
if (view != null) {
|
||||
view.setDuration(duration);
|
||||
view.setDuration(ThumbnailsTask.this.duration);
|
||||
view.invalidate();
|
||||
Log.i(TAG, "onPostExecute, we have " + (thumbnails != null ? thumbnails.size() : "null") + " thumbs");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnDurationListener {
|
||||
void onDurationKnown(long duration);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user