UpdateWorker: Sort the updates before caching in database
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -35,6 +35,7 @@ import dagger.assisted.Assisted
|
|||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A worker to check for updates for installed apps based on saved authentication data,
|
* A worker to check for updates for installed apps based on saved authentication data,
|
||||||
@@ -91,7 +92,10 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val updates = checkUpdates()
|
val updates = checkUpdates().also {
|
||||||
|
// Cache the updates into the database
|
||||||
|
updateDao.insertUpdates(it)
|
||||||
|
}
|
||||||
|
|
||||||
if (updates.isEmpty()) {
|
if (updates.isEmpty()) {
|
||||||
Log.i(TAG, "No updates found!")
|
Log.i(TAG, "No updates found!")
|
||||||
@@ -158,10 +162,8 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
|
|
||||||
if (canSelfUpdate) getSelfUpdate()?.let { updates.add(it) }
|
if (canSelfUpdate) getSelfUpdate()?.let { updates.add(it) }
|
||||||
|
|
||||||
return@withContext updates.map { Update.fromApp(appContext, it) }.also {
|
return@withContext updates.map { Update.fromApp(appContext, it) }
|
||||||
// Cache the updates into the database
|
.sortedBy { it.displayName.lowercase(Locale.getDefault()) }
|
||||||
updateDao.insertUpdates(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user