mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-24 03:42:15 +00:00
Add: Syncing enabled repos when edited
This commit is contained in:
parent
8c2f5011ef
commit
a4639aaa63
@ -78,7 +78,16 @@ class PrefsRepositoriesFragment : BaseNavFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun setupLayout() {
|
override fun setupLayout() {
|
||||||
viewModel.productsList.observe(requireActivity()) {
|
viewModel.repositories.observe(requireActivity()) {
|
||||||
|
// Function: sync when an enabled repo got edited
|
||||||
|
val enabledList = it.filter { it.enabled == 1 }
|
||||||
|
reposItemAdapter.adapterItems.filter(RepoItem::isEnabled).forEach { item ->
|
||||||
|
enabledList.firstOrNull { it.trueData?.id == item.item.id }?.let { repo ->
|
||||||
|
repo.trueData?.let { data ->
|
||||||
|
if (data != item.item) syncConnection.binder?.sync(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
reposItemAdapter.set(
|
reposItemAdapter.set(
|
||||||
it.mapNotNull { dbRepo ->
|
it.mapNotNull { dbRepo ->
|
||||||
dbRepo.trueData?.let { repo ->
|
dbRepo.trueData?.let { repo ->
|
||||||
|
@ -8,10 +8,10 @@ import com.looker.droidify.database.entity.Repository
|
|||||||
|
|
||||||
class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() {
|
class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() {
|
||||||
|
|
||||||
val productsList = MediatorLiveData<List<Repository>>()
|
val repositories = MediatorLiveData<List<Repository>>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
productsList.addSource(db.repositoryDao.allLive, productsList::setValue)
|
repositories.addSource(db.repositoryDao.allLive, repositories::setValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Factory(val db: DatabaseX) : ViewModelProvider.Factory {
|
class Factory(val db: DatabaseX) : ViewModelProvider.Factory {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user