Bladeren bron

Merge pull request #2686 from nextcloud/correctException

Use correct exception
Andy Scherzinger 6 jaren geleden
bovenliggende
commit
9d963cec33

+ 3 - 5
src/main/java/com/owncloud/android/ui/TextDrawable.java

@@ -99,7 +99,7 @@ public class TextDrawable extends Drawable {
     @NonNull
     @NextcloudServer(max = 12)
     public static TextDrawable createAvatar(String accountName, float radiusInDp) throws
-            UnsupportedEncodingException, NoSuchAlgorithmException {
+            NoSuchAlgorithmException {
         String username = AccountUtils.getAccountUsername(accountName);
         return createNamedAvatar(username, radiusInDp);
     }
@@ -117,7 +117,7 @@ public class TextDrawable extends Drawable {
     @NonNull
     @NextcloudServer(max = 12)
     public static TextDrawable createAvatarByUserId(String userId, float radiusInDp) throws
-            UnsupportedEncodingException, NoSuchAlgorithmException {
+            NoSuchAlgorithmException {
         return createNamedAvatar(userId, radiusInDp);
     }
 
@@ -128,12 +128,10 @@ public class TextDrawable extends Drawable {
      * @param name       the name
      * @param radiusInDp the circle's radius
      * @return the avatar as a TextDrawable
-     * @throws UnsupportedEncodingException if the charset is not supported when calculating the color values
      * @throws NoSuchAlgorithmException     if the specified algorithm is not available when calculating the color values
      */
     @NonNull
-    public static TextDrawable createNamedAvatar(String name, float radiusInDp) throws
-            UnsupportedEncodingException, NoSuchAlgorithmException {
+    public static TextDrawable createNamedAvatar(String name, float radiusInDp) throws NoSuchAlgorithmException {
         int[] hsl = BitmapUtils.calculateHSL(name);
         int[] rgb = BitmapUtils.HSLtoRGB(hsl[0], hsl[1], hsl[2], 1);
 

+ 3 - 4
src/main/java/com/owncloud/android/ui/adapter/ShareUserListAdapter.java

@@ -34,7 +34,6 @@ import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.ui.TextDrawable;
 
-import java.io.UnsupportedEncodingException;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 
@@ -95,20 +94,20 @@ public class ShareUserListAdapter extends ArrayAdapter {
                 name = getContext().getString(R.string.share_group_clarification, name);
                 try {
                     icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                } catch (NoSuchAlgorithmException e) {
                     icon.setImageResource(R.drawable.ic_group);
                 }
             } else if (share.getShareType() == ShareType.EMAIL) {
                 name = getContext().getString(R.string.share_email_clarification, name);
                 try {
                     icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                } catch (NoSuchAlgorithmException e) {
                     icon.setImageResource(R.drawable.ic_email);
                 }
             } else {
                 try {
                     icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                } catch (NoSuchAlgorithmException e) {
                     icon.setImageResource(R.drawable.ic_user);
                 }
             }

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

@@ -50,7 +50,6 @@ import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.ThemeUtils;
 
-import java.io.UnsupportedEncodingException;
 import java.security.NoSuchAlgorithmException;
 import java.util.List;
 
@@ -106,14 +105,14 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.UserVi
                 name = context.getString(R.string.share_group_clarification, name);
                 try {
                     holder.avatar.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                } catch (NoSuchAlgorithmException e) {
                     holder.avatar.setImageResource(R.drawable.ic_group);
                 }
             } else if (share.getShareType() == ShareType.EMAIL) {
                 name = context.getString(R.string.share_email_clarification, name);
                 try {
                     holder.avatar.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                } catch (NoSuchAlgorithmException e) {
                     holder.avatar.setImageResource(R.drawable.ic_email);
                 }
             } else {

+ 5 - 14
src/main/java/com/owncloud/android/utils/BitmapUtils.java

@@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 
 import org.apache.commons.codec.binary.Hex;
 
-import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Locale;
@@ -269,10 +268,9 @@ public class BitmapUtils {
      *
      * @param name The name
      * @return corresponding RGB color
-     * @throws UnsupportedEncodingException if the charset is not supported
      * @throws NoSuchAlgorithmException     if the specified algorithm is not available
      */
-    public static int[] calculateHSL(String name) throws UnsupportedEncodingException, NoSuchAlgorithmException {
+    public static int[] calculateHSL(String name) throws NoSuchAlgorithmException {
         // using adapted algorithm from https://github.com/nextcloud/server/blob/master/core/js/placeholder.js#L126
 
         String[] result = new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
@@ -352,18 +350,11 @@ public class BitmapUtils {
         return hsl;
     }
 
-    public static String md5(String string) {
-        try {
-            MessageDigest md5 = MessageDigest.getInstance("MD5");
-            md5.update(string.getBytes());
-
-            return new String(Hex.encodeHex(md5.digest()));
-
-        } catch (Exception e) {
-            Log_OC.e(TAG, e.getMessage());
-        }
+    public static String md5(String string) throws NoSuchAlgorithmException {
+        MessageDigest md5 = MessageDigest.getInstance("MD5");
+        md5.update(string.getBytes());
 
-        return "";
+        return new String(Hex.encodeHex(md5.digest()));
     }
 
     /**