mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +03:00
Replace ThemeAvatarUtils with common material3 utils
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
e969024a11
commit
b3a4a5f29f
13 changed files with 102 additions and 174 deletions
|
@ -355,7 +355,7 @@ dependencies {
|
|||
gplayImplementation "com.google.firebase:firebase-messaging:23.0.7"
|
||||
|
||||
// TODO change back to tag before merging
|
||||
implementation 'com.github.nextcloud.android-common:ui:f02df7f'
|
||||
implementation 'com.github.nextcloud.android-common:ui:8d8cd09'
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
|
|
|
@ -22,7 +22,6 @@ package com.nextcloud.client.di
|
|||
|
||||
import android.content.Context
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils
|
||||
import com.owncloud.android.utils.theme.ThemeSnackbarUtils
|
||||
|
@ -78,12 +77,6 @@ internal abstract class ThemeModule {
|
|||
return ThemeSnackbarUtils()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun themeAvatarUtils(): ThemeAvatarUtils {
|
||||
return ThemeAvatarUtils()
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideMaterialSchemes(materialSchemesProvider: MaterialSchemesProvider): MaterialSchemes {
|
||||
return materialSchemesProvider.getMaterialSchemesForCurrentUser()
|
||||
|
|
|
@ -38,9 +38,8 @@ import com.owncloud.android.R;
|
|||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.shares.ShareeUser;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
||||
import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -86,9 +85,8 @@ public class AvatarGroupLayout extends RelativeLayout implements DisplayUtils.Av
|
|||
|
||||
public void setAvatars(@NonNull User user,
|
||||
@NonNull List<ShareeUser> sharees,
|
||||
ThemeColorUtils themeColorUtils,
|
||||
ThemeDrawableUtils themeDrawableUtils,
|
||||
ThemeAvatarUtils themeAvatarUtils) {
|
||||
final ViewThemeUtils viewThemeUtils) {
|
||||
@NonNull Context context = getContext();
|
||||
removeAllViews();
|
||||
RelativeLayout.LayoutParams avatarLayoutParams;
|
||||
|
@ -122,7 +120,7 @@ public class AvatarGroupLayout extends RelativeLayout implements DisplayUtils.Av
|
|||
case EMAIL:
|
||||
case ROOM:
|
||||
case CIRCLE:
|
||||
themeAvatarUtils.createAvatar(sharee.getShareType(), avatar, context, themeColorUtils);
|
||||
viewThemeUtils.files.createAvatar(sharee.getShareType(), avatar, context);
|
||||
break;
|
||||
case FEDERATED:
|
||||
showFederatedShareAvatar(context,
|
||||
|
|
|
@ -35,8 +35,7 @@ import com.owncloud.android.databinding.FileDetailsShareLinkShareItemBinding;
|
|||
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.ui.fragment.util.SharingMenuHelper;
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
@ -45,8 +44,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
class LinkShareViewHolder extends RecyclerView.ViewHolder {
|
||||
private FileDetailsShareLinkShareItemBinding binding;
|
||||
private Context context;
|
||||
private ThemeColorUtils themeColorUtils;
|
||||
private ThemeAvatarUtils themeAvatarUtils;
|
||||
private ViewThemeUtils viewThemeUtils;
|
||||
|
||||
public LinkShareViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
@ -54,13 +52,11 @@ class LinkShareViewHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
public LinkShareViewHolder(FileDetailsShareLinkShareItemBinding binding,
|
||||
Context context,
|
||||
ThemeColorUtils themeColorUtils,
|
||||
ThemeAvatarUtils themeAvatarUtils) {
|
||||
final ViewThemeUtils viewThemeUtils) {
|
||||
this(binding.getRoot());
|
||||
this.binding = binding;
|
||||
this.context = context;
|
||||
this.themeColorUtils = themeColorUtils;
|
||||
this.themeAvatarUtils = themeAvatarUtils;
|
||||
this.viewThemeUtils = viewThemeUtils;
|
||||
}
|
||||
|
||||
public void bind(OCShare publicShare, ShareeListAdapterListener listener) {
|
||||
|
@ -83,7 +79,7 @@ class LinkShareViewHolder extends RecyclerView.ViewHolder {
|
|||
binding.name.setText(R.string.share_link);
|
||||
}
|
||||
|
||||
themeAvatarUtils.colorIconImageViewWithBackground(binding.icon, context, themeColorUtils);
|
||||
viewThemeUtils.platform.colorImageViewBackgroundAndIcon(binding.icon);
|
||||
}
|
||||
|
||||
String permissionName = SharingMenuHelper.getPermissionName(context, publicShare);
|
||||
|
|
|
@ -76,9 +76,9 @@ import com.owncloud.android.utils.FileSortOrder;
|
|||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
import com.owncloud.android.utils.theme.CapabilityUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
||||
import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -133,7 +133,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", Locale.getDefault());
|
||||
private final ThemeColorUtils themeColorUtils;
|
||||
private final ThemeDrawableUtils themeDrawableUtils;
|
||||
private final ThemeAvatarUtils themeAvatarUtils;
|
||||
private final ViewThemeUtils viewThemeUtils;
|
||||
private SearchType searchType;
|
||||
|
||||
public OCFileListAdapter(
|
||||
|
@ -146,8 +146,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
boolean gridView,
|
||||
ThemeColorUtils themeColorUtils,
|
||||
ThemeDrawableUtils themeDrawableUtils,
|
||||
ThemeAvatarUtils themeAvatarUtils
|
||||
) {
|
||||
final ViewThemeUtils viewThemeUtils) {
|
||||
this.ocFileListFragmentInterface = ocFileListFragmentInterface;
|
||||
this.activity = activity;
|
||||
this.preferences = preferences;
|
||||
|
@ -167,7 +166,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
|
||||
this.themeColorUtils = themeColorUtils;
|
||||
this.themeDrawableUtils = themeDrawableUtils;
|
||||
this.themeAvatarUtils = themeAvatarUtils;
|
||||
this.viewThemeUtils = viewThemeUtils;
|
||||
|
||||
ocFileListDelegate = new OCFileListDelegate(activity,
|
||||
ocFileListFragmentInterface,
|
||||
|
@ -416,7 +415,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
|
||||
Log_OC.d(this, "sharees of " + file.getFileName() + ": " + sharees);
|
||||
|
||||
holder.getSharedAvatars().setAvatars(user, sharees,themeColorUtils, themeDrawableUtils, themeAvatarUtils);
|
||||
holder.getSharedAvatars().setAvatars(user, sharees, themeDrawableUtils, viewThemeUtils);
|
||||
holder.getSharedAvatars().setOnClickListener(
|
||||
view -> ocFileListFragmentInterface.onShareIconClick(file));
|
||||
} else {
|
||||
|
|
|
@ -36,8 +36,7 @@ import com.owncloud.android.lib.resources.shares.OCShare;
|
|||
import com.owncloud.android.ui.TextDrawable;
|
||||
import com.owncloud.android.ui.fragment.util.SharingMenuHelper;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -48,8 +47,7 @@ class ShareViewHolder extends RecyclerView.ViewHolder {
|
|||
private float avatarRadiusDimension;
|
||||
private User user;
|
||||
private Context context;
|
||||
private ThemeColorUtils themeColorUtils;
|
||||
private ThemeAvatarUtils themeAvatarUtils;
|
||||
private ViewThemeUtils viewThemeUtils;
|
||||
|
||||
public ShareViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
@ -58,14 +56,12 @@ class ShareViewHolder extends RecyclerView.ViewHolder {
|
|||
public ShareViewHolder(FileDetailsShareShareItemBinding binding,
|
||||
User user,
|
||||
Context context,
|
||||
ThemeColorUtils themeColorUtils,
|
||||
ThemeAvatarUtils themeAvatarUtils) {
|
||||
final ViewThemeUtils viewThemeUtils) {
|
||||
this(binding.getRoot());
|
||||
this.binding = binding;
|
||||
this.user = user;
|
||||
this.context = context;
|
||||
this.themeColorUtils = themeColorUtils;
|
||||
this.themeAvatarUtils = themeAvatarUtils;
|
||||
this.viewThemeUtils = viewThemeUtils;
|
||||
}
|
||||
|
||||
public void bind(OCShare share,
|
||||
|
@ -80,14 +76,14 @@ class ShareViewHolder extends RecyclerView.ViewHolder {
|
|||
switch (share.getShareType()) {
|
||||
case GROUP:
|
||||
name = context.getString(R.string.share_group_clarification, name);
|
||||
themeAvatarUtils.createAvatar(share.getShareType(), binding.icon, context, themeColorUtils);
|
||||
viewThemeUtils.files.createAvatar(share.getShareType(), binding.icon, context);
|
||||
break;
|
||||
case ROOM:
|
||||
name = context.getString(R.string.share_room_clarification, name);
|
||||
themeAvatarUtils.createAvatar(share.getShareType(), binding.icon, context, themeColorUtils);
|
||||
viewThemeUtils.files.createAvatar(share.getShareType(), binding.icon, context);
|
||||
break;
|
||||
case CIRCLE:
|
||||
themeAvatarUtils.createAvatar(share.getShareType(), binding.icon, context, themeColorUtils);
|
||||
viewThemeUtils.files.createAvatar(share.getShareType(), binding.icon, context);
|
||||
break;
|
||||
case FEDERATED:
|
||||
name = context.getString(R.string.share_remote_clarification, name);
|
||||
|
|
|
@ -40,8 +40,7 @@ import com.owncloud.android.lib.resources.shares.OCShare;
|
|||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -62,23 +61,20 @@ public class ShareeListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
private final float avatarRadiusDimension;
|
||||
private final String userId;
|
||||
private final User user;
|
||||
private final ThemeColorUtils themeColorUtils;
|
||||
private final ThemeAvatarUtils themeAvatarUtils;
|
||||
private final ViewThemeUtils viewThemeUtils;
|
||||
|
||||
public ShareeListAdapter(FileActivity fileActivity,
|
||||
List<OCShare> shares,
|
||||
ShareeListAdapterListener listener,
|
||||
String userId,
|
||||
User user,
|
||||
ThemeColorUtils themeColorUtils,
|
||||
ThemeAvatarUtils themeAvatarUtils) {
|
||||
final ViewThemeUtils viewThemeUtils) {
|
||||
this.fileActivity = fileActivity;
|
||||
this.shares = shares;
|
||||
this.listener = listener;
|
||||
this.userId = userId;
|
||||
this.user = user;
|
||||
this.themeColorUtils = themeColorUtils;
|
||||
this.themeAvatarUtils = themeAvatarUtils;
|
||||
this.viewThemeUtils = viewThemeUtils;
|
||||
|
||||
avatarRadiusDimension = fileActivity.getResources().getDimension(R.dimen.user_icon_radius);
|
||||
|
||||
|
@ -101,8 +97,7 @@ public class ShareeListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
parent,
|
||||
false),
|
||||
fileActivity,
|
||||
themeColorUtils,
|
||||
themeAvatarUtils);
|
||||
viewThemeUtils);
|
||||
case NEW_PUBLIC_LINK:
|
||||
return new NewLinkShareViewHolder(
|
||||
FileDetailsSharePublicLinkAddNewItemBinding.inflate(LayoutInflater.from(fileActivity),
|
||||
|
@ -119,8 +114,7 @@ public class ShareeListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
false),
|
||||
user,
|
||||
fileActivity,
|
||||
themeColorUtils,
|
||||
themeAvatarUtils);
|
||||
viewThemeUtils);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,11 +61,11 @@ import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper;
|
|||
import com.owncloud.android.ui.helpers.FileOperationsHelper;
|
||||
import com.owncloud.android.utils.ClipboardUtil;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeSnackbarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
|
||||
import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -105,7 +105,7 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|||
@Inject ThemeToolbarUtils themeToolbarUtils;
|
||||
@Inject ThemeSnackbarUtils themeSnackbarUtils;
|
||||
@Inject ThemeDrawableUtils themeDrawableUtils;
|
||||
@Inject ThemeAvatarUtils themeAvatarUtils;
|
||||
@Inject ViewThemeUtils viewThemeUtils;
|
||||
|
||||
public static FileDetailSharingFragment newInstance(OCFile file, User user) {
|
||||
FileDetailSharingFragment fragment = new FileDetailSharingFragment();
|
||||
|
@ -171,8 +171,7 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|||
this,
|
||||
userId,
|
||||
user,
|
||||
themeColorUtils,
|
||||
themeAvatarUtils));
|
||||
viewThemeUtils));
|
||||
binding.sharesList.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
setupView();
|
||||
|
|
|
@ -27,7 +27,6 @@ package com.owncloud.android.ui.fragment;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -43,7 +42,6 @@ import android.view.ViewGroup;
|
|||
import android.widget.AbsListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
@ -109,7 +107,6 @@ import com.owncloud.android.utils.EncryptionUtils;
|
|||
import com.owncloud.android.utils.FileSortOrder;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeUtils;
|
||||
|
@ -198,7 +195,6 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
@Inject ThemeColorUtils themeColorUtils;
|
||||
@Inject ThemeToolbarUtils themeToolbarUtils;
|
||||
@Inject ThemeUtils themeUtils;
|
||||
@Inject ThemeAvatarUtils themeAvatarUtils;
|
||||
@Inject ArbitraryDataProvider arbitraryDataProvider;
|
||||
@Inject BackgroundJobManager backgroundJobManager;
|
||||
@Inject ViewThemeUtils viewThemeUtils;
|
||||
|
@ -428,7 +424,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
isGridViewPreferred(mFile),
|
||||
themeColorUtils,
|
||||
themeDrawableUtils,
|
||||
themeAvatarUtils
|
||||
viewThemeUtils
|
||||
);
|
||||
|
||||
setRecyclerViewAdapter(mAdapter);
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* @author Andy Scherzinger
|
||||
* Copyright (C) 2017 Tobias Kaminsky
|
||||
* Copyright (C) 2017 Nextcloud GmbH
|
||||
* Copyright (C) 2018 Andy Scherzinger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.utils.theme;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
/**
|
||||
* Utility class with methods for client side button theming.
|
||||
*/
|
||||
public final class ThemeAvatarUtils {
|
||||
public void colorIconImageViewWithBackground(ImageView imageView,
|
||||
Context context,
|
||||
ThemeColorUtils themeColorUtils) {
|
||||
int primaryColor = themeColorUtils.primaryColor(null, true, false, context);
|
||||
|
||||
imageView.getBackground().setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN);
|
||||
imageView.getDrawable().mutate().setColorFilter(themeColorUtils.getColorForPrimary(primaryColor, context),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
@SuppressFBWarnings(
|
||||
value = "SF_SWITCH_NO_DEFAULT",
|
||||
justification = "We only create avatars for a subset of share types")
|
||||
public void createAvatar(ShareType type,
|
||||
ImageView avatar,
|
||||
Context context,
|
||||
ThemeColorUtils themeColorUtils) {
|
||||
switch (type) {
|
||||
case GROUP:
|
||||
avatar.setImageResource(R.drawable.ic_group);
|
||||
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
|
||||
R.drawable.round_bgnd,
|
||||
null));
|
||||
avatar.setCropToPadding(true);
|
||||
avatar.setPadding(4, 4, 4, 4);
|
||||
colorIconImageViewWithBackground(avatar, context, themeColorUtils);
|
||||
break;
|
||||
|
||||
case ROOM:
|
||||
avatar.setImageResource(R.drawable.first_run_talk);
|
||||
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
|
||||
R.drawable.round_bgnd,
|
||||
null));
|
||||
avatar.setCropToPadding(true);
|
||||
avatar.setPadding(8, 8, 8, 8);
|
||||
colorIconImageViewWithBackground(avatar, context, themeColorUtils);
|
||||
break;
|
||||
|
||||
case CIRCLE:
|
||||
avatar.setImageResource(R.drawable.ic_circles);
|
||||
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
|
||||
R.drawable.round_bgnd,
|
||||
null));
|
||||
avatar.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
avatar.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
avatar.setCropToPadding(true);
|
||||
avatar.setPadding(4, 4, 4, 4);
|
||||
break;
|
||||
|
||||
case EMAIL:
|
||||
avatar.setImageResource(R.drawable.ic_email);
|
||||
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
|
||||
R.drawable.round_bgnd,
|
||||
null));
|
||||
avatar.setCropToPadding(true);
|
||||
avatar.setPadding(8, 8, 8, 8);
|
||||
avatar.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
avatar.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,15 +22,28 @@
|
|||
|
||||
package com.owncloud.android.utils.theme.newm3
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.PorterDuff
|
||||
import android.preference.PreferenceCategory
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.Px
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import com.nextcloud.android.common.ui.theme.utils.AndroidViewThemeUtils
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.lib.resources.shares.ShareType
|
||||
import javax.inject.Inject
|
||||
|
||||
class FilesSpecificViewThemeUtils @Inject constructor(schemes: MaterialSchemes) : ViewThemeUtilsBase(schemes) {
|
||||
class FilesSpecificViewThemeUtils @Inject constructor(
|
||||
schemes: MaterialSchemes,
|
||||
private val androidViewThemeUtils: AndroidViewThemeUtils
|
||||
) : ViewThemeUtilsBase(schemes) {
|
||||
// not ported to common lib because PreferenceCategory is deprecated
|
||||
fun themePreferenceCategory(category: PreferenceCategory) {
|
||||
withScheme(category.context) {
|
||||
|
@ -44,4 +57,57 @@ class FilesSpecificViewThemeUtils @Inject constructor(schemes: MaterialSchemes)
|
|||
category.title = text
|
||||
}
|
||||
}
|
||||
|
||||
fun createAvatar(type: ShareType?, avatar: ImageView, context: Context) {
|
||||
fun createAvatarBase(@DrawableRes icon: Int, padding: Int = AvatarPadding.SMALL) {
|
||||
avatar.setImageResource(icon)
|
||||
avatar.background = ResourcesCompat.getDrawable(
|
||||
context.resources,
|
||||
R.drawable.round_bgnd,
|
||||
null
|
||||
)
|
||||
avatar.cropToPadding = true
|
||||
avatar.setPadding(padding, padding, padding, padding)
|
||||
}
|
||||
|
||||
// TODO figure out why circle and email use grey background instead of primary
|
||||
when (type) {
|
||||
ShareType.GROUP -> {
|
||||
createAvatarBase(R.drawable.ic_group)
|
||||
androidViewThemeUtils.colorImageViewBackgroundAndIcon(avatar)
|
||||
}
|
||||
ShareType.ROOM -> {
|
||||
createAvatarBase(R.drawable.first_run_talk, AvatarPadding.LARGE)
|
||||
androidViewThemeUtils.colorImageViewBackgroundAndIcon(avatar)
|
||||
}
|
||||
ShareType.CIRCLE -> {
|
||||
createAvatarBase(R.drawable.ic_circles)
|
||||
avatar.background.setColorFilter(
|
||||
context.resources.getColor(R.color.nc_grey),
|
||||
PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
avatar.drawable.mutate().setColorFilter(
|
||||
context.resources.getColor(R.color.icon_on_nc_grey),
|
||||
PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
}
|
||||
ShareType.EMAIL -> {
|
||||
createAvatarBase(R.drawable.ic_email, AvatarPadding.LARGE)
|
||||
androidViewThemeUtils.colorImageViewBackgroundAndIcon(avatar)
|
||||
}
|
||||
else -> Log_OC.d(TAG, "Unknown share type")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = FilesSpecificViewThemeUtils::class.simpleName
|
||||
|
||||
private object AvatarPadding {
|
||||
@Px
|
||||
const val SMALL = 4
|
||||
|
||||
@Px
|
||||
const val LARGE = 8
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,5 +50,5 @@ class ViewThemeUtils @Inject constructor(
|
|||
val dialog = DialogViewThemeUtils(schemes)
|
||||
|
||||
@JvmField
|
||||
val files = FilesSpecificViewThemeUtils(schemes)
|
||||
val files = FilesSpecificViewThemeUtils(schemes, platform)
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@ import com.nextcloud.client.account.AnonymousUser
|
|||
import com.owncloud.android.lib.resources.shares.OCShare
|
||||
import com.owncloud.android.lib.resources.shares.ShareType
|
||||
import com.owncloud.android.ui.activity.FileActivity
|
||||
import com.owncloud.android.utils.theme.ThemeAvatarUtils
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils
|
||||
import com.owncloud.android.utils.theme.newm3.ViewThemeUtils
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
|
@ -43,10 +42,7 @@ class ShareeListAdapterTest {
|
|||
private val fileActivity: FileActivity? = null
|
||||
|
||||
@Mock
|
||||
private lateinit var themeColorUtils: ThemeColorUtils
|
||||
|
||||
@Mock
|
||||
private lateinit var themeAvatarUtils: ThemeAvatarUtils
|
||||
private lateinit var viewThemeUtils: ViewThemeUtils
|
||||
|
||||
private val orderedShares = listOf(
|
||||
OCShare("/1").apply {
|
||||
|
@ -91,8 +87,7 @@ class ShareeListAdapterTest {
|
|||
null,
|
||||
user.accountName,
|
||||
user,
|
||||
themeColorUtils,
|
||||
themeAvatarUtils
|
||||
viewThemeUtils
|
||||
)
|
||||
sut.sortShares()
|
||||
|
||||
|
|
Loading…
Reference in a new issue