Make autoplay toggle in player global and remove autoplay preference

This commit is contained in:
Bnyro 2023-06-25 10:20:06 +02:00
parent 4bb64bee05
commit 57bf610df1
7 changed files with 73 additions and 56 deletions

View File

@ -58,7 +58,7 @@ object PreferenceKeys {
* Player
*/
const val AUTO_FULLSCREEN = "auto_fullscreen"
const val AUTO_PLAY = "autoplay"
const val AUTOPLAY = "autoplay"
const val RELATED_STREAMS = "related_streams_toggle"
const val CUSTOM_PLAYBACK_SPEED = "custom_playback_speed"
const val PLAYBACK_SPEED = "playback_speed"

View File

@ -202,11 +202,14 @@ object PlayerHelper {
true
)
val autoPlayEnabled: Boolean
var autoPlayEnabled: Boolean
get() = PreferenceHelper.getBoolean(
PreferenceKeys.AUTO_PLAY,
PreferenceKeys.AUTOPLAY,
true
)
set(value) {
PreferenceHelper.putBoolean(PreferenceKeys.AUTOPLAY, value)
}
val autoPlayCountdown: Boolean
get() = PreferenceHelper.getBoolean(

View File

@ -111,6 +111,11 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
onLongTap()
}
binding.autoPlay.isChecked = PlayerHelper.autoPlayEnabled
binding.autoPlay.setOnCheckedChangeListener { _, isChecked ->
PlayerHelper.autoPlayEnabled = isChecked
}
binding.prev.setOnClickListener {
val currentIndex = PlayingQueue.currentIndex()
if (!PlayingQueue.hasPrev()) return@setOnClickListener

View File

@ -115,7 +115,6 @@ import com.github.libretube.util.TextUtils.toTimeInSeconds
import java.io.IOException
import java.util.*
import java.util.concurrent.Executors
import kotlin.math.abs
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -123,6 +122,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.serialization.encodeToString
import retrofit2.HttpException
import kotlin.math.abs
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class PlayerFragment : Fragment(), OnlinePlayerOptions {
@ -586,7 +586,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
binding.playerViewsInfo.text = viewInfo
if (this::chapters.isInitialized && chapters.isNotEmpty()) {
setCurrentChapterName(true, false)
setCurrentChapterName(forceUpdate = true, enqueueNew = false)
}
}
@ -966,7 +966,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
if (
playbackState == Player.STATE_ENDED &&
!transitioning &&
binding.player.autoplayEnabled
PlayerHelper.autoPlayEnabled
) {
transitioning = true
if (PlayerHelper.autoPlayCountdown) {

View File

@ -24,7 +24,6 @@ class OnlinePlayerView(
private var playerViewModel: PlayerViewModel? = null
private var trackSelector: TrackSelector? = null
private var viewLifecycleOwner: LifecycleOwner? = null
var autoplayEnabled = PlayerHelper.autoPlayEnabled
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
override fun getOptionsMenuItems(): List<BottomSheetItem> {
@ -97,10 +96,10 @@ class OnlinePlayerView(
}
)
binding.autoPlay.isChecked = autoplayEnabled
binding.autoPlay.isChecked = PlayerHelper.autoPlayEnabled
binding.autoPlay.setOnCheckedChangeListener { _, isChecked ->
autoplayEnabled = isChecked
PlayerHelper.autoPlayEnabled = isChecked
}
}

View File

@ -26,7 +26,7 @@
app:layout_constraintStart_toStartOf="@id/audio_player_container"
app:layout_constraintTop_toTopOf="@id/audio_player_container">
<FrameLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
@ -35,21 +35,38 @@
android:id="@+id/minimize_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|start"
android:layout_gravity="center"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/ic_arrow_down" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/autoPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:scaleX="0.8"
android:scaleY="0.8"
android:thumb="@drawable/player_switch_thumb"
app:thumbTint="?colorPrimary"
app:track="@drawable/player_switch_track"
app:trackTint="?colorControlNormal" />
<ImageView
android:id="@+id/dropdown_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|end"
android:layout_gravity="center"
android:background="?selectableItemBackgroundBorderless"
android:scaleX="0.8"
android:scaleY="0.8"
android:src="@drawable/ic_three_dots" />
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"

View File

@ -163,13 +163,6 @@
app:title="@string/player_resize_mode"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
android:icon="@drawable/ic_play_filled"
android:summary="@string/autoplay_summary"
app:defaultValue="true"
app:key="autoplay"
app:title="@string/player_autoplay" />
<SwitchPreferenceCompat
android:icon="@drawable/ic_speed"
android:summary="@string/autoplay_countdown_summary"