From abd57e23a60b5c9e3afbd706f3ebfef9ff523414 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 9 Oct 2021 21:22:18 +0800 Subject: Change playback speed. --- .../activities/ViewVideoActivity.java | 31 ++++- .../PlaybackSpeedBottomSheetFragment.java | 126 +++++++++++++++++ .../res/drawable-night/ic_playback_speed_24dp.xml | 6 + .../main/res/drawable/ic_playback_speed_24dp.xml | 6 + .../drawable/ic_playback_speed_toolbar_24dp.xml | 6 + .../main/res/layout/fragment_playback_speed.xml | 151 +++++++++++++++++++++ app/src/main/res/menu/view_video.xml | 7 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java create mode 100644 app/src/main/res/drawable-night/ic_playback_speed_24dp.xml create mode 100644 app/src/main/res/drawable/ic_playback_speed_24dp.xml create mode 100644 app/src/main/res/drawable/ic_playback_speed_toolbar_24dp.xml create mode 100644 app/src/main/res/layout/fragment_playback_speed.xml (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 3f17763b..53aa6188 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -36,6 +36,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import com.google.android.exoplayer2.ExoPlayerFactory; +import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.ProgressiveMediaSource; @@ -55,8 +56,6 @@ import com.google.android.exoplayer2.upstream.cache.SimpleCache; import com.google.android.exoplayer2.util.Util; import com.google.android.material.bottomappbar.BottomAppBar; import com.google.android.material.snackbar.Snackbar; -import app.futured.hauler.DragDirection; -import app.futured.hauler.HaulerView; import org.apache.commons.io.FilenameUtils; @@ -66,12 +65,15 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; +import app.futured.hauler.DragDirection; +import app.futured.hauler.HaulerView; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.apis.VReddIt; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment; import ml.docilealligator.infinityforreddit.font.ContentFontFamily; import ml.docilealligator.infinityforreddit.font.ContentFontStyle; import ml.docilealligator.infinityforreddit.font.FontFamily; @@ -91,6 +93,14 @@ import retrofit2.Retrofit; public class ViewVideoActivity extends AppCompatActivity { + public static final int PLAYBACK_SPEED_25 = 25; + public static final int PLAYBACK_SPEED_50 = 50; + public static final int PLAYBACK_SPEED_75 = 75; + public static final int PLAYBACK_SPEED_NORMAL = 100; + public static final int PLAYBACK_SPEED_125 = 125; + public static final int PLAYBACK_SPEED_150 = 150; + public static final int PLAYBACK_SPEED_175 = 175; + public static final int PLAYBACK_SPEED_200 = 200; public static final String EXTRA_VIDEO_DOWNLOAD_URL = "EVDU"; public static final String EXTRA_SUBREDDIT = "ES"; public static final String EXTRA_ID = "EI"; @@ -113,6 +123,7 @@ public class ViewVideoActivity extends AppCompatActivity { private static final String VIDEO_TYPE_STATE = "VTS"; private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String ID_STATE= "IS"; + private static final String PLAYBACK_SPEED_STATE = "PSS"; @BindView(R.id.hauler_view_view_video_activity) HaulerView haulerView; @@ -152,6 +163,7 @@ public class ViewVideoActivity extends AppCompatActivity { private boolean isDataSavingMode; private boolean isHd; private Integer originalOrientation; + private int playbackSpeed = 100; @Inject @Named("no_oauth") @@ -347,7 +359,9 @@ public class ViewVideoActivity extends AppCompatActivity { videoType = savedInstanceState.getInt(VIDEO_TYPE_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); id = savedInstanceState.getString(ID_STATE); + playbackSpeed = savedInstanceState.getInt(PLAYBACK_SPEED_STATE); } + setPlaybackSpeed(playbackSpeed); if (videoType == VIDEO_TYPE_V_REDD_IT) { loadVReddItVideo(savedInstanceState); @@ -626,11 +640,23 @@ public class ViewVideoActivity extends AppCompatActivity { isDownloading = true; requestPermissionAndDownload(); return true; + } else if (itemId == R.id.action_playback_speed_view_video_activity) { + PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed); + playbackSpeedBottomSheetFragment.setArguments(bundle); + playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag()); + return true; } return false; } + public void setPlaybackSpeed(int speed100X) { + this.playbackSpeed = speed100X; + player.setPlaybackParameters(new PlaybackParameters((float) (speed100X / 100.0))); + } + private void requestPermissionAndDownload() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (ContextCompat.checkSelfPermission(this, @@ -712,5 +738,6 @@ public class ViewVideoActivity extends AppCompatActivity { outState.putString(SUBREDDIT_NAME_STATE, subredditName); outState.putString(ID_STATE, id); } + outState.putInt(PLAYBACK_SPEED_STATE, playbackSpeed); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java new file mode 100644 index 00000000..47d50a4e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java @@ -0,0 +1,126 @@ +package ml.docilealligator.infinityforreddit.bottomsheetfragments; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity; +import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; + +public class PlaybackSpeedBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { + + public static final String EXTRA_PLAYBACK_SPEED = "EPS"; + + @BindView(R.id.playback_speed_025_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeed025TextView; + @BindView(R.id.playback_speed_050_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeed050TextView; + @BindView(R.id.playback_speed_075_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeed075TextView; + @BindView(R.id.playback_speed_normal_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeedNormalTextView; + @BindView(R.id.playback_speed_125_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeed125TextView; + @BindView(R.id.playback_speed_150_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeed150TextView; + @BindView(R.id.playback_speed_175_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeed175TextView; + @BindView(R.id.playback_speed_200_text_view_playback_speed_bottom_sheet_fragment) + TextView playbackSpeed200TextView; + private ViewVideoActivity viewVideoActivity; + + public PlaybackSpeedBottomSheetFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View rootView = inflater.inflate(R.layout.fragment_playback_speed, container, false); + + ButterKnife.bind(this, rootView); + int playbackSpeed = getArguments().getInt(EXTRA_PLAYBACK_SPEED, ViewVideoActivity.PLAYBACK_SPEED_NORMAL); + switch (playbackSpeed) { + case ViewVideoActivity.PLAYBACK_SPEED_25: + playbackSpeed025TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + case ViewVideoActivity.PLAYBACK_SPEED_50: + playbackSpeed050TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + case ViewVideoActivity.PLAYBACK_SPEED_75: + playbackSpeed075TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + case ViewVideoActivity.PLAYBACK_SPEED_NORMAL: + playbackSpeedNormalTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + case ViewVideoActivity.PLAYBACK_SPEED_125: + playbackSpeed125TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + case ViewVideoActivity.PLAYBACK_SPEED_150: + playbackSpeed150TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + case ViewVideoActivity.PLAYBACK_SPEED_175: + playbackSpeed175TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + case ViewVideoActivity.PLAYBACK_SPEED_200: + playbackSpeed200TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_24dp, 0); + break; + } + + playbackSpeed025TextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_25); + dismiss(); + }); + + playbackSpeed050TextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_50); + dismiss(); + }); + + playbackSpeed075TextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_75); + dismiss(); + }); + + playbackSpeedNormalTextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_NORMAL); + dismiss(); + }); + + playbackSpeed125TextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_125); + dismiss(); + }); + + playbackSpeed150TextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_150); + dismiss(); + }); + + playbackSpeed175TextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_175); + dismiss(); + }); + + playbackSpeed200TextView.setOnClickListener(view -> { + viewVideoActivity.setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_200); + dismiss(); + }); + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + viewVideoActivity = (ViewVideoActivity) context; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-night/ic_playback_speed_24dp.xml b/app/src/main/res/drawable-night/ic_playback_speed_24dp.xml new file mode 100644 index 00000000..1e774fee --- /dev/null +++ b/app/src/main/res/drawable-night/ic_playback_speed_24dp.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/drawable/ic_playback_speed_24dp.xml b/app/src/main/res/drawable/ic_playback_speed_24dp.xml new file mode 100644 index 00000000..1ab79da6 --- /dev/null +++ b/app/src/main/res/drawable/ic_playback_speed_24dp.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/drawable/ic_playback_speed_toolbar_24dp.xml b/app/src/main/res/drawable/ic_playback_speed_toolbar_24dp.xml new file mode 100644 index 00000000..289e7669 --- /dev/null +++ b/app/src/main/res/drawable/ic_playback_speed_toolbar_24dp.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/layout/fragment_playback_speed.xml b/app/src/main/res/layout/fragment_playback_speed.xml new file mode 100644 index 00000000..11402d8b --- /dev/null +++ b/app/src/main/res/layout/fragment_playback_speed.xml @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/view_video.xml b/app/src/main/res/menu/view_video.xml index fa54098f..fa00369b 100644 --- a/app/src/main/res/menu/view_video.xml +++ b/app/src/main/res/menu/view_video.xml @@ -7,4 +7,11 @@ android:title="@string/action_download" android:icon="@drawable/ic_file_download_toolbar_white_24dp" app:showAsAction="ifRoom" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 203126ca..11e062eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,6 +90,7 @@ Share RPAN Link Share Post Link Go to Wiki + Playback Speed Error occurred when parsing the JSON response Error Retrieving the token -- cgit v1.2.3