Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlwicked committed Sep 25, 2024
2 parents 8efccda + f313e2d commit 43362da
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,50 +1,83 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.foundation.richtext

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import me.him188.ani.app.ui.foundation.ProvideCompositionLocalsForPreview
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import me.him188.ani.app.ui.foundation.ProvideFoundationCompositionLocalsForPreview
import me.him188.ani.app.ui.richtext.RichText
import me.him188.ani.app.ui.richtext.UIRichElement

@Preview
@Composable
private fun PreviewRichText() {
ProvideCompositionLocalsForPreview {
RichText(
elements = listOf(
UIRichElement.AnnotatedText(
slice = listOf(
UIRichElement.Annotated.Text("hello", 16f),
UIRichElement.Annotated.Text("my italic content", 16f, italic = true),
UIRichElement.Annotated.Text("my bold content", 16f, bold = true),
UIRichElement.Annotated.Text("my underline content", 16f, underline = true),
UIRichElement.Annotated.Text("my strikethrough content", 16f, strikethrough = true),
UIRichElement.Annotated.Text(
"my combined content",
16f,
bold = true,
underline = true,
strikethrough = true,
),
UIRichElement.Annotated.Text("have link", 16f, url = "https://localhost"),
UIRichElement.Annotated.Text(
"have link combined",
16f,
bold = true,
strikethrough = true,
url = "https://localhost",
),
UIRichElement.Annotated.Sticker(
"sticker_1",
null,
"",
),
private fun PreviewImpl() {
RichText(
elements = listOf(
UIRichElement.AnnotatedText(
slice = listOf(
UIRichElement.Annotated.Text("hello", 16f),
UIRichElement.Annotated.Text("my italic content", 16f, italic = true),
UIRichElement.Annotated.Text("my bold content", 16f, bold = true),
UIRichElement.Annotated.Text("my underline content", 16f, underline = true),
UIRichElement.Annotated.Text("\nmy mask content\n", 16f, mask = true),
UIRichElement.Annotated.Text("my strikethrough content", 16f, strikethrough = true),
UIRichElement.Annotated.Text(
"my combined content",
16f,
bold = true,
underline = true,
strikethrough = true,
),
UIRichElement.Annotated.Text("have link", 16f, url = "https://localhost"),
UIRichElement.Annotated.Text(
"have link combined",
16f,
bold = true,
strikethrough = true,
url = "https://localhost",
),
UIRichElement.Annotated.Sticker(
"sticker_1",
null,
"",
),
),
),
modifier = Modifier.fillMaxWidth(),
)
),
modifier = Modifier
.fillMaxWidth()
.padding(all = 36.dp),
)
}

@PreviewLightDark
@Composable
private fun PreviewRichTextSurfaceContainer() {
ProvideFoundationCompositionLocalsForPreview {
Surface(color = MaterialTheme.colorScheme.surfaceContainer) {
PreviewImpl()
}
}
}

@PreviewLightDark
@Composable
private fun PreviewRichTextSurface() {
ProvideFoundationCompositionLocalsForPreview {
Surface(color = MaterialTheme.colorScheme.surface) {
PreviewImpl()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

@file:Suppress("PropertyName")

package me.him188.ani.app.ui.subject.cache
Expand Down Expand Up @@ -157,6 +166,7 @@ fun SettingsScope.EpisodeCacheListGroup(
MediaSelectorView(
selectorPresentation,
sourceResults = { MediaSourceResultsView(sourceResults, selectorPresentation) },
stickyHeaderBackgroundColor = BottomSheetDefaults.ContainerColor,
modifier = Modifier.padding(vertical = 12.dp, horizontal = 16.dp)
.navigationBarsPadding()
.fillMaxHeight() // 防止添加筛选后数量变少导致 bottom sheet 高度变化
Expand Down
22 changes: 20 additions & 2 deletions app/shared/src/commonMain/kotlin/ui/subject/episode/EpisodePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ import me.him188.ani.app.data.source.danmaku.protocol.DanmakuInfo
import me.him188.ani.app.data.source.danmaku.protocol.DanmakuLocation
import me.him188.ani.app.navigation.LocalNavigator
import me.him188.ani.app.platform.LocalContext
import me.him188.ani.app.platform.features.StreamType
import me.him188.ani.app.platform.features.getComponentAccessors
import me.him188.ani.app.tools.rememberUiMonoTasker
import me.him188.ani.app.ui.external.placeholder.placeholder
import me.him188.ani.app.ui.foundation.ImageViewer
Expand Down Expand Up @@ -117,6 +119,8 @@ import me.him188.ani.app.ui.subject.episode.notif.VideoNotifEffect
import me.him188.ani.app.ui.subject.episode.video.VideoDanmakuState
import me.him188.ani.app.ui.subject.episode.video.topbar.EpisodePlayerTitle
import me.him188.ani.app.videoplayer.ui.VideoControllerState
import me.him188.ani.app.videoplayer.ui.guesture.NoOpLevelController
import me.him188.ani.app.videoplayer.ui.guesture.asLevelController
import me.him188.ani.app.videoplayer.ui.progress.PlayerControllerDefaults
import me.him188.ani.app.videoplayer.ui.progress.PlayerControllerDefaults.randomDanmakuPlaceholder
import me.him188.ani.app.videoplayer.ui.progress.rememberMediaProgressSliderState
Expand Down Expand Up @@ -587,6 +591,12 @@ private fun EpisodeVideo(
)
val scope = rememberCoroutineScope()

// 必须在 UI 里, 跟随 context 变化. 否则 #958
val platformComponents by remember {
derivedStateOf {
context.getComponentAccessors()
}
}
EpisodeVideoImpl(
vm.playerState,
expanded = expanded,
Expand Down Expand Up @@ -658,8 +668,16 @@ private fun EpisodeVideo(
mediaSourceResultsPresentation = vm.mediaSourceResultsPresentation,
episodeSelectorState = vm.episodeSelectorState,
mediaSourceInfoProvider = vm.mediaSourceInfoProvider,
audioController = vm.audioController,
brightnessController = vm.brightnessController,
audioController = remember {
derivedStateOf {
platformComponents.audioManager?.asLevelController(StreamType.MUSIC) ?: NoOpLevelController
}
}.value,
brightnessController = remember {
derivedStateOf {
platformComponents.brightnessManager?.asLevelController() ?: NoOpLevelController
}
}.value,
leftBottomTips = {
AnimatedVisibility(
visible = vm.playerSkipOpEdState.showSkipTips,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.subject.episode

import androidx.annotation.UiThread
Expand Down Expand Up @@ -58,9 +67,6 @@ import me.him188.ani.app.data.source.media.selector.autoSelect
import me.him188.ani.app.data.source.media.selector.eventHandling
import me.him188.ani.app.data.source.session.AuthState
import me.him188.ani.app.platform.Context
import me.him188.ani.app.platform.features.PlatformComponentAccessors
import me.him188.ani.app.platform.features.StreamType
import me.him188.ani.app.platform.features.getComponentAccessors
import me.him188.ani.app.tools.caching.ContentPolicy
import me.him188.ani.app.ui.comment.BangumiCommentSticker
import me.him188.ani.app.ui.foundation.AbstractViewModel
Expand Down Expand Up @@ -94,9 +100,6 @@ import me.him188.ani.app.ui.subject.episode.video.VideoDanmakuStateImpl
import me.him188.ani.app.ui.subject.episode.video.sidesheet.EpisodeSelectorState
import me.him188.ani.app.videoplayer.ui.ControllerVisibility
import me.him188.ani.app.videoplayer.ui.VideoControllerState
import me.him188.ani.app.videoplayer.ui.guesture.LevelController
import me.him188.ani.app.videoplayer.ui.guesture.NoOpLevelController
import me.him188.ani.app.videoplayer.ui.guesture.asLevelController
import me.him188.ani.app.videoplayer.ui.state.PlaybackState
import me.him188.ani.app.videoplayer.ui.state.PlayerState
import me.him188.ani.app.videoplayer.ui.state.PlayerStateFactory
Expand Down Expand Up @@ -173,10 +176,6 @@ abstract class EpisodeViewModel : AbstractViewModel(), HasBackgroundScope {

abstract val mediaSourceInfoProvider: MediaSourceInfoProvider

abstract val audioController: LevelController
abstract val brightnessController: LevelController


// Video
abstract val videoControllerState: VideoControllerState
abstract val videoScaffoldConfig: VideoScaffoldConfig
Expand Down Expand Up @@ -336,17 +335,6 @@ private class EpisodeViewModelImpl(
getSourceInfoFlow = { mediaSourceManager.infoFlowByMediaSourceId(it) },
)

private val platformComponentAccessors: PlatformComponentAccessors = context.getComponentAccessors()

override val audioController: LevelController by lazy {
platformComponentAccessors.audioManager?.asLevelController(
StreamType.MUSIC,
) ?: NoOpLevelController
}
override val brightnessController: LevelController by lazy {
platformComponentAccessors.brightnessManager?.asLevelController() ?: NoOpLevelController
}

override val mediaSelectorPresentation: MediaSelectorPresentation =
MediaSelectorPresentation(mediaSelector, mediaSourceInfoProvider, backgroundScope.coroutineContext)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

package me.him188.ani.app.ui.foundation

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.SideEffect
Expand All @@ -28,6 +30,8 @@ import me.him188.ani.app.tools.TimeFormatter
import me.him188.ani.app.ui.foundation.navigation.LocalOnBackPressedDispatcherOwner
import me.him188.ani.app.ui.foundation.navigation.OnBackPressedDispatcher
import me.him188.ani.app.ui.foundation.navigation.OnBackPressedDispatcherOwner
import me.him188.ani.app.ui.foundation.theme.aniDarkColorTheme
import me.him188.ani.app.ui.foundation.theme.aniLightColorTheme
import me.him188.ani.app.ui.foundation.widgets.LocalToaster
import me.him188.ani.app.ui.foundation.widgets.NoOpToaster
import me.him188.ani.utils.platform.annotations.TestOnly
Expand Down Expand Up @@ -81,7 +85,9 @@ inline fun ProvideFoundationCompositionLocalsForPreview(
aniNavigator.setNavController(navController)
}
ProvidePlatformCompositionLocalsForPreview {
content()
MaterialTheme(colorScheme = if (isSystemInDarkTheme()) aniLightColorTheme() else aniDarkColorTheme()) {
content()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import me.him188.ani.app.ui.foundation.animation.EmphasizedAccelerateEasing
import me.him188.ani.app.ui.foundation.animation.EmphasizedDecelerateEasing
import me.him188.ani.app.ui.foundation.animation.StandardAccelerate
import me.him188.ani.app.ui.foundation.animation.StandardDecelerate

Expand Down Expand Up @@ -80,12 +82,27 @@ object AniThemeDefaults {
// Follow M3 Clean fades
val fadeIn = fadeIn(
animationSpec = tween(
EasingDurations.standardDecelerate,
delayMillis = EasingDurations.standardAccelerate,
easing = StandardDecelerate,
EasingDurations.standardAccelerate,
delayMillis = EasingDurations.standardDecelerate,
easing = StandardAccelerate,
),
)
val fadeOut = fadeOut(animationSpec = tween(EasingDurations.standardAccelerate, easing = StandardAccelerate))
val fadeOut = fadeOut(animationSpec = tween(EasingDurations.standardDecelerate, easing = StandardDecelerate))
fadeIn.togetherWith(fadeOut)
}

@Stable
val emphasizedAnimatedContentTransition: AnimatedContentTransitionScope<*>.() -> ContentTransform = {
// Follow M3 Clean fades
val fadeIn = fadeIn(
animationSpec = tween(
EasingDurations.emphasizedAccelerate,
delayMillis = EasingDurations.emphasizedDecelerate,
easing = EmphasizedAccelerateEasing,
),
)
val fadeOut =
fadeOut(animationSpec = tween(EasingDurations.emphasizedDecelerate, easing = EmphasizedDecelerateEasing))
fadeIn.togetherWith(fadeOut)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.richtext

import androidx.annotation.UiThread
Expand Down Expand Up @@ -30,6 +39,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.UriHandler
Expand Down Expand Up @@ -212,14 +223,23 @@ object RichTextDefaults {
)
}

val requestedColor = e.color.takeOrElse { contentColor }
val background by animateColorAsState(
if (maskState[index] == true) MaterialTheme.colorScheme.surfaceDim else {
if (e.code) colorScheme.surfaceContainer else Color.Unspecified
when {
maskState[index] == true -> {
requestedColor.copy(0.38f)
.compositeOver(colorScheme.surfaceDim)
}

e.code -> colorScheme.surfaceContainer
else -> Color.Unspecified
},
)
val textColor by animateColorAsState(
if (maskState[index] == true) MaterialTheme.colorScheme.surfaceDim else {
if (e.color == Color.Unspecified) contentColor else e.color
if (maskState[index] == true) {
requestedColor.copy(0.38f).compositeOver(colorScheme.surfaceDim)
} else {
requestedColor
},
)

Expand Down
Loading

0 comments on commit 43362da

Please sign in to comment.