[go: nahoru, domu]

Skip to content

Commit

Permalink
Migrating to Material 3 (5)
Browse files Browse the repository at this point in the history
  • Loading branch information
oblakr24 committed Jul 9, 2023
1 parent e2e2a4d commit 9bcb866
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
Expand All @@ -26,7 +26,7 @@ fun OptionsPopupMenu(
Box(
Modifier
.wrapContentSize().padding(8.dp).shadow(8.dp)
.background(MaterialTheme.colors.surface, RoundedCornerShape(8.dp))
.background(MaterialTheme.colorScheme.surface, RoundedCornerShape(8.dp))
) {
Column(modifier = Modifier.width(IntrinsicSize.Max)) {
options.options.forEach { (text, action) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.rokoblak.chatbackup.ui.commonui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.rokoblak.chatbackup.ui.theme.LocalTypography


@Composable
Expand All @@ -20,7 +20,7 @@ fun PromptDialog(
AlertDialog(
onDismissRequest = dismiss,
title = {
Text(text = title, style = LocalTypography.current.titleSemiBold)
Text(text = title, style = MaterialTheme.typography.titleMedium)
},
text = {
Column(
Expand Down Expand Up @@ -48,4 +48,4 @@ fun PromptDialog(
}
}
)
}
}
38 changes: 26 additions & 12 deletions app/src/main/java/com/rokoblak/chatbackup/ui/commonui/SearchBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ package com.rokoblak.chatbackup.ui.commonui

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
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.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
Expand All @@ -16,11 +29,11 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.rokoblak.chatbackup.ui.theme.AppThemePreviews
import com.rokoblak.chatbackup.ui.theme.ChatBackupTheme
import com.rokoblak.chatbackup.ui.theme.LocalTypography
import com.rokoblak.chatbackup.ui.theme.alpha

@OptIn(ExperimentalComposeUiApi::class)
@OptIn(ExperimentalComposeUiApi::class, ExperimentalMaterial3Api::class)
@Composable
fun SearchBar(
text: String,
Expand All @@ -33,13 +46,13 @@ fun SearchBar(
.padding(horizontal = 16.dp, vertical = 4.dp)
.fillMaxWidth()
.height(50.dp).clip(RoundedCornerShape(25.dp)),
elevation = 4.dp,
border = BorderStroke(1.dp, MaterialTheme.colors.onPrimary.alpha(0.5f)),
shadowElevation = 4.dp,
border = BorderStroke(1.dp, MaterialTheme.colorScheme.onPrimary.alpha(0.5f)),
shape = RoundedCornerShape(25.dp),
color = MaterialTheme.colors.background
color = MaterialTheme.colorScheme.background
) {
Row(
modifier = Modifier.background(MaterialTheme.colors.background),
modifier = Modifier.background(MaterialTheme.colorScheme.background),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically,
) {
Expand All @@ -53,17 +66,17 @@ fun SearchBar(
value = text,
onValueChange = onChange,
maxLines = 1,
colors = TextFieldDefaults.textFieldColors(backgroundColor = MaterialTheme.colors.background),
colors = TextFieldDefaults.textFieldColors(containerColor = MaterialTheme.colorScheme.background),
placeholder = {
Text(
text = placeholder,
style = LocalTypography.current.subheadRegular
style = MaterialTheme.typography.labelSmall
)
},
textStyle = LocalTypography.current.subheadRegular,
textStyle = MaterialTheme.typography.labelSmall,
modifier = Modifier
.weight(1f)
.background(MaterialTheme.colors.background)
.background(MaterialTheme.colorScheme.background)
)

if (text.isNotBlank()) {
Expand All @@ -83,6 +96,7 @@ fun SearchBar(
}
}

@AppThemePreviews
@Preview
@Composable
fun SearchBarPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package com.rokoblak.chatbackup.ui.commonui
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.rokoblak.chatbackup.ui.theme.ChatBackupTheme
import com.rokoblak.chatbackup.ui.theme.LocalTypography
import com.rokoblak.chatbackup.ui.theme.alpha


Expand All @@ -20,11 +19,11 @@ fun SectionItem(data: String, modifier: Modifier = Modifier) {
Text(
modifier = modifier
.fillMaxWidth()
.background(MaterialTheme.colors.background.alpha(0.9f))
.background(MaterialTheme.colorScheme.background.alpha(0.9f))
.padding(start = 20.dp, top = 12.dp, bottom = 8.dp, end = 16.dp),
text = data,
textAlign = TextAlign.Start,
style = LocalTypography.current.bodySemiBold,
style = MaterialTheme.typography.bodyMedium,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
package com.rokoblak.chatbackup.ui.theme

class AppThemePreviews {
}
import android.content.res.Configuration
import androidx.compose.ui.tooling.preview.Preview

@Preview(
name = "dark theme",
group = "themes",
uiMode = Configuration.UI_MODE_NIGHT_YES
)
@Preview(
name = "light theme",
group = "themes",
uiMode = Configuration.UI_MODE_NIGHT_NO
)
annotation class AppThemePreviews
4 changes: 2 additions & 2 deletions app/src/main/java/com/rokoblak/chatbackup/ui/theme/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.annotation.FloatRange
import androidx.annotation.IntRange
import androidx.compose.ui.graphics.Color

val PrimaryDark = Color.DarkGray
val PrimaryLight = Color(0xFFD6D6EC)
val PrimaryDark = Color(0xFFD6D6EC)
val PrimaryLight = Color(0xFF4C73FF)
val PrimaryVariantLight = Color(0xFFDBDBEC)
val PrimaryVariantDark = Color(0xFF303030)

Expand Down

0 comments on commit 9bcb866

Please sign in to comment.