-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Support showing progress indicator on the player
- Loading branch information
Showing
10 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...main/java/com/skyd/anivu/model/preference/player/PlayerShowProgressIndicatorPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/skyd/anivu/ui/mpv/controller/ProgressIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters