From c6b985519823d2d77310715c77c67cf8158d660f Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 7 Jan 2020 14:57:21 -0500 Subject: [PATCH] Always show view-once video remaining time. --- .../revealable/ViewOnceMessageActivity.java | 23 ++++--------------- .../securesms/video/VideoPlayer.java | 7 ++++++ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/revealable/ViewOnceMessageActivity.java b/app/src/main/java/org/thoughtcrime/securesms/revealable/ViewOnceMessageActivity.java index 5a215871800..0acae6b694c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/revealable/ViewOnceMessageActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/revealable/ViewOnceMessageActivity.java @@ -36,9 +36,6 @@ public class ViewOnceMessageActivity extends PassphraseRequiredActionBarActivity private static final String KEY_MESSAGE_ID = "message_id"; private static final String KEY_URI = "uri"; - private static final int OVERLAY_TIMEOUT_S = 2; - private static final int FADE_OUT_DURATION_MS = 200; - private ImageView image; private VideoPlayer video; private View closeButton; @@ -46,20 +43,14 @@ public class ViewOnceMessageActivity extends PassphraseRequiredActionBarActivity private ViewOnceMessageViewModel viewModel; private Uri uri; - private int updateCounter; - private final Handler handler = new Handler(Looper.getMainLooper()); private final Runnable durationUpdateRunnable = () -> { - long timeLeft = TimeUnit.MILLISECONDS.toSeconds(video.getDuration()) - updateCounter; + long timeLeft = TimeUnit.MILLISECONDS.toSeconds(video.getDuration() - video.getPlaybackPosition()); long minutes = timeLeft / 60; long seconds = timeLeft % 60; + duration.setText(getString(R.string.ViewOnceMessageActivity_video_duration, minutes, seconds)); - updateCounter++; - if (updateCounter > OVERLAY_TIMEOUT_S) { - animateOutOverlay(); - } else { - scheduleDurationUpdate(); - } + scheduleDurationUpdate(); }; public static Intent getIntent(@NonNull Context context, long messageId, @NonNull Uri uri) { @@ -108,7 +99,6 @@ protected void onStop() { @Override public void onPlayerReady() { - updateCounter = 0; handler.post(durationUpdateRunnable); } @@ -163,13 +153,8 @@ private void displayImage(@NonNull Uri uri) { .into(image); } - private void animateOutOverlay() { - duration.animate().alpha(0f).setDuration(200).start(); - closeButton.animate().alpha(0f).setDuration(200).start(); - } - private void scheduleDurationUpdate() { - handler.postDelayed(durationUpdateRunnable, 1000L); + handler.postDelayed(durationUpdateRunnable, 100); } private void cancelDurationUpdate() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java b/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java index ce7f7286d7f..0d38a618a81 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java +++ b/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java @@ -135,6 +135,13 @@ public long getDuration() { return 0L; } + public long getPlaybackPosition() { + if (this.exoPlayer != null) { + return this.exoPlayer.getCurrentPosition(); + } + return 0L; + } + public void setWindow(@Nullable Window window) { this.window = window; }