mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #2503 from Bnyro/data-saver-metered
Option to allow data saver on metered networks
This commit is contained in:
commit
dd1c215ba7
@ -82,6 +82,7 @@ import com.github.libretube.ui.sheets.CommentsSheet
|
||||
import com.github.libretube.ui.sheets.PlayingQueueSheet
|
||||
import com.github.libretube.util.BackgroundHelper
|
||||
import com.github.libretube.util.DashHelper
|
||||
import com.github.libretube.util.DataSaverMode
|
||||
import com.github.libretube.util.ImageHelper
|
||||
import com.github.libretube.util.NowPlayingNotification
|
||||
import com.github.libretube.util.PlayerHelper
|
||||
@ -651,13 +652,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
setupSeekbarPreview()
|
||||
if (!isLive) seekToWatchPosition()
|
||||
exoPlayer.prepare()
|
||||
if (!PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.DATA_SAVER_MODE,
|
||||
false
|
||||
)
|
||||
) {
|
||||
exoPlayer.play()
|
||||
}
|
||||
if (!DataSaverMode.isEnabled(requireContext())) exoPlayer.play()
|
||||
|
||||
if (binding.playerMotionLayout.progress != 1.0f) {
|
||||
// show controllers when not in picture in picture mode
|
||||
|
16
app/src/main/java/com/github/libretube/util/DataSaverMode.kt
Normal file
16
app/src/main/java/com/github/libretube/util/DataSaverMode.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.content.Context
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
|
||||
object DataSaverMode {
|
||||
fun isEnabled(context: Context): Boolean {
|
||||
val pref = PreferenceHelper.getString(PreferenceKeys.DATA_SAVER_MODE, "disabled")
|
||||
return when (pref) {
|
||||
"enabled" -> true
|
||||
"disabled" -> false
|
||||
"metered"-> NetworkHelper.isNetworkMobile(context)
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
}
|
@ -52,11 +52,7 @@ object ImageHelper {
|
||||
*/
|
||||
fun loadImage(url: String?, target: ImageView) {
|
||||
// only load the image if the data saver mode is disabled
|
||||
val dataSaverModeEnabled = PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.DATA_SAVER_MODE,
|
||||
false
|
||||
)
|
||||
if (!dataSaverModeEnabled) target.load(url, imageLoader)
|
||||
if (!DataSaverMode.isEnabled(target.context)) target.load(url, imageLoader)
|
||||
}
|
||||
|
||||
fun downloadImage(context: Context, url: String, fileName: String) {
|
||||
|
@ -109,7 +109,7 @@ class NowPlayingNotification(
|
||||
player: Player,
|
||||
callback: PlayerNotificationManager.BitmapCallback
|
||||
): Bitmap? {
|
||||
if (PreferenceHelper.getBoolean(PreferenceKeys.DATA_SAVER_MODE, false)) return null
|
||||
if (DataSaverMode.isEnabled(context)) return null
|
||||
|
||||
var bitmap: Bitmap? = null
|
||||
|
||||
|
@ -99,6 +99,6 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/thumbnailcard"
|
||||
app:shapeAppearance="@style/CircleImageView"
|
||||
app:srcCompat="@mipmap/ic_launcher" />
|
||||
tools:srcCompat="@mipmap/ic_launcher" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -425,4 +425,16 @@
|
||||
<item>name_reversed</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dataSaverModeOptions">
|
||||
<item>@string/disabled</item>
|
||||
<item>@string/network_metered</item>
|
||||
<item>@string/enabled</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dataSaverModeValues">
|
||||
<item>disabled</item>
|
||||
<item>metered</item>
|
||||
<item>enabled</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
@ -4,7 +4,10 @@
|
||||
|
||||
<PreferenceCategory app:title="@string/advanced">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
<ListPreference
|
||||
android:defaultValue="disabled"
|
||||
android:entries="@array/dataSaverModeOptions"
|
||||
android:entryValues="@array/dataSaverModeValues"
|
||||
android:icon="@drawable/ic_data_saver"
|
||||
android:summary="@string/data_saver_mode_summary"
|
||||
app:key="data_saver_mode"
|
||||
|
Loading…
Reference in New Issue
Block a user