1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-12 17:57:29 +00:00

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(),
MediaRepository.Companion.getInstance(),
GraphQLRepository.Companion.getInstance(),
accountRepository,
this,
getArguments()
)).get(ProfileFragmentViewModel.class);

View File

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

View File

@ -2,6 +2,10 @@ package awais.instagrabber.viewmodels
import androidx.lifecycle.SavedStateHandle
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.responses.*
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
fun testNoUsernameNoCurrentUser() {
val state = SavedStateHandle(
@ -144,6 +174,8 @@ internal class ProfileFragmentViewModelTest {
val storiesRepository = StoriesRepository(storiesService)
val mediaRepository = MediaRepository(mediaService)
val graphQLRepository = GraphQLRepository(graphQLService)
val accountDataSource = AccountDataSource(accountDao)
val accountRepository = AccountRepository(accountDataSource)
val viewModel = ProfileFragmentViewModel(
state,
userRepository,
@ -151,6 +183,7 @@ internal class ProfileFragmentViewModelTest {
storiesRepository,
mediaRepository,
graphQLRepository,
accountRepository,
)
}
}