Add: Install using Main's syncConnection

This commit is contained in:
machiav3lli 2022-03-04 15:20:14 +01:00
parent 5a3c4fb487
commit 71603ff3c4

View File

@ -102,7 +102,8 @@ class SyncService : ConnectionService<SyncService.Binder>() {
} }
} }
fun updateApps(prodcts: List<ProductItem>) = batchUpdate(prodcts) fun updateApps(products: List<ProductItem>) = batchUpdate(products)
fun installApps(products: List<ProductItem>) = batchUpdate(products, true)
fun sync(request: SyncRequest) { fun sync(request: SyncRequest) {
GlobalScope.launch { GlobalScope.launch {
@ -438,32 +439,32 @@ 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 batchUpdate(productItems: List<ProductItem>) { private fun batchUpdate(productItems: List<ProductItem>, install: Boolean = false) {
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 ->
Pair( Triple(
productItem.packageName,
db.installedDao.get(productItem.packageName), db.installedDao.get(productItem.packageName),
db.repositoryDao.get(productItem.repositoryId) db.repositoryDao.get(productItem.repositoryId)
) )
} }
.filter { pair -> pair.first != null && pair.second != null } .filter { pair -> (install || pair.second != null) && pair.third != null }
.forEach { installedRepository -> .forEach { installedRepository ->
run { run {
// Redundant !! as linter doesn't recognise the above filter's effects // Redundant !! as linter doesn't recognise the above filter's effects
val installedItem = installedRepository.first!! val packageName = installedRepository.first
val repository = installedRepository.second!! val installedItem = installedRepository.second
val repository = installedRepository.third!!
val productRepository = db.productDao.get( val productRepository = db.productDao.get(packageName)
installedItem.package_name
)
.filter { product -> product?.repository_id == repository.id } .filter { product -> product?.repository_id == repository.id }
.map { product -> Pair(product?.data!!, repository) } .map { product -> Pair(product?.data!!, repository) }
scope.launch { scope.launch {
Utils.startUpdate( Utils.startUpdate(
installedItem.package_name, packageName,
installedRepository.first, installedItem,
productRepository, productRepository,
downloadConnection downloadConnection
) )