diff --git a/android/app/src/main/java/com/example/mitbringsl/Navigation.kt b/android/app/src/main/java/com/example/mitbringsl/Navigation.kt index ac01186..db527b9 100644 --- a/android/app/src/main/java/com/example/mitbringsl/Navigation.kt +++ b/android/app/src/main/java/com/example/mitbringsl/Navigation.kt @@ -37,6 +37,7 @@ fun MainNavigation(sessionManager: SessionManager) { } entry { key -> ListDetailScreen( + listId = key.listId, onBack = { backStack.removeLastOrNull() } ) } diff --git a/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailScreen.kt b/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailScreen.kt index 2cf7042..02ec6bf 100644 --- a/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailScreen.kt +++ b/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailScreen.kt @@ -29,10 +29,15 @@ import com.example.mitbringsl.data.local.entity.ItemEntity @OptIn(ExperimentalMaterial3Api::class) @Composable fun ListDetailScreen( + listId: String, onBack: () -> Unit, modifier: Modifier = Modifier, viewModel: ListDetailViewModel = hiltViewModel(), ) { + LaunchedEffect(listId) { + viewModel.setListId(listId) + } + val items by viewModel.items.collectAsStateWithLifecycle() val query by viewModel.query.collectAsStateWithLifecycle() val suggestions by viewModel.suggestions.collectAsStateWithLifecycle() diff --git a/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailViewModel.kt b/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailViewModel.kt index eda893e..084d6be 100644 --- a/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailViewModel.kt +++ b/android/app/src/main/java/com/example/mitbringsl/ui/detail/ListDetailViewModel.kt @@ -1,34 +1,43 @@ package com.example.mitbringsl.ui.detail -import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.mitbringsl.data.local.entity.ItemEntity import com.example.mitbringsl.data.remote.api.MitbringslApi import com.example.mitbringsl.data.repository.ShoppingRepository import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import javax.inject.Inject -@OptIn(FlowPreview::class) +@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) @HiltViewModel class ListDetailViewModel @Inject constructor( private val repository: ShoppingRepository, private val api: MitbringslApi, - savedStateHandle: SavedStateHandle, ) : ViewModel() { - val listId: String = checkNotNull(savedStateHandle["listId"]) + private val _listId = MutableStateFlow(null) - val items: StateFlow> = repository.observeItems(listId) + val items: StateFlow> = _listId + .filterNotNull() + .flatMapLatest { id -> repository.observeItems(id) } .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5000), initialValue = emptyList() ) + fun setListId(id: String) { + if (_listId.value != id) { + _listId.value = id + } + } + + val currentListId: String get() = _listId.value ?: "" + private val _query = MutableStateFlow("") val query: StateFlow = _query.asStateFlow() @@ -61,10 +70,11 @@ class ListDetailViewModel @Inject constructor( } fun addItem(name: String, quantity: String? = null) { + val targetListId = _listId.value ?: return if (name.isBlank()) return val qty = quantity?.trim()?.takeIf { it.isNotEmpty() } viewModelScope.launch { - repository.addItem(listId, name.trim(), qty) + repository.addItem(targetListId, name.trim(), qty) _query.value = "" _suggestions.value = emptyList() } diff --git a/android/app/src/main/res/drawable/ic_app_icon.png b/android/app/src/main/res/drawable/ic_app_icon.png index 82eecd6..aff7c8a 100644 Binary files a/android/app/src/main/res/drawable/ic_app_icon.png and b/android/app/src/main/res/drawable/ic_app_icon.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png index 5b11d75..b8fcc2d 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png index 5b11d75..b8fcc2d 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png index 06c0a15..2f485a1 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png index 06c0a15..2f485a1 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png index 33bc6a7..daae7df 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png index 33bc6a7..daae7df 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 86c99b5..12c6731 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png index 86c99b5..12c6731 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index 49f9781..ab21fa8 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png index 49f9781..ab21fa8 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml index c55b9de..a3ed663 100644 --- a/android/app/src/main/res/values/colors.xml +++ b/android/app/src/main/res/values/colors.xml @@ -1,4 +1,4 @@ - #1B1B2F + #151829