Skip to content

Commit

Permalink
Merge pull request #7042 from Bnyro/master
Browse files Browse the repository at this point in the history
feat: remember repeat mode across app restarts
  • Loading branch information
Bnyro authored Jan 29, 2025
2 parents 2eaeaa9 + 252365b commit 0dc3b95
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
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
}
}

0 comments on commit 0dc3b95

Please sign in to comment.