Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit fe55ba58 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Add ContentLoadingView to design system

parent 45917c17
Loading
Loading
Loading
Loading
+46 −2
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ import androidx.compose.ui.unit.dp
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium
import app.k9mail.core.ui.compose.designsystem.molecule.ContentLoadingErrorState
import app.k9mail.core.ui.compose.designsystem.molecule.ContentLoadingErrorView
import app.k9mail.core.ui.compose.designsystem.molecule.ContentLoadingState
import app.k9mail.core.ui.compose.designsystem.molecule.ContentLoadingView
import app.k9mail.core.ui.compose.designsystem.molecule.ErrorView
import app.k9mail.core.ui.compose.designsystem.molecule.LoadingView
import app.k9mail.ui.catalog.ui.common.list.ItemOutlinedView
@@ -21,6 +23,7 @@ import app.k9mail.ui.catalog.ui.common.list.sectionHeaderItem
import app.k9mail.ui.catalog.ui.common.list.sectionInfoItem
import app.k9mail.ui.catalog.ui.common.list.sectionSubtitleItem

@Suppress("LongMethod")
fun LazyGridScope.stateItems() {
    sectionHeaderItem(text = "ErrorView")
    fullSpanItem {
@@ -72,19 +75,60 @@ fun LazyGridScope.stateItems() {
        }
    }

    sectionHeaderItem(text = "ContentLoadingView")
    sectionInfoItem(text = "Click below to change state")
    fullSpanItem {
        Column {
            ItemOutlinedView {
                StatefulContentLoadingView()
            }
        }
    }

    sectionHeaderItem(text = "ContentLoadingErrorView")
    sectionInfoItem(text = "Click below to change state")
    fullSpanItem {
        Column {
            ItemOutlinedView {
                StatefulContentLoadingErrorState()
                StatefulContentLoadingErrorView()
            }
        }
    }
}

@Composable
private fun StatefulContentLoadingView() {
    val state = remember {
        mutableStateOf(ContentLoadingState.Loading)
    }

    ContentLoadingView(
        state = state.value,
        modifier = Modifier
            .clickable {
                when (state.value) {
                    ContentLoadingState.Loading -> {
                        state.value = ContentLoadingState.Content
                    }

                    ContentLoadingState.Content -> {
                        state.value = ContentLoadingState.Loading
                    }
                }
            }
            .height(200.dp)
            .fillMaxSize(),
        loading = {
            TextTitleMedium(text = "Loading...")
        },
        content = {
            TextTitleMedium(text = "Content")
        },
    )
}

@Composable
private fun StatefulContentLoadingErrorState() {
private fun StatefulContentLoadingErrorView() {
    val state = remember {
        mutableStateOf(ContentLoadingErrorState.Loading)
    }
+53 −13
Original line number Diff line number Diff line
@@ -12,13 +12,43 @@ import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium

@Composable
@Preview(showBackground = true)
internal fun ContentLoadingErrorViewPreview() {
internal fun ContentLoadingErrorViewContentPreview() {
    PreviewWithThemes {
        DefaultContentLoadingErrorView(
            state = ContentLoadingErrorState.Content,
        )
    }
}

@Composable
@Preview(showBackground = true)
internal fun ContentLoadingErrorViewLoadingPreview() {
    PreviewWithThemes {
        DefaultContentLoadingErrorView(
            state = ContentLoadingErrorState.Loading,
        )
    }
}

@Composable
@Preview(showBackground = true)
internal fun ContentLoadingErrorViewErrorPreview() {
    PreviewWithThemes {
        DefaultContentLoadingErrorView(
            state = ContentLoadingErrorState.Error,
        )
    }
}

@Composable
@Preview(showBackground = true)
internal fun ContentLoadingErrorViewInteractivePreview() {
    PreviewWithThemes {
        val state = remember {
            mutableStateOf(ContentLoadingErrorState.Loading)
        }

        ContentLoadingErrorView(
        DefaultContentLoadingErrorView(
            state = state.value,
            modifier = Modifier
                .clickable {
@@ -35,8 +65,18 @@ internal fun ContentLoadingErrorViewPreview() {
                            state.value = ContentLoadingErrorState.Loading
                        }
                    }
                },
        )
    }
                .fillMaxSize(),
}

@Composable
private fun DefaultContentLoadingErrorView(
    state: ContentLoadingErrorState,
    modifier: Modifier = Modifier,
) {
    ContentLoadingErrorView(
        state = state,
        error = {
            TextTitleMedium(text = "Error")
        },
@@ -46,6 +86,6 @@ internal fun ContentLoadingErrorViewPreview() {
        content = {
            TextTitleMedium(text = "Content")
        },
        modifier = modifier.fillMaxSize(),
    )
}
}
+69 −0
Original line number Diff line number Diff line
package app.k9mail.core.ui.compose.designsystem.molecule

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.designsystem.PreviewWithThemes
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium

@Composable
@Preview(showBackground = true)
fun ContentLoadingViewPreview() {
    PreviewWithThemes {
        DefaultContentLoadingView(
            state = ContentLoadingState.Content,
        )
    }
}

@Composable
@Preview(showBackground = true)
internal fun ContentLoadingViewLoadingPreview() {
    PreviewWithThemes {
        DefaultContentLoadingView(
            state = ContentLoadingState.Loading,
        )
    }
}

@Composable
@Preview(showBackground = true)
internal fun ContentLoadingViewInteractivePreview() {
    PreviewWithThemes {
        val state = remember {
            mutableStateOf(ContentLoadingState.Loading)
        }

        DefaultContentLoadingView(
            state = state.value,
            modifier = Modifier
                .clickable {
                    when (state.value) {
                        ContentLoadingState.Loading -> state.value = ContentLoadingState.Content
                        ContentLoadingState.Content -> state.value = ContentLoadingState.Loading
                    }
                },
        )
    }
}

@Composable
private fun DefaultContentLoadingView(
    state: ContentLoadingState,
    modifier: Modifier = Modifier,
) {
    ContentLoadingView(
        state = state,
        loading = {
            TextTitleMedium(text = "Loading...")
        },
        content = {
            TextTitleMedium(text = "Content")
        },
        modifier = modifier.fillMaxSize(),
    )
}
+36 −0
Original line number Diff line number Diff line
package app.k9mail.core.ui.compose.designsystem.molecule

import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

@Composable
fun ContentLoadingView(
    state: ContentLoadingState,
    loading: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    contentAlignment: Alignment = Alignment.Center,
    content: @Composable () -> Unit,
) {
    Box(
        modifier = modifier,
        contentAlignment = contentAlignment,
    ) {
        AnimatedContent(
            targetState = state,
            label = "ContentLoadingView",
        ) { targetState ->
            when (targetState) {
                ContentLoadingState.Loading -> loading()
                ContentLoadingState.Content -> content()
            }
        }
    }
}

enum class ContentLoadingState {
    Loading,
    Content,
}
+14 −2
Original line number Diff line number Diff line
@@ -50,11 +50,23 @@ interface DomainContract {
    sealed interface BillingError {
        val message: String

        data class BillingServiceDisconnected(
        data class UserCancelled(
            override val message: String,
        ) : BillingError

        data class BillingUnknownError(
        data class PurchaseFailed(
            override val message: String,
        ) : BillingError

        data class ServiceDisconnected(
            override val message: String,
        ) : BillingError

        data class DeveloperError(
            override val message: String,
        ) : BillingError

        data class UnknownError(
            override val message: String,
        ) : BillingError
    }