Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
docs(app): add documentation to BackpackViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaBrighi committed May 16, 2023
1 parent f689b0a commit f4cca59
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

/**
* View model for the backpack.
*/
class BackpackViewModel(
private val desktopUseCase: DesktopUseCase
) : ViewModel() {

private val backpackImpl = MutableLiveData<Set<SchoolSupplyView>>()

/**
* Live data with representing the backpack.
*/
val backpack: LiveData<Set<SchoolSupplyView>> = backpackImpl

private val isBackpackAssociatedImpl = MutableLiveData<Boolean>()

/**
* Live data with representing if the backpack is associated.
*/
val isBackpackAssociated: LiveData<Boolean> = isBackpackAssociatedImpl

/**
* updates the livedata isBackpackAssociated.
*
* @param error the error callback.
*/
fun getBackpackAssociated(
error: (error: String) -> Unit
) {
Expand All @@ -44,6 +58,13 @@ class BackpackViewModel(
}
}

/**
* Associates a new backpack.
*
* @param hash the hash of the backpack.
* @param success the success callback.
* @param error the error callback.
*/
fun associateBackpack(
hash: String,
success: () -> Unit,
Expand All @@ -63,6 +84,12 @@ class BackpackViewModel(
}
}

/**
* Disassociates a backpack.
*
* @param success the success callback.
* @param error the error callback.
*/
fun disassociateBackpack(
success: () -> Unit,
error: (error: String) -> Unit
Expand Down Expand Up @@ -91,6 +118,11 @@ class BackpackViewModel(
}
}

/**
* Subscribes to the backpack updates.
*
* @param error the error callback.
*/
fun subscribe(
error: (error: String) -> Unit
) {
Expand Down Expand Up @@ -120,6 +152,9 @@ class BackpackViewModel(

companion object {

/**
* Factory for the view model.
*/
val Factory: ViewModelProvider.Factory = viewModelFactory {
initializer {
// Get the Application object from extras
Expand Down

0 comments on commit f4cca59

Please sign in to comment.