Skip to content

Commit

Permalink
submit 2.1.7 ios
Browse files Browse the repository at this point in the history
  • Loading branch information
matsumo0922 committed Oct 13, 2024
1 parent 2a4fe59 commit e82d5fd
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
Expand All @@ -32,7 +31,8 @@ fun <T> AsyncLoadContents(
otherModifier: Modifier = modifier,
containerColor: Color = MaterialTheme.colorScheme.surface,
cornerShape: RoundedCornerShape = RoundedCornerShape(0.dp),
retryAction: () -> Unit = {},
retryAction: (() -> Unit)? = null,
terminate: (() -> Unit)? = null,
content: @Composable (T) -> Unit,
) {
Scaffold(
Expand Down Expand Up @@ -72,76 +72,10 @@ fun <T> AsyncLoadContents(
modifier = otherModifier.fillMaxWidth(),
errorState = state,
retryAction = retryAction,
terminate = terminate,
)
}
}
}
}
}

@Composable
fun <T> AsyncLoadContentsWithoutAnimation(
screenState: ScreenState<T>,
modifier: Modifier = Modifier,
otherModifier: Modifier = Modifier,
containerColor: Color = MaterialTheme.colorScheme.surface,
cornerShape: RoundedCornerShape = RoundedCornerShape(0.dp),
retryAction: () -> Unit = {},
content: @Composable (T) -> Unit,
) {
Box(
modifier = modifier
.clip(cornerShape)
.background(containerColor),
) {
when (screenState) {
is ScreenState.Idle -> {
content.invoke(screenState.data)
}
is ScreenState.Loading -> {
LoadingView(
modifier = otherModifier
.fillMaxWidth()
.background(Color.Black.copy(alpha = 0.2f)),
)
}
is ScreenState.Error -> {
ErrorView(
modifier = otherModifier.fillMaxWidth(),
errorState = screenState,
retryAction = retryAction,
)
}
}
}
}

@Composable
fun <T> AsyncNoLoadContents(
screenState: ScreenState<T>,
modifier: Modifier = Modifier,
otherModifier: Modifier = Modifier,
containerColor: Color = MaterialTheme.colorScheme.surface,
cornerShape: RoundedCornerShape = RoundedCornerShape(0.dp),
retryAction: () -> Unit = {},
content: @Composable (T?) -> Unit,
) {
Box(
modifier = modifier
.clip(cornerShape)
.background(containerColor),
) {
when (screenState) {
is ScreenState.Idle, is ScreenState.Loading -> {
content.invoke((screenState as? ScreenState.Idle)?.data)
}
is ScreenState.Error -> {
ErrorView(
modifier = otherModifier.fillMaxWidth(),
errorState = screenState,
retryAction = retryAction,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fun <T : Any> LazyPagingItemsLoadContents(
ErrorView(
errorState = ScreenState.Error(Res.string.error_no_data),
retryAction = { lazyPagingItems.refresh() },
terminate = null,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ package me.matsumo.fanbox.core.ui.view

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ArrowBackIos
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -30,76 +36,97 @@ import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.koinInject

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ErrorView(
title: StringResource,
message: StringResource,
modifier: Modifier = Modifier,
retryTitle: StringResource? = null,
retryAction: (() -> Unit)? = null,
terminate: (() -> Unit)? = null,
) {
val navigatorExtension = koinInject<NavigatorExtension>()

Column(
modifier = modifier
.background(MaterialTheme.colorScheme.surface)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
space = 8.dp,
alignment = Alignment.CenterVertically,
),
) {
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(title),
style = MaterialTheme.typography.titleMedium.bold().center(),
color = MaterialTheme.colorScheme.onSurface,
)

Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(message),
style = MaterialTheme.typography.bodyMedium.center(),
color = MaterialTheme.colorScheme.onSurfaceVariant,
)

if (retryAction != null) {
Button(
modifier = Modifier.padding(top = 24.dp),
onClick = { retryAction.invoke() },
) {
Text(
text = stringResource(retryTitle ?: Res.string.common_reload),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onPrimary,
)
Box(modifier) {
TopAppBar(
modifier = Modifier
.align(Alignment.TopCenter)
.fillMaxWidth(),
title = { /* nothing */ },
navigationIcon = {
if (terminate != null) {
IconButton(terminate) {
Icon(
imageVector = Icons.AutoMirrored.Outlined.ArrowBackIos,
contentDescription = null,
)
}
}
}
}
)

TextButton(
modifier = Modifier.padding(top = 24.dp),
onClick = {
navigatorExtension.navigateToWebPage(
url = "https://github.com/matsumo0922/PixiView-KMP/blob/master/STATUS.md",
referrer = "ErrorView",
)
},
Column(
modifier = Modifier.fillMaxSize()
.background(MaterialTheme.colorScheme.surface)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
space = 8.dp,
alignment = Alignment.CenterVertically,
),
) {
Icon(
modifier = Modifier.size(14.dp),
imageVector = Icons.Outlined.Info,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(title),
style = MaterialTheme.typography.titleMedium.bold().center(),
color = MaterialTheme.colorScheme.onSurface,
)

Text(
modifier = Modifier.padding(start = 4.dp),
text = stringResource(Res.string.error_service_status),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth(),
text = stringResource(message),
style = MaterialTheme.typography.bodyMedium.center(),
color = MaterialTheme.colorScheme.onSurfaceVariant,
textDecoration = TextDecoration.Underline,
)

if (retryAction != null) {
Button(
modifier = Modifier.padding(top = 24.dp),
onClick = { retryAction.invoke() },
) {
Text(
text = stringResource(retryTitle ?: Res.string.common_reload),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onPrimary,
)
}
}

TextButton(
modifier = Modifier.padding(top = 24.dp),
onClick = {
navigatorExtension.navigateToWebPage(
url = "https://github.com/matsumo0922/PixiView-KMP/blob/master/STATUS.md",
referrer = "ErrorView",
)
},
) {
Icon(
modifier = Modifier.size(14.dp),
imageVector = Icons.Outlined.Info,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
)

Text(
modifier = Modifier.padding(start = 4.dp),
text = stringResource(Res.string.error_service_status),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textDecoration = TextDecoration.Underline,
)
}
}
}
}
Expand All @@ -108,6 +135,7 @@ fun ErrorView(
fun ErrorView(
errorState: ScreenState.Error,
retryAction: (() -> Unit)?,
terminate: (() -> Unit)?,
modifier: Modifier = Modifier,
) {
ErrorView(
Expand All @@ -116,5 +144,6 @@ fun ErrorView(
message = errorState.message,
retryTitle = errorState.retryTitle,
retryAction = retryAction,
terminate = terminate,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal fun AboutRoute(
AsyncLoadContents(
modifier = modifier,
screenState = screenState,
terminate = { terminate.invoke() },
) { uiState ->
AboutScreen(
modifier = Modifier.background(MaterialTheme.colorScheme.surface),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ internal fun BillingPlusRoute(
AsyncLoadContents(
modifier = modifier,
screenState = screenState,
retryAction = {
terminate.invoke()
},
retryAction = { terminate.invoke() },
terminate = { terminate.invoke() },
) { uiState ->
BillingPlusDialog(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal fun CreatorPostsDownloadRoute(
otherModifier = Modifier.fillMaxSize(),
screenState = screenState,
retryAction = { viewModel.fetch(creatorId) },
terminate = { terminate.invoke() },
) { uiState ->
CreatorPostsDownloadScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ internal fun FanCardRoute(
modifier = modifier,
screenState = screenState,
retryAction = { terminate.invoke() },
terminate = { terminate.invoke() },
) {
FanCardScreen(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal fun FollowingCreatorsRoute(
modifier = modifier,
screenState = screenState,
retryAction = { viewModel.fetch() },
terminate = { terminate.invoke() },
) { uiState ->
FollowingCreatorsScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal fun PaymentsRoute(
modifier = modifier,
screenState = screenState,
retryAction = { viewModel.fetch() },
terminate = { terminate.invoke() },
) {
PaymentsScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ internal fun SupportingCreatorsRoute(
modifier = modifier,
screenState = screenState,
retryAction = { viewModel.fetch() },
terminate = { terminate.invoke() },
) { uiState ->
SupportingCreatorsScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ internal fun CreatorTopRoute(
modifier = modifier,
screenState = screenState,
retryAction = { viewModel.fetch(creatorId) },
terminate = { terminate.invoke() },
) { uiState ->
val creatorPostsPaging = uiState.creatorPostsPaging.collectAsLazyPagingItems()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal fun BookmarkedPostsRoute(
AsyncLoadContents(
modifier = modifier,
screenState = screenState,
terminate = { terminate.invoke() },
) {
BookmarkedPostsScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ internal fun PostDetailRoute(
modifier = Modifier.fillMaxSize(),
errorState = ScreenState.Error(Res.string.error_network),
retryAction = { terminate.invoke() },
terminate = { terminate.invoke() },
)
}
}
Expand Down Expand Up @@ -194,6 +195,7 @@ private fun PostDetailView(
modifier = modifier,
screenState = screenState,
retryAction = { viewModel.fetch(postId) },
terminate = { terminate.invoke() },
) { uiState ->
PostDetailScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal fun PostImageRoute(
modifier = modifier,
screenState = screenState,
retryAction = { viewModel.fetch(postId) },
terminate = { terminate.invoke() },
) { uiState ->
PostImageScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Loading

0 comments on commit e82d5fd

Please sign in to comment.