Skip to content

Commit

Permalink
Merge pull request #10 from clemenceroumy/fix-lists
Browse files Browse the repository at this point in the history
fix custom list name
  • Loading branch information
clemenceroumy committed Sep 14, 2023
2 parents fd2a7c0 + 9e7939a commit b89f8c1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,32 @@ abstract class Category {

object Custom: Category() {
override val value: String = "custom"
override var label: String? = "Paused"
override var label: String? = ""
override val color: Color = Color(0xFF175A53)

fun updateLabel(newLabel: String?) {
label = newLabel
}
}

object Custom2: Category() {
override val value: String = "custom2"
override var label: String? = "Stopped"
override var label: String? = ""
override val color: Color = Color(0xFF175A53)

fun updateLabel(newLabel: String?) {
label = newLabel
}
}

object Custom3: Category() {
override val value: String = "custom3"
override var label: String? = "Let's Play"
override var label: String? = ""
override val color: Color = Color(0xFF175A53)

fun updateLabel(newLabel: String?) {
label = newLabel
}
}

object Completed: Category() {
Expand All @@ -48,8 +60,6 @@ abstract class Category {
override var label: String = "Retired"
override val color: Color = Color(0xFF9F2A2B)
}

companion object {
val all = listOf(Playing, Backlog, Custom, Custom2, Custom3, Completed, Retired).filter { it.label != null && it.label?.isNotEmpty() == true }
}
}
}
val categories = listOf(Category.Playing, Category.Backlog, Category.Custom, Category.Custom2, Category.Custom3, Category.Completed, Category.Retired)
.filter { it.label != null && it.label?.isNotEmpty() == true }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.croumy.hltb_wearos.presentation.models.api


data class GameRequest(
val lists: List<String> = Category.all.map { it.value },
val lists: List<String> = categories.map { it.value },
val set_playstyle: String = "comp_all",
val limit: Int = 1000,
val name: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.croumy.hltb_wearos.presentation.LocalNavController
import com.croumy.hltb_wearos.presentation.components.GameItem
import com.croumy.hltb_wearos.presentation.models.Constants
import com.croumy.hltb_wearos.presentation.models.api.Category
import com.croumy.hltb_wearos.presentation.models.api.categories
import com.croumy.hltb_wearos.presentation.theme.Dimensions
import com.croumy.hltb_wearos.presentation.theme.HLTBwearosTheme
import com.croumy.hltb_wearos.presentation.theme.shimmerColor
Expand All @@ -64,7 +65,7 @@ fun HomeScreen(
val previousGameId = navController.currentBackStackEntry?.savedStateHandle?.getLiveData<Int>("previousGameId")

// CROWN SCROLL CONFIG + LISTS STATES
val focusRequester = listOf(FocusRequester()).plus((Category.all).map { FocusRequester() })
val focusRequester = listOf(FocusRequester()).plus((categories).map { FocusRequester() })
val horizontalScrollState = rememberLazyListState(initialFirstVisibleItemIndex = 1)
val horizontalFirstVisibleIndex = remember { derivedStateOf { horizontalScrollState.firstVisibleItemIndex } }

Expand Down Expand Up @@ -112,7 +113,7 @@ fun HomeScreen(
)
}

itemsIndexed(Category.all) { index, category ->
itemsIndexed(categories) { index, category ->
val games = viewModel.gamesByCategories[category] ?: emptyList()

Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.croumy.hltb_wearos.presentation.data.AppService
import com.croumy.hltb_wearos.presentation.data.HLTBService
import com.croumy.hltb_wearos.presentation.models.api.Category
import com.croumy.hltb_wearos.presentation.models.api.Game
import com.croumy.hltb_wearos.presentation.models.api.categories
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -20,12 +21,12 @@ class HomeViewModel @Inject constructor(
): ViewModel() {
private val games: MutableState<List<Game>> = mutableStateOf(emptyList())
// IN VIEWMODEL TO KEEP LIST SCROLLSTATE ON NAVIGATION
val listStates = listOf(ScalingLazyListState(initialCenterItemIndex = 0)).plus((Category.all).map { ScalingLazyListState(initialCenterItemIndex = 0) })
val listStates = listOf(ScalingLazyListState(initialCenterItemIndex = 0)).plus((categories).map { ScalingLazyListState(initialCenterItemIndex = 0) })
val currentListState = mutableStateOf(listStates[1])

val gamesByCategories get(): Map<Category, List<Game>> {
val map = mutableMapOf<Category, List<Game>>()
Category.all.forEach { category ->
categories.forEach { category ->
map[category] = games.value.filter { it.categories.contains(category) }
}
return map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fun StartApp(
if (isLoggedIn.value) {
if (isLoggedIn.value && isLoggingIn.value) {
delay(400) // TIME TO SHOW THE CHECK ICON
viewModel.initCategories()
}
viewModel.initCategories()
navigateToHome()
}
}
Expand Down

0 comments on commit b89f8c1

Please sign in to comment.