Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7a95e4b authored by Lucas Silva's avatar Lucas Silva
Browse files

Fix bug where not all views are getting disabled alpha applied.

This ensures that we apply the alpha recursively to all views when the
item is disabled/enabled.

Bug: 226573932
Test: locally on device
Change-Id: I28ee1a21227706d01a6e4f6284871bf78af983f5
parent d191a16c
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@

<selector xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
    <item android:state_enabled="false" android:color="?androidprv:attr/colorSurface"
          android:alpha="?android:attr/disabledAlpha"/>
    <item android:state_selected="true" android:color="?androidprv:attr/colorAccentPrimary"/>
    <item android:color="?androidprv:attr/colorSurface"/>
</selector>
 No newline at end of file
+0 −2
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@

<selector xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
    <item android:state_enabled="false" android:color="?android:attr/textColorPrimary"
          android:alpha="?android:attr/disabledAlpha"/>
    <item android:state_selected="true" android:color="?androidprv:attr/textColorOnAccent"/>
    <item android:color="?android:attr/textColorPrimary"/>
</selector>
 No newline at end of file
+4 −9
Original line number Diff line number Diff line
@@ -50,14 +50,13 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
     * View holder for each {@link IDreamItem}.
     */
    private class DreamViewHolder extends RecyclerView.ViewHolder {
        private static final int VALUE_ENABLED_ALPHA = 255;
        private final TextView mTitleView;
        private final TextView mSummaryView;
        private final ImageView mPreviewView;
        private final ImageView mPreviewPlaceholderView;
        private final Button mCustomizeButton;
        private final Context mContext;
        private final int mDisabledAlphaValue;
        private final float mDisabledAlphaValue;

        DreamViewHolder(View view, Context context) {
            super(view);
@@ -67,7 +66,7 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
            mTitleView = view.findViewById(R.id.title_text);
            mSummaryView = view.findViewById(R.id.summary_text);
            mCustomizeButton = view.findViewById(R.id.customize_button);
            mDisabledAlphaValue = (int) (ColorUtil.getDisabledAlpha(context) * VALUE_ENABLED_ALPHA);
            mDisabledAlphaValue = ColorUtil.getDisabledAlpha(context);
        }

        /**
@@ -93,7 +92,6 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
                mPreviewView.setImageDrawable(null);
                mPreviewPlaceholderView.setVisibility(View.VISIBLE);
            }
            mPreviewView.setImageAlpha(getAlpha());

            final Drawable icon = item.isActive()
                    ? mContext.getDrawable(R.drawable.ic_dream_check_circle)
@@ -105,7 +103,6 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
            final int iconSize = mContext.getResources().getDimensionPixelSize(
                    R.dimen.dream_item_icon_size);
            icon.setBounds(0, 0, iconSize, iconSize);
            icon.setAlpha(getAlpha());
            mTitleView.setCompoundDrawablesRelative(icon, null, null, null);

            if (item.isActive()) {
@@ -130,10 +127,6 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
            setEnabledStateOnViews(itemView, mEnabled);
        }

        private int getAlpha() {
            return mEnabled ? VALUE_ENABLED_ALPHA : mDisabledAlphaValue;
        }

        /**
         * Makes sure the view (and any children) get the enabled state changed.
         */
@@ -145,6 +138,8 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
                for (int i = vg.getChildCount() - 1; i >= 0; i--) {
                    setEnabledStateOnViews(vg.getChildAt(i), enabled);
                }
            } else {
                v.setAlpha(enabled ? 1 : mDisabledAlphaValue);
            }
        }
    }