diff options
author | 2013-04-24 14:07:47 +0900 | |
---|---|---|
committer | 2013-04-24 22:49:50 +0900 | |
commit | cadea5d2fcd624501682d3ec3e1c67e9dcb989d1 (patch) | |
tree | cc68d5cb536e24620359888c6d934623e8ee1e03 /java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java | |
parent | c017f18a59a6b0ba1905a67193057b5b70410e06 (diff) | |
download | latinime-cadea5d2fcd624501682d3ec3e1c67e9dcb989d1.tar.gz latinime-cadea5d2fcd624501682d3ec3e1c67e9dcb989d1.tar.xz latinime-cadea5d2fcd624501682d3ec3e1c67e9dcb989d1.zip |
[PB5] Store state in a more convenient manner
This is more readable and will help with animations going forward.
Bug: 7600384
Change-Id: I255598d860d1e451fef106b00da63c282fe95f95
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java')
-rw-r--r-- | java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java | 39 |
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; + } + } } |