aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-04-24 19:47:34 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-04-24 19:47:34 -0700
commit7a9ec9dd5368c66bc4db8b52d217560339d7929f (patch)
tree74d5b8f3adcf604f0bc4ad1331f298c237e6b003 /java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
parent8b2dcbcbdcc6e4435ee1f31ad0355e5268413c57 (diff)
parente91387e281869cb93abb46720b7a80098946d80f (diff)
downloadlatinime-7a9ec9dd5368c66bc4db8b52d217560339d7929f.tar.gz
latinime-7a9ec9dd5368c66bc4db8b52d217560339d7929f.tar.xz
latinime-7a9ec9dd5368c66bc4db8b52d217560339d7929f.zip
am e91387e2: Merge "[PB5] Store state in a more convenient manner"
* commit 'e91387e281869cb93abb46720b7a80098946d80f': [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;
+ }
+ }
}