Skip to content

Commit

Permalink
🔧 Redundant processes have been standardized.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corvus400 committed Sep 6, 2024
1 parent be7818b commit 35d9ae6
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,22 @@ data class SponsorsScreenUiState(
)

data class SponsorsListUiState(
val platinumSponsorsUiState: PlatinumSponsorsUiState,
val goldSponsorsUiState: GoldSponsorsUiState,
val supportersUiState: SupportersUiState,
val platinumSponsorsUiState: SponsorsByPlanUiState,
val goldSponsorsUiState: SponsorsByPlanUiState,
val supportersUiState: SponsorsByPlanUiState,
)

sealed interface PlatinumSponsorsUiState {
sealed interface SponsorsByPlanUiState {
val userMessageStateHolder: UserMessageStateHolder

data class Loading(
override val userMessageStateHolder: UserMessageStateHolder,
) : PlatinumSponsorsUiState
) : SponsorsByPlanUiState

data class Exists(
override val userMessageStateHolder: UserMessageStateHolder,
val platinumSponsors: PersistentList<Sponsor>,
) : PlatinumSponsorsUiState
}

sealed interface GoldSponsorsUiState {
val userMessageStateHolder: UserMessageStateHolder

data class Loading(
override val userMessageStateHolder: UserMessageStateHolder,
) : GoldSponsorsUiState

data class Exists(
override val userMessageStateHolder: UserMessageStateHolder,
val goldSponsors: PersistentList<Sponsor>,
) : GoldSponsorsUiState
}

sealed interface SupportersUiState {
val userMessageStateHolder: UserMessageStateHolder

data class Loading(
override val userMessageStateHolder: UserMessageStateHolder,
) : SupportersUiState

data class Exists(
override val userMessageStateHolder: UserMessageStateHolder,
val supporters: PersistentList<Sponsor>,
) : SupportersUiState
val sponsors: PersistentList<Sponsor>,
) : SponsorsByPlanUiState
}

@Composable
Expand Down Expand Up @@ -174,17 +148,17 @@ fun SponsorsScreenPreview() {
SponsorsScreen(
uiState = SponsorsScreenUiState(
sponsorsListUiState = SponsorsListUiState(
platinumSponsorsUiState = PlatinumSponsorsUiState.Exists(
platinumSponsorsUiState = SponsorsByPlanUiState.Exists(
userMessageStateHolder = UserMessageStateHolderImpl(),
platinumSponsors = Sponsor.fakes().filter { it.plan == PLATINUM }.toPersistentList(),
sponsors = Sponsor.fakes().filter { it.plan == PLATINUM }.toPersistentList(),
),
goldSponsorsUiState = GoldSponsorsUiState.Exists(
goldSponsorsUiState = SponsorsByPlanUiState.Exists(
userMessageStateHolder = UserMessageStateHolderImpl(),
goldSponsors = Sponsor.fakes().filter { it.plan == GOLD }.toPersistentList(),
sponsors = Sponsor.fakes().filter { it.plan == GOLD }.toPersistentList(),
),
supportersUiState = SupportersUiState.Exists(
supportersUiState = SponsorsByPlanUiState.Exists(
userMessageStateHolder = UserMessageStateHolderImpl(),
supporters = Sponsor.fakes().filter { it.plan == SUPPORTER }.toPersistentList(),
sponsors = Sponsor.fakes().filter { it.plan == SUPPORTER }.toPersistentList(),
),
),
userMessageStateHolder = UserMessageStateHolderImpl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,34 @@ private fun sponsorList(
val supporters = sponsors.filter { it.plan == SUPPORTER }.toPersistentList()

val platinumSponsorsUiState = if (platinumSponsors.isNotEmpty()) {
PlatinumSponsorsUiState.Exists(
SponsorsByPlanUiState.Exists(
userMessageStateHolder = userMessageStateHolder,
platinumSponsors = platinumSponsors,
sponsors = platinumSponsors,
)
} else {
PlatinumSponsorsUiState.Loading(
SponsorsByPlanUiState.Loading(
userMessageStateHolder = userMessageStateHolder,
)
}

val goldSponsorsUiState = if (goldSponsors.isNotEmpty()) {
GoldSponsorsUiState.Exists(
SponsorsByPlanUiState.Exists(
userMessageStateHolder = userMessageStateHolder,
goldSponsors = goldSponsors,
sponsors = goldSponsors,
)
} else {
GoldSponsorsUiState.Loading(
SponsorsByPlanUiState.Loading(
userMessageStateHolder = userMessageStateHolder,
)
}

val supportersUiState = if (supporters.isNotEmpty()) {
SupportersUiState.Exists(
SponsorsByPlanUiState.Exists(
userMessageStateHolder = userMessageStateHolder,
supporters = supporters,
sponsors = supporters,
)
} else {
SupportersUiState.Loading(
SponsorsByPlanUiState.Loading(
userMessageStateHolder = userMessageStateHolder,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridItemSpanScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.CircularProgressIndicator
Expand All @@ -20,6 +22,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import conference_app_2024.feature.sponsors.generated.resources.gold_sponsor
import conference_app_2024.feature.sponsors.generated.resources.platinum_sponsor
Expand All @@ -31,14 +34,13 @@ import io.github.droidkaigi.confsched.model.Plan.PLATINUM
import io.github.droidkaigi.confsched.model.Plan.SUPPORTER
import io.github.droidkaigi.confsched.model.Sponsor
import io.github.droidkaigi.confsched.model.fakes
import io.github.droidkaigi.confsched.sponsors.GoldSponsorsUiState
import io.github.droidkaigi.confsched.sponsors.PlatinumSponsorsUiState
import io.github.droidkaigi.confsched.sponsors.SponsorsByPlanUiState
import io.github.droidkaigi.confsched.sponsors.SponsorsListUiState
import io.github.droidkaigi.confsched.sponsors.SponsorsRes
import io.github.droidkaigi.confsched.sponsors.SupportersUiState
import io.github.droidkaigi.confsched.sponsors.component.SponsorHeader
import io.github.droidkaigi.confsched.sponsors.component.SponsorItem
import kotlinx.collections.immutable.toPersistentList
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview

Expand Down Expand Up @@ -74,136 +76,88 @@ fun SponsorsList(
bottom = 48.dp + contentPadding.calculateBottomPadding(),
),
) {
item(span = { GridItemSpan(maxLineSpan) }) {
SponsorHeader(
text = stringResource(SponsorsRes.string.platinum_sponsor),
modifier = Modifier
.fillMaxWidth()
.testTag(
SponsorsListSponsorHeaderTestTagPrefix
.plus(stringResource(SponsorsRes.string.platinum_sponsor)),
),
)
}
when (uiState.platinumSponsorsUiState) {
is PlatinumSponsorsUiState.Exists -> {
items(
items = uiState.platinumSponsorsUiState.platinumSponsors,
span = { GridItemSpan(maxLineSpan) },
) { sponsor ->
SponsorItem(
modifier = Modifier
.fillMaxWidth()
.height(110.dp)
.testTag(SponsorsListSponsorItemTestTagPrefix.plus(sponsor.name)),
sponsor = sponsor,
onSponsorsItemClick = onSponsorsItemClick,
)
}
}
is PlatinumSponsorsUiState.Loading -> {
item(
span = { GridItemSpan(maxLineSpan) },
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.padding(contentPadding).fillMaxWidth(),
) {
CircularProgressIndicator()
}
}
}
}
sponsorsByPlanSection(
headerStringResource = SponsorsRes.string.platinum_sponsor,
sponsorsByPlanUiState = uiState.platinumSponsorsUiState,
onSponsorsItemClick = onSponsorsItemClick,
contentPadding = contentPadding,
sponsorItemSpan = { GridItemSpan(maxLineSpan) },
sponsorItemHeight = 110.dp,
)

item(span = { GridItemSpan(maxLineSpan) }) {
Spacer(modifier = Modifier.height(24.dp))
}
sponsorsByPlanSection(
headerStringResource = SponsorsRes.string.gold_sponsor,
sponsorsByPlanUiState = uiState.goldSponsorsUiState,
onSponsorsItemClick = onSponsorsItemClick,
contentPadding = contentPadding,
sponsorItemSpan = { GridItemSpan(3) },
sponsorItemHeight = 77.dp,
)

item(span = { GridItemSpan(maxLineSpan) }) {
SponsorHeader(
text = stringResource(SponsorsRes.string.gold_sponsor),
modifier = Modifier
.fillMaxWidth()
.testTag(
SponsorsListSponsorHeaderTestTagPrefix
.plus(stringResource(SponsorsRes.string.gold_sponsor)),
),
)
}
when (uiState.goldSponsorsUiState) {
is GoldSponsorsUiState.Exists -> {
items(
items = uiState.goldSponsorsUiState.goldSponsors,
span = { GridItemSpan(3) },
) { sponsor ->
SponsorItem(
modifier = Modifier
.fillMaxWidth()
.height(77.dp)
.testTag(SponsorsListSponsorItemTestTagPrefix.plus(sponsor.name)),
sponsor = sponsor,
onSponsorsItemClick = onSponsorsItemClick,
)
}
sponsorsByPlanSection(
headerStringResource = SponsorsRes.string.supporters,
sponsorsByPlanUiState = uiState.supportersUiState,
onSponsorsItemClick = onSponsorsItemClick,
contentPadding = contentPadding,
sponsorItemSpan = { GridItemSpan(2) },
sponsorItemHeight = 77.dp,
isLastSection = true,
)
}
}

private fun LazyGridScope.sponsorsByPlanSection(
headerStringResource: StringResource,
sponsorsByPlanUiState: SponsorsByPlanUiState,
contentPadding: PaddingValues,
sponsorItemSpan: LazyGridItemSpanScope.() -> GridItemSpan,
sponsorItemHeight: Dp,
onSponsorsItemClick: (url: String) -> Unit,
isLastSection: Boolean = false,
) {
item(span = { GridItemSpan(maxLineSpan) }) {
val headerText = stringResource(headerStringResource)
SponsorHeader(
text = headerText,
modifier = Modifier
.fillMaxWidth()
.testTag(SponsorsListSponsorHeaderTestTagPrefix.plus(headerText)),
)
}
when (sponsorsByPlanUiState) {
is SponsorsByPlanUiState.Exists -> {
items(
items = sponsorsByPlanUiState.sponsors,
span = { sponsorItemSpan() },
) { sponsor ->
SponsorItem(
modifier = Modifier
.fillMaxWidth()
.height(sponsorItemHeight)
.testTag(SponsorsListSponsorItemTestTagPrefix.plus(sponsor.name)),
sponsor = sponsor,
onSponsorsItemClick = onSponsorsItemClick,
)
}
is GoldSponsorsUiState.Loading -> {
item(
span = { GridItemSpan(maxLineSpan) },
}

is SponsorsByPlanUiState.Loading -> {
item(
span = { GridItemSpan(maxLineSpan) },
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.padding(contentPadding).fillMaxWidth(),
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.padding(contentPadding).fillMaxWidth(),
) {
CircularProgressIndicator()
}
CircularProgressIndicator()
}
}
}

}
if (isLastSection.not()) {
item(span = { GridItemSpan(maxLineSpan) }) {
Spacer(modifier = Modifier.height(24.dp))
}

item(span = { GridItemSpan(maxLineSpan) }) {
SponsorHeader(
text = stringResource(SponsorsRes.string.supporters),
modifier = Modifier
.fillMaxWidth()
.testTag(
SponsorsListSponsorHeaderTestTagPrefix
.plus(stringResource(SponsorsRes.string.supporters)),
),
)
}
when (uiState.supportersUiState) {
is SupportersUiState.Exists -> {
items(
items = uiState.supportersUiState.supporters,
span = { GridItemSpan(2) },
) { sponsor ->
SponsorItem(
modifier = Modifier
.fillMaxWidth()
.height(77.dp)
.testTag(SponsorsListSponsorItemTestTagPrefix.plus(sponsor.name)),
sponsor = sponsor,
onSponsorsItemClick = onSponsorsItemClick,
)
}
}
is SupportersUiState.Loading -> {
item(
span = { GridItemSpan(maxLineSpan) },
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.padding(contentPadding).fillMaxWidth(),
) {
CircularProgressIndicator()
}
}
}
}
}
}

Expand All @@ -215,17 +169,19 @@ fun SponsorsListPreview() {
Surface {
SponsorsList(
uiState = SponsorsListUiState(
platinumSponsorsUiState = PlatinumSponsorsUiState.Exists(
platinumSponsorsUiState = SponsorsByPlanUiState.Exists(
userMessageStateHolder = UserMessageStateHolderImpl(),
platinumSponsors = Sponsor.fakes().filter { it.plan == PLATINUM }.toPersistentList(),
sponsors = Sponsor.fakes().filter { it.plan == PLATINUM }
.toPersistentList(),
),
goldSponsorsUiState = GoldSponsorsUiState.Exists(
goldSponsorsUiState = SponsorsByPlanUiState.Exists(
userMessageStateHolder = UserMessageStateHolderImpl(),
goldSponsors = Sponsor.fakes().filter { it.plan == GOLD }.toPersistentList(),
sponsors = Sponsor.fakes().filter { it.plan == GOLD }.toPersistentList(),
),
supportersUiState = SupportersUiState.Exists(
supportersUiState = SponsorsByPlanUiState.Exists(
userMessageStateHolder = UserMessageStateHolderImpl(),
supporters = Sponsor.fakes().filter { it.plan == SUPPORTER }.toPersistentList(),
sponsors = Sponsor.fakes().filter { it.plan == SUPPORTER }
.toPersistentList(),
),
),
onSponsorsItemClick = {},
Expand Down

0 comments on commit 35d9ae6

Please sign in to comment.