feat(pip): Add option to skip forward 10 seconds

This commit is contained in:
Quickdesh 2023-12-07 01:32:02 -05:00 committed by jmir1
parent 56e806f3ba
commit cdfeb1677a
No known key found for this signature in database
GPG key ID: 7B3B624787A072BD
7 changed files with 67 additions and 39 deletions

View file

@ -312,6 +312,7 @@ object SettingsPlayerScreen : SearchableSettings {
val enablePip = playerPreferences.enablePip()
val pipEpisodeToasts = playerPreferences.pipEpisodeToasts()
val pipOnExit = playerPreferences.pipOnExit()
val pipReplaceWithPrevious = playerPreferences.pipReplaceWithPrevious()
val isPipEnabled by enablePip.collectAsState()
@ -332,6 +333,11 @@ object SettingsPlayerScreen : SearchableSettings {
title = stringResource(MR.strings.pref_pip_on_exit),
enabled = isPipEnabled,
),
Preference.PreferenceItem.SwitchPreference(
pref = pipReplaceWithPrevious,
title = stringResource(MR.strings.pref_pip_replace_with_previous),
enabled = isPipEnabled,
),
),
)
}

View file

@ -61,12 +61,13 @@ import eu.kanade.tachiyomi.ui.player.settings.sheets.subtitle.SubtitleSettingsSh
import eu.kanade.tachiyomi.ui.player.settings.sheets.subtitle.toHexString
import eu.kanade.tachiyomi.ui.player.viewer.ACTION_MEDIA_CONTROL
import eu.kanade.tachiyomi.ui.player.viewer.AspectState
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_NEXT
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_PAUSE
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_PLAY
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_PREVIOUS
import eu.kanade.tachiyomi.ui.player.viewer.EXTRA_CONTROL_TYPE
import eu.kanade.tachiyomi.ui.player.viewer.GestureHandler
import eu.kanade.tachiyomi.ui.player.viewer.PIP_NEXT
import eu.kanade.tachiyomi.ui.player.viewer.PIP_PAUSE
import eu.kanade.tachiyomi.ui.player.viewer.PIP_PLAY
import eu.kanade.tachiyomi.ui.player.viewer.PIP_PREVIOUS
import eu.kanade.tachiyomi.ui.player.viewer.PIP_SKIP
import eu.kanade.tachiyomi.ui.player.viewer.PictureInPictureHandler
import eu.kanade.tachiyomi.ui.player.viewer.PipState
import eu.kanade.tachiyomi.ui.player.viewer.SeekState
@ -838,11 +839,7 @@ class PlayerActivity : BaseActivity() {
super.onResume()
refreshUi()
if (pip.supportedAndEnabled && PipState.mode == PipState.ON) {
player.paused?.let {
pip.update(
!it,
)
}
player.paused?.let { pip.update(!it) }
}
}
@ -1441,18 +1438,21 @@ class PlayerActivity : BaseActivity() {
return
}
when (intent.getIntExtra(EXTRA_CONTROL_TYPE, 0)) {
CONTROL_TYPE_PLAY -> {
PIP_PLAY -> {
player.paused = false
}
CONTROL_TYPE_PAUSE -> {
PIP_PAUSE -> {
player.paused = true
}
CONTROL_TYPE_PREVIOUS -> {
PIP_PREVIOUS -> {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = true))
}
CONTROL_TYPE_NEXT -> {
PIP_NEXT -> {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = false))
}
PIP_SKIP -> {
doubleTapSeek(time = 10)
}
}
}
}

View file

@ -15,6 +15,7 @@ class PlayerPreferences(
fun enablePip() = preferenceStore.getBoolean("pref_enable_pip", true)
fun pipEpisodeToasts() = preferenceStore.getBoolean("pref_pip_episode_toasts", true)
fun pipOnExit() = preferenceStore.getBoolean("pref_pip_on_exit", false)
fun pipReplaceWithPrevious() = preferenceStore.getBoolean("pip_replace_with_previous", false)
fun rememberPlayerBrightness() = preferenceStore.getBoolean("pref_remember_brightness", false)
fun playerBrightnessValue() = preferenceStore.getFloat("player_brightness_value", -1.0F)

View file

@ -43,19 +43,21 @@ class PictureInPictureHandler(
titleRes: StringResource,
requestCode: Int,
controlType: Int,
isEnabled: Boolean = true,
): RemoteAction {
return RemoteAction(
val action = RemoteAction(
Icon.createWithResource(activity, iconResId),
activity.stringResource(titleRes),
activity.stringResource(titleRes),
PendingIntent.getBroadcast(
activity,
requestCode,
Intent(ACTION_MEDIA_CONTROL)
.putExtra(EXTRA_CONTROL_TYPE, controlType),
Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
PendingIntent.FLAG_IMMUTABLE,
),
)
action.isEnabled = isEnabled
return action
}
@RequiresApi(Build.VERSION_CODES.O)
@ -72,37 +74,50 @@ class PictureInPictureHandler(
activity.player.videoAspect!!.times(10000).toInt()
}
}
val plCount = activity.viewModel.currentPlaylist.size
val plPos = activity.viewModel.getCurrentEpisodeIndex()
val mPictureInPictureParams = PictureInPictureParams.Builder()
// Set action items for the picture-in-picture mode. These are the only custom controls
// available during the picture-in-picture mode.
.setActions(
arrayListOf(
createRemoteAction(
R.drawable.ic_skip_previous_24dp,
MR.strings.action_previous_episode,
CONTROL_TYPE_PREVIOUS,
REQUEST_PREVIOUS,
),
if (activity.playerPreferences.pipReplaceWithPrevious().get()) {
createRemoteAction(
R.drawable.ic_skip_previous_24dp,
MR.strings.action_previous_episode,
PIP_PREVIOUS,
PIP_PREVIOUS,
plPos != 0
)
} else {
createRemoteAction(
R.drawable.ic_forward_10_24dp,
MR.strings.pref_skip_10,
PIP_SKIP,
PIP_SKIP,
)
},
if (playing) {
createRemoteAction(
R.drawable.ic_pause_24dp,
MR.strings.action_pause,
CONTROL_TYPE_PAUSE,
REQUEST_PAUSE,
PIP_PAUSE,
PIP_PAUSE,
)
} else {
createRemoteAction(
R.drawable.ic_play_arrow_24dp,
MR.strings.action_play,
CONTROL_TYPE_PLAY,
REQUEST_PLAY,
PIP_PLAY,
PIP_PLAY,
)
},
createRemoteAction(
R.drawable.ic_skip_next_24dp,
MR.strings.action_next_episode,
CONTROL_TYPE_NEXT,
REQUEST_NEXT,
PIP_NEXT,
PIP_NEXT,
plPos != plCount - 1
),
),
)
@ -113,15 +128,11 @@ class PictureInPictureHandler(
}
}
private const val REQUEST_PLAY = 1
private const val REQUEST_PAUSE = 2
private const val REQUEST_PREVIOUS = 3
private const val REQUEST_NEXT = 4
internal const val CONTROL_TYPE_PLAY = 1
internal const val CONTROL_TYPE_PAUSE = 2
internal const val CONTROL_TYPE_PREVIOUS = 3
internal const val CONTROL_TYPE_NEXT = 4
internal const val PIP_PLAY = 1
internal const val PIP_PAUSE = 2
internal const val PIP_PREVIOUS = 3
internal const val PIP_NEXT = 4
internal const val PIP_SKIP = 5
internal const val ACTION_MEDIA_CONTROL = "media_control"
internal const val EXTRA_CONTROL_TYPE = "control_type"

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M18,13c0,3.31 -2.69,6 -6,6s-6,-2.69 -6,-6s2.69,-6 6,-6v4l5,-5l-5,-5v4c-4.42,0 -8,3.58 -8,8c0,4.42 3.58,8 8,8s8,-3.58 8,-8H18z"/>
<path android:fillColor="#000" android:pathData="M10.86,15.94l0,-4.27l-0.09,0l-1.77,0.63l0,0.69l1.01,-0.31l0,3.26z"/>
<path android:fillColor="#000" android:pathData="M12.25,13.44v0.74c0,1.9 1.31,1.82 1.44,1.82c0.14,0 1.44,0.09 1.44,-1.82v-0.74c0,-1.9 -1.31,-1.82 -1.44,-1.82C13.55,11.62 12.25,11.53 12.25,13.44zM14.29,13.32v0.97c0,0.77 -0.21,1.03 -0.59,1.03c-0.38,0 -0.6,-0.26 -0.6,-1.03v-0.97c0,-0.75 0.22,-1.01 0.59,-1.01C14.07,12.3 14.29,12.57 14.29,13.32z"/>
</vector>

View file

@ -2,8 +2,7 @@
android:width="20dp"
android:height="20dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
android:viewportHeight="24">
<path
android:fillColor="#000"
android:pathData="M7,14L5,14v5h5v-2L7,17v-3zM5,10h2L7,7h3L10,5L5,5v5zM17,17h-3v2h5v-5h-2v3zM14,5v2h3v3h2L19,5h-5z"/>

View file

@ -122,6 +122,7 @@
<string name="pref_enable_pip">Enable the use of PiP mode</string>
<string name="pref_pip_episode_toasts">Show episode toasts when switching episodes in PiP mode</string>
<string name="pref_pip_on_exit">Automatically switch to PiP mode on exiting the player</string>
<string name="pref_pip_replace_with_previous">Replaces the "Skip 10 seconds" option with "Previous episode"</string>
<string name="pref_remember_brightness">Remember and switch to the last used brightness</string>
<string name="pref_remember_volume">Remember and switch to the last used volume</string>
<string name="pref_mpv_conf">Edit MPV configuration file for further player settings</string>