소스 검색

theming for zip icon

AndyScherzinger 7 년 전
부모
커밋
2c076222b0

+ 1 - 1
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -474,7 +474,7 @@ public class ThumbnailsCacheManager {
                             if (MimeTypeUtil.isVideo(mFile)) {
                                 imageView.setImageBitmap(ThumbnailsCacheManager.mDefaultVideo);
                             } else {
-                                imageView.setImageResource(MimeTypeUtil.getFileTypeIconId(null, mFile.getName()));
+                                imageView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(null, mFile.getName(), null));
                             }
                         }
                     }

+ 1 - 2
src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java

@@ -251,8 +251,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
                 Glide.with(context).using(new CustomGlideStreamLoader()).load(uri).into(fileIcon); //Using custom fetcher
 
             } else {
-                fileIcon.setImageResource(MimeTypeUtil.getFileTypeIconId(file.getMimetype(),
-                        file.getFileName()));
+                fileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimetype(), file.getFileName(), null));
             }
         } else {
             // Folder

+ 1 - 5
src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -497,12 +497,8 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                             .getColor(R.color.background_color));
                 }
             } else {
-                fileIcon.setImageResource(MimeTypeUtil.getFileTypeIconId(
-                        upload.getMimeType(),
-                        fileName
-                ));
+                fileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(upload.getMimeType(), fileName, account));
             }
-
         }
 
         return view;

+ 3 - 1
src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -414,7 +414,9 @@ public class FileListListAdapter extends BaseAdapter {
 
 
                 } else {
-                    fileIcon.setImageResource(MimeTypeUtil.getFileTypeIconId(file.getMimetype(), file.getFileName()));
+                    fileIcon.setImageDrawable(
+                            MimeTypeUtil.getFileTypeIcon(file.getMimetype(), file.getFileName(), mAccount)
+                    );
                 }
 
 

+ 3 - 1
src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java

@@ -228,7 +228,9 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
                         } // else, already being generated, don't restart it
                     }
                 } else {
-                    fileIcon.setImageResource(MimeTypeUtil.getFileTypeIconId(null, file.getName()));
+                    fileIcon.setImageDrawable(
+                            MimeTypeUtil.getFileTypeIcon(null, file.getName(), null)
+                    );
                 }  
 
             } else {

+ 2 - 2
src/main/java/com/owncloud/android/ui/adapter/UploaderAdapter.java

@@ -126,8 +126,8 @@ public class UploaderAdapter extends SimpleAdapter {
                     }
                 }
             } else {
-                fileIcon.setImageResource(
-                        MimeTypeUtil.getFileTypeIconId(file.getMimetype(), file.getFileName())
+                fileIcon.setImageDrawable(
+                        MimeTypeUtil.getFileTypeIcon(file.getMimetype(), file.getFileName(), mAccount)
                 );
             }
         }

+ 2 - 4
src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -470,9 +470,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
         if (iv != null) {
             iv.setTag(file.getFileId());
             // Name of the file, to deduce the icon to use in case the MIME type is not precise enough
-            String filename = file.getFileName();
-            int resource = MimeTypeUtil.getFileTypeIconId(mimetype, filename);
-            iv.setImageResource(resource);
+            iv.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimetype(), file.getFileName(), mAccount));
 
             Bitmap thumbnail;
 
@@ -503,7 +501,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
                     }
                 }
             } else {
-                iv.setImageResource(resource);
+                iv.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimetype(), file.getFileName(), mAccount));
 			}
         }
     }

+ 3 - 2
src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java

@@ -206,8 +206,9 @@ public class ShareFileFragment extends Fragment implements ShareUserListAdapter.
         // Setup layout
         // Image
         ImageView icon = (ImageView) view.findViewById(R.id.shareFileIcon);
-        icon.setImageResource(MimeTypeUtil.getFileTypeIconId(mFile.getMimetype(),
-                mFile.getFileName()));
+        icon.setImageDrawable(
+                MimeTypeUtil.getFileTypeIcon(mFile.getMimetype(), mFile.getFileName(), mAccount)
+        );
         if (MimeTypeUtil.isImage(mFile)) {
             String remoteId = String.valueOf(mFile.getRemoteId());
             Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId);

+ 31 - 0
src/main/java/com/owncloud/android/utils/MimeTypeUtil.java

@@ -23,6 +23,7 @@ import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.webkit.MimeTypeMap;
 
+import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
 
@@ -71,6 +72,36 @@ public class MimeTypeUtil {
         populateMainMimeTypeMapping();
     }
 
+    /**
+     * Returns the Drawable of an image to use as icon associated to a known MIME type.
+     *
+     * @param mimetype MIME type string; if NULL, the method tries to guess it from the extension in filename
+     * @param filename Name, with extension.
+     * @return Drawable of an image resource.
+     */
+    public static Drawable getFileTypeIcon(String mimetype, String filename) {
+        return getFileTypeIcon(mimetype, filename, null);
+    }
+
+    /**
+     * Returns the Drawable of an image to use as icon associated to a known MIME type.
+     *
+     * @param mimetype MIME type string; if NULL, the method tries to guess it from the extension in filename
+     * @param filename Name, with extension.
+     * @param account account which color should be used
+     * @return Drawable of an image resource.
+     */
+    public static Drawable getFileTypeIcon(String mimetype, String filename, Account account) {
+        int iconId = MimeTypeUtil.getFileTypeIconId(mimetype, filename);
+        Drawable icon = MainApp.getAppContext().getResources().getDrawable(iconId);
+
+        if(R.drawable.file_zip == iconId) {
+            ThemeUtils.tintDrawable(icon, ThemeUtils.primaryColor(account));
+        }
+
+        return icon;
+    }
+
     /**
      * Returns the resource identifier of an image to use as icon associated to a known MIME type.
      *