瀏覽代碼

Reverse filter for preview of text files: all text/ but those in black list

David A. Velasco 9 年之前
父節點
當前提交
68ce6e62bf

+ 8 - 0
src/com/owncloud/android/datamodel/OCFile.java

@@ -548,6 +548,14 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
                 getMimeTypeFromName().startsWith("image/"));
     }
 
+    /**
+     * @return 'True' if the file is simple text (e.g. not application-dependent, like .doc or .docx)
+     */
+    public boolean isText() {
+        return ((mMimeType != null && mMimeType.startsWith("text/")) ||
+                getMimeTypeFromName().startsWith("text/"));
+    }
+
     public String getMimeTypeFromName() {
         String extension = "";
         int pos = mRemotePath.lastIndexOf('.');

+ 8 - 7
src/com/owncloud/android/ui/preview/PreviewTextFragment.java

@@ -391,13 +391,14 @@ public class PreviewTextFragment extends FileFragment {
      * @return 'True' if the file can be handled by the fragment.
      */
     public static boolean canBePreviewed(OCFile file) {
-        final List<String> supportedTypes = new LinkedList<String>();
-        supportedTypes.add("text/plain");
-        supportedTypes.add("text/html");
-        supportedTypes.add("text/css");
-        supportedTypes.add("text/csv");
-
-        return (file != null && file.isDown() && supportedTypes.contains(file.getMimetype()));
+        final List<String> unsupportedTypes = new LinkedList<String>();
+        unsupportedTypes.add("text/richtext");
+        unsupportedTypes.add("text/vnd.abc");
+        unsupportedTypes.add("text/vnd.fmi.flexstor");
+        unsupportedTypes.add("text/vnd.rn-realtext");
+        unsupportedTypes.add("text/vnd.wap.wml");
+        unsupportedTypes.add("text/vnd.wap.wmlscript");
+        return (file != null && file.isDown() && file.isText() && !unsupportedTypes.contains(file.getMimetype()));
     }
 
     /**