From de9a1e06a9ef0ba4460e2626e9ae3accdbfbbce6 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 12 Jun 2021 13:22:49 +0900 Subject: [PATCH] Add FavoriteRepository to ProfileFragmentViewModel constructor --- .../fragments/main/ProfileFragment.java | 1 + .../viewmodels/ProfileFragmentViewModel.kt | 4 +++ .../awais/instagrabber/common/Adapters.kt | 29 +++++++++++++++++++ .../ProfileFragmentViewModelTest.kt | 4 +++ 4 files changed, 38 insertions(+) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index e008387c..e8d199b6 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -349,6 +349,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe MediaRepository.Companion.getInstance(), GraphQLRepository.Companion.getInstance(), accountRepository, + favoriteRepository, this, getArguments() )).get(ProfileFragmentViewModel.class); diff --git a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt index 9812b581..2efb83b2 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt @@ -5,6 +5,7 @@ import android.util.Log import androidx.lifecycle.* import androidx.savedstate.SavedStateRegistryOwner import awais.instagrabber.db.repositories.AccountRepository +import awais.instagrabber.db.repositories.FavoriteRepository import awais.instagrabber.repositories.responses.User import awais.instagrabber.utils.extensions.TAG import awais.instagrabber.webservices.* @@ -17,6 +18,7 @@ class ProfileFragmentViewModel( mediaRepository: MediaRepository, graphQLRepository: GraphQLRepository, accountRepository: AccountRepository, + favoriteRepository: FavoriteRepository, ) : ViewModel() { private val _profile = MutableLiveData() val profile: LiveData = _profile @@ -40,6 +42,7 @@ class ProfileFragmentViewModelFactory( private val mediaRepository: MediaRepository, private val graphQLRepository: GraphQLRepository, private val accountRepository: AccountRepository, + private val favoriteRepository: FavoriteRepository, owner: SavedStateRegistryOwner, defaultArgs: Bundle? = null, ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { @@ -56,6 +59,7 @@ class ProfileFragmentViewModelFactory( mediaRepository, graphQLRepository, accountRepository, + favoriteRepository, ) as T } } diff --git a/app/src/test/java/awais/instagrabber/common/Adapters.kt b/app/src/test/java/awais/instagrabber/common/Adapters.kt index 75bd6cc7..e3153c6c 100644 --- a/app/src/test/java/awais/instagrabber/common/Adapters.kt +++ b/app/src/test/java/awais/instagrabber/common/Adapters.kt @@ -1,7 +1,10 @@ package awais.instagrabber.common import awais.instagrabber.db.dao.AccountDao +import awais.instagrabber.db.dao.FavoriteDao import awais.instagrabber.db.entities.Account +import awais.instagrabber.db.entities.Favorite +import awais.instagrabber.models.enums.FavoriteType import awais.instagrabber.repositories.* import awais.instagrabber.repositories.responses.* @@ -151,4 +154,30 @@ open class AccountDaoAdapter : AccountDao { override suspend fun deleteAllAccounts() { TODO("Not yet implemented") } +} + +open class FavoriteDaoAdapter: FavoriteDao { + override suspend fun getAllFavorites(): List { + TODO("Not yet implemented") + } + + override suspend fun findFavoriteByQueryAndType(query: String, type: FavoriteType): Favorite? { + TODO("Not yet implemented") + } + + override suspend fun insertFavorites(vararg favorites: Favorite) { + TODO("Not yet implemented") + } + + override suspend fun updateFavorites(vararg favorites: Favorite) { + TODO("Not yet implemented") + } + + override suspend fun deleteFavorites(vararg favorites: Favorite) { + TODO("Not yet implemented") + } + + override suspend fun deleteAllFavorites() { + TODO("Not yet implemented") + } } \ No newline at end of file diff --git a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt index b3cd3f55..4f72bfe3 100644 --- a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt +++ b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt @@ -4,7 +4,9 @@ import androidx.lifecycle.SavedStateHandle import androidx.test.ext.junit.runners.AndroidJUnit4 import awais.instagrabber.common.* import awais.instagrabber.db.datasources.AccountDataSource +import awais.instagrabber.db.datasources.FavoriteDataSource import awais.instagrabber.db.repositories.AccountRepository +import awais.instagrabber.db.repositories.FavoriteRepository import awais.instagrabber.webservices.* import org.junit.Test import org.junit.runner.RunWith @@ -25,6 +27,7 @@ internal class ProfileFragmentViewModelTest { val graphQLRepository = GraphQLRepository(GraphQLServiceAdapter()) val accountDataSource = AccountDataSource(AccountDaoAdapter()) val accountRepository = AccountRepository(accountDataSource) + val favoriteRepository = FavoriteRepository(FavoriteDataSource(FavoriteDaoAdapter())) val viewModel = ProfileFragmentViewModel( state, userRepository, @@ -33,6 +36,7 @@ internal class ProfileFragmentViewModelTest { mediaRepository, graphQLRepository, accountRepository, + favoriteRepository ) } } \ No newline at end of file