Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M3 tweaks #796

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 60 additions & 42 deletions app/src/main/kotlin/at/bitfire/davdroid/ui/AccountsDrawerHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.net.toUri
import at.bitfire.davdroid.BuildConfig
Expand Down Expand Up @@ -80,7 +81,7 @@ abstract class AccountsDrawerHandler {
.fillMaxWidth()
.verticalScroll(rememberScrollState())
) {
Header()
BrandingHeader()

val closeDrawerHandler = object : CloseDrawerHandler() {
override fun closeDrawer() {
Expand Down Expand Up @@ -176,47 +177,6 @@ abstract class AccountsDrawerHandler {

// building blocks

@Composable
fun Header() {
Column(
Modifier
.background(Color.DarkGray)
.fillMaxWidth()
.padding(16.dp)
) {
Spacer(Modifier.height(16.dp))
Box(
Modifier.background(
color = MaterialTheme.colorScheme.primary,
shape = RoundedCornerShape(16.dp)
)
) {
Icon(
painterResource(R.drawable.ic_launcher_foreground),
stringResource(R.string.app_name),
tint = Color.White,
modifier = Modifier
.scale(1.2f)
.size(64.dp)
)
}
Spacer(Modifier.height(8.dp))

Text(
stringResource(R.string.app_name),
color = Color.White,
style = MaterialTheme.typography.bodyLarge
)
Text(
stringResource(R.string.navigation_drawer_subtitle),
color = Color.White.copy(alpha = 0.7f),
style = MaterialTheme.typography.bodyMedium
)
}

Spacer(Modifier.height(8.dp))
}

@Composable
fun MenuHeading(text: String) {
HorizontalDivider(Modifier.padding(vertical = 8.dp))
Expand Down Expand Up @@ -262,4 +222,62 @@ abstract class AccountsDrawerHandler {
)
}

}


@Composable
fun BrandingHeader() {
Column(
Modifier
.background(Color.DarkGray)
.fillMaxWidth()
.padding(16.dp)
) {
Spacer(Modifier.height(16.dp))
Box(
Modifier.background(
color = M3ColorScheme.md_theme_light_primary,
shape = RoundedCornerShape(16.dp)
)
) {
Icon(
painterResource(R.drawable.ic_launcher_foreground),
stringResource(R.string.app_name),
tint = Color.White,
modifier = Modifier
.scale(1.2f)
.size(64.dp)
)
}
Spacer(Modifier.height(8.dp))

Text(
stringResource(R.string.app_name),
color = Color.White,
style = MaterialTheme.typography.bodyLarge
)
Text(
stringResource(R.string.navigation_drawer_subtitle),
color = Color.White.copy(alpha = 0.7f),
style = MaterialTheme.typography.bodyMedium
)
}

Spacer(Modifier.height(8.dp))
}

@Composable
@Preview
fun BrandingHeader_Preview_Light() {
AppTheme(useDarkTheme = false) {
BrandingHeader()
}
}

@Composable
@Preview
fun BrandingHeader_Preview_Dark() {
AppTheme(useDarkTheme = true) {
BrandingHeader()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,10 @@ fun AccountScreen(

idxCalDav -> {
val permissions = mutableListOf(Manifest.permission.WRITE_CALENDAR)
TaskUtils.currentProvider(context)?.let { tasksProvider ->
permissions += tasksProvider.permissions
}
if (!LocalInspectionMode.current) // TaskUtils.currentProvider prevents preview
TaskUtils.currentProvider(context)?.let { tasksProvider ->
permissions += tasksProvider.permissions
}
AccountScreen_ServiceTab(
requiredPermissions = permissions,
progress = calDavProgress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.EventNote
import androidx.compose.material.icons.filled.Contacts
Expand All @@ -29,7 +31,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.SuggestionChip
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -198,6 +199,7 @@ fun CollectionsList_Item_Standard_Preview() {
displayName = "Sample Calendar",
description = "This Sample Calendar even has some lengthy description.",
color = 0xffff0000.toInt(),
sync = true,
forceReadOnly = true,
supportsVEVENT = true,
supportsVTODO = true,
Expand Down Expand Up @@ -243,9 +245,21 @@ fun CollectionList_Item_Webcal_Preview() {

@Composable
fun CollectionList_Item_Chip(icon: ImageVector, text: String) {
SuggestionChip(
icon = { Icon(icon, contentDescription = text) },
label = { Text(text) },
onClick = {}
)
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.background(MaterialTheme.colorScheme.surfaceVariant, shape = RoundedCornerShape(8.dp))
.padding(horizontal = 8.dp, vertical = 4.dp)
) {
Icon(
icon,
contentDescription = text,
modifier = Modifier.size(20.dp)
)
Text(
text,
style = MaterialTheme.typography.labelMedium,
modifier = Modifier.padding(start = 4.dp)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ package at.bitfire.davdroid.ui.composable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
Expand All @@ -16,6 +20,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberMultiplePermissionsState

Expand Down Expand Up @@ -50,7 +55,15 @@ fun PermissionSwitchRow(
}
Switch(
checked = allPermissionsGranted,
enabled = !allPermissionsGranted,
thumbContent = if (allPermissionsGranted) {
{
Icon(
Icons.Default.Check,
contentDescription = null,
modifier = Modifier.padding(4.dp)
)
}
} else null,
onCheckedChange = { checked ->
if (checked) {
onLaunchRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.ContentAlpha
import androidx.compose.material.LocalContentColor
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideTextStyle
import androidx.compose.material.RadioButton
import androidx.compose.material.Switch
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProvideTextStyle
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
Expand All @@ -31,8 +29,7 @@ import androidx.compose.ui.tooling.preview.Preview
* @param isSelected Whether the item is currently selected. Refers to the radio button.
* @param isToggled Whether the switch is toggled.
* @param modifier Any modifiers to apply to the row.
* @param enabled Whether the radio button should be enabled. The enabled state of the switch is
* reverse from this. So if it's `true`, the switch will be disabled.
* @param enabled Whether the radio button should be enabled.
* @param onSelected Gets called whenever the user requests this row to be enabled. Either by
* selecting the radio button or tapping the text.
* @param onToggled Gets called whenever the switch gets updated. Contains the checked status.
Expand All @@ -58,29 +55,19 @@ fun RadioWithSwitch(
) {
Text(
text = title,
color = LocalContentColor.current.copy(
alpha = if (enabled) 1f else ContentAlpha.disabled
),
style = MaterialTheme.typography.body1,
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.fillMaxWidth()
)
summary?.let { sum ->
ProvideTextStyle(
value = MaterialTheme.typography.body2.copy(
color = LocalContentColor.current.copy(
alpha = if (enabled) 1f else ContentAlpha.disabled
)
)
) {
ProvideTextStyle(MaterialTheme.typography.bodyMedium) {
sum()
}
}
}

Switch(
checked = isToggled,
onCheckedChange = onToggled,
enabled = !enabled
onCheckedChange = onToggled
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import androidx.activity.addCallback
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.ComposeView
Expand Down Expand Up @@ -89,8 +91,10 @@ class IntroActivity : AppIntro2() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
AppTheme {
Box(Modifier.padding(bottom = dimensionResource(com.github.appintro.R.dimen.appintro2_bottombar_height))) {
page.ComposePage()
Surface(Modifier.fillMaxSize()) {
Box(Modifier.padding(bottom = dimensionResource(com.github.appintro.R.dimen.appintro2_bottombar_height))) {
page.ComposePage()
}
}
}
}
Expand Down
Loading
Loading