-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow searching artists and albums (#244)
- Loading branch information
Showing
7 changed files
with
244 additions
and
59 deletions.
There are no files selected for viewing
32 changes: 31 additions & 1 deletion
32
app/src/main/java/me/vanpetegem/accentor/ui/albums/AlbumGrid.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
package me.vanpetegem.accentor.ui.albums | ||
|
||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.ScaffoldState | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavController | ||
import me.vanpetegem.accentor.R | ||
import me.vanpetegem.accentor.ui.main.BaseToolbar | ||
import me.vanpetegem.accentor.ui.main.SearchToolbar | ||
import me.vanpetegem.accentor.ui.util.FastScrollableGrid | ||
|
||
@Composable | ||
fun AlbumGrid(navController: NavController, albumsViewModel: AlbumsViewModel = hiltViewModel()) { | ||
val albums by albumsViewModel.allAlbums.observeAsState() | ||
val albums by albumsViewModel.filteredAlbums.observeAsState() | ||
if (albums != null) { | ||
FastScrollableGrid(albums!!, { it.firstCharacter().uppercase() }) { album -> AlbumCard(album, navController) } | ||
} | ||
} | ||
|
||
@Composable | ||
fun AlbumToolbar(scaffoldState: ScaffoldState, albumsViewModel: AlbumsViewModel = hiltViewModel()) { | ||
val searching by albumsViewModel.searching.observeAsState() | ||
if (searching ?: false) { | ||
val query by albumsViewModel.query.observeAsState() | ||
SearchToolbar(query ?: "", { albumsViewModel.setQuery(it) }) { | ||
albumsViewModel.setSearching(false) | ||
albumsViewModel.setQuery("") | ||
} | ||
} else { | ||
BaseToolbar( | ||
scaffoldState, | ||
extraActions = { | ||
IconButton(onClick = { albumsViewModel.setSearching(true) }) { | ||
Icon(Icons.Filled.Search, contentDescription = stringResource(R.string.search)) | ||
} | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 31 additions & 1 deletion
32
app/src/main/java/me/vanpetegem/accentor/ui/artists/ArtistGrid.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
package me.vanpetegem.accentor.ui.artists | ||
|
||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.ScaffoldState | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavController | ||
import me.vanpetegem.accentor.R | ||
import me.vanpetegem.accentor.ui.main.BaseToolbar | ||
import me.vanpetegem.accentor.ui.main.SearchToolbar | ||
import me.vanpetegem.accentor.ui.util.FastScrollableGrid | ||
|
||
@Composable | ||
fun ArtistGrid(navController: NavController, artistsViewModel: ArtistsViewModel = hiltViewModel()) { | ||
val artists by artistsViewModel.allArtists.observeAsState() | ||
val artists by artistsViewModel.filteredArtists.observeAsState() | ||
if (artists != null) { | ||
FastScrollableGrid(artists!!, { it.firstCharacter().uppercase() }) { artist -> ArtistCard(navController, artist) } | ||
} | ||
} | ||
|
||
@Composable | ||
fun ArtistToolbar(scaffoldState: ScaffoldState, artistsViewModel: ArtistsViewModel = hiltViewModel()) { | ||
val searching by artistsViewModel.searching.observeAsState() | ||
if (searching ?: false) { | ||
val query by artistsViewModel.query.observeAsState() | ||
SearchToolbar(query ?: "", { artistsViewModel.setQuery(it) }) { | ||
artistsViewModel.setSearching(false) | ||
artistsViewModel.setQuery("") | ||
} | ||
} else { | ||
BaseToolbar( | ||
scaffoldState, | ||
extraActions = { | ||
IconButton(onClick = { artistsViewModel.setSearching(true) }) { | ||
Icon(Icons.Filled.Search, contentDescription = stringResource(R.string.search)) | ||
} | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.