Add AccountRepository to ProfileFragmentViewModel constructor

This commit is contained in:
Ammar Githam 2021-06-12 13:04:55 +09:00
parent 06508ca78d
commit 8253328788
3 changed files with 38 additions and 0 deletions

View File

@ -349,6 +349,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
StoriesRepository.Companion.getInstance(), StoriesRepository.Companion.getInstance(),
MediaRepository.Companion.getInstance(), MediaRepository.Companion.getInstance(),
GraphQLRepository.Companion.getInstance(), GraphQLRepository.Companion.getInstance(),
accountRepository,
this, this,
getArguments() getArguments()
)).get(ProfileFragmentViewModel.class); )).get(ProfileFragmentViewModel.class);

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.util.Log import android.util.Log
import androidx.lifecycle.* import androidx.lifecycle.*
import androidx.savedstate.SavedStateRegistryOwner import androidx.savedstate.SavedStateRegistryOwner
import awais.instagrabber.db.repositories.AccountRepository
import awais.instagrabber.repositories.responses.User import awais.instagrabber.repositories.responses.User
import awais.instagrabber.utils.extensions.TAG import awais.instagrabber.utils.extensions.TAG
import awais.instagrabber.webservices.* import awais.instagrabber.webservices.*
@ -15,6 +16,7 @@ class ProfileFragmentViewModel(
storiesRepository: StoriesRepository, storiesRepository: StoriesRepository,
mediaRepository: MediaRepository, mediaRepository: MediaRepository,
graphQLRepository: GraphQLRepository, graphQLRepository: GraphQLRepository,
accountRepository: AccountRepository,
) : ViewModel() { ) : ViewModel() {
private val _profile = MutableLiveData<User?>() private val _profile = MutableLiveData<User?>()
val profile: LiveData<User?> = _profile val profile: LiveData<User?> = _profile
@ -37,6 +39,7 @@ class ProfileFragmentViewModelFactory(
private val storiesRepository: StoriesRepository, private val storiesRepository: StoriesRepository,
private val mediaRepository: MediaRepository, private val mediaRepository: MediaRepository,
private val graphQLRepository: GraphQLRepository, private val graphQLRepository: GraphQLRepository,
private val accountRepository: AccountRepository,
owner: SavedStateRegistryOwner, owner: SavedStateRegistryOwner,
defaultArgs: Bundle? = null, defaultArgs: Bundle? = null,
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@ -52,6 +55,7 @@ class ProfileFragmentViewModelFactory(
storiesRepository, storiesRepository,
mediaRepository, mediaRepository,
graphQLRepository, graphQLRepository,
accountRepository,
) as T ) as T
} }
} }

View File

@ -2,6 +2,10 @@ package awais.instagrabber.viewmodels
import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.SavedStateHandle
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import awais.instagrabber.db.dao.AccountDao
import awais.instagrabber.db.datasources.AccountDataSource
import awais.instagrabber.db.entities.Account
import awais.instagrabber.db.repositories.AccountRepository
import awais.instagrabber.repositories.* import awais.instagrabber.repositories.*
import awais.instagrabber.repositories.responses.* import awais.instagrabber.repositories.responses.*
import awais.instagrabber.webservices.* import awais.instagrabber.webservices.*
@ -132,6 +136,32 @@ internal class ProfileFragmentViewModelTest {
} }
} }
private val accountDao = object : AccountDao{
override suspend fun getAllAccounts(): List<Account> {
TODO("Not yet implemented")
}
override suspend fun findAccountByUid(uid: String): Account? {
TODO("Not yet implemented")
}
override suspend fun insertAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun updateAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun deleteAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun deleteAllAccounts() {
TODO("Not yet implemented")
}
}
@Test @Test
fun testNoUsernameNoCurrentUser() { fun testNoUsernameNoCurrentUser() {
val state = SavedStateHandle( val state = SavedStateHandle(
@ -144,6 +174,8 @@ internal class ProfileFragmentViewModelTest {
val storiesRepository = StoriesRepository(storiesService) val storiesRepository = StoriesRepository(storiesService)
val mediaRepository = MediaRepository(mediaService) val mediaRepository = MediaRepository(mediaService)
val graphQLRepository = GraphQLRepository(graphQLService) val graphQLRepository = GraphQLRepository(graphQLService)
val accountDataSource = AccountDataSource(accountDao)
val accountRepository = AccountRepository(accountDataSource)
val viewModel = ProfileFragmentViewModel( val viewModel = ProfileFragmentViewModel(
state, state,
userRepository, userRepository,
@ -151,6 +183,7 @@ internal class ProfileFragmentViewModelTest {
storiesRepository, storiesRepository,
mediaRepository, mediaRepository,
graphQLRepository, graphQLRepository,
accountRepository,
) )
} }
} }