-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(mobile-app): Updated catalog list viewmodel * feat(mobile-app): Renamed old files * feat(mobile-app): Deleted catalog list viewmodel factory * feat(mobile-app): Added catalog search headline * feat(mobile-app): Added catalog search string resources * feat(mobile-app): Added catalog search input field slot * feat(core-database): Added catalog search dao * feat(core-database): Added catalog search dao unit tests * feat(core-database): Added catalog search dao android ui tests * feat(mobile-app): Added catalog search dao into di modules * feat(mobile-app): Updated normalize title generation in catalog items * feat(mobile-app): Updated catalog search headline composable * feat(mobile-app): Updated catalog search text input slot * feat(mobile-app): Added catalog search repository * feat(mobile-app): Added catalog search route ui state * feat(mobile-app): Added catalog search viewmodel * feat(mobile-app): Updated drawable and string resources for catalog search ui * feat(mobile-app): Updated cataloglist banner composable ui * feat(mobile-app): Updated navigation graph * feat(mobile-app): Updated catalog search item card composable ui * feat(mobile-app): Updated catalog search slot composables by search ui state * feat(mobile-app): Updated catalog search repository * feat(mobile-app): Updated catalog search viewmodel * feat(mobile-app): Updated catalog search route composable ui * feat(mobile-app): Added fake local datasource search feature * feat(mobile-app): Added fake catalog search repository unit tests * feat(mobile-app): Updated unit test for settings viewmodel * feat(mobile-app): Updated catalog settings viewmodel * feat(mobile-app): Updated catalog search repository, viemwodel and unit tests for viewmodel * feat(mobile-app): Updated fake catalog local data source * codefactor: Removed unnecesary parenthesis
- Loading branch information
Showing
39 changed files
with
1,388 additions
and
107 deletions.
There are no files selected for viewing
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
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
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
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
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
28 changes: 28 additions & 0 deletions
28
...main/kotlin/dev/marlonlom/apps/cappajv/features/catalog_search/CatalogSearchRepository.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 Marlonlom | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dev.marlonlom.apps.cappajv.features.catalog_search | ||
|
||
import dev.marlonlom.apps.cappajv.core.database.datasource.LocalDataSource | ||
|
||
/** | ||
* Catalog search repository. | ||
* | ||
* @author marlonlom | ||
* | ||
* @property localDataSource Local data source. | ||
*/ | ||
class CatalogSearchRepository( | ||
private val localDataSource: LocalDataSource, | ||
) { | ||
|
||
/** | ||
* Perform search using provided text. | ||
* | ||
* @param searchText Query text. | ||
*/ | ||
fun performSearch(searchText: String) = localDataSource.searchProducts("%$searchText%") | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
.../src/main/kotlin/dev/marlonlom/apps/cappajv/features/catalog_search/CatalogSearchRoute.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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 Marlonlom | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dev.marlonlom.apps.cappajv.features.catalog_search | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.parts.CatalogSearchHeadline | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.slots.CatalogSearchInputSlot | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.slots.CatalogSearchResultsSlot | ||
import dev.marlonlom.apps.cappajv.ui.main.CappajvAppState | ||
import org.koin.androidx.compose.koinViewModel | ||
import timber.log.Timber | ||
|
||
@ExperimentalFoundationApi | ||
@Composable | ||
fun CatalogSearchRoute( | ||
appState: CappajvAppState, | ||
viewModel: CatalogSearchViewModel = koinViewModel(), | ||
) { | ||
val contentHorizontalPadding = when { | ||
appState.isLandscape.not().and(appState.isMediumWidth) -> 40.dp | ||
appState.isLandscape.not().and(appState.isExpandedWidth) -> 80.dp | ||
else -> 20.dp | ||
} | ||
|
||
val queryText = rememberSaveable { viewModel.queryText } | ||
val showClearIcon = remember { | ||
derivedStateOf { viewModel.queryText.value.isNotEmpty() } | ||
} | ||
|
||
val searchResultState by viewModel.searchResult.collectAsStateWithLifecycle() | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(contentHorizontalPadding) | ||
) { | ||
CatalogSearchHeadline(appState) | ||
CatalogSearchInputSlot( | ||
appState = appState, | ||
queryText = queryText, | ||
showClearIcon = showClearIcon, | ||
onSearchReady = viewModel::onQueryTextChanged, | ||
) | ||
CatalogSearchResultsSlot( | ||
appState = appState, | ||
searchResultUiState = searchResultState, | ||
onSearchedItemClicked = { | ||
Timber.d("[CatalogSearchRoute] clicked item[$it] ") | ||
}, | ||
) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...rc/main/kotlin/dev/marlonlom/apps/cappajv/features/catalog_search/CatalogSearchUiState.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2024 Marlonlom | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dev.marlonlom.apps.cappajv.features.catalog_search | ||
|
||
import dev.marlonlom.apps.cappajv.core.database.entities.CatalogItemTuple | ||
|
||
/** | ||
* Catalog search ui state. | ||
* | ||
* @author marlonlom | ||
*/ | ||
sealed class CatalogSearchUiState { | ||
|
||
/** | ||
* Default catalog search ui state. | ||
* | ||
* @author marlonlom | ||
* | ||
*/ | ||
data object None : CatalogSearchUiState() | ||
|
||
/** | ||
* Searching phase of catalog search ui state. | ||
* | ||
* @author marlonlom | ||
* | ||
*/ | ||
data object Searching : CatalogSearchUiState() | ||
|
||
/** | ||
* Empty results phase of catalog search ui state. | ||
* | ||
* @author marlonlom | ||
* | ||
*/ | ||
data object Empty : CatalogSearchUiState() | ||
|
||
/** | ||
* Success result phase of catalog search ui state. | ||
* | ||
* @author marlonlom | ||
* | ||
* @property results Catalog tuples result list. | ||
*/ | ||
data class Success( | ||
val results: List<CatalogItemTuple> | ||
) : CatalogSearchUiState() | ||
} |
55 changes: 55 additions & 0 deletions
55
.../main/kotlin/dev/marlonlom/apps/cappajv/features/catalog_search/CatalogSearchViewModel.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2024 Marlonlom | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dev.marlonlom.apps.cappajv.features.catalog_search | ||
|
||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.CatalogSearchUiState.Empty | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.CatalogSearchUiState.None | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.CatalogSearchUiState.Searching | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.CatalogSearchUiState.Success | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.stateIn | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* Catalog search viewmodel. | ||
* | ||
* @author marlonlom | ||
* | ||
* @property repository Catalog search repository. | ||
*/ | ||
class CatalogSearchViewModel( | ||
private val repository: CatalogSearchRepository | ||
) : ViewModel() { | ||
var queryText = mutableStateOf("") | ||
private set | ||
|
||
private val _searchResult = MutableStateFlow<CatalogSearchUiState>(None) | ||
|
||
val searchResult = _searchResult.stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.Eagerly, | ||
initialValue = None | ||
) | ||
|
||
/** Handles query text value change. */ | ||
fun onQueryTextChanged() { | ||
_searchResult.value = if (queryText.value.isNotEmpty()) Searching else None | ||
if (_searchResult.value is None) return | ||
viewModelScope.launch { | ||
_searchResult.update { | ||
val searchResults = repository.performSearch(queryText.value).first() | ||
if (searchResults.isEmpty()) Empty else Success(searchResults) | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.