aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-05-15 11:04:38 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-05-15 11:04:38 -0700
commit6ace5215005fb888d86009999c49cd6243398f11 (patch)
tree78c719412fc10143c9fe309624bc906093ddf138 /java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
parent6116b9f7b54c9b3ee9a265af2cf3b4db3de58052 (diff)
parent7a9ec9dd5368c66bc4db8b52d217560339d7929f (diff)
downloadlatinime-6ace5215005fb888d86009999c49cd6243398f11.tar.gz
latinime-6ace5215005fb888d86009999c49cd6243398f11.tar.xz
latinime-6ace5215005fb888d86009999c49cd6243398f11.zip
am 7a9ec9dd: am e91387e2: Merge "[PB5] Store state in a more convenient manner"
* commit '7a9ec9dd5368c66bc4db8b52d217560339d7929f': [PB5] Store state in a more convenient manner
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java39
1 files changed, 38 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
index cbf0476a3..8975d69a8 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
@@ -16,9 +16,46 @@
package com.android.inputmethod.dictionarypack;
+import com.android.inputmethod.latin.CollectionUtils;
+
+import java.util.HashMap;
+
/**
* Helper class to maintain the interface state of word list preferences.
+ *
+ * This is necessary because the views are created on-demand by calling code. There are many
+ * situations where views are renewed with little relation with user interaction. For example,
+ * when scrolling, the view is reused so it doesn't keep its state, which means we need to keep
+ * it separately. Also whenever the underlying dictionary list undergoes a change (for example,
+ * update the metadata, or finish downloading) the whole list has to be thrown out and recreated
+ * in case some dictionaries appeared, disappeared, changed states etc.
*/
public class DictionaryListInterfaceState {
- public String mLastClickedId = null;
+ private static class State {
+ public boolean mOpen = false;
+ public int mStatus = MetadataDbHelper.STATUS_UNKNOWN;
+ }
+
+ private HashMap<String, State> mWordlistToState = CollectionUtils.newHashMap();
+
+ public boolean isOpen(final String wordlistId) {
+ final State state = mWordlistToState.get(wordlistId);
+ if (null == state) return false;
+ return state.mOpen;
+ }
+
+ public void setOpen(final String wordlistId, final int status) {
+ final State newState;
+ final State state = mWordlistToState.get(wordlistId);
+ newState = null == state ? new State() : state;
+ newState.mOpen = true;
+ newState.mStatus = status;
+ mWordlistToState.put(wordlistId, newState);
+ }
+
+ public void closeAll() {
+ for (final State state : mWordlistToState.values()) {
+ state.mOpen = false;
+ }
+ }
}