From 206ba280e66c004154929e559d7654299b16a091 Mon Sep 17 00:00:00 2001 From: SkyD666 Date: Mon, 2 Sep 2024 23:53:17 +0800 Subject: [PATCH] [feature] Support showing progress indicator on the player --- app/build.gradle.kts | 2 +- .../java/com/skyd/anivu/ext/PreferenceExt.kt | 2 ++ .../skyd/anivu/model/preference/Settings.kt | 4 +++ .../PlayerShowProgressIndicatorPreference.kt | 26 ++++++++++++++++++ .../com/skyd/anivu/ui/local/LocalValue.kt | 3 +++ .../ui/mpv/controller/PlayerController.kt | 12 ++++++--- .../ui/mpv/controller/ProgressIndicator.kt | 27 +++++++++++++++++++ .../playerconfig/PlayerConfigScreen.kt | 17 ++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/skyd/anivu/model/preference/player/PlayerShowProgressIndicatorPreference.kt create mode 100644 app/src/main/java/com/skyd/anivu/ui/mpv/controller/ProgressIndicator.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5d433166..863ee468 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -22,7 +22,7 @@ android { minSdk = 24 targetSdk = 35 versionCode = 24 - versionName = "2.1-alpha28" + versionName = "2.1-alpha29" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt b/app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt index 2f26b1e3..61e0f060 100644 --- a/app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt +++ b/app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt @@ -39,6 +39,7 @@ import com.skyd.anivu.model.preference.player.PlayerMaxBackCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerMaxCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerSeekOptionPreference import com.skyd.anivu.model.preference.player.PlayerShow85sButtonPreference +import com.skyd.anivu.model.preference.player.PlayerShowProgressIndicatorPreference import com.skyd.anivu.model.preference.player.PlayerShowScreenshotButtonPreference import com.skyd.anivu.model.preference.proxy.ProxyHostnamePreference import com.skyd.anivu.model.preference.proxy.ProxyModePreference @@ -100,6 +101,7 @@ fun Preferences.toSettings(): Settings { playerDoubleTap = PlayerDoubleTapPreference.fromPreferences(this), playerShow85sButton = PlayerShow85sButtonPreference.fromPreferences(this), playerShowScreenshotButton = PlayerShowScreenshotButtonPreference.fromPreferences(this), + playerShowProgressIndicator = PlayerShowProgressIndicatorPreference.fromPreferences(this), hardwareDecode = HardwareDecodePreference.fromPreferences(this), playerAutoPip = PlayerAutoPipPreference.fromPreferences(this), playerMaxCacheSize = PlayerMaxCacheSizePreference.fromPreferences(this), diff --git a/app/src/main/java/com/skyd/anivu/model/preference/Settings.kt b/app/src/main/java/com/skyd/anivu/model/preference/Settings.kt index 6f1adf52..0b0ab65b 100644 --- a/app/src/main/java/com/skyd/anivu/model/preference/Settings.kt +++ b/app/src/main/java/com/skyd/anivu/model/preference/Settings.kt @@ -44,6 +44,7 @@ import com.skyd.anivu.model.preference.player.PlayerMaxBackCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerMaxCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerSeekOptionPreference import com.skyd.anivu.model.preference.player.PlayerShow85sButtonPreference +import com.skyd.anivu.model.preference.player.PlayerShowProgressIndicatorPreference import com.skyd.anivu.model.preference.player.PlayerShowScreenshotButtonPreference import com.skyd.anivu.model.preference.proxy.ProxyHostnamePreference import com.skyd.anivu.model.preference.proxy.ProxyModePreference @@ -88,6 +89,7 @@ import com.skyd.anivu.ui.local.LocalPlayerMaxBackCacheSize import com.skyd.anivu.ui.local.LocalPlayerMaxCacheSize import com.skyd.anivu.ui.local.LocalPlayerSeekOption import com.skyd.anivu.ui.local.LocalPlayerShow85sButton +import com.skyd.anivu.ui.local.LocalPlayerShowProgressIndicator import com.skyd.anivu.ui.local.LocalPlayerShowScreenshotButton import com.skyd.anivu.ui.local.LocalProxyHostname import com.skyd.anivu.ui.local.LocalProxyMode @@ -151,6 +153,7 @@ data class Settings( val playerDoubleTap: String = PlayerDoubleTapPreference.default, val playerShow85sButton: Boolean = PlayerShow85sButtonPreference.default, val playerShowScreenshotButton: Boolean = PlayerShowScreenshotButtonPreference.default, + val playerShowProgressIndicator: Boolean = PlayerShowProgressIndicatorPreference.default, val hardwareDecode: Boolean = HardwareDecodePreference.default, val playerAutoPip: Boolean = PlayerAutoPipPreference.default, val playerMaxCacheSize: Long = PlayerMaxCacheSizePreference.default, @@ -220,6 +223,7 @@ fun SettingsProvider( LocalPlayerDoubleTap provides settings.playerDoubleTap, LocalPlayerShow85sButton provides settings.playerShow85sButton, LocalPlayerShowScreenshotButton provides settings.playerShowScreenshotButton, + LocalPlayerShowProgressIndicator provides settings.playerShowProgressIndicator, LocalHardwareDecode provides settings.hardwareDecode, LocalPlayerAutoPip provides settings.playerAutoPip, LocalPlayerMaxCacheSize provides settings.playerMaxCacheSize, diff --git a/app/src/main/java/com/skyd/anivu/model/preference/player/PlayerShowProgressIndicatorPreference.kt b/app/src/main/java/com/skyd/anivu/model/preference/player/PlayerShowProgressIndicatorPreference.kt new file mode 100644 index 00000000..517e3204 --- /dev/null +++ b/app/src/main/java/com/skyd/anivu/model/preference/player/PlayerShowProgressIndicatorPreference.kt @@ -0,0 +1,26 @@ +package com.skyd.anivu.model.preference.player + +import android.content.Context +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.booleanPreferencesKey +import com.skyd.anivu.base.BasePreference +import com.skyd.anivu.ext.dataStore +import com.skyd.anivu.ext.put +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +object PlayerShowProgressIndicatorPreference : BasePreference { + private const val PLAYER_SHOW_PROGRESS_INDICATOR = "playerShowProgressIndicator" + override val default = false + + val key = booleanPreferencesKey(PLAYER_SHOW_PROGRESS_INDICATOR) + + fun put(context: Context, scope: CoroutineScope, value: Boolean) { + scope.launch(Dispatchers.IO) { + context.dataStore.put(key, value) + } + } + + override fun fromPreferences(preferences: Preferences): Boolean = preferences[key] ?: default +} \ No newline at end of file diff --git a/app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt b/app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt index fda91da6..1869c305 100644 --- a/app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt +++ b/app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt @@ -40,6 +40,7 @@ import com.skyd.anivu.model.preference.player.PlayerMaxBackCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerMaxCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerSeekOptionPreference import com.skyd.anivu.model.preference.player.PlayerShow85sButtonPreference +import com.skyd.anivu.model.preference.player.PlayerShowProgressIndicatorPreference import com.skyd.anivu.model.preference.player.PlayerShowScreenshotButtonPreference import com.skyd.anivu.model.preference.proxy.ProxyHostnamePreference import com.skyd.anivu.model.preference.proxy.ProxyModePreference @@ -115,6 +116,8 @@ val LocalPlayerDoubleTap = compositionLocalOf { PlayerDoubleTapPreference.defaul val LocalPlayerShow85sButton = compositionLocalOf { PlayerShow85sButtonPreference.default } val LocalPlayerShowScreenshotButton = compositionLocalOf { PlayerShowScreenshotButtonPreference.default } +val LocalPlayerShowProgressIndicator = + compositionLocalOf { PlayerShowProgressIndicatorPreference.default } val LocalHardwareDecode = compositionLocalOf { HardwareDecodePreference.default } val LocalPlayerAutoPip = compositionLocalOf { PlayerAutoPipPreference.default } val LocalPlayerMaxCacheSize = compositionLocalOf { PlayerMaxCacheSizePreference.default } diff --git a/app/src/main/java/com/skyd/anivu/ui/mpv/controller/PlayerController.kt b/app/src/main/java/com/skyd/anivu/ui/mpv/controller/PlayerController.kt index 802dde5b..dd79e62c 100644 --- a/app/src/main/java/com/skyd/anivu/ui/mpv/controller/PlayerController.kt +++ b/app/src/main/java/com/skyd/anivu/ui/mpv/controller/PlayerController.kt @@ -4,18 +4,14 @@ import android.content.Context import android.os.Build import android.os.Vibrator import android.os.VibratorManager -import android.util.Log import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.Spring import androidx.compose.animation.core.spring import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.safeGestures -import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.FastForward import androidx.compose.material.icons.rounded.FastRewind @@ -44,6 +40,7 @@ import androidx.core.view.WindowInsetsControllerCompat import com.skyd.anivu.ext.tickVibrate import com.skyd.anivu.ui.component.rememberSystemUiController import com.skyd.anivu.ui.local.LocalPlayerShow85sButton +import com.skyd.anivu.ui.local.LocalPlayerShowProgressIndicator import com.skyd.anivu.ui.local.LocalPlayerShowScreenshotButton import com.skyd.anivu.ui.mpv.controller.bar.BottomBar import com.skyd.anivu.ui.mpv.controller.bar.BottomBarCallback @@ -223,6 +220,13 @@ internal fun PlayerController( onRestartAutoHideControllerRunnable = restartAutoHideControllerRunnable, ) + if (LocalPlayerShowProgressIndicator.current && !showController) { + ProgressIndicator( + modifier = Modifier.align(Alignment.BottomCenter), + playState = playState, + ) + } + // Seek time preview if (showSeekTimePreview) { SeekTimePreview( diff --git a/app/src/main/java/com/skyd/anivu/ui/mpv/controller/ProgressIndicator.kt b/app/src/main/java/com/skyd/anivu/ui/mpv/controller/ProgressIndicator.kt new file mode 100644 index 00000000..88c66e07 --- /dev/null +++ b/app/src/main/java/com/skyd/anivu/ui/mpv/controller/ProgressIndicator.kt @@ -0,0 +1,27 @@ +package com.skyd.anivu.ui.mpv.controller + +import android.util.Log +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.LinearProgressIndicator +import androidx.compose.material3.ProgressIndicatorDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import com.skyd.anivu.ui.mpv.controller.state.PlayState + +@Composable +fun ProgressIndicator(modifier: Modifier = Modifier, playState: () -> PlayState) { + val animatedProgress by animateFloatAsState( + targetValue = playState().run { currentPosition.toFloat() / duration }, + animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, + label = "playerProgressIndicatorAnimate" + ) + Log.e("TAG", "ProgressIndicator: $animatedProgress", ) + LinearProgressIndicator( + modifier = Modifier + .fillMaxWidth() + .then(modifier), + progress = { animatedProgress }, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/settings/playerconfig/PlayerConfigScreen.kt b/app/src/main/java/com/skyd/anivu/ui/screen/settings/playerconfig/PlayerConfigScreen.kt index 4fafeef3..e6afabe8 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/settings/playerconfig/PlayerConfigScreen.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/settings/playerconfig/PlayerConfigScreen.kt @@ -15,6 +15,7 @@ import androidx.compose.material.icons.outlined.PhotoCamera import androidx.compose.material.icons.outlined.PictureInPictureAlt import androidx.compose.material.icons.outlined.Restore import androidx.compose.material.icons.outlined.Save +import androidx.compose.material.icons.outlined.Timelapse import androidx.compose.material.icons.outlined.TouchApp import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme @@ -44,6 +45,7 @@ import com.skyd.anivu.model.preference.player.PlayerMaxBackCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerMaxCacheSizePreference import com.skyd.anivu.model.preference.player.PlayerSeekOptionPreference import com.skyd.anivu.model.preference.player.PlayerShow85sButtonPreference +import com.skyd.anivu.model.preference.player.PlayerShowProgressIndicatorPreference import com.skyd.anivu.model.preference.player.PlayerShowScreenshotButtonPreference import com.skyd.anivu.ui.component.AniVuIconButton import com.skyd.anivu.ui.component.AniVuTopBar @@ -60,6 +62,7 @@ import com.skyd.anivu.ui.local.LocalPlayerMaxBackCacheSize import com.skyd.anivu.ui.local.LocalPlayerMaxCacheSize import com.skyd.anivu.ui.local.LocalPlayerSeekOption import com.skyd.anivu.ui.local.LocalPlayerShow85sButton +import com.skyd.anivu.ui.local.LocalPlayerShowProgressIndicator import com.skyd.anivu.ui.local.LocalPlayerShowScreenshotButton import com.skyd.anivu.ui.screen.settings.playerconfig.advanced.PLAYER_CONFIG_ADVANCED_SCREEN_ROUTE @@ -176,6 +179,20 @@ fun PlayerConfigScreen() { } ) } + item { + SwitchSettingsItem( + imageVector = Icons.Outlined.Timelapse, + text = stringResource(id = R.string.player_config_screen_show_progress_indicator), + checked = LocalPlayerShowProgressIndicator.current, + onCheckedChange = { + PlayerShowProgressIndicatorPreference.put( + context = context, + scope = scope, + value = it, + ) + } + ) + } item { CategorySettingsItem(text = stringResource(id = R.string.player_config_screen_cache_category)) } diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 9966e081..2fe8fed1 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -333,6 +333,7 @@ 请求头 + 进度指示 已读 %d 项 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd7c1a6e..792bc623 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -340,6 +340,7 @@ Request headers Key Value + Progress indicator Read %d item Read %d items