LicenseInfoScreen: Replaced "Loading.." animation with Fade In.

This commit is contained in:
acclorite 2024-07-27 00:36:42 +03:00
parent 5bcda4a7d9
commit 945634c653

View file

@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
@ -20,7 +19,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Language import androidx.compose.material.icons.outlined.Language
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LargeTopAppBar import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -31,13 +29,10 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
@ -52,6 +47,7 @@ import ua.acclorite.book_story.presentation.data.Screen
import ua.acclorite.book_story.presentation.screens.about.nested.license_info.data.LicenseInfoEvent import ua.acclorite.book_story.presentation.screens.about.nested.license_info.data.LicenseInfoEvent
import ua.acclorite.book_story.presentation.screens.about.nested.license_info.data.LicenseInfoState import ua.acclorite.book_story.presentation.screens.about.nested.license_info.data.LicenseInfoState
import ua.acclorite.book_story.presentation.screens.about.nested.license_info.data.LicenseInfoViewModel import ua.acclorite.book_story.presentation.screens.about.nested.license_info.data.LicenseInfoViewModel
import ua.acclorite.book_story.presentation.ui.DefaultTransition
import ua.acclorite.book_story.presentation.ui.SlidingTransition import ua.acclorite.book_story.presentation.ui.SlidingTransition
@Composable @Composable
@ -87,65 +83,71 @@ private fun LicenseInfoScreen(
val scrollState = TopAppBarDefaults.collapsibleUntilExitScrollBehaviorWithLazyListState() val scrollState = TopAppBarDefaults.collapsibleUntilExitScrollBehaviorWithLazyListState()
val context = LocalContext.current val context = LocalContext.current
if (state.value.license != null) { val licenses = remember(state.value.license?.licenses) {
val licenses = remember(state.value) { state.value.license?.licenses?.toList()
state.value.license!!.licenses.toList() }
}
Scaffold( Scaffold(
Modifier Modifier
.fillMaxSize() .fillMaxSize()
.nestedScroll(scrollState.first.nestedScrollConnection) .nestedScroll(scrollState.first.nestedScrollConnection)
.windowInsetsPadding(WindowInsets.navigationBars), .windowInsetsPadding(WindowInsets.navigationBars),
containerColor = MaterialTheme.colorScheme.surface, containerColor = MaterialTheme.colorScheme.surface,
topBar = { topBar = {
LargeTopAppBar( LargeTopAppBar(
title = { title = {
DefaultTransition(
visible = state.value.license?.name != null
) {
Text( Text(
state.value.license!!.name, state.value.license?.name ?: "",
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis overflow = TextOverflow.Ellipsis
) )
}, }
navigationIcon = { },
GoBackButton(onNavigate = onNavigate) navigationIcon = {
}, GoBackButton(onNavigate = onNavigate)
actions = { },
if (state.value.license?.website?.isNotBlank() == true) { actions = {
CustomIconButton( if (state.value.license?.website?.isNotBlank() == true) {
icon = Icons.Outlined.Language, CustomIconButton(
contentDescription = R.string.open_in_web_content_desc, icon = Icons.Outlined.Language,
disableOnClick = false contentDescription = R.string.open_in_web_content_desc,
) { disableOnClick = false
var url = state.value.license?.website!! ) {
if (!url.startsWith("http://") && !url.startsWith("https://")) { var url = state.value.license?.website!!
url = "https://$url" if (url.startsWith("http://") || !url.startsWith("https://")) {
} url = "https://$url"
onEvent(
LicenseInfoEvent.OnOpenLicensePage(
page = url,
context = context,
noAppsFound = {
Toast.makeText(
context,
context.getString(R.string.error_no_browser),
Toast.LENGTH_SHORT
).show()
}
)
)
} }
onEvent(
LicenseInfoEvent.OnOpenLicensePage(
page = url,
context = context,
noAppsFound = {
Toast.makeText(
context,
context.getString(R.string.error_no_browser),
Toast.LENGTH_SHORT
).show()
}
)
)
} }
}, }
scrollBehavior = scrollState.first, },
colors = TopAppBarDefaults.largeTopAppBarColors( scrollBehavior = scrollState.first,
containerColor = MaterialTheme.colorScheme.surface, colors = TopAppBarDefaults.largeTopAppBarColors(
scrolledContainerColor = MaterialTheme.colorScheme.surfaceContainer containerColor = MaterialTheme.colorScheme.surface,
) scrolledContainerColor = MaterialTheme.colorScheme.surfaceContainer
) )
} )
) { paddingValues -> }
) { paddingValues ->
DefaultTransition(
visible = state.value.license != null
) {
LazyColumn( LazyColumn(
Modifier Modifier
.fillMaxSize() .fillMaxSize()
@ -158,9 +160,12 @@ private fun LicenseInfoScreen(
Spacer(modifier = Modifier.height(12.dp)) Spacer(modifier = Modifier.height(12.dp))
} }
customItems(licenses, key = { it.name }) { license -> customItems(
licenses ?: emptyList(),
key = { it.name }
) { license ->
val showed = remember { val showed = remember {
mutableStateOf(licenses.size == 1) mutableStateOf(licenses?.size == 1)
} }
Column( Column(
@ -212,25 +217,5 @@ private fun LicenseInfoScreen(
} }
} }
} }
} else {
Column(
Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = stringResource(id = R.string.loading),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.titleLarge,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Spacer(modifier = Modifier.height(12.dp))
LinearProgressIndicator(
modifier = Modifier.fillMaxWidth(0.55f),
strokeCap = StrokeCap.Round,
trackColor = MaterialTheme.colorScheme.secondaryContainer.copy(0.7f)
)
}
} }
} }