Skip to content

Commit

Permalink
Always show view-once video remaining time.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal authored and alan-signal committed Jan 7, 2020
1 parent c142928 commit c6b9855
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Expand Up @@ -36,30 +36,21 @@ 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;
private TextView duration;
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) {
Expand Down Expand Up @@ -108,7 +99,6 @@ protected void onStop() {

@Override
public void onPlayerReady() {
updateCounter = 0;
handler.post(durationUpdateRunnable);
}

Expand Down Expand Up @@ -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() {
Expand Down
Expand Up @@ -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;
}
Expand Down

0 comments on commit c6b9855

Please sign in to comment.