From 9490c37a09e4c7920a5129974da7a0f40a84d75a Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 12 May 2020 17:42:38 +0800 Subject: Resume video position when viewing it in fullscreen. --- .../infinityforreddit/Activity/ViewVideoActivity.java | 8 ++++++++ .../Adapter/CommentAndPostRecyclerViewAdapter.java | 1 + .../infinityforreddit/Adapter/PostRecyclerViewAdapter.java | 1 + 3 files changed, 10 insertions(+) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index 11e0d56d..00f9e848 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -69,6 +69,7 @@ public class ViewVideoActivity extends AppCompatActivity { public static final String EXTRA_SUBREDDIT = "ES"; public static final String EXTRA_ID = "EI"; public static final String EXTRA_POST_TITLE = "EPT"; + public static final String EXTRA_PROGRESS_SECONDS = "EPS"; private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; private static final String IS_MUTE_STATE = "IMS"; @BindView(R.id.relative_layout_view_video_activity) @@ -93,6 +94,7 @@ public class ViewVideoActivity extends AppCompatActivity { private float totalLengthY = 0.0f; private float touchY = -1.0f; private String postTitle; + private long resumePosition = -1; @Inject @Named("default") @@ -134,6 +136,9 @@ public class ViewVideoActivity extends AppCompatActivity { videoDownloadUrl = intent.getStringExtra(EXTRA_VIDEO_DOWNLOAD_URL); videoFileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_ID) + ".mp4"; postTitle = intent.getStringExtra(EXTRA_POST_TITLE); + if (savedInstanceState == null) { + resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1); + } if (postTitle != null) { setTitle(Html.fromHtml(String.format("%s", postTitle))); @@ -320,6 +325,9 @@ public class ViewVideoActivity extends AppCompatActivity { player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); player.setRepeatMode(Player.REPEAT_MODE_ALL); + if (resumePosition > 0) { + player.seekTo(resumePosition); + } player.setPlayWhenReady(true); wasPlaying = true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index f2a12781..64ab34ff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -2057,6 +2057,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter