diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-10-09 13:22:18 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-10-09 13:22:18 +0000 |
commit | abd57e23a60b5c9e3afbd706f3ebfef9ff523414 (patch) | |
tree | ce256a90f24901632141ed1f37ee2a6461c2ad14 /app/src/main | |
parent | e02f5a28b3376a649867c11c8bf3a5a74646fc54 (diff) | |
download | infinity-for-reddit-abd57e23a60b5c9e3afbd706f3ebfef9ff523414.tar infinity-for-reddit-abd57e23a60b5c9e3afbd706f3ebfef9ff523414.tar.gz infinity-for-reddit-abd57e23a60b5c9e3afbd706f3ebfef9ff523414.tar.bz2 infinity-for-reddit-abd57e23a60b5c9e3afbd706f3ebfef9ff523414.tar.lz infinity-for-reddit-abd57e23a60b5c9e3afbd706f3ebfef9ff523414.tar.xz infinity-for-reddit-abd57e23a60b5c9e3afbd706f3ebfef9ff523414.tar.zst infinity-for-reddit-abd57e23a60b5c9e3afbd706f3ebfef9ff523414.zip |
Change playback speed.
Diffstat (limited to 'app/src/main')
8 files changed, 332 insertions, 2 deletions
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 @@ +<vector android:height="24dp" + android:viewportHeight="24" android:viewportWidth="24" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M20.38,8.57l-1.23,1.85a8,8 0,0 1,-0.22 7.58H5.07A8,8 0,0 1,15.58 6.85l1.85,-1.23A10,10 0,0 0,3.35 19a2,2 0,0 0,1.72 1h13.85a2,2 0,0 0,1.74 -1,10 10,0 0,0 -0.27,-10.44z"/> + <path android:fillColor="@android:color/white" android:pathData="M10.59,15.41a2,2 0,0 0,2.83 0l5.66,-8.49 -8.49,5.66a2,2 0,0 0,0 2.83z"/> +</vector> 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 @@ +<vector android:height="24dp" + android:viewportHeight="24" android:viewportWidth="24" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/black" android:pathData="M20.38,8.57l-1.23,1.85a8,8 0,0 1,-0.22 7.58H5.07A8,8 0,0 1,15.58 6.85l1.85,-1.23A10,10 0,0 0,3.35 19a2,2 0,0 0,1.72 1h13.85a2,2 0,0 0,1.74 -1,10 10,0 0,0 -0.27,-10.44z"/> + <path android:fillColor="@android:color/black" android:pathData="M10.59,15.41a2,2 0,0 0,2.83 0l5.66,-8.49 -8.49,5.66a2,2 0,0 0,0 2.83z"/> +</vector> 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 @@ +<vector android:height="24dp" android:tint="#FFFFFF" + android:viewportHeight="24" android:viewportWidth="24" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M20.38,8.57l-1.23,1.85a8,8 0,0 1,-0.22 7.58H5.07A8,8 0,0 1,15.58 6.85l1.85,-1.23A10,10 0,0 0,3.35 19a2,2 0,0 0,1.72 1h13.85a2,2 0,0 0,1.74 -1,10 10,0 0,0 -0.27,-10.44z"/> + <path android:fillColor="@android:color/white" android:pathData="M10.59,15.41a2,2 0,0 0,2.83 0l5.66,-8.49 -8.49,5.66a2,2 0,0 0,0 2.83z"/> +</vector> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingBottom="8dp" + android:overScrollMode="never"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/playback_speed_025_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="0.25x" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + <TextView + android:id="@+id/playback_speed_050_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="0.5x" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + <TextView + android:id="@+id/playback_speed_075_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="0.75x" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + <TextView + android:id="@+id/playback_speed_normal_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="@string/normal" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + <TextView + android:id="@+id/playback_speed_125_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="1.25x" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + <TextView + android:id="@+id/playback_speed_150_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="1.5x" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + <TextView + android:id="@+id/playback_speed_175_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="1.75x" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + <TextView + android:id="@+id/playback_speed_200_text_view_playback_speed_bottom_sheet_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" + android:text="2x" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" /> + + </LinearLayout> + +</androidx.core.widget.NestedScrollView>
\ 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" /> + + <item + android:id="@+id/action_playback_speed_view_video_activity" + android:orderInCategory="2" + android:title="@string/action_playback_speed" + android:icon="@drawable/ic_playback_speed_toolbar_24dp" + app:showAsAction="ifRoom" /> </menu>
\ 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 @@ <string name="action_share_rpan_link">Share RPAN Link</string> <string name="action_share_post_link">Share Post Link</string> <string name="action_go_to_wiki">Go to Wiki</string> + <string name="action_playback_speed">Playback Speed</string> <string name="parse_json_response_error">Error occurred when parsing the JSON response</string> <string name="retrieve_token_error">Error Retrieving the token</string> |