Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck committed Apr 11, 2024
1 parent 8428b0b commit d57b4fd
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand All @@ -18,6 +21,9 @@ fun NavGraphBuilder.itemSearchDestination(
}
}

/**
* Navigate to the item search screen.
*/
fun NavController.navigateToSearch() {
navigate(route = ITEM_SEARCH_ROUTE)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -125,6 +128,9 @@ fun ItemSearchScreen(
}
}

/**
* Dialogs displayed within the context of the item search screen.
*/
@Composable
private fun ItemSearchDialogs(
dialogState: ItemSearchState.DialogState?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<DisplayItem>,
) : 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,
Expand All @@ -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<List<VerificationCodeItem>>,
) : 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d57b4fd

Please sign in to comment.