Composables
Docs Login
Pairel

Notifications

Jetpack Compose Screen

Download
package com.composables.pairel

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.composables.pairel.components.Card
import com.composables.pairel.components.CenteredAppBar
import com.composables.pairel.components.Icon
import com.composables.pairel.components.IconButton
import com.composables.pairel.components.PreferenceToggle
import com.composables.pairel.components.ScreenScaffold
import com.composables.pairel.components.Text
import com.composables.pairel.theme.ArrowLeft
import com.composables.pairel.theme.Icons
import com.composables.pairel.theme.Theme

private data class NotificationSetting(val label: String, val enabledByDefault: Boolean)

private val notificationGroups =
    listOf(
        "Activity" to
            listOf(
                NotificationSetting("New matches", true),
                NotificationSetting("New messages", true),
                NotificationSetting("Someone likes you", true),
                NotificationSetting("A match is about to expire", true),
            ),
        "From Pairel" to
            listOf(
                NotificationSetting("Tips for your profile", false),
                NotificationSetting("News and offers", false),
            ),
    )

@Composable
fun NotificationsScreen(
    navigateBack: () -> Unit,
    modifier: Modifier = Modifier,
) {
    ScreenScaffold(
        modifier = modifier,
        topBar = {
            CenteredAppBar(
                title = { Text("Notifications") },
                navigation = {
                    IconButton(onClick = navigateBack) {
                        Icon(
                            Icons.ArrowLeft,
                            contentDescription = "Back",
                            modifier = Modifier.size(24.dp),
                        )
                    }
                },
            )
        },
    ) {
        Column(
            Modifier.fillMaxSize()
                .verticalScroll(rememberScrollState())
                .padding(top = 8.dp, bottom = 24.dp)
                .windowInsetsPadding(
                    WindowInsets.navigationBars.union(
                        WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal)
                    )
                )
                .padding(horizontal = 20.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {
            Column(
                Modifier.widthIn(max = 560.dp).fillMaxWidth(),
                verticalArrangement = Arrangement.spacedBy(24.dp),
            ) {
                Text(
                    "Choose what Pairel tells you about. Changes apply right away.",
                    color = Theme.colors.onBackgroundMuted,
                )
                for ((group, settings) in notificationGroups) {
                    Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
                        Text(
                            group,
                            style =
                                Theme.typography.title.copy(fontSize = 18.sp, lineHeight = 24.sp),
                        )
                        Card(Modifier.fillMaxWidth()) {
                            Column(verticalArrangement = Arrangement.spacedBy(20.dp)) {
                                for (setting in settings) {
                                    PreferenceToggle(
                                        label = setting.label,
                                        initialChecked = setting.enabledByDefault,
                                        onCheckedChange = {},
                                        modifier = Modifier.fillMaxWidth(),
                                    )
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

More screens from Pairel

by Alex Styl

Search screens and components

Screen flows

Screens

UI Elements

One Android lesson, every Wednesday

Building Android apps?

What Alex learned building Android apps for 14 years, so you don't have to. Reads in under a minute.

Join 3,500+ Android developers. Unsubscribe any time.

You're subscribed

The next lesson lands in on Wednesday.