Skip to content

Commit

Permalink
[feature] Support showing progress indicator on the player
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Sep 2, 2024
1 parent f904ce3 commit 206ba28
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk = 24
targetSdk = 35
versionCode = 24
versionName = "2.1-alpha28"
versionName = "2.1-alpha29"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/preference/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Boolean> {
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
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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 },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
<string name="request_headers_screen_name">请求头</string>
<string name="request_headers_screen_key">键</string>
<string name="request_headers_screen_value">值</string>
<string name="player_config_screen_show_progress_indicator">进度指示</string>
<plurals name="feed_screen_read_all_result">
<item quantity="other">已读 %d 项</item>
</plurals>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
<string name="request_headers_screen_name">Request headers</string>
<string name="request_headers_screen_key">Key</string>
<string name="request_headers_screen_value">Value</string>
<string name="player_config_screen_show_progress_indicator">Progress indicator</string>
<plurals name="feed_screen_read_all_result">
<item quantity="one">Read %d item</item>
<item quantity="other">Read %d items</item>
Expand Down

0 comments on commit 206ba28

Please sign in to comment.