diff --git a/app/src/main/java/com/example/labwork/button_navigation/SlideGraph.kt b/app/src/main/java/com/example/labwork/button_navigation/SlideGraph.kt index ddf2027..318a5c8 100644 --- a/app/src/main/java/com/example/labwork/button_navigation/SlideGraph.kt +++ b/app/src/main/java/com/example/labwork/button_navigation/SlideGraph.kt @@ -9,11 +9,11 @@ import androidx.navigation.compose.composable import com.example.labwork.database.DAO.BicycleDao import com.example.labwork.database.DAO.UserDao import com.example.labwork.repository.BicycleRepository -import com.example.labwork.repository.BicycleViewModelFactory import com.example.labwork.repository.UserRepository -import com.example.labwork.repository.UserViewModelFactory import com.example.labwork.viewmodel.BicycleViewModel import com.example.labwork.viewmodel.UserViewModel +import com.example.labwork.viewmodel.factory.BicycleViewModelFactory +import com.example.labwork.viewmodel.factory.UserViewModelFactory @Composable diff --git a/app/src/main/java/com/example/labwork/repository/BicycleRepository.kt b/app/src/main/java/com/example/labwork/repository/BicycleRepository.kt index 004fbf8..643d863 100644 --- a/app/src/main/java/com/example/labwork/repository/BicycleRepository.kt +++ b/app/src/main/java/com/example/labwork/repository/BicycleRepository.kt @@ -35,12 +35,4 @@ class BicycleRepository(private val bicycleDao: BicycleDao) { } } -class BicycleViewModelFactory(private val bicycleRepository: BicycleRepository): ViewModelProvider.Factory { - override fun create(modelClass: Class): T { - if (modelClass.isAssignableFrom(BicycleViewModel::class.java)) { - return BicycleViewModel(bicycleRepository) as T - } - throw IllegalArgumentException("Unknown ViewModel class") - } -} diff --git a/app/src/main/java/com/example/labwork/repository/UserRepository.kt b/app/src/main/java/com/example/labwork/repository/UserRepository.kt index 94d3c69..de815e5 100644 --- a/app/src/main/java/com/example/labwork/repository/UserRepository.kt +++ b/app/src/main/java/com/example/labwork/repository/UserRepository.kt @@ -36,11 +36,3 @@ class UserRepository(private val userDao: UserDao) { } } -class UserViewModelFactory(private val userRepository: UserRepository): ViewModelProvider.Factory { - override fun create(modelClass: Class): T { - if (modelClass.isAssignableFrom(UserViewModel::class.java)) { - return UserViewModel(userRepository) as T - } - throw IllegalArgumentException("Unknown ViewModel class") - } -} diff --git a/app/src/main/java/com/example/labwork/viewmodel/factory/BicycleViewModelFactory.kt b/app/src/main/java/com/example/labwork/viewmodel/factory/BicycleViewModelFactory.kt new file mode 100644 index 0000000..4ef11ba --- /dev/null +++ b/app/src/main/java/com/example/labwork/viewmodel/factory/BicycleViewModelFactory.kt @@ -0,0 +1,15 @@ +package com.example.labwork.viewmodel.factory + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.example.labwork.repository.BicycleRepository +import com.example.labwork.viewmodel.BicycleViewModel + +class BicycleViewModelFactory(private val bicycleRepository: BicycleRepository): ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(BicycleViewModel::class.java)) { + return BicycleViewModel(bicycleRepository) as T + } + throw IllegalArgumentException("Unknown ViewModel class") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/labwork/viewmodel/factory/UserViewModelFactory.kt b/app/src/main/java/com/example/labwork/viewmodel/factory/UserViewModelFactory.kt new file mode 100644 index 0000000..b2096f0 --- /dev/null +++ b/app/src/main/java/com/example/labwork/viewmodel/factory/UserViewModelFactory.kt @@ -0,0 +1,15 @@ +package com.example.labwork.viewmodel.factory + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.example.labwork.repository.UserRepository +import com.example.labwork.viewmodel.UserViewModel + +class UserViewModelFactory(private val userRepository: UserRepository): ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(UserViewModel::class.java)) { + return UserViewModel(userRepository) as T + } + throw IllegalArgumentException("Unknown ViewModel class") + } +} \ No newline at end of file