Skip to content

Commit

Permalink
feat: added quick skip button on player
Browse files Browse the repository at this point in the history
  • Loading branch information
MrIkso committed Jun 30, 2024
1 parent 02ba293 commit 733abd3
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.Rational;
import android.view.KeyEvent;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
Expand Down Expand Up @@ -127,9 +127,9 @@ public class PlayerActivity extends AppCompatActivity {
private ImageView exoNextEp;

// Bottom buttons
private ImageView exoPip;
private ImageView exoSkip;
private ImageView exoScreen;
private ImageButton exoPip;
private ImageButton exoSkip;
private ImageButton exoScreen;

private LinearLayout exoTopControllers;
private LinearLayout exoMiddleControllers;
Expand Down Expand Up @@ -164,6 +164,7 @@ public class PlayerActivity extends AppCompatActivity {
private BaseAnimeModel animeModel;
private String episodePath;
private int doubleTapSeek;
private int fastSeek;
private boolean autoPlayNextEpisode;
private boolean gesturesEnabled;
private boolean autoContinue;
Expand All @@ -173,11 +174,12 @@ public class PlayerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadSettings();
setView();
initViewModel();

setupViews();
loadSettings();

// if (savedInstanceState == null) {
hideNavBar();
parseExtra();
Expand Down Expand Up @@ -228,7 +230,10 @@ private void setupViews() {

// Bottom buttons
exoPip = findViewById(R.id.exo_pip);
// exoSkip = findViewById(R.id.exo_skip);
exoSkip = findViewById(R.id.exo_quick_skip);
if (!(fastSeek > 0)) {
exoSkip.setVisibility(View.GONE);
}
exoScreen = findViewById(R.id.exo_screen);

youTubeOverlay = findViewById(R.id.youtube_overlay);
Expand Down Expand Up @@ -337,7 +342,7 @@ private void preparePlayer(boolean restorePlayer) {
exoPlayer.prepare();

playVideo();
if (Utils.isPiPSupported(this)){
if (Utils.isPiPSupported(this)) {
setPictureInPictureParams(getPipParams(exoPlayer.isPlaying()));
}
}
Expand All @@ -348,7 +353,7 @@ private void setupTextViewValues() {
}

private void setupMiddleControllers() {
// Log.i("TAG", "epnum:" + episodeNumber + "size:" + listRepo.getList().size());
// Log.i("TAG", "epnum:" + episodeNumber + "size:" + listRepo.getList().size());

if (episodeNumber == 1) {
exoPrevEp.setAlpha(0.4f);
Expand Down Expand Up @@ -434,7 +439,7 @@ private void setupQuality() {
exoQuality.setOnItemClickListener((parent, view, position, id) -> {
currentQuality = (String) parent.getAdapter().getItem(position);
String qualityItem = episodeLinks.getLinksQuality().get(currentQuality);
currentPosition = Math.max(0, exoPlayer.getContentPosition());
currentPosition = Math.max(0, exoPlayer.getCurrentPosition());

MediaSource mediaSource = mediaSourceHelper.getMediaSource(qualityItem, true);
exoPlayer.setMediaSource(mediaSource);
Expand Down Expand Up @@ -474,7 +479,7 @@ private void updateQualityArray() {

private void savePlayer() {
if (exoPlayer != null) {
currentPosition = Math.max(0, exoPlayer.getContentPosition());
currentPosition = Math.max(0, exoPlayer.getCurrentPosition());
sharedViewModel.addOrUpdateWatchedAnime(
animeModel, episodePath, episodeNumber, exoPlayer.getContentDuration(), currentPosition);
sharedViewModel.addOrUpdateWatchedEpisode(
Expand Down Expand Up @@ -547,6 +552,9 @@ private void setClickListeners() {
exoPip.setOnClickListener(v -> {
enterPiP();
});
exoSkip.setOnClickListener(v -> {
exoPlayer.seekTo(exoPlayer.getCurrentPosition() + fastSeek * 1000L);
});
}

private void playPrevEpisode() {
Expand Down Expand Up @@ -831,6 +839,7 @@ private void loadSettings() {
var prefs = PreferencesHelper.getInstance();

doubleTapSeek = prefs.getPlayerDoubleTapSeek();
fastSeek = prefs.getPlayerFastSeek();
autoPlayNextEpisode = prefs.isPlayerEnabledPlayNextEpisode();
gesturesEnabled = prefs.isPlayerEnabledSwipeControls();
autoContinue = prefs.isPlayerAutoContinuePlay();
Expand Down Expand Up @@ -870,7 +879,7 @@ public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, @Non
} else {
if (broadcastReceiver != null) {
unregisterReceiver(broadcastReceiver);
broadcastReceiver=null;
broadcastReceiver = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PreferenceKeys {
public static final String PREF_KEY_REVERSE_EPISODE_LIST = "pref_key_reverse_episode_list";
public static final String PREF_ENDPOINT_KEY = "pref_streamsb_api_endpoint";
public static final String PREF_PLAYER_DOUBLE_TAP_SEEK = "player_double_tap_seek";
public static final String PREF_PLAYER_FAST_SEEK = "player_fast_seek";
public static final String PREF_PLAYER_SWIPE_CONTROLS = "player_swipe_controls";
public static final String PREF_PLAYER_AUTOPLAY_NEXT_EPISODE = "player_autoplay_next_episode";
public static final String PREF_PLAYER_AUTO_CONTINUE_PLAY = "player_auto_continue_play";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ public void setDleHash(String hash) {
}

public int getPlayerDoubleTapSeek() {
String sec = preferences.getString(PreferenceKeys.PREF_PLAYER_DOUBLE_TAP_SEEK, "10");
if(sec.equals("off")){
String seek = preferences.getString(PreferenceKeys.PREF_PLAYER_DOUBLE_TAP_SEEK, "10");
if (seek.equals("off")) {
return -1;
}
return Integer.parseInt(sec);
return Integer.parseInt(seek);
}

public int getPlayerFastSeek() {
String seek = preferences.getString(PreferenceKeys.PREF_PLAYER_FAST_SEEK, "60");
return Integer.parseInt(seek);
}

public boolean isPlayerEnabledSwipeControls() {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_fast_forward.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M100,645L100,315Q100,297 112,286Q124,275 140,275Q145,275 151,276Q157,277 162,281L410,447Q419,453 423.5,461.5Q428,470 428,480Q428,490 423.5,498.5Q419,507 410,513L162,679Q157,683 151,684Q145,685 140,685Q124,685 112,674Q100,663 100,645ZM500,645L500,315Q500,297 512,286Q524,275 540,275Q545,275 551,276Q557,277 562,281L810,447Q819,453 823.5,461.5Q828,470 828,480Q828,490 823.5,498.5Q819,507 810,513L562,679Q557,683 551,684Q545,685 540,685Q524,685 512,674Q500,663 500,645ZM180,480L180,480L180,480ZM580,480L580,480L580,480ZM180,570L316,480L180,390L180,570ZM580,570L716,480L580,390L580,570Z" />
</vector>
17 changes: 15 additions & 2 deletions app/src/main/res/layout/custom_controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,26 @@
tools:ignore="TextContrastCheck"
tools:text="24:00" />

<ImageButton
android:id="@+id/exo_quick_skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/transparent_circle_background"
android:clickable="true"
android:contentDescription="@null"
android:focusable="true"
android:padding="11dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_fast_forward"
app:tint="#fff" />

<ImageButton
android:id="@+id/exo_pip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="@drawable/transparent_circle_background"
android:padding="8dp"
android:padding="11dp"
app:srcCompat="@drawable/ic_picture_in_picture"
app:tint="@color/white"
tools:ignore="ContentDescription,SpeakableTextPresentCheck" />
Expand All @@ -257,7 +270,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/transparent_circle_background"
android:padding="8dp"
android:padding="11dp"
app:srcCompat="@drawable/ic_open_in_fullscreen"
app:tint="@color/white"
tools:ignore="ContentDescription,SpeakableTextPresentCheck,TouchTargetSizeCheck" />
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<item>10 секунд</item>
<item>15 секунд</item>
<item>30 секунд</item>
<item>60 секунд</item>
<item>120 секунд</item>
<item>1 хвилина</item>
<item>2 хвилини</item>
</string-array>

<string-array name="double_tap_seek_values">
Expand All @@ -55,4 +55,26 @@
<item>60</item>
<item>120</item>
</string-array>

<string-array name="fast_seek_entries">
<item>@string/disabled</item>
<item>30 секунд</item>
<item>45 секунд</item>
<item>1 хвилина</item>
<item>1 хвилина 30 cекунд</item>
<item>2 хвилини</item>
<item>3 хвилини</item>
<item>4 хвилини</item>
</string-array>

<string-array name="fast_seek_values">
<item>0</item>
<item>30</item>
<item>45</item>
<item>60</item>
<item>90</item>
<item>120</item>
<item>180</item>
<item>240</item>
</string-array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@
<string name="state_no_recent_search_desc">Почніть шукати аніме і тут з\'явиться історія вашого пошуку</string>
<string name="pause">Пауза</string>
<string name="resume">Відновити</string>
<string name="fast_seek">Швидка перемотка</string>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
app:title="@string/double_tap_seek"
app:useSimpleSummaryProvider="true" />

<ListPreference
app:defaultValue="60"
app:entries="@array/fast_seek_entries"
app:entryValues="@array/fast_seek_values"
app:icon="@drawable/ic_fast_forward"
app:key="player_fast_seek"
app:title="@string/fast_seek"
app:useSimpleSummaryProvider="true" />

<SwitchPreferenceCompat
app:defaultValue="true"
app:icon="@drawable/ic_swipe_gesture"
Expand Down

0 comments on commit 733abd3

Please sign in to comment.