Feat(ToolView): Add preview tooltip
This commit is contained in:
@@ -145,7 +145,9 @@ fun OxygenApp(appState: OxygenAppState) {
|
||||
if (destination != null) {
|
||||
OxygenTopAppBar(
|
||||
scrollBehavior = topAppBarScrollBehavior,
|
||||
titleRes = destination.titleTextId,
|
||||
title = {
|
||||
Text(text = stringResource(id = destination.titleTextId))
|
||||
},
|
||||
navigationIcon = OxygenIcons.Search,
|
||||
navigationIconContentDescription = stringResource(R.string.feature_settings_top_app_bar_navigation_icon_description),
|
||||
actionIcon = OxygenIcons.MoreVert,
|
||||
|
||||
@@ -84,7 +84,9 @@ internal fun AboutScreen(
|
||||
) {
|
||||
OxygenTopAppBar(
|
||||
scrollBehavior = topAppBarScrollBehavior,
|
||||
titleRes = R.string.feature_settings_more_about,
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.feature_settings_more_about))
|
||||
},
|
||||
navigationIcon = OxygenIcons.Back,
|
||||
navigationIconContentDescription = stringResource(R.string.core_back),
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
|
||||
|
||||
@@ -134,7 +134,9 @@ internal fun LibrariesScreen(
|
||||
) {
|
||||
OxygenTopAppBar(
|
||||
scrollBehavior = topAppBarScrollBehavior,
|
||||
titleRes = R.string.feature_settings_open_source_license,
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.feature_settings_open_source_license))
|
||||
},
|
||||
navigationIcon = OxygenIcons.Back,
|
||||
navigationIconContentDescription = stringResource(R.string.core_back),
|
||||
actionIcon = OxygenIcons.Search,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package top.fatweb.oxygen.toolbox.ui.component
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.animation.core.animateIntAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
@@ -46,7 +45,7 @@ import android.R as androidR
|
||||
fun OxygenTopAppBar(
|
||||
modifier: Modifier = Modifier,
|
||||
scrollBehavior: TopAppBarScrollBehavior? = null,
|
||||
@StringRes titleRes: Int? = null,
|
||||
title: @Composable () -> Unit = {},
|
||||
navigationIcon: ImageVector? = null,
|
||||
navigationIconContentDescription: String? = null,
|
||||
actionIcon: ImageVector? = null,
|
||||
@@ -120,7 +119,7 @@ fun OxygenTopAppBar(
|
||||
if ("\n" !in it) onQueryChange(it)
|
||||
}
|
||||
)
|
||||
else if (titleRes != null) Text(stringResource(titleRes))
|
||||
else title()
|
||||
},
|
||||
navigationIcon = {
|
||||
navigationIcon?.let {
|
||||
@@ -161,7 +160,7 @@ fun OxygenTopAppBar(
|
||||
private fun OxygenTopAppBarPreview() {
|
||||
OxygenTheme {
|
||||
OxygenTopAppBar(
|
||||
titleRes = androidR.string.untitled,
|
||||
title = { Text(text = stringResource(androidR.string.untitled)) },
|
||||
navigationIcon = OxygenIcons.Search,
|
||||
navigationIconContentDescription = "Navigation icon",
|
||||
actionIcon = OxygenIcons.MoreVert,
|
||||
|
||||
@@ -47,10 +47,12 @@ internal fun ToolViewRoute(
|
||||
viewModel: ToolViewScreenViewModel = hiltViewModel(),
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
val isPreview by viewModel.isPreview.collectAsStateWithLifecycle()
|
||||
val toolViewUiState by viewModel.toolViewUiState.collectAsStateWithLifecycle()
|
||||
|
||||
ToolViewScreen(
|
||||
modifier = modifier,
|
||||
isPreview = isPreview,
|
||||
onBackClick = onBackClick,
|
||||
toolViewUiState = toolViewUiState
|
||||
)
|
||||
@@ -61,6 +63,7 @@ internal fun ToolViewRoute(
|
||||
@Composable
|
||||
internal fun ToolViewScreen(
|
||||
modifier: Modifier = Modifier,
|
||||
isPreview: Boolean,
|
||||
onBackClick: () -> Unit,
|
||||
toolViewUiState: ToolViewUiState
|
||||
) {
|
||||
@@ -70,7 +73,7 @@ internal fun ToolViewScreen(
|
||||
Scaffold(
|
||||
modifier = Modifier,
|
||||
containerColor = Color.Transparent,
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier
|
||||
@@ -85,6 +88,18 @@ internal fun ToolViewScreen(
|
||||
) {
|
||||
OxygenTopAppBar(
|
||||
modifier = Modifier.zIndex(100f),
|
||||
title = {
|
||||
Text(
|
||||
text = when (toolViewUiState) {
|
||||
ToolViewUiState.Loading -> stringResource(R.string.core_loading)
|
||||
ToolViewUiState.Error -> stringResource(R.string.feature_tools_can_not_open)
|
||||
is ToolViewUiState.Success -> if (isPreview) stringResource(
|
||||
R.string.feature_tool_view_preview_suffix,
|
||||
toolViewUiState.toolName
|
||||
) else toolViewUiState.toolName
|
||||
}
|
||||
)
|
||||
},
|
||||
navigationIcon = OxygenIcons.Back,
|
||||
navigationIconContentDescription = stringResource(R.string.core_back),
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
|
||||
|
||||
@@ -27,11 +27,14 @@ class ToolViewScreenViewModel @Inject constructor(
|
||||
toolRepository: ToolRepository,
|
||||
savedStateHandle: SavedStateHandle
|
||||
) : ViewModel() {
|
||||
val isPreview = savedStateHandle.getStateFlow(IS_PREVIEW, false)
|
||||
|
||||
private val toolViewArgs = ToolViewArgs(savedStateHandle)
|
||||
val username = toolViewArgs.username
|
||||
val toolId = toolViewArgs.toolId
|
||||
private val username = toolViewArgs.username
|
||||
private val toolId = toolViewArgs.toolId
|
||||
|
||||
val toolViewUiState: StateFlow<ToolViewUiState> = toolViewUiState(
|
||||
savedStateHandle = savedStateHandle,
|
||||
username = username,
|
||||
toolId = toolId,
|
||||
storeRepository = storeRepository,
|
||||
@@ -45,6 +48,7 @@ class ToolViewScreenViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun toolViewUiState(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
username: String,
|
||||
toolId: String,
|
||||
storeRepository: StoreRepository,
|
||||
@@ -56,6 +60,7 @@ private fun toolViewUiState(
|
||||
return flow {
|
||||
combine(entityFlow, toolViewTemplate, ::Pair).collect { (entityFlow, toolViewTemplate) ->
|
||||
if (entityFlow == null) {
|
||||
savedStateHandle[IS_PREVIEW] = true
|
||||
storeRepository.detail(username, toolId).collect {
|
||||
emit(
|
||||
when (it) {
|
||||
@@ -63,6 +68,7 @@ private fun toolViewUiState(
|
||||
val dist = it.data.dist!!
|
||||
val base = it.data.base!!
|
||||
ToolViewUiState.Success(
|
||||
it.data.name,
|
||||
processHtml(
|
||||
toolViewTemplate = toolViewTemplate,
|
||||
distBase64 = dist,
|
||||
@@ -83,8 +89,10 @@ private fun toolViewUiState(
|
||||
)
|
||||
}
|
||||
} else {
|
||||
savedStateHandle[IS_PREVIEW] = false
|
||||
emit(
|
||||
ToolViewUiState.Success(
|
||||
entityFlow.name,
|
||||
processHtml(
|
||||
toolViewTemplate = toolViewTemplate,
|
||||
distBase64 = entityFlow.dist!!,
|
||||
@@ -98,7 +106,10 @@ private fun toolViewUiState(
|
||||
}
|
||||
|
||||
sealed interface ToolViewUiState {
|
||||
data class Success(val htmlData: String) : ToolViewUiState
|
||||
data class Success(
|
||||
val toolName: String,
|
||||
val htmlData: String
|
||||
) : ToolViewUiState
|
||||
|
||||
data object Error : ToolViewUiState
|
||||
|
||||
@@ -112,3 +123,5 @@ private fun processHtml(toolViewTemplate: String, distBase64: String, baseBase64
|
||||
|
||||
return toolViewTemplate.replace("{{replace_code}}", "$dist\n$base")
|
||||
}
|
||||
|
||||
private const val IS_PREVIEW = "IS_PREVIEW"
|
||||
|
||||
Reference in New Issue
Block a user