mirror of
https://github.com/LucasVbr/Queezer.git
synced 2026-05-13 17:11:55 +00:00
feat: Edit filters + fix scroll
This commit is contained in:
@@ -15,9 +15,11 @@
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Queezer">
|
||||
android:theme="@style/Theme.Queezer"
|
||||
tools:ignore="DiscouragedApi,LockedOrientationActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ package fr.univpau.queezer.data
|
||||
import android.util.Log
|
||||
|
||||
data class Filter(
|
||||
var dateOrderIsAscending: Boolean = true,
|
||||
// var dateOrderIsAscending: Boolean = true,
|
||||
val orderByNbTitle : Boolean = false,
|
||||
|
||||
val mode : Map<GameMode, Boolean> = mapOf(
|
||||
GameMode.TITLE to true,
|
||||
@@ -11,7 +12,6 @@ data class Filter(
|
||||
GameMode.ALL to true
|
||||
),
|
||||
|
||||
val nbTitleIsAscending : Boolean = true,
|
||||
)
|
||||
|
||||
fun filterGames(filter: Filter, games: List<Game>): List<Game> {
|
||||
@@ -19,14 +19,14 @@ fun filterGames(filter: Filter, games: List<Game>): List<Game> {
|
||||
|
||||
return games
|
||||
.filter { game ->
|
||||
// Filtrer uniquement par les modes de jeu activés
|
||||
filter.mode.filter { it.value }.keys.contains(game.settings.gameMode)
|
||||
}
|
||||
.sortedWith(compareBy<Game> { game ->
|
||||
// Tri par date
|
||||
if (filter.dateOrderIsAscending) -game.date.time else game.date.time
|
||||
}.thenBy { game ->
|
||||
// Tri par nombre de titres
|
||||
if (filter.nbTitleIsAscending) game.settings.numberOfTitles ?: 0 else -(game.settings.numberOfTitles ?: 0)
|
||||
if (filter.orderByNbTitle) {
|
||||
-game.settings.numberOfTitles!!
|
||||
} else {
|
||||
-game.date.time
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -13,14 +15,10 @@ import fr.univpau.queezer.data.Game
|
||||
|
||||
@Composable
|
||||
fun GameCardItemList(games: List<Game>) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
for (game in games) GameCardItem(game)
|
||||
items(games) { game -> GameCardItem(game) }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -12,10 +14,10 @@ import fr.univpau.queezer.data.Track
|
||||
|
||||
@Composable
|
||||
fun TrackCardItemList(tracks: List<Track>) {
|
||||
Column(
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
for (track in tracks) TrackCardItem(track)
|
||||
items(tracks) { track -> TrackCardItem(track) }
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import fr.univpau.queezer.data.Playlist
|
||||
import fr.univpau.queezer.manager.GameManager
|
||||
import fr.univpau.queezer.manager.fetchPlaylist
|
||||
import fr.univpau.queezer.service.DatabaseService
|
||||
import fr.univpau.queezer.view.components.TrackCardItemList
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
@Composable
|
||||
@@ -258,17 +259,39 @@ fun LoadingScreen() {
|
||||
|
||||
@Composable
|
||||
fun FinishScreen(gameManager: GameManager, context: Context, navController: NavHostController) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
Scaffold(
|
||||
bottomBar = {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text("Partie terminée !", fontSize = 24.sp)
|
||||
Text("Score : ${gameManager.score}", fontSize = 20.sp)
|
||||
Button(onClick = {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
gameManager.save(context)
|
||||
gameManager.stop()
|
||||
navController.popBackStack()
|
||||
}) { Text(context.resources.getString(R.string.back)) }
|
||||
}
|
||||
}
|
||||
) { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier.padding(innerPadding),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
){
|
||||
Text("Partie terminée !", fontSize = 24.sp)
|
||||
Text("Score : ${gameManager.score}", fontSize = 20.sp)
|
||||
|
||||
TrackCardItemList(gameManager.playlist.tracks)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,10 @@ fun HomeScreen(navController: NavHostController) {
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
Text("Partie rapide")
|
||||
Text(
|
||||
"Partie rapide",
|
||||
fontSize = 18.sp
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
@@ -70,7 +73,7 @@ fun HomeScreen(navController: NavHostController) {
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
Text("Partie personnalisée")
|
||||
Text("Partie personnalisée", fontSize = 18.sp)
|
||||
}
|
||||
|
||||
Button(
|
||||
@@ -80,7 +83,7 @@ fun HomeScreen(navController: NavHostController) {
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
Text("Paramètres")
|
||||
Text("Paramètres", fontSize = 18.sp)
|
||||
}
|
||||
|
||||
Button(
|
||||
@@ -88,9 +91,8 @@ fun HomeScreen(navController: NavHostController) {
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
Text("Scores")
|
||||
Text("Scores", fontSize = 18.sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -47,7 +48,7 @@ import fr.univpau.queezer.data.filterGames
|
||||
import fr.univpau.queezer.view.components.GameCardItemList
|
||||
import fr.univpau.queezer.viewmodel.GameViewModel
|
||||
import java.util.Locale
|
||||
import kotlin.math.round
|
||||
import java.util.concurrent.Flow
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
@@ -86,8 +87,7 @@ fun ScoreScreen(navController: NavHostController, gameViewModel: GameViewModel)
|
||||
},
|
||||
) { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(innerPadding),
|
||||
modifier = Modifier.padding(innerPadding),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
Row(
|
||||
@@ -108,38 +108,20 @@ fun ScoreScreen(navController: NavHostController, gameViewModel: GameViewModel)
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
// Todo add filters
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Text("Mode de jeu", fontSize = 16.sp)
|
||||
FlowRow(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
FilterChip(
|
||||
selected = true,
|
||||
onClick = {
|
||||
// Inverser l'ordre de tri
|
||||
filter = filter.copy(dateOrderIsAscending = !filter.dateOrderIsAscending)
|
||||
},
|
||||
label = { Text("Date") },
|
||||
leadingIcon = {
|
||||
if (filter.dateOrderIsAscending) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.KeyboardArrowUp,
|
||||
contentDescription = "Tri Ascendant",
|
||||
modifier = Modifier.size(FilterChipDefaults.IconSize)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.KeyboardArrowDown,
|
||||
contentDescription = "Tri Descendant",
|
||||
modifier = Modifier.size(FilterChipDefaults.IconSize)
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
val gameModesLabels = context.resources.getStringArray(R.array.game_modes)
|
||||
filter.mode.entries.forEachIndexed { index, entry ->
|
||||
FilterChip(
|
||||
@@ -166,31 +148,31 @@ fun ScoreScreen(navController: NavHostController, gameViewModel: GameViewModel)
|
||||
) },
|
||||
)
|
||||
}
|
||||
|
||||
// Filtrer par nombre de titres
|
||||
FilterChip(
|
||||
selected = true,
|
||||
onClick = {
|
||||
// Inverser l'ordre de tri
|
||||
filter = filter.copy(nbTitleIsAscending = !filter.nbTitleIsAscending)
|
||||
},
|
||||
label = { Text("Nombre de titres") },
|
||||
leadingIcon = {
|
||||
if (filter.nbTitleIsAscending) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.KeyboardArrowUp,
|
||||
contentDescription = "Tri Ascendant",
|
||||
modifier = Modifier.size(FilterChipDefaults.IconSize)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.KeyboardArrowDown,
|
||||
contentDescription = "Tri Descendant",
|
||||
modifier = Modifier.size(FilterChipDefaults.IconSize)
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Text("Filtrer par", fontSize = 16.sp)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text("Date")
|
||||
|
||||
Switch(
|
||||
checked = filter.orderByNbTitle,
|
||||
onCheckedChange = {
|
||||
filter = filter.copy(orderByNbTitle = it)
|
||||
}
|
||||
)
|
||||
|
||||
Text("Nombre de titres")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filteredGames.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user