]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryManagerActivity.java
Refine handling of broken dictionaries.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryManagerActivity.java
index d9b1eed447eb87f95940f4e51a97ad7c0a5fb598..8ec7d2c0e7aa579e021f563474743b42045f63e0 100644 (file)
@@ -173,7 +173,12 @@ public class DictionaryManagerActivity extends ActionBarActivity {
                     Toast.makeText(context, getString(R.string.installationFinished, dest),
                             Toast.LENGTH_LONG).show();
                 } catch (Exception e) {
-                    new AlertDialog.Builder(context).setTitle(getString(R.string.error)).setMessage(getString(R.string.unzippingFailed, dest)).setNeutralButton("Close", null).show();
+                    String msg = getString(R.string.unzippingFailed, dest);
+                    File dir = application.getDictDir();
+                    if (!dir.canWrite() || !application.checkFileCreate(dir)) {
+                        msg = getString(R.string.notWritable, dir.getAbsolutePath());
+                    }
+                    new AlertDialog.Builder(context).setTitle(getString(R.string.error)).setMessage(msg).setNeutralButton("Close", null).show();
                     Log.e(LOG, "Failed to unzip.", e);
                 } finally {
                     localZipFile.delete();
@@ -514,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);
@@ -524,8 +529,13 @@ public class DictionaryManagerActivity extends ActionBarActivity {
 
         final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
         final Button downloadButton = (Button) row.findViewById(R.id.downloadButton);
-        if (!canLaunch || updateAvailable) {
-            final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
+        final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
+        boolean broken = false;
+        if (!dictionaryInfo.isValid()) {
+            broken = true;
+            canLaunch = false;
+        }
+        if (downloadable != null && (!canLaunch || updateAvailable)) {
             downloadButton
                     .setText(getString(
                             R.string.downloadButton,
@@ -569,6 +579,16 @@ public class DictionaryManagerActivity extends ActionBarActivity {
             builder.append(getString(R.string.indexInfo, indexInfo.shortName,
                     indexInfo.mainTokenCount));
         }
+        if (downloadable != null || dictionaryInfo != null) {
+            builder.append("; ");
+            builder.append(getString(R.string.downloadButton, (dictionaryInfo != null ? dictionaryInfo.uncompressedBytes : 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");
+            // Allow deleting, but cannot open
+            row.setLongClickable(true);
+        }
         details.setText(builder.toString());
 
         if (canLaunch) {