UpdateWorker: Sort the updates before caching in database

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-10-21 10:02:43 +05:30
parent 23e5c5273a
commit 0f1b7f2602

View File

@@ -35,6 +35,7 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.util.Locale
/**
* A worker to check for updates for installed apps based on saved authentication data,
@@ -91,7 +92,10 @@ class UpdateWorker @AssistedInject constructor(
}
try {
val updates = checkUpdates()
val updates = checkUpdates().also {
// Cache the updates into the database
updateDao.insertUpdates(it)
}
if (updates.isEmpty()) {
Log.i(TAG, "No updates found!")
@@ -158,10 +162,8 @@ class UpdateWorker @AssistedInject constructor(
if (canSelfUpdate) getSelfUpdate()?.let { updates.add(it) }
return@withContext updates.map { Update.fromApp(appContext, it) }.also {
// Cache the updates into the database
updateDao.insertUpdates(it)
}
return@withContext updates.map { Update.fromApp(appContext, it) }
.sortedBy { it.displayName.lowercase(Locale.getDefault()) }
}
}