aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-06-28 13:06:59 +0900
committerJean Chalard <jchalard@google.com>2013-07-01 14:47:30 +0900
commit3f0858eb2bcb9414dd94e01991b02c785af7b871 (patch)
tree12d7f458cc550e8163e1e33ea0c52e21cd57b6bd /java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
parent8142a7b637326e8fe8736de94246b1fffb4f2886 (diff)
downloadlatinime-3f0858eb2bcb9414dd94e01991b02c785af7b871.tar.gz
latinime-3f0858eb2bcb9414dd94e01991b02c785af7b871.tar.xz
latinime-3f0858eb2bcb9414dd94e01991b02c785af7b871.zip
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
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java25
1 files changed, 20 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
index 4b89d20bb..7bbd041e7 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
@@ -30,6 +30,7 @@ import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
+import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.animation.AnimationUtils;
@@ -104,9 +105,16 @@ public final class DictionarySettingsFragment extends PreferenceFragment
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
- mUpdateNowMenu = menu.add(Menu.NONE, MENU_UPDATE_NOW, 0, R.string.check_for_updates_now);
- mUpdateNowMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
- refreshNetworkState();
+ final String metadataUri =
+ MetadataDbHelper.getMetadataUriAsString(getActivity(), mClientId);
+ // We only add the "Refresh" button if we have a non-empty URL to refresh from. If the
+ // URL is empty, of course we can't refresh so it makes no sense to display this.
+ if (!TextUtils.isEmpty(metadataUri)) {
+ mUpdateNowMenu =
+ menu.add(Menu.NONE, MENU_UPDATE_NOW, 0, R.string.check_for_updates_now);
+ mUpdateNowMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ refreshNetworkState();
+ }
}
@Override
@@ -353,7 +361,12 @@ public final class DictionarySettingsFragment extends PreferenceFragment
new Thread("updateByHand") {
@Override
public void run() {
- UpdateHandler.update(activity, true);
+ // We call tryUpdate(), which returns whether we could successfully start an update.
+ // If we couldn't, we'll never receive the end callback, so we stop the loading
+ // animation and return to the previous screen.
+ if (!UpdateHandler.tryUpdate(activity, true)) {
+ stopLoadingAnimation();
+ }
}
}.start();
}
@@ -368,7 +381,9 @@ public final class DictionarySettingsFragment extends PreferenceFragment
private void startLoadingAnimation() {
mLoadingView.setVisibility(View.VISIBLE);
getView().setVisibility(View.GONE);
- mUpdateNowMenu.setTitle(R.string.cancel);
+ // We come here when the menu element is pressed so presumably it can't be null. But
+ // better safe than sorry.
+ if (null != mUpdateNowMenu) mUpdateNowMenu.setTitle(R.string.cancel);
}
private void stopLoadingAnimation() {