Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Skip credits #633

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
92eaefe
skip credits
cd16b Jan 22, 2024
85ff16d
skip credits
cd16b Jan 22, 2024
14eb313
fix lint
cd16b Jan 22, 2024
7f02f3d
fix lint
cd16b Jan 22, 2024
6a917be
Merge branch 'jarnedemeulemeester:main' into Skip-credit
cd16b Jan 22, 2024
4a3a22d
fix PlayerActivityViewModel.kt
cd16b Jan 22, 2024
bdef58d
Merge remote-tracking branch 'origin/Skip-credit' into Skip-credit
cd16b Jan 22, 2024
916d71a
fix PlayerActivityViewModel.kt
cd16b Jan 22, 2024
9711f4c
Close player on the last episode of a series
cd16b Jan 22, 2024
a740d3f
fix lint
cd16b Jan 22, 2024
6402a6a
fix and change pref_player_intro_skipper_summary
cd16b Jan 22, 2024
2b9831a
fix next episode no credits
cd16b Jan 22, 2024
f945402
clean code
cd16b Jan 22, 2024
674699a
fix code
cd16b Jan 23, 2024
05730a5
change text hasNextMediaItem() false
cd16b Jan 23, 2024
3c6e03d
Merge branch 'main' into Skip-credit
cd16b Feb 25, 2024
50b39d6
Update strings.xml
cd16b Feb 25, 2024
4a3afe6
Update strings-da
cd16b Feb 25, 2024
f75079f
fix skipButton still visible after intro end
cd16b Mar 3, 2024
d4e6351
Merge branch 'main' into Skip-credit
cd16b Mar 3, 2024
ce9eed6
fix skipButton hide on click
cd16b Mar 5, 2024
e10ae9c
Merge branch 'main' into Skip-credit
cd16b Apr 15, 2024
0999823
Merge branch 'jarnedemeulemeester:main' into Skip-credit
cd16b Jun 2, 2024
9f3be43
Merge branch 'main' into Skip-credit
cd16b Jun 20, 2024
df984fb
FindroidSegment
cd16b Jun 20, 2024
91cccc5
Improve skipButton visibility/usability
cd16b Jun 21, 2024
6095c97
Materia3 buttons and WatchCredits button
cd16b Jun 24, 2024
5ab6506
Merge remote-tracking branch 'refs/remotes/origin/main' into Skip-credit
cd16b Jun 24, 2024
ba2f9d9
Update Database
cd16b Jun 24, 2024
350afaa
Fix buttons still visible
cd16b Jun 24, 2024
09f3d21
Remove buttons colors and fix lint
cd16b Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 78 additions & 6 deletions app/phone/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ import dagger.hilt.android.AndroidEntryPoint
import dev.jdtech.jellyfin.databinding.ActivityPlayerBinding
import dev.jdtech.jellyfin.dialogs.SpeedSelectionDialogFragment
import dev.jdtech.jellyfin.dialogs.TrackSelectionDialogFragment
import dev.jdtech.jellyfin.models.FindroidSegment
import dev.jdtech.jellyfin.utils.PlayerGestureHelper
import dev.jdtech.jellyfin.utils.PreviewScrubListener
import dev.jdtech.jellyfin.viewmodels.PlayerActivityViewModel
import dev.jdtech.jellyfin.viewmodels.PlayerEvents
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
import dev.jdtech.jellyfin.core.R as CoreR

var isControlsLocked: Boolean = false

Expand All @@ -58,6 +60,8 @@ class PlayerActivity : BasePlayerActivity() {
override val viewModel: PlayerActivityViewModel by viewModels()
private var previewScrubListener: PreviewScrubListener? = null
private var wasZoom: Boolean = false
private var oldSegment: FindroidSegment? = null
private var buttonPressed: Boolean = false

private val isPipSupported by lazy {
// Check if device has PiP feature
Expand Down Expand Up @@ -119,7 +123,8 @@ class PlayerActivity : BasePlayerActivity() {
val audioButton = binding.playerView.findViewById<ImageButton>(R.id.btn_audio_track)
val subtitleButton = binding.playerView.findViewById<ImageButton>(R.id.btn_subtitle)
val speedButton = binding.playerView.findViewById<ImageButton>(R.id.btn_speed)
val skipIntroButton = binding.playerView.findViewById<Button>(R.id.btn_skip_intro)
val skipButton = binding.playerView.findViewById<Button>(R.id.btn_skip_intro)
val watchCreditsButton = binding.playerView.findViewById<Button>(R.id.btn_watch_credits)
val pipButton = binding.playerView.findViewById<ImageButton>(R.id.btn_pip)
val lockButton = binding.playerView.findViewById<ImageButton>(R.id.btn_lockview)
val unlockButton = binding.playerView.findViewById<ImageButton>(R.id.btn_unlock)
Expand All @@ -133,13 +138,80 @@ class PlayerActivity : BasePlayerActivity() {
// Title
videoNameTextView.text = currentItemTitle

// Skip Intro button
skipIntroButton.isVisible = !isInPictureInPictureMode && currentIntro != null
skipIntroButton.setOnClickListener {
currentIntro?.let {
binding.playerView.player?.seekTo((it.introEnd * 1000).toLong())
// Skip Button
if (currentSegment != oldSegment) buttonPressed = false
// Button Visibility and Text
when (currentSegment?.type) {
"intro" -> {
skipButton.text =
getString(CoreR.string.skip_intro_button)
skipButton.isVisible =
!isInPictureInPictureMode && !buttonPressed && (showSkip == true || (binding.playerView.isControllerFullyVisible && currentSegment?.skip == true))
watchCreditsButton.isVisible = false
}

"credit" -> {
skipButton.text =
if (binding.playerView.player?.hasNextMediaItem() == true) {
getString(CoreR.string.skip_credit_button)
} else {
getString(CoreR.string.skip_credit_button_last)
}
skipButton.isVisible =
!isInPictureInPictureMode && !buttonPressed && currentSegment?.skip == true && !binding.playerView.isControllerFullyVisible
watchCreditsButton.isVisible = skipButton.isVisible
}

else -> {
skipButton.isVisible = false
watchCreditsButton.isVisible = false
}
}
binding.playerView.setControllerVisibilityListener(
PlayerView.ControllerVisibilityListener { visibility ->
when (currentSegment?.type) {
"intro" -> {
skipButton.isVisible =
!buttonPressed && (showSkip == true || (visibility == View.VISIBLE && currentSegment?.skip == true))
}

"credit" -> {
skipButton.isVisible =
!buttonPressed && currentSegment?.skip == true && visibility == View.GONE
watchCreditsButton.isVisible = skipButton.isVisible
}
}
},
)
// onClick
if (currentSegment?.type == "credit") {
watchCreditsButton.setOnClickListener {
buttonPressed = true
skipButton.isVisible = false
watchCreditsButton.isVisible = false
}
}
skipButton.setOnClickListener {
when (currentSegment?.type) {
"intro" -> {
currentSegment?.let {
binding.playerView.player?.seekTo((it.endTime * 1000).toLong())
}
}

"credit" -> {
if (binding.playerView.player?.hasNextMediaItem() == true) {
binding.playerView.player?.seekToNext()
} else {
finish()
}
}
}
buttonPressed = true
skipButton.isVisible = false
watchCreditsButton.isVisible = false
}
oldSegment = currentSegment

// Trickplay
previewScrubListener?.let {
Expand Down
47 changes: 29 additions & 18 deletions app/phone/src/main/res/layout/exo_player_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@
android:textColor="@android:color/white"
android:textSize="14sp" />

<Button
android:id="@+id/btn_skip_intro"
style="@style/Widget.Material3.Button.OutlinedButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="24dp"
android:layout_marginBottom="64dp"
android:text="@string/player_controls_skip_intro"
android:textColor="@android:color/white"
android:visibility="gone"
app:backgroundTint="@color/player_background"
app:icon="@drawable/ic_skip_forward"
app:iconGravity="end"
app:iconTint="@android:color/white"
app:strokeColor="@android:color/white"
tools:visibility="visible" />

</androidx.media3.ui.AspectRatioFrameLayout>

<androidx.media3.ui.SubtitleView
Expand All @@ -89,4 +71,33 @@
android:layout_height="match_parent"
app:animation_enabled="false"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="end|bottom"
android:layout_marginEnd="24dp"
android:layout_marginBottom="64dp">

<Button
android:id="@+id/btn_watch_credits"
style="@style/Widget.Material3.Button.TonalButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:text="@string/watch_credits"
android:visibility="gone"
tools:visibility="visible" />

<Button
android:id="@+id/btn_skip_intro"
style="@style/Widget.Material3.Button.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:icon="@drawable/ic_skip_forward"
tools:visibility="visible" />

</LinearLayout>

</merge>
4 changes: 4 additions & 0 deletions app/phone/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="watch_credits">Watch credits</string>
</resources>
14 changes: 7 additions & 7 deletions core/src/main/java/dev/jdtech/jellyfin/utils/DownloaderImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import dev.jdtech.jellyfin.models.toFindroidEpisodeDto
import dev.jdtech.jellyfin.models.toFindroidMediaStreamDto
import dev.jdtech.jellyfin.models.toFindroidMovieDto
import dev.jdtech.jellyfin.models.toFindroidSeasonDto
import dev.jdtech.jellyfin.models.toFindroidSegmentsDto
import dev.jdtech.jellyfin.models.toFindroidShowDto
import dev.jdtech.jellyfin.models.toFindroidSourceDto
import dev.jdtech.jellyfin.models.toFindroidTrickplayInfoDto
import dev.jdtech.jellyfin.models.toFindroidUserDataDto
import dev.jdtech.jellyfin.models.toIntroDto
import dev.jdtech.jellyfin.repository.JellyfinRepository
import java.io.File
import java.util.UUID
Expand All @@ -47,7 +47,7 @@ class DownloaderImpl(
): Pair<Long, UiText?> {
try {
val source = jellyfinRepository.getMediaSources(item.id, true).first { it.id == sourceId }
val intro = jellyfinRepository.getIntroTimestamps(item.id)
val segments = jellyfinRepository.getSegmentsTimestamps(item.id)
val trickplayInfo = if (item is FindroidSources) {
item.trickplayInfo?.get(sourceId)
} else {
Expand Down Expand Up @@ -79,8 +79,8 @@ class DownloaderImpl(
if (trickplayInfo != null) {
downloadTrickplayData(item.id, sourceId, trickplayInfo)
}
if (intro != null) {
database.insertIntro(intro.toIntroDto(item.id))
if (segments != null) {
database.insertSegments(segments.toFindroidSegmentsDto(item.id))
}
val request = DownloadManager.Request(source.path.toUri())
.setTitle(item.name)
Expand Down Expand Up @@ -108,8 +108,8 @@ class DownloaderImpl(
if (trickplayInfo != null) {
downloadTrickplayData(item.id, sourceId, trickplayInfo)
}
if (intro != null) {
database.insertIntro(intro.toIntroDto(item.id))
if (segments != null) {
database.insertSegments(segments.toFindroidSegmentsDto(item.id))
}
val request = DownloadManager.Request(source.path.toUri())
.setTitle(item.name)
Expand Down Expand Up @@ -171,7 +171,7 @@ class DownloaderImpl(

database.deleteUserData(item.id)

database.deleteIntro(item.id)
database.deleteSegments(item.id)

File(context.filesDir, "trickplay/${item.id}").deleteRecursively()
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<string name="add">Aggiungi</string>
<string name="quick_connect">Connessione Rapida</string>
<string name="pref_player_intro_skipper">Salta intro</string>
<string name="pref_player_intro_skipper_summary">Richiede il plugin Intro Skipper di ConfusedPolarBear installato sul server</string>
<string name="pref_player_intro_skipper_summary">Richiede il plugin <b>Intro Skipper</b> di <i>jumoog</i> installato sul server</string>
<string name="player_gestures_seek_summary">Scorri orizzontalmente per posizionarti avanti o indietro</string>
<string name="player_gestures_seek">Gesto posizionamento</string>
<string name="audio">Audio</string>
Expand All @@ -147,6 +147,8 @@
<string name="extra_info">Mostra più informazioni</string>
<string name="amoled_theme">Tema scuro AMOLED</string>
<string name="amoled_theme_summary">Usa il tema AMOLED con lo sfondo nero</string>
<string name="pref_player_trickplay">Anteprima</string>
<string name="pref_player_trickplay_summary">Richiede il plugin Jellyscrub di nicknsy installato sul server</string>
<string name="size">Dimensione</string>
<string name="privacy_policy_notice">Utilizzando Findroid accetti l\'<a href="https://raw.githubusercontent.com/jarnedemeulemeester/findroid/main/PRIVACY">informativa sulla privacy</a> che afferma che non raccogliamo alcun dato</string>
<string name="episode_name_with_end">%1$d-%2$d. %3$s</string>
Expand Down Expand Up @@ -183,6 +185,9 @@
<string name="live_tv">Diretta TV</string>
<string name="play">Riproduci</string>
<string name="remove_from_favorites">Rimuovi dai preferiti</string>
<string name="skip_intro_button">Salta intro</string>
<string name="skip_credit_button">Prossimo episodio</string>
<string name="skip_credit_button_last">Chiudi player</string>
<string name="player_gestures_chapter_skip">Gesto per le scene</string>
<string name="pref_player_chapter_markers">Marcatori delle scene</string>
<string name="pref_player_chapter_markers_summary">Mostra i marcatori delle scene sulla timebar</string>
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<string name="pref_player_mpv_vo">Video output</string>
<string name="pref_player_mpv_ao">Audio output</string>
<string name="pref_player_intro_skipper">Intro Skipper</string>
<string name="pref_player_intro_skipper_summary">Requires ConfusedPolarBear\'s Intro Skipper plugin to be installed on the server</string>
<string name="pref_player_intro_skipper_summary">Requires <i>jumoog\'s</i> <b>Intro Skipper</b> plugin to be installed on the server</string>
<string name="pref_player_trickplay">Trickplay</string>
<string name="pref_player_trickplay_summary">Display preview images while scrubbing</string>
<string name="pref_player_chapter_markers">Chapter markers</string>
Expand Down Expand Up @@ -192,4 +192,7 @@
<string name="unmark_as_played">Unmark as played</string>
<string name="add_to_favorites">Add to favorites</string>
<string name="remove_from_favorites">Remove from favorites</string>
<string name="skip_intro_button">Skip Intro</string>
<string name="skip_credit_button">Next episode</string>
<string name="skip_credit_button_last">Close player</string>
</resources>
Loading