Add: Update all in installed tab (closes #3)

This commit is contained in:
machiav3lli 2022-03-04 01:16:31 +01:00
parent cb568c84e5
commit ce647baaf3
3 changed files with 11 additions and 3 deletions

View File

@ -102,6 +102,8 @@ class SyncService : ConnectionService<SyncService.Binder>() {
} }
} }
fun updateApps(prodcts: List<ProductItem>) = batchUpdate(prodcts)
fun sync(request: SyncRequest) { fun sync(request: SyncRequest) {
GlobalScope.launch { GlobalScope.launch {
val ids = db.repositoryDao.all.filter { it.enabled }.map { it.id }.toList() val ids = db.repositoryDao.all.filter { it.enabled }.map { it.id }.toList()
@ -406,7 +408,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
handleNextTask(false) handleNextTask(false)
if (result.isNotEmpty()) { if (result.isNotEmpty()) {
if (Preferences[Preferences.Key.InstallAfterSync]) if (Preferences[Preferences.Key.InstallAfterSync])
runAutoUpdate(result) batchUpdate(result)
if (hasUpdates && Preferences[Preferences.Key.UpdateNotify] && if (hasUpdates && Preferences[Preferences.Key.UpdateNotify] &&
updateNotificationBlockerFragment?.get()?.isAdded == true updateNotificationBlockerFragment?.get()?.isAdded == true
) )
@ -436,7 +438,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
* @param productItems a list of apps pending updates * @param productItems a list of apps pending updates
* @see SyncService.displayUpdatesNotification * @see SyncService.displayUpdatesNotification
*/ */
private fun runAutoUpdate(productItems: List<ProductItem>) { private fun batchUpdate(productItems: List<ProductItem>) {
if (Preferences[Preferences.Key.InstallAfterSync]) GlobalScope.launch { if (Preferences[Preferences.Key.InstallAfterSync]) GlobalScope.launch {
// run startUpdate on every item // run startUpdate on every item
productItems.map { productItem -> productItems.map { productItem ->

View File

@ -55,7 +55,7 @@ class MainActivityX : AppCompatActivity() {
private val viewModel: MainActivityViewModelX by viewModels() private val viewModel: MainActivityViewModelX by viewModels()
val menuSetup = MutableLiveData<Boolean>() val menuSetup = MutableLiveData<Boolean>()
private val syncConnection = Connection(SyncService::class.java, onBind = { _, _ -> val syncConnection = Connection(SyncService::class.java, onBind = { _, _ ->
navController.currentDestination?.let { navController.currentDestination?.let {
val source = Source.values()[when (it.id) { val source = Source.values()[when (it.id) {
R.id.latestTab -> 1 R.id.latestTab -> 1

View File

@ -10,6 +10,7 @@ import androidx.compose.material.Scaffold
import com.google.android.material.composethemeadapter.MdcTheme import com.google.android.material.composethemeadapter.MdcTheme
import com.looker.droidify.R import com.looker.droidify.R
import com.looker.droidify.content.Preferences import com.looker.droidify.content.Preferences
import com.looker.droidify.database.entity.Product
import com.looker.droidify.database.entity.Repository import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentInstalledXBinding import com.looker.droidify.databinding.FragmentInstalledXBinding
import com.looker.droidify.ui.compose.ProductsHorizontalRecycler import com.looker.droidify.ui.compose.ProductsHorizontalRecycler
@ -99,6 +100,11 @@ class InstalledFragment : MainNavFragmentX() {
} }
} }
} }
binding.buttonUpdateAll.setOnClickListener {
viewModel.secondaryProducts.value?.let {
mainActivityX.syncConnection.binder?.updateApps(it.map(Product::item))
}
}
mainActivityX.menuSetup.observe(viewLifecycleOwner) { mainActivityX.menuSetup.observe(viewLifecycleOwner) {
if (it != null) { if (it != null) {
val searchView = val searchView =