From 7f85bffa9399f7fd68ae6775ddb8c00781cbbb88 Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Sun, 20 May 2018 19:34:34 +0200 Subject: [PATCH] fix codacy + revert to handling name-to-color exceptions --- .../com/owncloud/android/ui/TextDrawable.java | 11 ++++++--- .../ui/activity/FileDisplayActivity.java | 8 +++---- .../ui/adapter/ShareUserListAdapter.java | 23 +++++++++++++++---- .../android/ui/adapter/UserListAdapter.java | 14 +++++++++-- .../fragment/FileDetailSharingFragment.java | 11 --------- .../util/FileDetailSharingFragmentHelper.java | 2 -- 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/TextDrawable.java b/src/main/java/com/owncloud/android/ui/TextDrawable.java index b488783ec1..2ba8c563e2 100644 --- a/src/main/java/com/owncloud/android/ui/TextDrawable.java +++ b/src/main/java/com/owncloud/android/ui/TextDrawable.java @@ -97,7 +97,8 @@ public class TextDrawable extends Drawable { */ @NonNull @NextcloudServer(max = 12) - public static TextDrawable createAvatar(String accountName, float radiusInDp) { + public static TextDrawable createAvatar(String accountName, float radiusInDp) throws + UnsupportedEncodingException, NoSuchAlgorithmException { String username = AccountUtils.getAccountUsername(accountName); return createNamedAvatar(username, radiusInDp); } @@ -114,7 +115,8 @@ public class TextDrawable extends Drawable { */ @NonNull @NextcloudServer(max = 12) - public static TextDrawable createAvatarByUserId(String userId, float radiusInDp) { + public static TextDrawable createAvatarByUserId(String userId, float radiusInDp) throws + UnsupportedEncodingException, NoSuchAlgorithmException { return createNamedAvatar(userId, radiusInDp); } @@ -125,9 +127,12 @@ 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) { + public static TextDrawable createNamedAvatar(String name, float radiusInDp) throws + UnsupportedEncodingException, NoSuchAlgorithmException { int[] hsl = BitmapUtils.calculateHSL(name); int[] rgb = BitmapUtils.HSLtoRGB(hsl[0], hsl[1], hsl[2], 1); diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 0e76cc81eb..7555449d22 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1895,11 +1895,9 @@ public class FileDisplayActivity extends HookActivity private void onUpdateSharePermissionsFinished(RemoteOperationResult result) { Fragment fileDetailFragment = getSecondFragment(); - if (result.isSuccess()) { - if (fileDetailFragment instanceof FileDetailFragment) { - ((FileDetailFragment) fileDetailFragment).getFileDetailSharingFragment() - .onUpdateSharePermissionsFinished(result); - } + if (result.isSuccess() && fileDetailFragment instanceof FileDetailFragment) { + ((FileDetailFragment) fileDetailFragment).getFileDetailSharingFragment() + .onUpdateSharePermissionsFinished(result); } } diff --git a/src/main/java/com/owncloud/android/ui/adapter/ShareUserListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/ShareUserListAdapter.java index 125a0c4abb..f8c24fe185 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/ShareUserListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/ShareUserListAdapter.java @@ -1,4 +1,4 @@ -/** +/* * ownCloud Android client application * * @author masensio @@ -34,6 +34,8 @@ 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; /** @@ -91,12 +93,25 @@ public class ShareUserListAdapter extends ArrayAdapter { String name = share.getSharedWithDisplayName(); if (share.getShareType() == ShareType.GROUP) { name = getContext().getString(R.string.share_group_clarification, name); - icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension)); + try { + icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension)); + } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { + icon.setImageResource(R.drawable.ic_group); + } } else if (share.getShareType() == ShareType.EMAIL) { name = getContext().getString(R.string.share_email_clarification, name); - icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension)); + try { + icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension)); + } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { + icon.setImageResource(R.drawable.ic_email); + } } else { - icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension)); + try { + + icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension)); + } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { + icon.setImageResource(R.drawable.ic_user); + } } userName.setText(name); diff --git a/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java index c2bd3aa79f..812b220573 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java @@ -45,6 +45,8 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.ui.TextDrawable; import com.owncloud.android.utils.DisplayUtils; +import java.io.UnsupportedEncodingException; +import java.security.NoSuchAlgorithmException; import java.util.ArrayList; /** @@ -109,10 +111,18 @@ public class UserListAdapter extends ArrayAdapter implements DisplayUtils.Avatar String name = share.getSharedWithDisplayName(); if (share.getShareType() == ShareType.GROUP) { name = getContext().getString(R.string.share_group_clarification, name); - icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension)); + try { + icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension)); + } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { + icon.setImageResource(R.drawable.ic_group); + } } else if (share.getShareType() == ShareType.EMAIL) { name = getContext().getString(R.string.share_email_clarification, name); - icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension)); + try { + icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension)); + } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { + icon.setImageResource(R.drawable.ic_email); + } } else { icon.setTag(share.getShareWith()); DisplayUtils.setAvatar(account, share.getShareWith(), this, avatarRadiusDimension, diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index c7f2787e35..814a99b893 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -30,44 +30,34 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; -import android.support.v7.widget.AppCompatCheckBox; import android.support.v7.widget.SearchView; -import android.support.v7.widget.SwitchCompat; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ListAdapter; import android.widget.ListView; import android.widget.PopupMenu; import android.widget.TextView; import com.owncloud.android.R; -import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.SharePermissionsBuilder; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.status.OCCapability; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.adapter.UserListAdapter; import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment; import com.owncloud.android.ui.dialog.SharePasswordDialogFragment; import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper; -import com.owncloud.android.utils.ThemeUtils; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import butterknife.BindView; import butterknife.ButterKnife; @@ -75,7 +65,6 @@ import butterknife.OnClick; import butterknife.Unbinder; public class FileDetailSharingFragment extends Fragment implements UserListAdapter.ShareeListAdapterListener { - private static final String TAG = FileDetailSharingFragment.class.getSimpleName(); private static final String ARG_FILE = "FILE"; private static final String ARG_ACCOUNT = "ACCOUNT"; diff --git a/src/main/java/com/owncloud/android/ui/fragment/util/FileDetailSharingFragmentHelper.java b/src/main/java/com/owncloud/android/ui/fragment/util/FileDetailSharingFragmentHelper.java index 7d4e381f03..f10dd83638 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/util/FileDetailSharingFragmentHelper.java +++ b/src/main/java/com/owncloud/android/ui/fragment/util/FileDetailSharingFragmentHelper.java @@ -22,7 +22,6 @@ package com.owncloud.android.ui.fragment.util; import android.app.SearchManager; import android.content.ComponentName; -import android.content.Context; import android.content.res.Resources; import android.support.v7.widget.SearchView; import android.view.MenuItem; @@ -33,7 +32,6 @@ import android.widget.ListAdapter; import android.widget.ListView; import com.owncloud.android.R; -import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.status.OCCapability;