Merge pull request #6400 from nextcloud/themeIconImagesWithUnicolorBackgrounds

Add theming logic for share link icons
This commit is contained in:
Tobias Kaminsky 2020-07-02 13:55:14 +02:00 committed by GitHub
commit 1126823db9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 19 deletions

View file

@ -23,13 +23,12 @@
package com.owncloud.android.ui.adapter;
import android.content.Context;
import android.graphics.PorterDuff;
import android.text.TextUtils;
import android.view.View;
import com.owncloud.android.R;
import com.owncloud.android.databinding.FileDetailsSharePublicLinkItemBinding;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.utils.ThemeUtils;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@ -52,15 +51,8 @@ class PublicShareViewHolder extends RecyclerView.ViewHolder {
if (!TextUtils.isEmpty(publicShare.getLabel())) {
binding.publicShareLabel.setText(publicShare.getLabel());
}
binding.copyInternalLinkIcon
.getBackground()
.setColorFilter(context.getResources().getColor(R.color.primary_button_background_color),
PorterDuff.Mode.SRC_IN);
binding.copyInternalLinkIcon
.getDrawable()
.mutate()
.setColorFilter(context.getResources().getColor(R.color.black),
PorterDuff.Mode.SRC_IN);
ThemeUtils.colorIconImageViewWithBackground(binding.copyInternalLinkIcon, context);
binding.shareLinkCopyIcon.setOnClickListener(v -> listener.copyLink(publicShare));

View file

@ -688,15 +688,9 @@ public final class ThemeUtils {
public static void colorFloatingActionButton(FloatingActionButton button, @DrawableRes int drawable,
Context context) {
int primaryColor = ThemeUtils.primaryColor(null, true, false, context);
colorFloatingActionButton(button, context, primaryColor);
if (Color.BLACK == primaryColor) {
button.setImageDrawable(ThemeUtils.tintDrawable(drawable, Color.WHITE));
} else if (Color.WHITE == primaryColor) {
button.setImageDrawable(ThemeUtils.tintDrawable(drawable, Color.BLACK));
} else {
button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.fontColor(context, false)));
}
colorFloatingActionButton(button, context, primaryColor);
button.setImageDrawable(ThemeUtils.tintDrawable(drawable, getColorForPrimary(primaryColor, context)));
}
public static void colorFloatingActionButton(FloatingActionButton button, Context context) {
@ -712,6 +706,29 @@ public final class ThemeUtils {
button.setRippleColor(rippleColor);
}
public static void colorIconImageViewWithBackground(ImageView imageView, Context context) {
int primaryColor = ThemeUtils.primaryColor(null, true, false, context);
imageView.getBackground().setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN);
imageView.getDrawable().mutate().setColorFilter(getColorForPrimary(primaryColor, context),
PorterDuff.Mode.SRC_IN);
}
/**
* returns a primary color matching color for texts/icons on top of a primary-colored element (like buttons).
*
* @param primaryColor the primary color
*/
private static int getColorForPrimary(int primaryColor, Context context) {
if (Color.BLACK == primaryColor) {
return Color.WHITE;
} else if (Color.WHITE == primaryColor) {
return Color.BLACK;
} else {
return ThemeUtils.fontColor(context, false);
}
}
private static OCCapability getCapability(Context context) {
return getCapability(null, context);
}