Вынес factory
This commit is contained in:
parent
b46391b649
commit
e96160ad7d
@ -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
|
||||
|
@ -35,12 +35,4 @@ class BicycleRepository(private val bicycleDao: BicycleDao) {
|
||||
}
|
||||
}
|
||||
|
||||
class BicycleViewModelFactory(private val bicycleRepository: BicycleRepository): ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(BicycleViewModel::class.java)) {
|
||||
return BicycleViewModel(bicycleRepository) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,11 +36,3 @@ class UserRepository(private val userDao: UserDao) {
|
||||
}
|
||||
}
|
||||
|
||||
class UserViewModelFactory(private val userRepository: UserRepository): ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(UserViewModel::class.java)) {
|
||||
return UserViewModel(userRepository) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class")
|
||||
}
|
||||
}
|
||||
|
@ -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 <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(BicycleViewModel::class.java)) {
|
||||
return BicycleViewModel(bicycleRepository) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class")
|
||||
}
|
||||
}
|
@ -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 <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(UserViewModel::class.java)) {
|
||||
return UserViewModel(userRepository) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user