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

Unverified Commit 6a88a33c authored by Wolf Montwé's avatar Wolf Montwé
Browse files

Add catalog implementation using a LazyVerticalGrid and adding all components...

Add catalog implementation using a LazyVerticalGrid and adding all components from the design system
parent 0b572ec0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ android {

dependencies {
    implementation(projects.core.ui.compose.designsystem)
    implementation(libs.androidx.compose.material)

    androidTestImplementation(libs.androidx.test.ext.junit.ktx)
    androidTestImplementation(libs.androidx.test.espresso.core)
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
        android:theme="@style/Theme.Thunderbird"
        >
        <activity
            android:name=".MainActivity"
            android:name=".CatalogActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
+6 −2
Original line number Diff line number Diff line
@@ -3,12 +3,16 @@ package app.k9mail.ui.catalog
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
class MainActivity : ComponentActivity() {
import androidx.core.view.WindowCompat

class CatalogActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        WindowCompat.setDecorFitsSystemWindows(window, false)

        setContent {
            MainView()
            CatalogScreen()
        }
    }
}
+66 −0
Original line number Diff line number Diff line
package app.k9mail.ui.catalog

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import app.k9mail.core.ui.compose.common.DevicePreviews
import app.k9mail.core.ui.compose.designsystem.atom.Surface
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.ui.catalog.items.buttonItems
import app.k9mail.ui.catalog.items.colorItems
import app.k9mail.ui.catalog.items.imageItems
import app.k9mail.ui.catalog.items.selectionControlItems
import app.k9mail.ui.catalog.items.themeHeaderItem
import app.k9mail.ui.catalog.items.themeSelectorItems
import app.k9mail.ui.catalog.items.typographyItems

@Composable
fun CatalogContent(
    catalogTheme: CatalogTheme,
    catalogThemeVariant: CatalogThemeVariant,
    onThemeChange: () -> Unit,
    onThemeVariantChange: () -> Unit,
    contentPadding: PaddingValues,
    modifier: Modifier = Modifier,
) {
    Surface {
        LazyVerticalGrid(
            columns = GridCells.Adaptive(300.dp),
            contentPadding = contentPadding,
            horizontalArrangement = Arrangement.spacedBy(MainTheme.spacings.double),
            verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double),
            modifier = modifier.padding(MainTheme.spacings.double),
        ) {
            themeHeaderItem(text = "Thunderbird Catalog")
            themeSelectorItems(
                catalogTheme = catalogTheme,
                catalogThemeVariant = catalogThemeVariant,
                onThemeChange = onThemeChange,
                onThemeVariantChange = onThemeVariantChange,
            )

            typographyItems()
            colorItems()
            buttonItems()
            selectionControlItems()
            imageItems()
        }
    }
}

@DevicePreviews
@Composable
internal fun CatalogContentPreview() {
    CatalogContent(
        catalogTheme = CatalogTheme.K9,
        catalogThemeVariant = CatalogThemeVariant.LIGHT,
        onThemeChange = {},
        onThemeVariantChange = {},
        contentPadding = PaddingValues(),
    )
}
+50 −0
Original line number Diff line number Diff line
package app.k9mail.ui.catalog

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import app.k9mail.core.ui.compose.common.DevicePreviews

@Composable
fun CatalogScreen(
    modifier: Modifier = Modifier,
) {
    val themeState = remember { mutableStateOf(CatalogTheme.K9) }
    val themeVariantState = remember { mutableStateOf(CatalogThemeVariant.LIGHT) }

    CatalogThemeSwitch(theme = themeState.value, themeVariation = themeVariantState.value) {
        val contentPadding = WindowInsets.systemBars.asPaddingValues()

        CatalogContent(
            catalogTheme = themeState.value,
            catalogThemeVariant = themeVariantState.value,
            onThemeChange = {
                themeState.value = when (themeState.value) {
                    CatalogTheme.K9 -> CatalogTheme.THUNDERBIRD
                    CatalogTheme.THUNDERBIRD -> CatalogTheme.K9
                }
            },
            onThemeVariantChange = {
                themeVariantState.value = when (themeVariantState.value) {
                    CatalogThemeVariant.LIGHT -> CatalogThemeVariant.DARK
                    CatalogThemeVariant.DARK -> CatalogThemeVariant.LIGHT
                }
            },
            contentPadding = contentPadding,
            modifier = Modifier
                .fillMaxSize()
                .then(modifier),
        )
    }
}

@DevicePreviews
@Composable
internal fun CatalogScreenPreview() {
    CatalogScreen()
}
Loading