Skip to content

Commit

Permalink
Upgrade material 3 and fix #1346
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Aug 12, 2024
1 parent 4ce6212 commit e4b8e4c
Show file tree
Hide file tree
Showing 86 changed files with 5,950 additions and 3,952 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ dependencies {
implementation(libs.media3.okhttp)

implementation(libs.room.runtime)
annotationProcessor(libs.room.compiler)
ksp(libs.room.compiler)
implementation(libs.room.ktx)

Expand Down
207 changes: 13 additions & 194 deletions app/src/main/java/com/zionhuang/music/MainActivity.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ val RepeatModeKey = intPreferencesKey("repeatMode")
val SearchSourceKey = stringPreferencesKey("searchSource")

enum class SearchSource {
LOCAL, ONLINE
LOCAL, ONLINE;

fun toggle() = when (this) {
LOCAL -> ONLINE
ONLINE -> LOCAL
}
}

val VisitorDataKey = stringPreferencesKey("visitorData")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class BottomSheetState(
isTopReached = false
}

return if (isTopReached && available.y < 0 && source == NestedScrollSource.Drag) {
return if (isTopReached && available.y < 0 && source == NestedScrollSource.UserInput) {
dispatchRawDelta(available.y)
available
} else {
Expand All @@ -267,7 +267,7 @@ class BottomSheetState(
isTopReached = consumed.y == 0f && available.y > 0
}

return if (isTopReached && source == NestedScrollSource.Drag) {
return if (isTopReached && source == NestedScrollSource.UserInput) {
dispatchRawDelta(available.y)
available
} else {
Expand Down
28 changes: 24 additions & 4 deletions app/src/main/java/com/zionhuang/music/ui/component/Dialog.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
package com.zionhuang.music.ui.component

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.material3.AlertDialogDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProvideTextStyle
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
Expand Down Expand Up @@ -171,7 +191,7 @@ fun TextFieldDialog(
placeholder = placeholder,
singleLine = singleLine,
maxLines = maxLines,
colors = TextFieldDefaults.outlinedTextFieldColors(),
colors = TextFieldDefaults.colors(),
keyboardOptions = KeyboardOptions(imeAction = if (singleLine) ImeAction.Done else ImeAction.None),
keyboardActions = KeyboardActions(
onDone = {
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/zionhuang/music/ui/component/IconButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.material3.toShape
import androidx.compose.material3.ripple
import androidx.compose.material3.tokens.IconButtonTokens
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
Expand Down Expand Up @@ -47,7 +47,7 @@ fun ResizableIconButton(
colorFilter = ColorFilter.tint(color),
modifier = Modifier
.clickable(
indication = indication ?: rememberRipple(bounded = false),
indication = indication ?: ripple(bounded = false),
interactionSource = remember { MutableInteractionSource() },
enabled = enabled,
onClick = onClick
Expand All @@ -72,22 +72,22 @@ fun IconButton(
modifier = modifier
.minimumInteractiveComponentSize()
.size(IconButtonTokens.StateLayerSize)
.clip(IconButtonTokens.StateLayerShape.toShape())
.background(color = colors.containerColor(enabled).value)
.clip(CircleShape)
.background(color = colors.containerColor(enabled))
.combinedClickable(
onClick = onClick,
onLongClick = onLongClick,
enabled = enabled,
role = Role.Button,
interactionSource = interactionSource,
indication = rememberRipple(
indication = ripple(
bounded = false,
radius = IconButtonTokens.StateLayerSize / 2
)
),
contentAlignment = Alignment.Center
) {
val contentColor = colors.contentColor(enabled).value
val contentColor = colors.contentColor(enabled)
CompositionLocalProvider(LocalContentColor provides contentColor, content = content)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun NavigationTitle(
.clickable(enabled = onClick != null) {
onClick?.invoke()
}
.padding(horizontal = 12.dp, vertical = 12.dp)
.padding(horizontal = 12.dp, vertical = 16.dp)
) {
Text(
text = title,
Expand Down
50 changes: 25 additions & 25 deletions app/src/main/java/com/zionhuang/music/ui/component/SearchBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
Expand All @@ -20,7 +20,6 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
Expand All @@ -33,19 +32,19 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Decoration
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SearchBarColors
import androidx.compose.material3.SearchBarDefaults
import androidx.compose.material3.Strings
import androidx.compose.material3.SearchBarDefaults.TonalElevation
import androidx.compose.material3.Surface
import androidx.compose.material3.TextFieldColors
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.contentColorFor
import androidx.compose.material3.getString
import androidx.compose.material3.internal.Strings
import androidx.compose.material3.internal.getString
import androidx.compose.material3.tokens.MotionTokens
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
Expand Down Expand Up @@ -74,6 +73,7 @@ import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
Expand All @@ -99,7 +99,7 @@ fun SearchBar(
trailingIcon: @Composable (() -> Unit)? = null,
shape: Shape = SearchBarDefaults.inputFieldShape,
colors: SearchBarColors = SearchBarDefaults.colors(),
tonalElevation: Dp = SearchBarDefaults.Elevation,
tonalElevation: Dp = TonalElevation,
windowInsets: WindowInsets = WindowInsets.systemBars,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
focusRequester: FocusRequester = remember { FocusRequester() },
Expand Down Expand Up @@ -244,10 +244,12 @@ private fun SearchBarInputField(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
focusRequester: FocusRequester = remember { FocusRequester() },
) {
val focused = interactionSource.collectIsFocusedAsState().value

val searchSemantics = getString(Strings.SearchBarSearch)
val suggestionsAvailableSemantics = getString(Strings.SuggestionsAvailable)
val textColor = LocalTextStyle.current.color.takeOrElse {
colors.textColor(enabled).value
colors.textColor(enabled, isError = false, focused = focused)
}

Row(
Expand Down Expand Up @@ -294,26 +296,24 @@ private fun SearchBarInputField(
enabled = enabled,
singleLine = true,
textStyle = LocalTextStyle.current.merge(TextStyle(color = textColor)),
cursorBrush = SolidColor(colors.cursorColor(isError = false).value),
cursorBrush = SolidColor(colors.cursorColor(isError = false)),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
keyboardActions = KeyboardActions(onSearch = { onSearch(query.text) }),
interactionSource = interactionSource,
decorationBox = { innerTextField ->
Box(
modifier = Modifier.fillMaxHeight(),
contentAlignment = Alignment.CenterStart
) {
if (placeholder != null && query.text.isEmpty()) {
Box(Modifier.alpha(0.8f)) {
Decoration(
contentColor = colors.placeholderColor(enabled).value,
typography = MaterialTheme.typography.bodyLarge,
content = placeholder
)
}
}
innerTextField()
}
decorationBox = @Composable { innerTextField ->
TextFieldDefaults.DecorationBox(
value = query.text,
innerTextField = innerTextField,
enabled = enabled,
singleLine = true,
visualTransformation = VisualTransformation.None,
interactionSource = interactionSource,
placeholder = placeholder,
shape = SearchBarDefaults.inputFieldShape,
colors = colors,
contentPadding = PaddingValues(),
container = {},
)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.ripple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -49,7 +49,7 @@ inline fun <reified T : Enum<T>> SortHeader(
modifier = Modifier
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(bounded = false)
indication = ripple(bounded = false)
) {
menuExpanded = !menuExpanded
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/zionhuang/music/ui/menu/AlbumMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -188,7 +188,7 @@ fun AlbumMenu(
}
)

Divider()
HorizontalDivider()

GridMenu(
contentPadding = PaddingValues(
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/zionhuang/music/ui/menu/ArtistMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -63,7 +63,7 @@ fun ArtistMenu(
}
)

Divider()
HorizontalDivider()

GridMenu(
contentPadding = PaddingValues(
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/zionhuang/music/ui/menu/PlaylistMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand Down Expand Up @@ -216,7 +216,7 @@ fun PlaylistMenu(
}
)

Divider()
HorizontalDivider()

GridMenu(
contentPadding = PaddingValues(
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/zionhuang/music/ui/menu/SongMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -176,7 +176,7 @@ fun SongMenu(
}
)

Divider()
HorizontalDivider()

GridMenu(
contentPadding = PaddingValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -183,7 +183,7 @@ fun YouTubeAlbumMenu(
}
)

Divider()
HorizontalDivider()

GridMenu(
contentPadding = PaddingValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -69,7 +69,7 @@ fun YouTubeArtistMenu(
}
)

Divider()
HorizontalDivider()

GridMenu(
contentPadding = PaddingValues(
Expand Down
Loading

0 comments on commit e4b8e4c

Please sign in to comment.