Migrate MimeTypeUtil.getFileTypeIcon to User model

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2020-07-06 20:46:13 +01:00
parent 6b431a388e
commit eb722457ca
No known key found for this signature in database
GPG key ID: 30D28CA4CCC665C6
3 changed files with 15 additions and 13 deletions

View file

@ -156,7 +156,7 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
thumbnail.setImageDrawable(MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
creator.getExtension(),
user.toPlatformAccount(),
user,
getContext()));
creatorView.setOnClickListener(v -> {

View file

@ -92,8 +92,7 @@ public final class MimeTypeUtil {
* @return Drawable of an image resource.
*/
public static Drawable getFileTypeIcon(String mimetype, String filename, Context context) {
final Account nullAccount = null;
return getFileTypeIcon(mimetype, filename, nullAccount, context);
return getFileTypeIcon(mimetype, filename, null, context);
}
/**
@ -101,18 +100,17 @@ public final class MimeTypeUtil {
*
* @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
* @param user user which color should be used
* @return Drawable of an image resource.
*/
@Nullable
@Deprecated
public static Drawable getFileTypeIcon(String mimetype, String filename, Account account, Context context) {
public static Drawable getFileTypeIcon(String mimetype, String filename, @Nullable User user, Context context) {
if (context != null) {
int iconId = MimeTypeUtil.getFileTypeIconId(mimetype, filename);
Drawable icon = ContextCompat.getDrawable(context, iconId);
if (R.drawable.file_zip == iconId) {
ThemeUtils.tintDrawable(icon, ThemeUtils.primaryColor(account, true, context));
ThemeUtils.tintDrawable(icon, ThemeUtils.primaryColor(user, true, context));
}
return icon;
@ -121,11 +119,6 @@ public final class MimeTypeUtil {
}
}
@Nullable
public static Drawable getFileTypeIcon(String mimetype, String filename, User user, Context context) {
return getFileTypeIcon(mimetype, filename, user.toPlatformAccount(), context);
}
/**
* Returns the resource identifier of an image to use as icon associated to a known MIME type.
*

View file

@ -50,6 +50,7 @@ import com.google.android.material.button.MaterialButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManagerImpl;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
@ -138,7 +139,15 @@ public final class ThemeUtils {
}
public static int primaryColor(Context context, boolean replaceEdgeColors) {
return primaryColor(null, replaceEdgeColors, context);
User nullUser = null;
return primaryColor(nullUser, replaceEdgeColors, context);
}
public static int primaryColor(User user, boolean replaceEdgeColors, Context context) {
return primaryColor(user != null ? user.toPlatformAccount() : null,
replaceEdgeColors,
false,
context);
}
public static int primaryColor(Account account, boolean replaceEdgeColors, Context context) {