feat: about screen compose previews
This commit is contained in:
parent
80deed419d
commit
f988846af2
7 changed files with 159 additions and 66 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
package com.aliucord.manager.ui.components
|
package com.aliucord.manager.ui.components
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import androidx.activity.compose.LocalActivity
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.platform.LocalInspectionMode
|
import androidx.compose.ui.platform.LocalInspectionMode
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
|
@ -19,7 +19,7 @@ import com.aliucord.manager.ui.screens.home.HomeScreen
|
||||||
@Composable
|
@Composable
|
||||||
fun BackButton() {
|
fun BackButton() {
|
||||||
// Support rendering in @Preview
|
// Support rendering in @Preview
|
||||||
val context = if (LocalInspectionMode.current) null else LocalContext.current as Activity
|
val context = if (LocalInspectionMode.current) null else LocalActivity.current
|
||||||
val navigator = LocalNavigator.current
|
val navigator = LocalNavigator.current
|
||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.aliucord.manager.ui.previews.screens.about
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import com.aliucord.manager.ui.components.ManagerTheme
|
||||||
|
import com.aliucord.manager.ui.screens.about.AboutScreenContent
|
||||||
|
import com.aliucord.manager.ui.screens.about.AboutScreenState
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
|
private fun AboutScreenFailedPreview() {
|
||||||
|
ManagerTheme {
|
||||||
|
AboutScreenContent(
|
||||||
|
state = remember { mutableStateOf(AboutScreenState.Failure) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.aliucord.manager.ui.previews.screens.about
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import com.aliucord.manager.ui.components.ManagerTheme
|
||||||
|
import com.aliucord.manager.ui.screens.about.AboutScreenContent
|
||||||
|
import com.aliucord.manager.ui.screens.about.AboutScreenState
|
||||||
|
|
||||||
|
// This preview cannot be properly viewed from an IDE
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
|
private fun AboutScreenFailedPreview() {
|
||||||
|
ManagerTheme {
|
||||||
|
AboutScreenContent(
|
||||||
|
state = remember { mutableStateOf(AboutScreenState.Loading) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ import com.aliucord.manager.ui.util.DiscordVersion
|
||||||
import io.ktor.util.decodeBase64Bytes
|
import io.ktor.util.decodeBase64Bytes
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
|
|
||||||
// This preview has animations that cannot be properly viewed from an IDE
|
// This preview has animations that cannot be properly viewed from an IDE preview
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.aliucord.manager.ui.components.ManagerTheme
|
||||||
import com.aliucord.manager.ui.screens.home.HomeScreenLoadingContent
|
import com.aliucord.manager.ui.screens.home.HomeScreenLoadingContent
|
||||||
import com.aliucord.manager.ui.screens.home.components.HomeAppBar
|
import com.aliucord.manager.ui.screens.home.components.HomeAppBar
|
||||||
|
|
||||||
// This preview cannot be properly viewed from an IDE
|
// This preview cannot be properly viewed from an IDE preview
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
|
|
||||||
|
|
@ -33,78 +33,82 @@ class AboutScreen : Screen, Parcelable {
|
||||||
@Composable
|
@Composable
|
||||||
override fun Content() {
|
override fun Content() {
|
||||||
val model = getScreenModel<AboutModel>()
|
val model = getScreenModel<AboutModel>()
|
||||||
val state by model.state.collectAsState()
|
|
||||||
|
|
||||||
Scaffold(
|
AboutScreenContent(state = model.state.collectAsState())
|
||||||
topBar = {
|
}
|
||||||
TopAppBar(
|
}
|
||||||
title = { Text(stringResource(R.string.navigation_about)) },
|
|
||||||
navigationIcon = { BackButton() },
|
@Composable
|
||||||
|
fun AboutScreenContent(state: State<AboutScreenState>) {
|
||||||
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.navigation_about)) },
|
||||||
|
navigationIcon = { BackButton() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { paddingValues ->
|
||||||
|
LazyColumn(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
contentPadding = paddingValues
|
||||||
|
.exclude(PaddingValuesSides.Horizontal + PaddingValuesSides.Top),
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(paddingValues.exclude(PaddingValuesSides.Bottom))
|
||||||
|
.padding(16.dp),
|
||||||
|
) {
|
||||||
|
item(key = "PROJECT_HEADER") {
|
||||||
|
ProjectHeader()
|
||||||
|
}
|
||||||
|
|
||||||
|
item(key = "HEADER_DIVIDER") {
|
||||||
|
TextDivider(
|
||||||
|
text = stringResource(R.string.contributors_lead),
|
||||||
|
modifier = Modifier.padding(top = 18.dp, bottom = 20.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
|
||||||
LazyColumn(
|
|
||||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
contentPadding = paddingValues
|
|
||||||
.exclude(PaddingValuesSides.Horizontal + PaddingValuesSides.Top),
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(paddingValues.exclude(PaddingValuesSides.Bottom))
|
|
||||||
.padding(16.dp),
|
|
||||||
) {
|
|
||||||
item(key = "PROJECT_HEADER") {
|
|
||||||
ProjectHeader()
|
|
||||||
}
|
|
||||||
|
|
||||||
item(key = "HEADER_DIVIDER") {
|
item(key = "MAIN_CONTRIBUTORS") {
|
||||||
TextDivider(
|
Row(
|
||||||
text = stringResource(R.string.contributors_lead),
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
modifier = Modifier.padding(top = 18.dp, bottom = 30.dp),
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
LeadContributor("Vendicated", "the ven")
|
||||||
|
LeadContributor("Juby210", "Fox")
|
||||||
|
LeadContributor("rushii", "explod", "rushiiMachine")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
item(key = "CONTRIBUTORS_DIVIDER") {
|
||||||
|
TextDivider(
|
||||||
|
text = stringResource(R.string.contributors),
|
||||||
|
modifier = Modifier.padding(top = 16.dp, bottom = 6.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
when (val state = state.value) {
|
||||||
|
AboutScreenState.Loading -> item(key = "CONTRIBUTIONS_LOADING") {
|
||||||
|
Box(
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
content = { CircularProgressIndicator() },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(vertical = 38.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
item(key = "MAIN_CONTRIBUTORS") {
|
AboutScreenState.Failure -> item(key = "LOAD_FAILURE") {
|
||||||
Row(
|
LoadFailure(
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
modifier = Modifier
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
.fillMaxSize()
|
||||||
modifier = Modifier.fillMaxWidth(),
|
.padding(vertical = 38.dp)
|
||||||
) {
|
|
||||||
LeadContributor("Vendicated", "the ven")
|
|
||||||
LeadContributor("Juby210", "Fox")
|
|
||||||
LeadContributor("rushii", "explod", "rushiiMachine")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item(key = "CONTRIBUTORS_DIVIDER") {
|
|
||||||
TextDivider(
|
|
||||||
text = stringResource(R.string.contributors),
|
|
||||||
modifier = Modifier.padding(vertical = 18.dp)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (val state = state) {
|
is AboutScreenState.Loaded -> {
|
||||||
AboutScreenState.Loading -> item(key = "CONTRIBUTIONS_LOADING") {
|
items(state.contributors, key = { it.username }) { user ->
|
||||||
Box(
|
ContributorCommitsItem(user)
|
||||||
contentAlignment = Alignment.Center,
|
|
||||||
content = { CircularProgressIndicator() },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(vertical = 38.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
AboutScreenState.Failure -> item(key = "LOAD_FAILURE") {
|
|
||||||
LoadFailure(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(vertical = 38.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
is AboutScreenState.Loaded -> {
|
|
||||||
items(state.contributors, key = { it.username }) { user ->
|
|
||||||
ContributorCommitsItem(user)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue