]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
List broken/corrupted dictionaries in list.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 13 Dec 2015 15:58:55 +0000 (16:58 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 13 Dec 2015 15:58:55 +0000 (16:58 +0100)
Should help debugging "dictionaries disappear" issues.

src/com/hughes/android/dictionary/DictionaryApplication.java
src/com/hughes/android/dictionary/DictionaryInfo.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java
src/com/hughes/android/dictionary/engine/Dictionary.java

index d5b19e5e40d8d2efda4b0cde679f36b30310498f..3a970343b740317e63b9c4dac7d1046422178c88 100644 (file)
@@ -590,7 +590,7 @@ public class DictionaryApplication extends Application {
                 for (final String uncompressedFilename : oldDictionaryConfig.dictionaryFilesOrdered) {
                     final File dictFile = getPath(uncompressedFilename);
                     final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(dictFile);
-                    if (dictionaryInfo != null) {
+                    if (dictionaryInfo.isValid()) {
                         newDictionaryConfig.dictionaryFilesOrdered.add(uncompressedFilename);
                         newDictionaryConfig.uncompressedFilenameToDictionaryInfo.put(
                                 uncompressedFilename, dictionaryInfo);
@@ -619,9 +619,8 @@ public class DictionaryApplication extends Application {
                             continue;
                         }
                         final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file);
-                        if (dictionaryInfo == null) {
+                        if (!dictionaryInfo.isValid()) {
                             Log.e(LOG, "Unable to parse dictionary: " + file.getPath());
-                            continue;
                         }
 
                         toAddSorted.add(file.getName());
index cfe95f6d7f03ba33067a5d2933ccf4fb5fa96f0c..8a956775ce95c25168fc8095b8ac44936763daa5 100644 (file)
@@ -64,6 +64,10 @@ public class DictionaryInfo implements Serializable {
         // Blank object.
     }
 
+    public boolean isValid() {
+        return !indexInfos.isEmpty();
+    }
+
     public StringBuilder append(final StringBuilder result) {
         result.append(uncompressedFilename);
         result.append("\t").append(downloadUrl);
index b8144a4041d9f1797d64170747c0ee06abe0df7f..13dc94f482df5efad563540432b3f772d2fb423f 100644 (file)
@@ -519,7 +519,7 @@ public class DictionaryManagerActivity extends ActionBarActivity {
     }
 
     private View createDictionaryRow(final DictionaryInfo dictionaryInfo,
-            final ViewGroup parent, final boolean canLaunch) {
+            final ViewGroup parent, boolean canLaunch) {
 
         View row = LayoutInflater.from(parent.getContext()).inflate(
                 R.layout.dictionary_manager_row, parent, false);
@@ -530,7 +530,12 @@ public class DictionaryManagerActivity extends ActionBarActivity {
         final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
         final Button downloadButton = (Button) row.findViewById(R.id.downloadButton);
         final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
-        if (!canLaunch || updateAvailable) {
+        boolean broken = false;
+        if (!dictionaryInfo.isValid()) {
+            broken = true;
+            canLaunch = false;
+        }
+        if (downloadable != null && (!canLaunch || updateAvailable)) {
             downloadButton
                     .setText(getString(
                             R.string.downloadButton,
@@ -578,6 +583,10 @@ public class DictionaryManagerActivity extends ActionBarActivity {
             builder.append("; ");
             builder.append(getString(R.string.downloadButton, downloadable.uncompressedBytes / 1024.0 / 1024.0));
         }
+        if (broken) {
+            name.setText("Broken: " + application.getDictionaryName(dictionaryInfo.uncompressedFilename));
+            builder.append("; Cannot be used, redownload, check hardware/file system");
+        }
         details.setText(builder.toString());
 
         if (canLaunch) {
index 084546def8d4316042ceb60a87f80d843f960652..1a57d89c44942094e996613e1ee62bdca6030ec3 100644 (file)
@@ -194,7 +194,10 @@ public class Dictionary implements RAFSerializable<Dictionary> {
             raf.close();
             return dictionaryInfo;
         } catch (IOException e) {
-            return null;
+            final DictionaryInfo dictionaryInfo = new DictionaryInfo();
+            dictionaryInfo.uncompressedFilename = file.getName();
+            dictionaryInfo.uncompressedBytes = file.length();
+            return dictionaryInfo;
         } finally {
             if (raf != null) {
                 try {