Skip to content

Commit

Permalink
Move rating UI from ui-subject to ui-comment to be more common
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Mar 4, 2025
1 parent fa452e9 commit 796eba0
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 208 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
* Copyright (C) 2024-2025 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.
Expand All @@ -14,6 +14,7 @@ import androidx.compose.runtime.Stable
import me.him188.ani.app.domain.search.SubjectType
import me.him188.ani.app.navigation.SubjectDetailPlaceholder
import me.him188.ani.datasources.api.PackedDate
import me.him188.ani.utils.platform.annotations.TestOnly

/**
* 条目本身的信息
Expand Down Expand Up @@ -46,7 +47,7 @@ data class SubjectInfo(
/**
* 总集数, 0 表示未知.
*/
@Deprecated("This includes all MainStory/OVA/SP while the app only supports MainStory")
@Deprecated("This includes all MainStory/OVA/SP while the app only supports MainStory")
val totalEpisodes: Int,
/**
* 放送开始日期. 时区为条目所在地区的时区, 即一般为 UTC+9.
Expand Down Expand Up @@ -151,4 +152,47 @@ val SubjectInfo.nameCnOrName get() = nameCn.takeIf { it.isNotBlank() } ?: name

fun SubjectInfo.toNavPlaceholder(): SubjectDetailPlaceholder {
return SubjectDetailPlaceholder(subjectId, name, nameCn, imageLarge)
}
}

@TestOnly
val TestSubjectInfo
get() = SubjectInfo.Empty.copy(
nameCn = "孤独摇滚!",
name = "ぼっち・ざ・ろっく!",
airDate = PackedDate(2023, 10, 1),
summary = """
作为网络吉他手“吉他英雄”而广受好评的后藤一里,在现实中却是个什么都不会的沟通障碍者。一里有着组建乐队的梦想,但因为不敢向人主动搭话而一直没有成功,直到一天在公园中被伊地知虹夏发现并邀请进入缺少吉他手的“结束乐队”。可是,完全没有和他人合作经历的一里,在人前完全发挥不出原本的实力。为了努力克服沟通障碍,一里与“结束乐队”的成员们一同开始努力……
""".trimIndent(),
tags = listOf(
Tag("芳文社", 7098),
Tag("音乐", 5000),
Tag("CloverWorks", 5000),
Tag("轻百合", 4000),
Tag("日常", 3758),
),
ratingInfo = TestRatingInfo,
collectionStats = TestCollectionStats,
)


@TestOnly
val TestRatingInfo
get() = RatingInfo(
rank = 123,
total = 100,
count = RatingCounts(IntArray(10) { it * 10 }),
score = "6.7",
)

@TestOnly
val TestCollectionStats
get() = SubjectCollectionStats(
wish = 100,
doing = 200,
done = 300,
onHold = 400,
dropped = 500,
)

@TestOnly
const val TestCoverImage = "https://ui-avatars.com/api/?name=John+Doe"
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
* Copyright (C) 2024-2025 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.rating
package me.him188.ani.app.ui.rating

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand All @@ -33,6 +33,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.ripple
Expand All @@ -53,7 +54,9 @@ import androidx.compose.ui.layout.layout
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import me.him188.ani.app.ui.foundation.ProvideCompositionLocalsForPreview
import me.him188.ani.app.ui.foundation.icons.EditSquare
import org.jetbrains.compose.ui.tooling.preview.Preview
import kotlin.math.max

@Stable
Expand Down Expand Up @@ -335,3 +338,90 @@ fun scoreColor(score: Float): Color {
else -> MaterialTheme.colorScheme.onSurface
}
}


@Composable
@Preview
private fun PreviewEditRatingDialog() {
ProvideCompositionLocalsForPreview {
RatingEditorDialog(
remember {
RatingEditorState(
initialScore = 0,
initialComment = "",
initialIsPrivate = false,
)
},
onDismissRequest = {},
onRate = {},
)
}
}

@Composable
@Preview
private fun PreviewEditRatingDialogLoading() {
ProvideCompositionLocalsForPreview {
RatingEditorDialog(
remember {
RatingEditorState(
initialScore = 0,
initialComment = "",
initialIsPrivate = false,
)
},
onDismissRequest = {},
onRate = {},
isLoading = true,
)
}
}

@Composable
@Preview
private fun PreviewEditRating() {
ProvideCompositionLocalsForPreview {
val state = remember {
RatingEditorState(
initialScore = 4,
initialComment = "",
initialIsPrivate = false,
)
}
Surface {
RatingEditor(
score = state.score,
onScoreChange = { state.score = it },
comment = state.comment,
onCommentChange = { state.comment = it },
isPrivate = state.isPrivate,
onIsPrivateChange = { state.isPrivate = it },
)
}
}
}

@Composable
@Preview
private fun PreviewEditRatingDisabled() {
ProvideCompositionLocalsForPreview {
val state = remember {
RatingEditorState(
initialScore = 0,
initialComment = "",
initialIsPrivate = false,
)
}
Surface {
RatingEditor(
score = state.score,
onScoreChange = { state.score = it },
comment = state.comment,
onCommentChange = { state.comment = it },
isPrivate = state.isPrivate,
onIsPrivateChange = { state.isPrivate = it },
enabled = false,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
* Copyright (C) 2024-2025 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.rating
package me.him188.ani.app.ui.rating

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
Expand All @@ -27,8 +27,8 @@ import me.him188.ani.app.data.models.subject.RatingInfo
import me.him188.ani.app.data.models.subject.SelfRatingInfo
import me.him188.ani.app.data.models.subject.SubjectInfo
import me.him188.ani.app.data.models.subject.TestSelfRatingInfo
import me.him188.ani.app.data.models.subject.TestSubjectInfo
import me.him188.ani.app.tools.MonoTasker
import me.him188.ani.app.ui.subject.details.TestSubjectInfo
import me.him188.ani.utils.platform.annotations.TestOnly


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
* Copyright (C) 2024-2025 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.rating
package me.him188.ani.app.ui.rating

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -34,7 +34,10 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import me.him188.ani.app.data.models.subject.RatingInfo
import me.him188.ani.app.ui.rating.renderScore
import me.him188.ani.app.data.models.subject.TestRatingInfo
import me.him188.ani.app.ui.foundation.ProvideCompositionLocalsForPreview
import me.him188.ani.utils.platform.annotations.TestOnly
import org.jetbrains.compose.ui.tooling.preview.Preview

/**
* 展示自己的评分和评分信息
Expand Down Expand Up @@ -165,3 +168,30 @@ fun FiveRatingStars(
}
}
}


@OptIn(TestOnly::class)
@Composable
@Preview
private fun PreviewRating() {
ProvideCompositionLocalsForPreview {
Rating(
rating = TestRatingInfo,
selfRatingScore = 0,
{},
)
}
}

@OptIn(TestOnly::class)
@Composable
@Preview
private fun PreviewRatingWithSelf() {
ProvideCompositionLocalsForPreview {
Rating(
rating = TestRatingInfo,
selfRatingScore = 7,
{},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.tooling.preview.Preview
import me.him188.ani.app.data.models.subject.TestSubjectInfo
import me.him188.ani.app.domain.foundation.LoadError
import me.him188.ani.app.domain.session.TestAuthState
import me.him188.ani.app.ui.foundation.ProvideCompositionLocalsForPreview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewLightDark
import me.him188.ani.app.data.models.subject.TestSubjectInfo
import me.him188.ani.app.ui.foundation.ProvideCompositionLocalsForPreview
import me.him188.ani.app.ui.search.rememberTestLazyPagingItems
import me.him188.ani.app.ui.subject.details.TestRelatedSubjects
import me.him188.ani.app.ui.subject.details.TestSubjectCharacterList
import me.him188.ani.app.ui.subject.details.TestSubjectInfo
import me.him188.ani.app.ui.subject.details.TestSubjectStaffInfo
import me.him188.ani.utils.platform.annotations.TestOnly

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import me.him188.ani.app.data.models.subject.SubjectAiringInfo
import me.him188.ani.app.data.models.subject.SubjectAiringKind
import me.him188.ani.app.data.models.subject.SubjectInfo
import me.him188.ani.app.data.models.subject.SubjectProgressInfo
import me.him188.ani.app.data.models.subject.TestCoverImage
import me.him188.ani.app.data.models.subject.TestSubjectInfo
import me.him188.ani.app.ui.foundation.ProvideCompositionLocalsForPreview
import me.him188.ani.app.ui.foundation.stateOf
import me.him188.ani.app.ui.subject.AiringLabelState
import me.him188.ani.app.ui.subject.TestSubjectAiringInfo
import me.him188.ani.app.ui.subject.collection.components.EditableSubjectCollectionTypeButton
import me.him188.ani.app.ui.subject.collection.components.rememberTestEditableSubjectCollectionTypeState
import me.him188.ani.app.ui.subject.collection.progress.rememberTestSubjectProgressState
import me.him188.ani.app.ui.subject.details.TestCoverImage
import me.him188.ani.app.ui.subject.details.TestSubjectInfo
import me.him188.ani.app.ui.subject.rating.EditableRating
import me.him188.ani.app.ui.subject.rating.rememberTestEditableRatingState
import me.him188.ani.app.ui.rating.EditableRating
import me.him188.ani.app.ui.rating.rememberTestEditableRatingState
import me.him188.ani.datasources.api.EpisodeSort
import me.him188.ani.datasources.api.PackedDate
import me.him188.ani.utils.platform.annotations.TestOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import me.him188.ani.app.data.models.subject.TestSelfRatingInfo
import me.him188.ani.app.data.models.subject.TestSubjectCollections
import me.him188.ani.app.data.models.subject.TestSubjectInfo
import me.him188.ani.app.ui.comment.createTestCommentState
import me.him188.ani.app.ui.foundation.stateOf
import me.him188.ani.app.ui.rating.createTestEditableRatingState
import me.him188.ani.app.ui.search.createTestPager
import me.him188.ani.app.ui.subject.collection.components.createTestEditableSubjectCollectionTypeState
import me.him188.ani.app.ui.subject.collection.progress.createTestEpisodeListState
import me.him188.ani.app.ui.subject.collection.progress.createTestSubjectProgressState
import me.him188.ani.app.ui.subject.createTestAiringLabelState
import me.him188.ani.app.ui.subject.details.TestRelatedSubjects
import me.him188.ani.app.ui.subject.details.TestSubjectCharacterList
import me.him188.ani.app.ui.subject.details.TestSubjectInfo
import me.him188.ani.app.ui.subject.rating.createTestEditableRatingState
import me.him188.ani.datasources.api.topic.UnifiedCollectionType
import me.him188.ani.utils.coroutines.flows.flowOfEmptyList
import me.him188.ani.utils.platform.annotations.TestOnly
Expand Down
Loading

0 comments on commit 796eba0

Please # to comment.