Skip to content

Commit

Permalink
[optimize|build] Optimize code; update kotlinCompilerExtensionVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed May 17, 2024
1 parent 70374dd commit 3d0ea3b
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 144 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 16
versionName = "1.1-beta26"
versionName = "1.1-beta27"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -105,7 +105,7 @@ android {
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.12"
kotlinCompilerExtensionVersion = "1.5.14"
}
packaging {
resources.excludes += mutableSetOf(
Expand Down
190 changes: 79 additions & 111 deletions app/src/main/java/com/skyd/anivu/ui/mpv/PlayerView.kt

Large diffs are not rendered by default.

47 changes: 25 additions & 22 deletions app/src/main/java/com/skyd/anivu/ui/mpv/PointerInputDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.skyd.anivu.ext.detectDoubleFingerTransformGestures
import com.skyd.anivu.ext.getScreenBrightness
import com.skyd.anivu.model.preference.player.PlayerDoubleTapPreference
import com.skyd.anivu.ui.local.LocalPlayerDoubleTap
import com.skyd.anivu.ui.mpv.state.PlayState
import com.skyd.anivu.ui.mpv.state.TransformState
import kotlin.math.abs

private val inStatusBarArea: PointerInputScope.(y: Float) -> Boolean = { y ->
Expand All @@ -30,10 +32,9 @@ private val inStatusBarArea: PointerInputScope.(y: Float) -> Boolean = { y ->
@Composable
internal fun Modifier.detectPressGestures(
controllerWidth: () -> Int,
currentPosition: () -> Int,
onSeekTo: (Int) -> Unit,
playState: () -> PlayState,
onSeekTo: (position: Int) -> Unit,
onPlayOrPause: () -> Unit,
speed: () -> Float,
onSpeedChanged: (Float) -> Unit,
showController: () -> Boolean,
onShowControllerChanged: (Boolean) -> Unit,
Expand All @@ -44,26 +45,26 @@ internal fun Modifier.detectPressGestures(
cancelAutoHideControllerRunnable: () -> Boolean,
restartAutoHideControllerRunnable: () -> Unit,
): Modifier {
var beforeLongPressingSpeed by remember { mutableFloatStateOf(speed()) }
var beforeLongPressingSpeed by remember { mutableFloatStateOf(playState().speed) }

val playerDoubleTap = LocalPlayerDoubleTap.current
val onDoubleTapPausePlay: () -> Unit = remember { { onPlayOrPause() } }

val onDoubleTapBackwardForward: (Offset) -> Unit = { offset ->
val onDoubleTapBackwardForward: PlayState.(Offset) -> Unit = { offset ->
if (offset.x < controllerWidth() / 2f) {
onSeekTo(currentPosition() - 10) // -10s.
onSeekTo(currentPosition - 10) // -10s.
onShowBackwardRipple(offset)
} else {
onSeekTo(currentPosition() + 10) // +10s.
onSeekTo(currentPosition + 10) // +10s.
onShowForwardRipple(offset)
}
}
val onDoubleTapBackwardPausePlayForward: (Offset) -> Unit = { offset ->
val onDoubleTapBackwardPausePlayForward: PlayState.(Offset) -> Unit = { offset ->
if (offset.x <= controllerWidth() * 0.25f) {
onSeekTo(currentPosition() - 10) // -10s.
onSeekTo(currentPosition - 10) // -10s.
onShowBackwardRipple(offset)
} else if (offset.x >= controllerWidth() * 0.75f) {
onSeekTo(currentPosition() + 10) // +10s.
onSeekTo(currentPosition + 10) // +10s.
onShowForwardRipple(offset)
} else {
onDoubleTapPausePlay()
Expand All @@ -72,9 +73,11 @@ internal fun Modifier.detectPressGestures(

val onDoubleTap: (Offset) -> Unit = { offset ->
when (playerDoubleTap) {
PlayerDoubleTapPreference.BACKWARD_FORWARD -> onDoubleTapBackwardForward(offset)
PlayerDoubleTapPreference.BACKWARD_FORWARD ->
playState().onDoubleTapBackwardForward(offset)

PlayerDoubleTapPreference.BACKWARD_PAUSE_PLAY_FORWARD ->
onDoubleTapBackwardPausePlayForward(offset)
playState().onDoubleTapBackwardPausePlayForward(offset)

else -> onDoubleTapPausePlay()
}
Expand All @@ -83,7 +86,7 @@ internal fun Modifier.detectPressGestures(
return pointerInput(playerDoubleTap) {
detectTapGestures(
onLongPress = {
beforeLongPressingSpeed = speed()
beforeLongPressingSpeed = playState().speed
isLongPressingChanged(true)
onSpeedChanged(3f)
},
Expand Down Expand Up @@ -117,15 +120,13 @@ internal fun Modifier.detectControllerGestures(
onShowVolume: (Boolean) -> Unit,
onVolumeRangeChanged: (IntRange) -> Unit,
onVolumeChanged: (Int) -> Unit,
currentPosition: () -> Int,
playState: () -> PlayState,
onSeekTo: (position: Int) -> Unit,
onShowSeekTimePreview: (Boolean) -> Unit,
onTimePreviewChanged: (Int) -> Unit,
onSeekTo: (Int) -> Unit,
videoRotate: () -> Float,
transformState: () -> TransformState,
onVideoRotate: (Float) -> Unit,
videoZoom: () -> Float,
onVideoZoom: (Float) -> Unit,
videoOffset: () -> Offset,
onVideoOffset: (Offset) -> Unit,
cancelAutoHideControllerRunnable: () -> Boolean,
restartAutoHideControllerRunnable: () -> Unit,
Expand Down Expand Up @@ -224,7 +225,7 @@ internal fun Modifier.detectControllerGestures(
pointerStartX = it.x
pointerStartY = it.y
if (inStatusBarArea(it.y)) return@onHorizontalDragStart
seekTimePreviewStartPosition = currentPosition()
seekTimePreviewStartPosition = playState().currentPosition
seekTimePreviewPositionDelta = 0
onShowSeekTimePreview(true)
},
Expand All @@ -245,9 +246,11 @@ internal fun Modifier.detectControllerGestures(
onTimePreviewChanged(seekTimePreviewStartPosition + seekTimePreviewPositionDelta)
},
onGesture = onGesture@{ _: Offset, pan: Offset, zoom: Float, rotation: Float ->
onVideoOffset(videoOffset() + pan)
onVideoRotate(videoRotate() + rotation)
onVideoZoom(videoZoom() * zoom)
with(transformState()) {
onVideoOffset(videoOffset + pan)
onVideoRotate(videoRotate + rotation)
onVideoZoom(videoZoom * zoom)
}
}
)
}
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/com/skyd/anivu/ui/mpv/SubtitleTrack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import com.skyd.anivu.R
import com.skyd.anivu.ui.component.dialog.AniVuDialog
import com.skyd.anivu.ui.mpv.state.SubtitleTrackDialogState

data class SubtitleTrackDialogState(
val show: Boolean,
val currentSubtitleTrack: MPVView.Track,
val subtitleTrack: List<MPVView.Track>,
)

@Composable
internal fun SubtitleTrackDialog(
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/skyd/anivu/ui/mpv/state/PlayState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.skyd.anivu.ui.mpv.state

data class PlayState(
val isPlaying: Boolean,
val isSeeking: Boolean,
val currentPosition: Int,
val duration: Int,
val speed: Float,
val title: String,
) {
companion object {
val initial = PlayState(
isPlaying = false,
isSeeking = false,
currentPosition = 0,
duration = 0,
speed = 1f,
title = "",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skyd.anivu.ui.mpv.state

import com.skyd.anivu.ui.mpv.MPVView

data class SubtitleTrackDialogState(
val show: Boolean,
val currentSubtitleTrack: MPVView.Track,
val subtitleTrack: List<MPVView.Track>,
) {
companion object {
val initial = SubtitleTrackDialogState(
show = false,
currentSubtitleTrack = MPVView.Track(0, ""),
subtitleTrack = emptyList(),
)
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/skyd/anivu/ui/mpv/state/TransformState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skyd.anivu.ui.mpv.state

import androidx.compose.ui.geometry.Offset

data class TransformState(
val videoRotate: Float,
val videoZoom: Float,
val videoOffset: Offset,
) {
companion object {
val initial = TransformState(
videoRotate = 0f,
videoZoom = 1f,
videoOffset = Offset.Zero,
)
}
}
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.4.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.23" apply false
id("com.google.dagger.hilt.android") version "2.51" apply false
id("com.google.devtools.ksp") version "1.9.23-1.0.19" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.23"
id("org.jetbrains.kotlin.android") version "1.9.24" apply false
id("com.google.dagger.hilt.android") version "2.51.1" apply false
id("com.google.devtools.ksp") version "1.9.24-1.0.20" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.24"
}

0 comments on commit 3d0ea3b

Please sign in to comment.