Merge "Check the main dict id to be able to fallback."

main
Jean Chalard 2011-08-18 19:55:16 -07:00 committed by Android (Google) Code Review
commit 1e841de2ce
1 changed files with 20 additions and 7 deletions

View File

@ -213,6 +213,13 @@ class BinaryDictionaryGetter {
return cacheFiles; return cacheFiles;
} }
/**
* Returns the id of the main dict for a specified locale.
*/
private static String getMainDictId(final Locale locale) {
return locale.toString();
}
/** /**
* Returns a list of file addresses for a given locale, trying relevant methods in order. * Returns a list of file addresses for a given locale, trying relevant methods in order.
* *
@ -234,12 +241,18 @@ class BinaryDictionaryGetter {
BinaryDictionaryFileDumper.cacheDictionariesFromContentProvider(locale, context); BinaryDictionaryFileDumper.cacheDictionariesFromContentProvider(locale, context);
final File[] cachedDictionaryList = getCachedDictionaryList(locale, context); final File[] cachedDictionaryList = getCachedDictionaryList(locale, context);
final String mainDictId = getMainDictId(locale);
final DictPackSettings dictPackSettings = new DictPackSettings(context); final DictPackSettings dictPackSettings = new DictPackSettings(context);
boolean foundMainDict = false;
final ArrayList<AssetFileAddress> fileList = new ArrayList<AssetFileAddress>(); final ArrayList<AssetFileAddress> fileList = new ArrayList<AssetFileAddress>();
// cachedDictionaryList may not be null, see doc for getCachedDictionaryList // cachedDictionaryList may not be null, see doc for getCachedDictionaryList
for (final File f : cachedDictionaryList) { for (final File f : cachedDictionaryList) {
final String wordListId = getWordListIdFromFileName(f.getName()); final String wordListId = getWordListIdFromFileName(f.getName());
if (wordListId.equals(mainDictId)) {
foundMainDict = true;
}
if (!dictPackSettings.isWordListActive(wordListId)) continue; if (!dictPackSettings.isWordListActive(wordListId)) continue;
if (f.canRead()) { if (f.canRead()) {
fileList.add(AssetFileAddress.makeFromFileName(f.getPath())); fileList.add(AssetFileAddress.makeFromFileName(f.getPath()));
@ -248,14 +261,14 @@ class BinaryDictionaryGetter {
} }
} }
if (!fileList.isEmpty()) { if (!foundMainDict && dictPackSettings.isWordListActive(mainDictId)) {
return fileList; final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId,
locale);
if (null != fallbackAsset) {
fileList.add(fallbackAsset);
}
} }
// If the list is empty, fall through and return the fallback
final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId, return fileList;
locale);
if (null == fallbackAsset) return null;
return Arrays.asList(fallbackAsset);
} }
} }