1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06:37:30 +00:00

Add FavoriteRepository to ProfileFragmentViewModel constructor

This commit is contained in:
Ammar Githam 2021-06-12 13:22:49 +09:00
parent 77868838b9
commit de9a1e06a9
4 changed files with 38 additions and 0 deletions

View File

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

View File

@ -5,6 +5,7 @@ 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.db.repositories.AccountRepository
import awais.instagrabber.db.repositories.FavoriteRepository
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.*
@ -17,6 +18,7 @@ class ProfileFragmentViewModel(
mediaRepository: MediaRepository, mediaRepository: MediaRepository,
graphQLRepository: GraphQLRepository, graphQLRepository: GraphQLRepository,
accountRepository: AccountRepository, accountRepository: AccountRepository,
favoriteRepository: FavoriteRepository,
) : ViewModel() { ) : ViewModel() {
private val _profile = MutableLiveData<User?>() private val _profile = MutableLiveData<User?>()
val profile: LiveData<User?> = _profile val profile: LiveData<User?> = _profile
@ -40,6 +42,7 @@ class ProfileFragmentViewModelFactory(
private val mediaRepository: MediaRepository, private val mediaRepository: MediaRepository,
private val graphQLRepository: GraphQLRepository, private val graphQLRepository: GraphQLRepository,
private val accountRepository: AccountRepository, private val accountRepository: AccountRepository,
private val favoriteRepository: FavoriteRepository,
owner: SavedStateRegistryOwner, owner: SavedStateRegistryOwner,
defaultArgs: Bundle? = null, defaultArgs: Bundle? = null,
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@ -56,6 +59,7 @@ class ProfileFragmentViewModelFactory(
mediaRepository, mediaRepository,
graphQLRepository, graphQLRepository,
accountRepository, accountRepository,
favoriteRepository,
) as T ) as T
} }
} }

View File

@ -1,7 +1,10 @@
package awais.instagrabber.common package awais.instagrabber.common
import awais.instagrabber.db.dao.AccountDao import awais.instagrabber.db.dao.AccountDao
import awais.instagrabber.db.dao.FavoriteDao
import awais.instagrabber.db.entities.Account 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.*
import awais.instagrabber.repositories.responses.* import awais.instagrabber.repositories.responses.*
@ -151,4 +154,30 @@ open class AccountDaoAdapter : AccountDao {
override suspend fun deleteAllAccounts() { override suspend fun deleteAllAccounts() {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
open class FavoriteDaoAdapter: FavoriteDao {
override suspend fun getAllFavorites(): List<Favorite> {
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")
}
} }

View File

@ -4,7 +4,9 @@ import androidx.lifecycle.SavedStateHandle
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import awais.instagrabber.common.* import awais.instagrabber.common.*
import awais.instagrabber.db.datasources.AccountDataSource import awais.instagrabber.db.datasources.AccountDataSource
import awais.instagrabber.db.datasources.FavoriteDataSource
import awais.instagrabber.db.repositories.AccountRepository import awais.instagrabber.db.repositories.AccountRepository
import awais.instagrabber.db.repositories.FavoriteRepository
import awais.instagrabber.webservices.* import awais.instagrabber.webservices.*
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -25,6 +27,7 @@ internal class ProfileFragmentViewModelTest {
val graphQLRepository = GraphQLRepository(GraphQLServiceAdapter()) val graphQLRepository = GraphQLRepository(GraphQLServiceAdapter())
val accountDataSource = AccountDataSource(AccountDaoAdapter()) val accountDataSource = AccountDataSource(AccountDaoAdapter())
val accountRepository = AccountRepository(accountDataSource) val accountRepository = AccountRepository(accountDataSource)
val favoriteRepository = FavoriteRepository(FavoriteDataSource(FavoriteDaoAdapter()))
val viewModel = ProfileFragmentViewModel( val viewModel = ProfileFragmentViewModel(
state, state,
userRepository, userRepository,
@ -33,6 +36,7 @@ internal class ProfileFragmentViewModelTest {
mediaRepository, mediaRepository,
graphQLRepository, graphQLRepository,
accountRepository, accountRepository,
favoriteRepository
) )
} }
} }