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

Commit

Permalink
Add view model to home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Jul 15, 2024
1 parent eaed8ef commit aaf86fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ui-logic/src/main/java/dev/medzik/librepass/android/ui/Home.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.medzik.librepass.android.ui

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import dev.medzik.librepass.android.database.injection.DatabaseProvider
import dev.medzik.librepass.android.ui.vault.VaultHome
import dev.medzik.librepass.android.ui.vault.VaultHomeScreen
import kotlinx.serialization.Serializable
Expand All @@ -12,10 +11,11 @@ import kotlinx.serialization.Serializable
object Home

@Composable
fun HomeScreen(navController: NavController) {
val context = LocalContext.current
val repository = DatabaseProvider.provideRepository(context)
val credentials = repository.credentials.get()
fun HomeScreen(
navController: NavController,
viewModel: HomeScreenViewModel = hiltViewModel()
) {
val credentials = viewModel.getCredentials()

if (credentials != null) {
val args = VaultHome(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.medzik.librepass.android.ui

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.medzik.librepass.android.database.Credentials
import dev.medzik.librepass.android.database.Repository
import javax.inject.Inject

@HiltViewModel
class HomeScreenViewModel @Inject constructor(
private val repository: Repository
) : ViewModel() {
fun getCredentials(): Credentials? {
return repository.credentials.get()
}
}

0 comments on commit aaf86fa

Please sign in to comment.