1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +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(),
GraphQLRepository.Companion.getInstance(),
accountRepository,
favoriteRepository,
this,
getArguments()
)).get(ProfileFragmentViewModel.class);

View File

@ -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<User?>()
val profile: LiveData<User?> = _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
}
}

View File

@ -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<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 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
)
}
}