From 0439fabd79a4d0eaf6e6d018fe34b6d537390c22 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Fri, 17 Feb 2017 23:10:46 -0500 Subject: [PATCH] Fixed a crash under API level 21 on the main timeline due to trying to tint the status buttons with selectors. --- .../keylesspalace/tusky/ComposeActivity.java | 2 + .../com/keylesspalace/tusky/StatusButton.java | 54 ------------------- .../keylesspalace/tusky/StatusViewHolder.java | 30 +++++++---- .../com/keylesspalace/tusky/ThemeUtils.java | 6 +++ .../main/res/color/favourite_button_dark.xml | 7 --- .../main/res/color/favourite_button_light.xml | 7 --- app/src/main/res/color/media_button_dark.xml | 5 -- app/src/main/res/color/media_button_light.xml | 5 -- app/src/main/res/color/reblog_button_dark.xml | 8 --- .../main/res/color/reblog_button_light.xml | 8 --- app/src/main/res/layout/activity_compose.xml | 1 - app/src/main/res/layout/item_status.xml | 8 +-- app/src/main/res/values/attrs.xml | 8 ++- app/src/main/res/values/colors.xml | 14 +++++ app/src/main/res/values/styles.xml | 36 +++++-------- 15 files changed, 67 insertions(+), 132 deletions(-) delete mode 100644 app/src/main/java/com/keylesspalace/tusky/StatusButton.java delete mode 100644 app/src/main/res/color/favourite_button_dark.xml delete mode 100644 app/src/main/res/color/favourite_button_light.xml delete mode 100644 app/src/main/res/color/media_button_dark.xml delete mode 100644 app/src/main/res/color/media_button_light.xml delete mode 100644 app/src/main/res/color/reblog_button_dark.xml delete mode 100644 app/src/main/res/color/reblog_button_light.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 41ef87fa0..b222c91ca 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -626,11 +626,13 @@ public class ComposeActivity extends BaseActivity { private void enableMediaPicking() { mediaPick.setEnabled(true); + ThemeUtils.setImageViewTint(mediaPick, R.attr.compose_media_button_tint); mediaPick.setImageResource(R.drawable.ic_media); } private void disableMediaPicking() { mediaPick.setEnabled(false); + ThemeUtils.setImageViewTint(mediaPick, R.attr.compose_media_button_disabled_tint); mediaPick.setImageResource(R.drawable.ic_media_disabled); } diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusButton.java b/app/src/main/java/com/keylesspalace/tusky/StatusButton.java deleted file mode 100644 index 926c1224d..000000000 --- a/app/src/main/java/com/keylesspalace/tusky/StatusButton.java +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2017 Andrew Dawson - * - * This file is part of Tusky. - * - * Tusky is free software: you can redistribute it and/or modify it under the terms of the GNU - * General Public License as published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Tusky 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 General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Tusky. If not, see - * . */ - -package com.keylesspalace.tusky; - -import android.content.Context; -import android.content.res.TypedArray; -import android.support.v7.widget.AppCompatImageButton; -import android.util.AttributeSet; - -public class StatusButton extends AppCompatImageButton { - private static final int[] STATE_MARKED = { R.attr.state_marked }; - - private boolean marked; - - public StatusButton(Context context, AttributeSet attributeSet) { - super(context, attributeSet); - TypedArray array = context.getTheme().obtainStyledAttributes( - attributeSet, R.styleable.StatusButton, 0, 0); - try { - marked = array.getBoolean(R.styleable.StatusButton_state_marked, false); - } finally { - array.recycle(); - } - } - - @Override - public int[] onCreateDrawableState(int extraSpace) { - if (marked) { - extraSpace += 1; - } - int[] drawableState = super.onCreateDrawableState(extraSpace); - if (marked) { - mergeDrawableStates(drawableState, STATE_MARKED); - } - return drawableState; - } - - public void setMarked(boolean marked) { - this.marked = marked; - } -} diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java index 7ded23d18..3b3e35950 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java @@ -44,8 +44,8 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { private View rebloggedBar; private TextView rebloggedByDisplayName; private ImageButton replyButton; - private StatusButton reblogButton; - private StatusButton favouriteButton; + private ImageButton reblogButton; + private ImageButton favouriteButton; private ImageButton moreButton; private boolean favourited; private boolean reblogged; @@ -71,8 +71,8 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { rebloggedBar = itemView.findViewById(R.id.status_reblogged_bar); rebloggedByDisplayName = (TextView) itemView.findViewById(R.id.status_reblogged); replyButton = (ImageButton) itemView.findViewById(R.id.status_reply); - reblogButton = (StatusButton) itemView.findViewById(R.id.status_reblog); - favouriteButton = (StatusButton) itemView.findViewById(R.id.status_favourite); + reblogButton = (ImageButton) itemView.findViewById(R.id.status_reblog); + favouriteButton = (ImageButton) itemView.findViewById(R.id.status_favourite); moreButton = (ImageButton) itemView.findViewById(R.id.status_more); reblogged = false; favourited = false; @@ -189,21 +189,33 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { public void setReblogged(boolean reblogged) { this.reblogged = reblogged; - reblogButton.setMarked(reblogged); + int attribute; + if (reblogged) { + attribute = R.attr.status_reblog_button_marked_tint; + } else { + attribute = R.attr.status_reblog_button_tint; + } + ThemeUtils.setImageViewTint(reblogButton, attribute); } + /** This should only be called after setReblogged, in order to override the tint correctly. */ public void setRebloggingEnabled(boolean enabled) { reblogButton.setEnabled(enabled); - if (enabled) { - reblogButton.setImageResource(R.drawable.ic_reblog); - } else { + if (!enabled) { + ThemeUtils.setImageViewTint(reblogButton, R.attr.status_reblog_button_disabled_tint); reblogButton.setImageResource(R.drawable.ic_reblog_disabled); } } public void setFavourited(boolean favourited) { this.favourited = favourited; - favouriteButton.setMarked(favourited); + int attribute; + if (favourited) { + attribute = R.attr.status_favourite_button_marked_tint; + } else { + attribute = R.attr.status_favourite_button_tint; + } + ThemeUtils.setImageViewTint(favouriteButton, attribute); } public void setMediaPreviews(final Status.MediaAttachment[] attachments, diff --git a/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java index 8ca916128..8db45facd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java @@ -16,9 +16,11 @@ package com.keylesspalace.tusky; import android.content.Context; +import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.util.TypedValue; +import android.widget.ImageView; public class ThemeUtils { public static Drawable getDrawable(Context context, int attribute, int fallbackDrawable) { @@ -49,4 +51,8 @@ public class ThemeUtils { return android.R.color.black; } } + + public static void setImageViewTint(ImageView view, int attribute) { + view.setColorFilter(getColor(view.getContext(), attribute), PorterDuff.Mode.SRC_IN); + } } diff --git a/app/src/main/res/color/favourite_button_dark.xml b/app/src/main/res/color/favourite_button_dark.xml deleted file mode 100644 index fe6dc5a86..000000000 --- a/app/src/main/res/color/favourite_button_dark.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/color/favourite_button_light.xml b/app/src/main/res/color/favourite_button_light.xml deleted file mode 100644 index c9511a3c1..000000000 --- a/app/src/main/res/color/favourite_button_light.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/color/media_button_dark.xml b/app/src/main/res/color/media_button_dark.xml deleted file mode 100644 index 7f29d8664..000000000 --- a/app/src/main/res/color/media_button_dark.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/color/media_button_light.xml b/app/src/main/res/color/media_button_light.xml deleted file mode 100644 index 73da3f031..000000000 --- a/app/src/main/res/color/media_button_light.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/color/reblog_button_dark.xml b/app/src/main/res/color/reblog_button_dark.xml deleted file mode 100644 index cd05a725a..000000000 --- a/app/src/main/res/color/reblog_button_dark.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/color/reblog_button_light.xml b/app/src/main/res/color/reblog_button_light.xml deleted file mode 100644 index a2fb223c3..000000000 --- a/app/src/main/res/color/reblog_button_light.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_compose.xml b/app/src/main/res/layout/activity_compose.xml index 7fb1ce9ba..e8d732eed 100644 --- a/app/src/main/res/layout/activity_compose.xml +++ b/app/src/main/res/layout/activity_compose.xml @@ -16,7 +16,6 @@ android:layout_height="48dp" app:srcCompat="@drawable/ic_media" style="?attr/image_button_style" - android:tint="?attr/compose_media_button_tint" android:id="@+id/compose_photo_pick" android:layout_marginLeft="8dp" /> diff --git a/app/src/main/res/layout/item_status.xml b/app/src/main/res/layout/item_status.xml index ae9469304..3beb77c12 100644 --- a/app/src/main/res/layout/item_status.xml +++ b/app/src/main/res/layout/item_status.xml @@ -209,10 +209,10 @@ android:layout_height="match_parent" android:layout_weight="1" /> - @@ -221,10 +221,10 @@ android:layout_height="match_parent" android:layout_weight="1" /> - diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index e48b50a9f..f1a251822 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -14,8 +14,11 @@ - - + + + + + @@ -26,6 +29,7 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index dfa06414e..3aaf87694 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -20,12 +20,19 @@ #44A673 #FFFFFF #CFCFCF + #CFCFCF + #00DFAF + #6F6F6F + #CFCFCF + #DFCF00 #303030 #2F2F2F #A4B4BC #000000 #4C534B #000000 + #FFFFFF + #8F8F8F #AFBFCF #9F9F9F #CFCFCF @@ -46,12 +53,19 @@ #f6f7f7 #000000 #2F2F2F + #4F4F4F + #009F6F + #BFBFBF + #4F4F4F + #BFAF00 #B0B0B0 #CFCFCF #34444C #CFCFCF #9F9F9F #EFEFEF + #000000 + #8F8F8F #2F5F6F #7F7F7F #1F1F1F diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 560f19b01..2c8b7246d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -27,8 +27,11 @@ @color/toolbar_background_dark @color/toolbar_icon_dark @style/AppTheme.ImageButton.Dark - @style/AppTheme.ReblogButton.Dark - @style/AppTheme.FavouriteButton.Dark + @color/status_reblog_button_dark + @color/status_reblog_button_marked_dark + @color/status_reblog_button_disabled_dark + @color/status_favourite_button_dark + @color/status_favourite_button_marked_dark @drawable/toggle_small @color/sensitive_media_warning_background_dark @color/status_text_secondary_dark @@ -36,7 +39,8 @@ @drawable/status_divider_dark @drawable/tab_page_margin_dark @color/account_header_background_dark - @color/media_button_dark + @color/compose_media_button_dark + @color/compose_media_button_disabled_dark @color/compose_mention_dark @color/notification_content_faded_dark @color/notification_icon_tint_dark @@ -46,14 +50,6 @@ @color/image_button_dark - - - - - - - -