Merge "Reuse old preferences if possible."
commit
2564bd0937
|
@ -66,6 +66,8 @@ public final class DictionarySettingsFragment extends PreferenceFragment
|
||||||
private boolean mChangedSettings;
|
private boolean mChangedSettings;
|
||||||
private DictionaryListInterfaceState mDictionaryListInterfaceState =
|
private DictionaryListInterfaceState mDictionaryListInterfaceState =
|
||||||
new DictionaryListInterfaceState();
|
new DictionaryListInterfaceState();
|
||||||
|
private TreeMap<String, WordListPreference> mCurrentPreferenceMap =
|
||||||
|
new TreeMap<String, WordListPreference>(); // never null
|
||||||
|
|
||||||
private final BroadcastReceiver mConnectivityChangedReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mConnectivityChangedReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -278,7 +280,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
final String systemLocaleString = Locale.getDefault().toString();
|
final String systemLocaleString = Locale.getDefault().toString();
|
||||||
final TreeMap<String, WordListPreference> prefList =
|
final TreeMap<String, WordListPreference> prefMap =
|
||||||
new TreeMap<String, WordListPreference>();
|
new TreeMap<String, WordListPreference>();
|
||||||
final int idIndex = cursor.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN);
|
final int idIndex = cursor.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN);
|
||||||
final int versionIndex = cursor.getColumnIndex(MetadataDbHelper.VERSION_COLUMN);
|
final int versionIndex = cursor.getColumnIndex(MetadataDbHelper.VERSION_COLUMN);
|
||||||
|
@ -299,16 +301,31 @@ public final class DictionarySettingsFragment extends PreferenceFragment
|
||||||
// The key is sorted in lexicographic order, according to the match level, then
|
// The key is sorted in lexicographic order, according to the match level, then
|
||||||
// the description.
|
// the description.
|
||||||
final String key = matchLevelString + "." + description + "." + wordlistId;
|
final String key = matchLevelString + "." + description + "." + wordlistId;
|
||||||
final WordListPreference existingPref = prefList.get(key);
|
final WordListPreference existingPref = prefMap.get(key);
|
||||||
if (null == existingPref || hasPriority(status, existingPref.mStatus)) {
|
if (null == existingPref || hasPriority(status, existingPref.mStatus)) {
|
||||||
final WordListPreference pref = new WordListPreference(activity,
|
final WordListPreference oldPreference = mCurrentPreferenceMap.get(key);
|
||||||
mDictionaryListInterfaceState, mClientId, wordlistId, version, locale,
|
final WordListPreference pref;
|
||||||
description, status, filesize);
|
if (null != oldPreference
|
||||||
prefList.put(key, pref);
|
&& oldPreference.mVersion == version
|
||||||
|
&& oldPreference.mLocale.equals(locale)) {
|
||||||
|
// If the old preference has all the new attributes, reuse it. We test
|
||||||
|
// for version and locale because although attributes other than status
|
||||||
|
// need to be the same, others have been tested through the key of the
|
||||||
|
// map. Also, status may differ so we don't want to use #equals() here.
|
||||||
|
pref = oldPreference;
|
||||||
|
pref.mStatus = status;
|
||||||
|
} else {
|
||||||
|
// Otherwise, discard it and create a new one instead.
|
||||||
|
pref = new WordListPreference(activity, mDictionaryListInterfaceState,
|
||||||
|
mClientId, wordlistId, version, locale, description, status,
|
||||||
|
filesize);
|
||||||
|
}
|
||||||
|
prefMap.put(key, pref);
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return prefList.values();
|
mCurrentPreferenceMap = prefMap;
|
||||||
|
return prefMap.values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@ public final class WordListPreference extends Preference {
|
||||||
// The metadata word list id and version of this word list.
|
// The metadata word list id and version of this word list.
|
||||||
public final String mWordlistId;
|
public final String mWordlistId;
|
||||||
public final int mVersion;
|
public final int mVersion;
|
||||||
|
public final Locale mLocale;
|
||||||
|
public final String mDescription;
|
||||||
// The status
|
// The status
|
||||||
public int mStatus;
|
public int mStatus;
|
||||||
// The size of the dictionary file
|
// The size of the dictionary file
|
||||||
|
@ -80,6 +82,8 @@ public final class WordListPreference extends Preference {
|
||||||
mVersion = version;
|
mVersion = version;
|
||||||
mWordlistId = wordlistId;
|
mWordlistId = wordlistId;
|
||||||
mFilesize = filesize;
|
mFilesize = filesize;
|
||||||
|
mLocale = locale;
|
||||||
|
mDescription = description;
|
||||||
|
|
||||||
setLayoutResource(R.layout.dictionary_line);
|
setLayoutResource(R.layout.dictionary_line);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue