Make "batchUpdates" mode an implementation detail of the AddUpdateStatusManager
class.
Because of the way that this can be misused without the compiler knowing (e.g. by forgetting to call `endBatchUpdates()`) it may be safer to move it to an internal implementation detail of the class. It could probably be done away with completely if the `notify*` methods were moved out of the respective `*ApkInternal()` methods, but that requires more significant refactoring to get right without code duplication.
This commit is contained in:
parent
aa945367c9
commit
30d3f8efcc
@ -19,6 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AppUpdateStatusManager {
|
||||
@ -187,6 +188,15 @@ public class AppUpdateStatusManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addApks(List<Apk> apksToUpdate, Status status) {
|
||||
startBatchUpdates();
|
||||
for (Apk apk : apksToUpdate) {
|
||||
addApk(apk, status, null);
|
||||
}
|
||||
endBatchUpdates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an Apk to the AppUpdateStatusManager manager.
|
||||
* @param apk The apk to add.
|
||||
@ -250,13 +260,13 @@ public class AppUpdateStatusManager {
|
||||
}
|
||||
}
|
||||
|
||||
void startBatchUpdates() {
|
||||
private void startBatchUpdates() {
|
||||
synchronized (appMapping) {
|
||||
isBatchUpdating = true;
|
||||
}
|
||||
}
|
||||
|
||||
void endBatchUpdates() {
|
||||
private void endBatchUpdates() {
|
||||
synchronized (appMapping) {
|
||||
isBatchUpdating = false;
|
||||
notifyChange();
|
||||
|
@ -489,14 +489,13 @@ public class UpdateService extends IntentService {
|
||||
private void showAppUpdatesNotification(Cursor hasUpdates) {
|
||||
if (hasUpdates != null) {
|
||||
hasUpdates.moveToFirst();
|
||||
appUpdateStatusManager.startBatchUpdates();
|
||||
List<Apk> apksToUpdate = new ArrayList<>(hasUpdates.getCount());
|
||||
for (int i = 0; i < hasUpdates.getCount(); i++) {
|
||||
App app = new App(hasUpdates);
|
||||
hasUpdates.moveToNext();
|
||||
Apk apk = ApkProvider.Helper.findApkFromAnyRepo(this, app.packageName, app.suggestedVersionCode);
|
||||
appUpdateStatusManager.addApk(apk, AppUpdateStatusManager.Status.UpdateAvailable, null);
|
||||
apksToUpdate.add(ApkProvider.Helper.findApkFromAnyRepo(this, app.packageName, app.suggestedVersionCode));
|
||||
}
|
||||
appUpdateStatusManager.endBatchUpdates();
|
||||
appUpdateStatusManager.addApks(apksToUpdate, AppUpdateStatusManager.Status.UpdateAvailable);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user