am fdc41732: Merge "Fix a view-related crash"

* commit 'fdc417321345037fdcf31de95fbaf7cc195856b3':
  Fix a view-related crash
main
Jean Chalard 2014-02-14 01:38:52 -08:00 committed by Android Git Automerger
commit 82b92b2147
2 changed files with 14 additions and 5 deletions

View File

@ -317,15 +317,19 @@ public final class DictionarySettingsFragment extends PreferenceFragment
final WordListPreference pref; final WordListPreference pref;
if (null != oldPreference if (null != oldPreference
&& oldPreference.mVersion == version && oldPreference.mVersion == version
&& oldPreference.hasStatus(status)
&& oldPreference.mLocale.equals(locale)) { && oldPreference.mLocale.equals(locale)) {
// If the old preference has all the new attributes, reuse it. We test // If the old preference has all the new attributes, reuse it. Ideally, we
// for version and locale because although attributes other than status // should reuse the old pref even if its status is different and call
// need to be the same, others have been tested through the key of the // setStatus here, but setStatus calls Preference#setSummary() which needs
// map. Also, status may differ so we don't want to use #equals() here. // to be done on the UI thread and we're not on the UI thread here. We
// could do all this work on the UI thread, but in this case it's probably
// lighter to stay on a background thread and throw this old preference out.
pref = oldPreference; pref = oldPreference;
pref.setStatus(status);
} else { } else {
// Otherwise, discard it and create a new one instead. // Otherwise, discard it and create a new one instead.
// TODO: when the status is different from the old one, we need to
// animate the old one out before animating the new one in.
pref = new WordListPreference(activity, mDictionaryListInterfaceState, pref = new WordListPreference(activity, mDictionaryListInterfaceState,
mClientId, wordlistId, version, locale, description, status, mClientId, wordlistId, version, locale, description, status,
filesize); filesize);

View File

@ -98,6 +98,10 @@ public final class WordListPreference extends Preference {
setSummary(getSummary(status)); setSummary(getSummary(status));
} }
public boolean hasStatus(final int status) {
return status == mStatus;
}
@Override @Override
public View onCreateView(final ViewGroup parent) { public View onCreateView(final ViewGroup parent) {
final View orphanedView = mInterfaceState.findFirstOrphanedView(); final View orphanedView = mInterfaceState.findFirstOrphanedView();
@ -217,6 +221,7 @@ public final class WordListPreference extends Preference {
progressBar.setIds(mClientId, mWordlistId); progressBar.setIds(mClientId, mWordlistId);
progressBar.setMax(mFilesize); progressBar.setMax(mFilesize);
final boolean showProgressBar = (MetadataDbHelper.STATUS_DOWNLOADING == mStatus); final boolean showProgressBar = (MetadataDbHelper.STATUS_DOWNLOADING == mStatus);
setSummary(getSummary(mStatus));
status.setVisibility(showProgressBar ? View.INVISIBLE : View.VISIBLE); status.setVisibility(showProgressBar ? View.INVISIBLE : View.VISIBLE);
progressBar.setVisibility(showProgressBar ? View.VISIBLE : View.INVISIBLE); progressBar.setVisibility(showProgressBar ? View.VISIBLE : View.INVISIBLE);