-
-
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 files after merging from main branch
- Loading branch information
Showing
47 changed files
with
1,618 additions
and
114 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
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%") | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
.../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,49 @@ | ||
/* | ||
* 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.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.lifecycle.compose.collectAsStateWithLifecycle | ||
import dev.marlonlom.apps.cappajv.features.catalog_search.screens.CatalogSearchRouteScreen | ||
import dev.marlonlom.apps.cappajv.ui.main.CappajvAppState | ||
import org.koin.androidx.compose.koinViewModel | ||
import timber.log.Timber | ||
|
||
/** | ||
* Catalog search route composable ui. | ||
* | ||
* @author marlonlom | ||
* | ||
* @param appState Application ui state. | ||
* @param viewModel Catalog search viewmodel. | ||
*/ | ||
@ExperimentalFoundationApi | ||
@Composable | ||
fun CatalogSearchRoute( | ||
appState: CappajvAppState, | ||
viewModel: CatalogSearchViewModel = koinViewModel(), | ||
) { | ||
val queryText = rememberSaveable { viewModel.queryText } | ||
val showClearIcon = remember { | ||
derivedStateOf { viewModel.queryText.value.isNotEmpty() } | ||
} | ||
val searchResultState by viewModel.searchResult.collectAsStateWithLifecycle() | ||
CatalogSearchRouteScreen( | ||
appState = appState, | ||
queryText = queryText, | ||
showClearIcon = showClearIcon, | ||
onSearchReady = viewModel::onQueryTextChanged, | ||
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.