Refactor(Preview): Change all preview to OxygenPreviews
Change all preview to OxygenPreviews. Fix can not preview OxygenTopAppBar bug.
This commit is contained in:
@@ -23,9 +23,7 @@ import androidx.compose.ui.text.font.FontWeight
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import top.fatweb.oxygen.toolbox.R
|
import top.fatweb.oxygen.toolbox.R
|
||||||
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
|
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
|
||||||
import top.fatweb.oxygen.toolbox.ui.component.ApiLevelPreviews
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
|
||||||
import top.fatweb.oxygen.toolbox.ui.component.OxygenPreviews
|
|
||||||
import top.fatweb.oxygen.toolbox.ui.component.ThemePreviews
|
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
||||||
import top.fatweb.oxygen.toolbox.ui.util.ResourcesUtils
|
import top.fatweb.oxygen.toolbox.ui.util.ResourcesUtils
|
||||||
|
|
||||||
@@ -137,7 +135,7 @@ private fun AboutFooter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun AboutToolBarPreview() {
|
fun AboutToolBarPreview() {
|
||||||
OxygenTheme {
|
OxygenTheme {
|
||||||
@@ -145,7 +143,7 @@ fun AboutToolBarPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiLevelPreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun AboutAppInfoPreview() {
|
fun AboutAppInfoPreview() {
|
||||||
OxygenTheme {
|
OxygenTheme {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package top.fatweb.oxygen.toolbox.ui.component
|
package top.fatweb.oxygen.toolbox.ui.component
|
||||||
|
|
||||||
import android.content.res.Configuration
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
@@ -15,12 +14,12 @@ import androidx.compose.ui.draw.drawWithCache
|
|||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.GradientColors
|
import top.fatweb.oxygen.toolbox.ui.theme.GradientColors
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.LocalBackgroundTheme
|
import top.fatweb.oxygen.toolbox.ui.theme.LocalBackgroundTheme
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.LocalGradientColors
|
import top.fatweb.oxygen.toolbox.ui.theme.LocalGradientColors
|
||||||
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
||||||
import kotlin.math.tan
|
import kotlin.math.tan
|
||||||
|
|
||||||
@@ -92,21 +91,7 @@ fun OxygenGradientBackground(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OxygenPreviews
|
||||||
@Preview(name = "Light theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_NO)
|
|
||||||
@Preview(name = "Dark theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_YES)
|
|
||||||
@Preview(name = "Api 21", group = "ApiLevelPreviews", apiLevel = 21)
|
|
||||||
annotation class OxygenPreviews
|
|
||||||
|
|
||||||
@Preview(name = "Light theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_NO)
|
|
||||||
@Preview(name = "Dark theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_YES)
|
|
||||||
annotation class ThemePreviews
|
|
||||||
|
|
||||||
@Preview(name = "Api 21", group = "ApiLevelPreviews", apiLevel = 21)
|
|
||||||
@Preview(name = "Api Default", group = "ApiLevelPreviews")
|
|
||||||
annotation class ApiLevelPreviews
|
|
||||||
|
|
||||||
@ThemePreviews
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BackgroundDefault() {
|
fun BackgroundDefault() {
|
||||||
OxygenTheme(dynamicColor = false) {
|
OxygenTheme(dynamicColor = false) {
|
||||||
@@ -114,7 +99,7 @@ fun BackgroundDefault() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun BackgroundDynamic() {
|
fun BackgroundDynamic() {
|
||||||
OxygenTheme(dynamicColor = true) {
|
OxygenTheme(dynamicColor = true) {
|
||||||
@@ -122,7 +107,7 @@ fun BackgroundDynamic() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun BackgroundAndroid() {
|
fun BackgroundAndroid() {
|
||||||
OxygenTheme(androidTheme = true) {
|
OxygenTheme(androidTheme = true) {
|
||||||
@@ -130,7 +115,7 @@ fun BackgroundAndroid() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun GradientBackgroundDefault() {
|
fun GradientBackgroundDefault() {
|
||||||
OxygenTheme(dynamicColor = false) {
|
OxygenTheme(dynamicColor = false) {
|
||||||
@@ -138,7 +123,7 @@ fun GradientBackgroundDefault() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun GradientBackgroundDynamic() {
|
fun GradientBackgroundDynamic() {
|
||||||
OxygenTheme(dynamicColor = true) {
|
OxygenTheme(dynamicColor = true) {
|
||||||
@@ -146,7 +131,7 @@ fun GradientBackgroundDynamic() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun GradientBackgroundAndroid() {
|
fun GradientBackgroundAndroid() {
|
||||||
OxygenTheme(androidTheme = true) {
|
OxygenTheme(androidTheme = true) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import androidx.compose.ui.graphics.Color
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import top.fatweb.oxygen.toolbox.navigation.TopLevelDestination
|
import top.fatweb.oxygen.toolbox.navigation.TopLevelDestination
|
||||||
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -116,7 +117,7 @@ object OxygenNavigationDefaults {
|
|||||||
fun navigationIndicatorColor() = MaterialTheme.colorScheme.primaryContainer
|
fun navigationIndicatorColor() = MaterialTheme.colorScheme.primaryContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun OxygenNavigationBarPreview() {
|
fun OxygenNavigationBarPreview() {
|
||||||
val items = TopLevelDestination.entries
|
val items = TopLevelDestination.entries
|
||||||
@@ -147,7 +148,7 @@ fun OxygenNavigationBarPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun OxygenNavigationRailPreview() {
|
fun OxygenNavigationRailPreview() {
|
||||||
val items = TopLevelDestination.entries
|
val items = TopLevelDestination.entries
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
|
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
|
||||||
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
||||||
import android.R as androidR
|
import android.R as androidR
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ fun OxygenTopAppBar(
|
|||||||
onActionClick: () -> Unit = {}
|
onActionClick: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val topInset by animateIntAsState(
|
val topInset by animateIntAsState(
|
||||||
if (-scrollBehavior?.state?.heightOffset!! >= with(LocalDensity.current) { 64.0.dp.toPx() }) 0
|
if (scrollBehavior != null && -scrollBehavior.state.heightOffset >= with(LocalDensity.current) { 64.0.dp.toPx() }) 0
|
||||||
else TopAppBarDefaults.windowInsets.getTop(LocalDensity.current), label = ""
|
else TopAppBarDefaults.windowInsets.getTop(LocalDensity.current), label = ""
|
||||||
)
|
)
|
||||||
CenterAlignedTopAppBar(
|
CenterAlignedTopAppBar(
|
||||||
@@ -70,7 +70,7 @@ fun OxygenTopAppBar(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Preview
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
private fun OxygenTopAppBarPreview() {
|
private fun OxygenTopAppBarPreview() {
|
||||||
OxygenTheme {
|
OxygenTheme {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import top.fatweb.oxygen.toolbox.data.tool.ToolDataSource
|
|||||||
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
|
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
|
||||||
import top.fatweb.oxygen.toolbox.model.tool.Tool
|
import top.fatweb.oxygen.toolbox.model.tool.Tool
|
||||||
import top.fatweb.oxygen.toolbox.model.tool.ToolGroup
|
import top.fatweb.oxygen.toolbox.model.tool.ToolGroup
|
||||||
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -152,7 +153,7 @@ fun SwitchableIcon(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
private fun ToolGroupCardPreview() {
|
private fun ToolGroupCardPreview() {
|
||||||
val groups = runBlocking { ToolDataSource().tool.first() }
|
val groups = runBlocking { ToolDataSource().tool.first() }
|
||||||
@@ -171,7 +172,7 @@ private fun ToolGroupCardPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun SwitchableIconPreview() {
|
fun SwitchableIconPreview() {
|
||||||
var switched by remember { mutableStateOf(false) }
|
var switched by remember { mutableStateOf(false) }
|
||||||
@@ -185,7 +186,7 @@ fun SwitchableIconPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun ToolGroupItemPreview() {
|
fun ToolGroupItemPreview() {
|
||||||
OxygenTheme {
|
OxygenTheme {
|
||||||
@@ -193,7 +194,7 @@ fun ToolGroupItemPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun ToolGroupContentPreview() {
|
fun ToolGroupContentPreview() {
|
||||||
OxygenTheme {
|
OxygenTheme {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import top.fatweb.oxygen.toolbox.model.userdata.LanguageConfig
|
|||||||
import top.fatweb.oxygen.toolbox.model.userdata.LaunchPageConfig
|
import top.fatweb.oxygen.toolbox.model.userdata.LaunchPageConfig
|
||||||
import top.fatweb.oxygen.toolbox.model.userdata.ThemeBrandConfig
|
import top.fatweb.oxygen.toolbox.model.userdata.ThemeBrandConfig
|
||||||
import top.fatweb.oxygen.toolbox.model.userdata.UserData
|
import top.fatweb.oxygen.toolbox.model.userdata.UserData
|
||||||
import top.fatweb.oxygen.toolbox.ui.component.ThemePreviews
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
||||||
import top.fatweb.oxygen.toolbox.ui.theme.supportsDynamicTheming
|
import top.fatweb.oxygen.toolbox.ui.theme.supportsDynamicTheming
|
||||||
|
|
||||||
@@ -316,7 +316,7 @@ private fun SettingsDialogClickerRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
private fun SettingsDialogLoadingPreview() {
|
private fun SettingsDialogLoadingPreview() {
|
||||||
OxygenTheme {
|
OxygenTheme {
|
||||||
@@ -334,7 +334,7 @@ private fun SettingsDialogLoadingPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThemePreviews
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
private fun SettingDialogPreview() {
|
private fun SettingDialogPreview() {
|
||||||
OxygenTheme {
|
OxygenTheme {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package top.fatweb.oxygen.toolbox.ui.theme
|
package top.fatweb.oxygen.toolbox.ui.theme
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.ChecksSdkIntAtLeast
|
import androidx.annotation.ChecksSdkIntAtLeast
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
@@ -13,6 +14,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
val LightDefaultColorScheme = lightColorScheme(
|
val LightDefaultColorScheme = lightColorScheme(
|
||||||
@@ -192,3 +194,17 @@ fun OxygenTheme(
|
|||||||
|
|
||||||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
|
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
|
||||||
fun supportsDynamicTheming() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
fun supportsDynamicTheming() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||||
|
|
||||||
|
@Preview(
|
||||||
|
name = "Light theme", group = "ThemePreviews",
|
||||||
|
uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL
|
||||||
|
)
|
||||||
|
@Preview(
|
||||||
|
name = "Dark theme", group = "ThemePreviews",
|
||||||
|
uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL
|
||||||
|
)
|
||||||
|
@Preview(
|
||||||
|
name = "Api 21 Light", group = "ApiLevelPreviews", apiLevel = 21,
|
||||||
|
uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL
|
||||||
|
)
|
||||||
|
annotation class OxygenPreviews
|
||||||
@@ -25,7 +25,6 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
@@ -36,6 +35,8 @@ import top.fatweb.oxygen.toolbox.data.tool.ToolDataSource
|
|||||||
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.DraggableScrollbar
|
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.DraggableScrollbar
|
||||||
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.rememberDraggableScroller
|
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.rememberDraggableScroller
|
||||||
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.scrollbarState
|
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.scrollbarState
|
||||||
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
|
||||||
|
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun ToolsRoute(
|
internal fun ToolsRoute(
|
||||||
@@ -110,15 +111,18 @@ fun howManyItems(toolScreenUiState: ToolsScreenUiState) =
|
|||||||
is ToolsScreenUiState.Success -> toolScreenUiState.toolGroups.size
|
is ToolsScreenUiState.Success -> toolScreenUiState.toolGroups.size
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview("Loading")
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun ToolsScreenLoadingPreview() {
|
fun ToolsScreenLoadingPreview() {
|
||||||
|
OxygenTheme {
|
||||||
ToolsScreen(toolsScreenUiState = ToolsScreenUiState.Loading)
|
ToolsScreen(toolsScreenUiState = ToolsScreenUiState.Loading)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview("ToolsPage")
|
@OxygenPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun ToolsScreenPreview() {
|
fun ToolsScreenPreview() {
|
||||||
|
OxygenTheme {
|
||||||
ToolsScreen(
|
ToolsScreen(
|
||||||
toolsScreenUiState = ToolsScreenUiState.Success(
|
toolsScreenUiState = ToolsScreenUiState.Success(
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@@ -126,3 +130,4 @@ fun ToolsScreenPreview() {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user