diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchContent.kt b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchContent.kt index 3be8dcdd6..c91248738 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchContent.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchContent.kt @@ -11,6 +11,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.x8bit.bitwarden.authenticator.ui.authenticator.feature.search.handlers.SearchHandlers +/** + * The content state for the item search screen. + */ @Composable fun ItemSearchContent( viewState: ItemSearchState.ViewState.Content, diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchEmptyContent.kt b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchEmptyContent.kt index 6e22191f6..4d53b395e 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchEmptyContent.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchEmptyContent.kt @@ -22,7 +22,7 @@ import androidx.compose.ui.unit.dp import com.x8bit.bitwarden.authenticator.R /** - * The empty state for the search screen. + * The empty state for the item search screen. */ @Composable fun ItemSearchEmptyContent( diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchNavigation.kt b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchNavigation.kt index c1a8d9c6d..3ca7002eb 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchNavigation.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchNavigation.kt @@ -6,6 +6,9 @@ import com.x8bit.bitwarden.authenticator.ui.platform.base.util.composableWithSli const val ITEM_SEARCH_ROUTE = "item_search" +/** + * Add item search destination to the nav graph. + */ fun NavGraphBuilder.itemSearchDestination( onNavigateBack: () -> Unit, ) { @@ -18,6 +21,9 @@ fun NavGraphBuilder.itemSearchDestination( } } +/** + * Navigate to the item search screen. + */ fun NavController.navigateToSearch() { navigate(route = ITEM_SEARCH_ROUTE) } diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchScreen.kt b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchScreen.kt index 5a2efd65f..6af943a2e 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchScreen.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchScreen.kt @@ -34,6 +34,9 @@ import com.x8bit.bitwarden.authenticator.ui.platform.components.dialog.Bitwarden import com.x8bit.bitwarden.authenticator.ui.platform.components.dialog.LoadingDialogState import com.x8bit.bitwarden.authenticator.ui.platform.components.scaffold.BitwardenScaffold +/** + * The search screen for authenticator items. + */ @OptIn(ExperimentalMaterial3Api::class) @Composable fun ItemSearchScreen( @@ -125,6 +128,9 @@ fun ItemSearchScreen( } } +/** + * Dialogs displayed within the context of the item search screen. + */ @Composable private fun ItemSearchDialogs( dialogState: ItemSearchState.DialogState?, diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchViewModel.kt b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchViewModel.kt index ea7e7ee93..7a42e6fed 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchViewModel.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/ItemSearchViewModel.kt @@ -20,6 +20,9 @@ import kotlinx.coroutines.flow.update import kotlinx.parcelize.Parcelize import javax.inject.Inject +/** + * View model for the item search screen. + */ @HiltViewModel class ItemSearchViewModel @Inject constructor( private val authenticatorRepository: AuthenticatorRepository, @@ -240,40 +243,72 @@ class ItemSearchViewModel @Inject constructor( //endregion Utility Functions } +/** + * Represents the overall state for the [ItemSearchScreen]. + */ data class ItemSearchState( val searchTerm: String, val viewState: ViewState, val dialogState: DialogState?, ) { + /** + * Represents the specific view state for the search screen. + */ sealed class ViewState : Parcelable { + + /** + * Show the populated state. + */ @Parcelize data class Content( val displayItems: List, ) : ViewState() + /** + * Show the empty state. + */ @Parcelize data class Empty(val message: Text?) : ViewState() + /** + * Show the error state. + */ @Parcelize data class Error(val message: Text) : ViewState() + /** + * Show the loading state. + */ @Parcelize data object Loading : ViewState() } + /** + * Represents the current state of any dialogs on the screen. + */ sealed class DialogState : Parcelable { + + /** + * Represents a dismissible dialog with the given error [message]. + */ @Parcelize data class Error( val title: Text?, val message: Text, ) : DialogState() + /** + * Represents a loading dialog with the given [message]. + */ @Parcelize data class Loading( val message: Text, ) : DialogState() } + /** + * An item to be displayed. + */ @Parcelize data class DisplayItem( val id: String, @@ -288,29 +323,61 @@ data class ItemSearchState( ) : Parcelable } +/** + * Models actions for the [ItemSearchScreen]. + */ sealed class ItemSearchAction { + /** + * User clicked the back button. + */ data object BackClick : ItemSearchAction() + /** + * User clicked to dismiss the dialog. + */ data object DismissDialogClick : ItemSearchAction() + /** + * User updated the search term. + */ data class SearchTermChange(val searchTerm: String) : ItemSearchAction() + /** + * User clicked a row item. + */ data class ItemClick(val itemId: String) : ItemSearchAction() + /** + * Models actions that the [ItemSearchViewModel] itself might send. + */ sealed class Internal : ItemSearchAction() { + + /** + * Indicates authenticate data was received. + */ data class AuthenticatorDataReceive( val dataState: DataState>, ) : Internal() } } +/** + * Models events for the [ItemSearchScreen]. + */ sealed class ItemSearchEvent { + + /** + * Navigate back to the previous screen. + */ data object NavigateBack : ItemSearchEvent() + /** + * Show a toast with the given [message]. + */ data class ShowToast(val message: Text) : ItemSearchEvent() } -enum class SortPriority { +private enum class SortPriority { HIGH, LOW } diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/handlers/SearchHandlers.kt b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/handlers/SearchHandlers.kt index 7b0a98e7f..e74123e88 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/handlers/SearchHandlers.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/search/handlers/SearchHandlers.kt @@ -3,12 +3,19 @@ package com.x8bit.bitwarden.authenticator.ui.authenticator.feature.search.handle import com.x8bit.bitwarden.authenticator.ui.authenticator.feature.search.ItemSearchAction import com.x8bit.bitwarden.authenticator.ui.authenticator.feature.search.ItemSearchViewModel +/** + * A collection of delegate functions for managing actions within the context of the search screen. + */ class SearchHandlers( val onBackClick: () -> Unit, val onDismissRequest: () -> Unit, val onItemClick: (String) -> Unit, val onSearchTermChange: (String) -> Unit, ) { + /** + * Creates an instance of [SearchHandlers] by binding actions to the provided + * [ItemSearchViewModel]. + */ companion object { fun create(viewModel: ItemSearchViewModel): SearchHandlers = SearchHandlers(