From 37bb799efc7331dac10e18ba0293ea753d883872 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 7 Mar 2017 02:28:12 -0500 Subject: [PATCH] Fixes crash when opening the block list. Also, fixes an issue where the collapsed toolbar appears dark on profiles even when using the light theme. --- app/build.gradle | 8 ++--- .../keylesspalace/tusky/AccountActivity.java | 34 ++++++++++++++++--- .../com/keylesspalace/tusky/ThemeUtils.java | 11 ++++-- app/src/main/res/layout/activity_account.xml | 10 ++++-- app/src/main/res/layout/item_blocked_user.xml | 2 +- app/src/main/res/layout/item_follow.xml | 2 +- app/src/main/res/values/attrs.xml | 4 ++- app/src/main/res/values/colors.xml | 2 ++ app/src/main/res/values/styles.xml | 23 ++++++++++++- 9 files changed, 77 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6de288cc..cb9c558c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,11 +25,11 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.1.0' - compile 'com.android.support:recyclerview-v7:25.1.0' - compile 'com.android.support:support-v13:25.1.0' + compile 'com.android.support:appcompat-v7:25.2.0' + compile 'com.android.support:recyclerview-v7:25.2.0' + compile 'com.android.support:support-v13:25.2.0' + compile 'com.android.support:design:25.2.0' compile 'com.android.volley:volley:1.0.0' - compile 'com.android.support:design:25.1.0' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.pkmmte.view:circularimageview:1.1' testCompile 'junit:junit:4.12' diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index 313086b3..7868b4b0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -19,15 +19,16 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; -import android.icu.text.NumberFormat; -import android.media.Image; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.AttrRes; import android.support.annotation.Nullable; +import android.support.design.widget.AppBarLayout; import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; +import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; @@ -42,10 +43,8 @@ import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; -import com.android.volley.toolbox.ImageLoader; import com.android.volley.toolbox.JsonArrayRequest; import com.android.volley.toolbox.JsonObjectRequest; -import com.android.volley.toolbox.NetworkImageView; import com.pkmmte.view.CircularImageView; import com.squareup.picasso.Picasso; @@ -82,7 +81,7 @@ public class AccountActivity extends BaseActivity { accessToken = preferences.getString("accessToken", null); String loggedInAccountId = preferences.getString("loggedInAccountId", null); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); @@ -93,6 +92,31 @@ public class AccountActivity extends BaseActivity { actionBar.setDisplayShowHomeEnabled(true); } + // Add a listener to change the toolbar icon color when it enters/exits its collapsed state. + AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.account_app_bar_layout); + final CollapsingToolbarLayout collapsingToolbar = + (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); + appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { + @AttrRes int priorAttribute = R.attr.account_toolbar_icon_tint_uncollapsed; + + @Override + public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { + @AttrRes int attribute; + if (collapsingToolbar.getHeight() + verticalOffset + < 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) { + attribute = R.attr.account_toolbar_icon_tint_collapsed; + } else { + attribute = R.attr.account_toolbar_icon_tint_uncollapsed; + } + if (attribute != priorAttribute) { + priorAttribute = attribute; + Context context = toolbar.getContext(); + ThemeUtils.setDrawableTint(context, toolbar.getNavigationIcon(), attribute); + ThemeUtils.setDrawableTint(context, toolbar.getOverflowIcon(), attribute); + } + } + }); + FloatingActionButton floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn); floatingBtn.hide(); diff --git a/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java index 01f5476f..da9f1b88 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java @@ -16,10 +16,11 @@ package com.keylesspalace.tusky; import android.content.Context; +import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.AttrRes; -import android.support.annotation.ColorRes; +import android.support.annotation.ColorInt; import android.support.annotation.DrawableRes; import android.support.v4.content.ContextCompat; import android.util.TypedValue; @@ -48,16 +49,20 @@ class ThemeUtils { } } - static @ColorRes int getColor(Context context, @AttrRes int attribute) { + static @ColorInt int getColor(Context context, @AttrRes int attribute) { TypedValue value = new TypedValue(); if (context.getTheme().resolveAttribute(attribute, value, true)) { return value.data; } else { - return android.R.color.black; + return Color.BLACK; } } static void setImageViewTint(ImageView view, @AttrRes int attribute) { view.setColorFilter(getColor(view.getContext(), attribute), PorterDuff.Mode.SRC_IN); } + + static void setDrawableTint(Context context, Drawable drawable, @AttrRes int attribute) { + drawable.setColorFilter(getColor(context, attribute), PorterDuff.Mode.SRC_IN); + } } diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index 3ffb121d..3f838cdc 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -10,8 +10,9 @@ + android:layout_height="wrap_content" + android:theme="@style/AppTheme.Account.AppBarLayout" + android:id="@+id/account_app_bar_layout"> + + + app:layout_collapseMode="pin" + app:popupTheme="?attr/account_toolbar_popup_theme" /> diff --git a/app/src/main/res/layout/item_blocked_user.xml b/app/src/main/res/layout/item_blocked_user.xml index 2c2aa87a..661280c0 100644 --- a/app/src/main/res/layout/item_blocked_user.xml +++ b/app/src/main/res/layout/item_blocked_user.xml @@ -48,7 +48,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/blocked_user_username" - android:textColor="?attr/status_text_color_secondary" /> + android:textColor="?android:textColorSecondary" /> + android:textColor="?android:textColorSecondary" /> - + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 13f0502f..dca7e262 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -30,6 +30,7 @@ #A4B4BC #2f3441 #4C534B + #FFFFFF #000000 #FFFFFF #8F8F8F @@ -65,6 +66,7 @@ #34444C #CFCFCF #9F9F9F + #000000 #EFEFEF #000000 #8F8F8F diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 249a40ae..e0c2cfb9 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,6 +8,12 @@ normal|bold + + + + + +