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: remember repeat mode across app restarts #7042

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ object PreferenceKeys {
const val SHOW_TIME_LEFT = "show_time_left"
const val ALLOW_PLAYBACK_DURING_CALL = "playback_during_call"
const val BEHAVIOR_WHEN_MINIMIZED = "behavior_when_minimized"
const val REPEAT_MODE = "repeat_mode"

// SponsorBlock
const val SB_USER_ID = "sb_user_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ object PlayerHelper {
true
)

var repeatMode: Int
get() = PreferenceHelper.getInt(PreferenceKeys.REPEAT_MODE, Player.REPEAT_MODE_OFF)
set(value) {
PreferenceHelper.putInt(PreferenceKeys.REPEAT_MODE, value)
}

fun isAutoPlayEnabled(isPlaylist: Boolean = false): Boolean {
return autoPlayEnabled || (isPlaylist && PreferenceHelper
.getBoolean(PreferenceKeys.AUTOPLAY_PLAYLISTS, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
): ListenableFuture<SessionResult> {
when (customCommand.customAction) {
START_SERVICE_ACTION -> {
PlayingQueue.resetToDefaults()

CoroutineScope(Dispatchers.IO).launch {
onServiceCreated(args)
notificationProvider?.intentActivity = getIntentActivity()
Expand Down Expand Up @@ -361,8 +359,6 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
// java.lang.SecurityException: Session rejected the connection request.
// because there can't be two active playerControllers at the same time.
handler.postDelayed(50) {
PlayingQueue.resetToDefaults()

saveWatchPosition()

notificationProvider = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class PlaylistFragment : DynamicLayoutManagerFragment(R.layout.fragment_playlist
binding.bookmark.text = getString(R.string.shuffle)
binding.bookmark.setOnClickListener {
val queue = playlistFeed.shuffled()
PlayingQueue.resetToDefaults()
PlayingQueue.add(*queue.toTypedArray())
NavigationHelper.navigateVideo(
requireContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc
val watchHistory = history.filterByStatusAndWatchPosition()

binding.playAll.setOnClickListener {
PlayingQueue.resetToDefaults()
PlayingQueue.add(
*watchHistory.reversed().map(WatchHistoryItem::toStreamItem).toTypedArray()
)
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/github/libretube/util/PlayingQueue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ object PlayingQueue {

private val queueJobs = mutableListOf<Job>()

var repeatMode: Int = Player.REPEAT_MODE_OFF
// wrapper around PlayerHelper#repeatMode for compatibility
var repeatMode: Int
get() = PlayerHelper.repeatMode
set(value) {
PlayerHelper.repeatMode = value
}

fun clear() {
queueJobs.forEach {
Expand Down Expand Up @@ -216,8 +221,4 @@ object PlayingQueue {

add(*streams.filter { !it.isLive }.toTypedArray(), skipExisting = true)
}

fun resetToDefaults() {
repeatMode = Player.REPEAT_MODE_OFF
}
}
Loading