From 3f0858eb2bcb9414dd94e01991b02c785af7b871 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 28 Jun 2013 13:06:59 +0900 Subject: Fix a bug where no URL means refresh never ends This patch does two things: - If there is no URL to download new data from, then the Refresh button is not shown. - Even if for some reason refresh starts for a client for which there is no URL, loading correctly finishes. Bug: 9388602 Change-Id: I3fd9214da50faa4b59d0bd3e775293dd34f07547 --- .../com/android/inputmethod/dictionarypack/UpdateHandler.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java') diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java index 719f24e59..8a23acdef 100644 --- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java +++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java @@ -173,14 +173,15 @@ public final class UpdateHandler { * Download latest metadata from the server through DownloadManager for all known clients * @param context The context for retrieving resources * @param updateNow Whether we should update NOW, or respect bandwidth policies + * @return true if an update successfully started, false otherwise. */ - public static void update(final Context context, final boolean updateNow) { + public static boolean tryUpdate(final Context context, final boolean updateNow) { // TODO: loop through all clients instead of only doing the default one. final TreeSet uris = new TreeSet(); final Cursor cursor = MetadataDbHelper.queryClientIds(context); - if (null == cursor) return; + if (null == cursor) return false; try { - if (!cursor.moveToFirst()) return; + if (!cursor.moveToFirst()) return false; do { final String clientId = cursor.getString(0); final String metadataUri = @@ -192,6 +193,7 @@ public final class UpdateHandler { } finally { cursor.close(); } + boolean started = false; for (final String metadataUri : uris) { if (!TextUtils.isEmpty(metadataUri)) { // If the metadata URI is empty, that means we should never update it at all. @@ -200,8 +202,10 @@ public final class UpdateHandler { // is a bug and it happens anyway, doing nothing is the right thing to do. // For more information, {@see DictionaryProvider#insert(Uri, ContentValues)}. updateClientsWithMetadataUri(context, updateNow, metadataUri); + started = true; } } + return started; } /** -- cgit v1.2.3-83-g751a