From 6d2d0b16650071056af822a8ea67d19d63660372 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Wed, 4 Dec 2019 12:08:01 +0100 Subject: [PATCH] Fix library items styles (#2402) --- .../ui/adapters/BookmarkAdapter.java | 32 +++++---- .../vrbrowser/ui/adapters/HistoryAdapter.java | 29 +++++--- app/src/main/res/layout/bookmark_item.xml | 72 ++++++++----------- app/src/main/res/layout/history_item.xml | 16 ++--- 4 files changed, 72 insertions(+), 77 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/BookmarkAdapter.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/BookmarkAdapter.java index 57a47e5ba..731fb0ac3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/BookmarkAdapter.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/BookmarkAdapter.java @@ -24,7 +24,6 @@ import org.mozilla.vrbrowser.utils.AnimationHelper; import org.mozilla.vrbrowser.utils.SystemUtils; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -44,8 +43,6 @@ public class BookmarkAdapter extends RecyclerView.Adapter { + binding.setIsHovered(true); int ev = motionEvent.getActionMasked(); switch (ev) { case MotionEvent.ACTION_UP: - binding.setIsHovered(true); if (mBookmarkItemCallback != null) { mBookmarkItemCallback.onMore(view, binding.getItem()); } + binding.more.setImageState(new int[]{android.R.attr.state_active},true); return true; case MotionEvent.ACTION_DOWN: - binding.setIsHovered(true); + binding.more.setImageState(new int[]{android.R.attr.state_pressed},true); return true; + + case MotionEvent.ACTION_CANCEL: + binding.more.setImageState(new int[]{android.R.attr.state_active},true); + return false; } return false; }); binding.trash.setOnHoverListener(mIconHoverListener); binding.trash.setOnTouchListener((view, motionEvent) -> { + binding.setIsHovered(true); int ev = motionEvent.getActionMasked(); switch (ev) { case MotionEvent.ACTION_UP: - binding.setIsHovered(true); if (mBookmarkItemCallback != null) { mBookmarkItemCallback.onDelete(view, binding.getItem()); } + binding.trash.setImageState(new int[]{android.R.attr.state_active},true); return true; case MotionEvent.ACTION_DOWN: - binding.setIsHovered(true); + binding.trash.setImageState(new int[]{android.R.attr.state_pressed},true); return true; + + case MotionEvent.ACTION_CANCEL: + binding.trash.setImageState(new int[]{android.R.attr.state_active},true); + return false; } return false; }); @@ -324,7 +330,7 @@ static class BookmarkSeparatorViewHolder extends RecyclerView.ViewHolder { int ev = motionEvent.getActionMasked(); switch (ev) { case MotionEvent.ACTION_HOVER_ENTER: - icon.setColorFilter(mIconColorHover); + icon.setImageState(new int[]{android.R.attr.state_hovered},true); AnimationHelper.animateViewPadding(view, mMaxPadding, mMinPadding, @@ -332,11 +338,11 @@ static class BookmarkSeparatorViewHolder extends RecyclerView.ViewHolder { return false; case MotionEvent.ACTION_HOVER_EXIT: + icon.setImageState(new int[]{android.R.attr.state_active},true); AnimationHelper.animateViewPadding(view, mMinPadding, mMaxPadding, - ICON_ANIMATION_DURATION, - () -> icon.setColorFilter(mIconNormalColor)); + ICON_ANIMATION_DURATION); return false; } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/HistoryAdapter.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/HistoryAdapter.java index 92ad5fb07..bbac8fc78 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/HistoryAdapter.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/HistoryAdapter.java @@ -41,8 +41,6 @@ public class HistoryAdapter extends RecyclerView.Adapter { + binding.setIsHovered(true); int ev = motionEvent.getActionMasked(); switch (ev) { case MotionEvent.ACTION_UP: - binding.setIsHovered(true); if (mHistoryItemCallback != null) { mHistoryItemCallback.onMore(view, binding.getItem()); } + binding.more.setImageState(new int[]{android.R.attr.state_active},true); return true; case MotionEvent.ACTION_DOWN: - binding.setIsHovered(true); + binding.more.setImageState(new int[]{android.R.attr.state_pressed},true); return true; + + case MotionEvent.ACTION_CANCEL: + binding.more.setImageState(new int[]{android.R.attr.state_active},true); + return false; } return false; }); @@ -198,11 +200,16 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int if (mHistoryItemCallback != null) { mHistoryItemCallback.onDelete(view, binding.getItem()); } + binding.trash.setImageState(new int[]{android.R.attr.state_active},true); return true; case MotionEvent.ACTION_DOWN: - binding.setIsHovered(true); + binding.trash.setImageState(new int[]{android.R.attr.state_pressed},true); return true; + + case MotionEvent.ACTION_CANCEL: + binding.trash.setImageState(new int[]{android.R.attr.state_active},true); + return false; } return false; }); @@ -261,7 +268,7 @@ private boolean isPositionHeader(int position) { int ev = motionEvent.getActionMasked(); switch (ev) { case MotionEvent.ACTION_HOVER_ENTER: - icon.setColorFilter(mIconColorHover); + icon.setImageState(new int[]{android.R.attr.state_hovered},true); AnimationHelper.animateViewPadding(view, mMaxPadding, mMinPadding, @@ -269,11 +276,11 @@ private boolean isPositionHeader(int position) { return false; case MotionEvent.ACTION_HOVER_EXIT: + icon.setImageState(new int[]{android.R.attr.state_active},true); AnimationHelper.animateViewPadding(view, mMinPadding, mMaxPadding, - ICON_ANIMATION_DURATION, - () -> icon.setColorFilter(mIconNormalColor)); + ICON_ANIMATION_DURATION); return false; } diff --git a/app/src/main/res/layout/bookmark_item.xml b/app/src/main/res/layout/bookmark_item.xml index d1a57fbee..6da1e5d6a 100644 --- a/app/src/main/res/layout/bookmark_item.xml +++ b/app/src/main/res/layout/bookmark_item.xml @@ -36,13 +36,13 @@ android:layout_height="match_parent" android:background="@drawable/library_item_background_color" android:clickable="true" - android:descendantFocusability="blocksDescendants" android:focusable="true" android:gravity="center_vertical" android:onClick="@{(view) -> callback.onClick(view, item)}" android:paddingStart="10dp" android:paddingEnd="10dp" - android:soundEffectsEnabled="false"> + android:soundEffectsEnabled="false" + android:addStatesFromChildren="true"> @@ -85,52 +84,39 @@ android:visibility="visible"/> - + android:layout_gravity="end" + android:orientation="horizontal" + app:visibleInvisible="@{isHovered}" + android:addStatesFromChildren="true"> - + - - - - - + + diff --git a/app/src/main/res/layout/history_item.xml b/app/src/main/res/layout/history_item.xml index 123e67bef..d8a023664 100644 --- a/app/src/main/res/layout/history_item.xml +++ b/app/src/main/res/layout/history_item.xml @@ -36,13 +36,13 @@ android:layout_height="match_parent" android:background="@drawable/library_item_background_color" android:clickable="true" - android:descendantFocusability="blocksDescendants" android:focusable="true" android:gravity="center_vertical" android:onClick="@{(view) -> callback.onClick(view, item)}" android:paddingStart="10dp" android:paddingEnd="10dp" - android:soundEffectsEnabled="false"> + android:soundEffectsEnabled="false" + android:addStatesFromChildren="true"> + android:gravity="center_vertical" + android:addStatesFromChildren="true"> + app:visibleInvisible="@{isHovered}" + android:addStatesFromChildren="true">