Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Nov 25, 2024
1 parent 070f90c commit 486edb0
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ interface MovieRepository {
movieId: MovieId
): MoviePojo

suspend fun moviesWidget(
language: String
): List<MovieDbMini>
suspend fun moviesWidget(language: String): List<MovieDbMini>

suspend fun removeMovies(
pagingKey: PagingKey
)
suspend fun removeMovies(pagingKey: PagingKey)

suspend fun removeMovie(
pagingKey: PagingKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,11 @@ internal class MovieRepositoryImpl(
}
}

override suspend fun removeMovies(
pagingKey: PagingKey
) {
override suspend fun removeMovies(pagingKey: PagingKey) {
moviePersistence.removeMovies(pagingKey)
}

override suspend fun removeMovie(
pagingKey: PagingKey,
movieId: MovieId
) {
override suspend fun removeMovie(pagingKey: PagingKey, movieId: MovieId) {
moviePersistence.removeMovie(pagingKey, movieId)
}

Expand All @@ -129,10 +124,7 @@ internal class MovieRepositoryImpl(
moviePersistence.insertMovies(moviesDb)
}

override suspend fun insertMovie(
pagingKey: PagingKey,
movie: MoviePojo
) {
override suspend fun insertMovie(pagingKey: PagingKey, movie: MoviePojo) {
val maxPosition = moviePersistence.maxPosition(pagingKey).orEmpty()
moviePersistence.insertMovie(
movie.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.material.icons.filled.MovieFilter
import androidx.compose.material.icons.outlined.AccountCircle
import androidx.compose.material.icons.outlined.Check
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.FileDownload
import androidx.compose.material.icons.outlined.Fingerprint
import androidx.compose.material.icons.outlined.GridView
Expand Down Expand Up @@ -64,6 +65,7 @@ object MoviesIcons {
val ArrowBack = Icons.AutoMirrored.Outlined.ArrowBack
val Check = Icons.Outlined.Check
val Close = Icons.Outlined.Close
val Delete = Icons.Outlined.Delete
val Info = Icons.Outlined.Info
val FileDownload = Icons.Outlined.FileDownload
val Fingerprint = Icons.Outlined.Fingerprint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ fun Number.n2(tonalPalettes: TonalPalettes): Color {
return tonalPalettes neutral2 toDouble()
}

/** Light default theme color scheme. */
val LightColorScheme = lightColorScheme()

/** Dark default theme color scheme. */
val DarkColorScheme = darkColorScheme()

val TonalPalettes.paletteLightColorScheme: ColorScheme
@Composable get() = lightColorScheme(
background = 98.n1(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ internal fun SearchScreenContent(
onChangeActiveState(false)
},
active = active,
onActiveChange = { state ->
onChangeActiveState(state)
},
onActiveChange = onChangeActiveState,
onBackClick = onBackClick,
onCloseClick = {
onChangeActiveState(query.isNotEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package org.michaelbel.movies.search.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -21,8 +22,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.jetbrains.compose.ui.tooling.preview.PreviewParameter
import org.michaelbel.movies.persistence.database.entity.pojo.MoviePojo
import org.michaelbel.movies.persistence.database.entity.pojo.SuggestionPojo
import org.michaelbel.movies.persistence.database.typealiases.MovieId
Expand All @@ -32,8 +31,6 @@ import org.michaelbel.movies.ui.compose.iconbutton.BackIcon
import org.michaelbel.movies.ui.compose.iconbutton.CloseIcon
import org.michaelbel.movies.ui.compose.iconbutton.VoiceIcon
import org.michaelbel.movies.ui.ktx.rememberSpeechRecognitionLauncher
import org.michaelbel.movies.ui.preview.SuggestionDbPreviewParameterProvider
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
internal fun SearchToolbar(
Expand Down Expand Up @@ -99,15 +96,26 @@ internal fun SearchToolbar(
)

LazyColumn {
items(searchHistoryMovies) { movie ->
SearchRecentResult(
text = movie.title,
onRemoveClick = { onHistoryMovieRemoveClick(movie.movieId) },
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
.clickable { onInputText(movie.title) }
)
items(
items = searchHistoryMovies,
key = { it.movieId }
) { movieDb ->
SwipeToDismiss(
item = movieDb,
onDelete = { deletedMovieDb ->
onHistoryMovieRemoveClick(deletedMovieDb.movieId)
}
) { swipedMovieDb, onDelete ->
SearchRecentResult(
text = swipedMovieDb.title,
onRemoveClick = { onDelete(swipedMovieDb) },
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
.background(MaterialTheme.colorScheme.inversePrimary)
.clickable { onInputText(swipedMovieDb.title) }
)
}
}
}
}
Expand Down Expand Up @@ -144,127 +152,4 @@ internal fun SearchToolbar(
}
}
}

/*SearchBar(
inputField = {
TextField(
value = query,
onValueChange = onQueryChange,
placeholder = {
Text(
text = stringResource(R.string.search_title)
)
},
leadingIcon = {
BackIcon(
onClick = onBackClick
)
},
trailingIcon = {
if (query.isNotEmpty()) {
CloseIcon(
onClick = onCloseClick
)
} else {
VoiceIcon(
onInputText = onInputText
)
}
},
colors = TextFieldDefaults.colors(
focusedContainerColor = MaterialTheme.colorScheme.inversePrimary,
unfocusedContainerColor = MaterialTheme.colorScheme.inversePrimary,
focusedTextColor = MaterialTheme.colorScheme.onPrimaryContainer,
unfocusedTextColor = MaterialTheme.colorScheme.onPrimaryContainer
)
)
},
expanded = active,
onExpandedChange = onActiveChange,
modifier = modifier
//onSearch = onSearch,
) {
when {
searchHistoryMovies.isNotEmpty() -> {
Column(
modifier = Modifier
.fillMaxSize()
.imePadding()
) {
SearchHistoryHeader(
onClearButtonClick = onClearHistoryClick,
modifier = Modifier
.fillMaxWidth()
.height(48.dp)
)
LazyColumn {
items(searchHistoryMovies) { movie ->
SearchRecentResult(
text = movie.title,
onRemoveClick = { onHistoryMovieRemoveClick(movie.movieId) },
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
.clickable { onInputText(movie.title) }
)
}
}
}
}
suggestions.isNotEmpty() -> {
Box(
modifier = Modifier
.fillMaxSize()
.imePadding(),
contentAlignment = Alignment.Center
) {
LazyColumn {
items(suggestions) { suggestion ->
SearchSuggestion(
text = suggestion.title,
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
.clickable { onInputText(suggestion.title) }
)
}
}
}
}
else -> {
Box(
modifier = Modifier
.fillMaxSize()
.imePadding(),
contentAlignment = Alignment.Center
) {
SearchEmpty()
}
}
}
}*/
}

@Preview
@Composable
private fun SearchToolbarPreview(
@PreviewParameter(SuggestionDbPreviewParameterProvider::class) suggestions: List<SuggestionPojo>
) {
MoviesTheme {
SearchToolbar(
query = "Napoleon",
onQueryChange = {},
onSearch = {},
active = true,
onActiveChange = {},
onBackClick = {},
onCloseClick = {},
onInputText = {},
suggestions = suggestions,
searchHistoryMovies = emptyList(),
onHistoryMovieRemoveClick = {},
onClearHistoryClick = {}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.michaelbel.movies.search.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue.EndToStart
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import org.michaelbel.movies.ui.accessibility.MoviesContentDescription
import org.michaelbel.movies.ui.icons.MoviesIcons

@Composable
internal fun <T> SwipeToDismiss(
item: T,
onDelete: (T) -> Unit,
modifier: Modifier = Modifier,
duration: Long = 500L,
content: @Composable (T, (T) -> Unit) -> Unit
) {
val hapticFeedback = LocalHapticFeedback.current
var removed by rememberSaveable { mutableStateOf(false) }
val state = rememberSwipeToDismissBoxState(
confirmValueChange = { value ->
if (value == EndToStart) {
removed = true
true
} else {
false
}
}
)

LaunchedEffect(removed) {
if (removed) {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
delay(duration)
onDelete(item)
}
}

AnimatedVisibility(
visible = !removed,
modifier = modifier,
exit = shrinkVertically(animationSpec = tween(durationMillis = duration.toInt()), shrinkTowards = Alignment.Top) + fadeOut()
) {
SwipeToDismissBox(
state = state,
enableDismissFromStartToEnd = false,
enableDismissFromEndToStart = true,
backgroundContent = {
val color = if (state.dismissDirection == EndToStart) MaterialTheme.colorScheme.errorContainer else Color.Transparent

Box(
modifier = Modifier
.fillMaxSize()
.background(color)
.padding(16.dp),
contentAlignment = Alignment.CenterEnd
) {
Icon(
imageVector = MoviesIcons.Delete,
contentDescription = MoviesContentDescription.None,
tint = MaterialTheme.colorScheme.onErrorContainer
)
}
},
content = {
content(item, onDelete)
}
)
}
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Choose a run configuration for an appropriate target in Android Studio and run i
- [x] CompileSDK 34
- [x] [Dark Theme](https://d.android.com/develop/ui/views/theming/darktheme)
- [x] Amoled Theme
- [x] SwipeToDismiss
- [x] [Material You Dynamic Colors](https://d.android.com/develop/ui/views/theming/dynamic-colors)
- [x] [Themed App Icon](https://d.android.com/develop/ui/views/launch/icon_design_adaptive)
- [x] [Palette Colors API](https://d.android.com/develop/ui/views/graphics/palette-colors)
Expand Down
1 change: 1 addition & 0 deletions readme.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ TMDB_API_KEY=your_own_tmdb_api_key
- [x] CompileSDK 34
- [x] [Dark Theme](https://d.android.com/develop/ui/views/theming/darktheme)
- [x] Amoled Theme
- [x] SwipeToDismiss
- [x] [Material You Dynamic Colors](https://d.android.com/develop/ui/views/theming/dynamic-colors)
- [x] [Themed App Icon](https://d.android.com/develop/ui/views/launch/icon_design_adaptive)
- [x] [Palette Colors API](https://d.android.com/develop/ui/views/graphics/palette-colors)
Expand Down

0 comments on commit 486edb0

Please sign in to comment.