Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Fix library items styles (#2402)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and MortimerGoro committed Dec 4, 2019
1 parent 9e5ebd4 commit 6d2d0b1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,8 +43,6 @@ public class BookmarkAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde

private int mMinPadding;
private int mMaxPadding;
private int mIconColorHover;
private int mIconNormalColor;
private boolean mIsNarrowLayout;

@Nullable
Expand All @@ -57,9 +54,6 @@ public BookmarkAdapter(@Nullable BookmarkItemCallback clickCallback, Context aCo
mMinPadding = WidgetPlacement.pixelDimension(aContext, R.dimen.library_icon_padding_min);
mMaxPadding = WidgetPlacement.pixelDimension(aContext, R.dimen.library_icon_padding_max);

mIconColorHover = aContext.getResources().getColor(R.color.white, aContext.getTheme());
mIconNormalColor = aContext.getResources().getColor(R.color.rhino, aContext.getTheme());

mIsNarrowLayout = false;

setHasStableIds(false);
Expand Down Expand Up @@ -193,6 +187,8 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
return false;

case MotionEvent.ACTION_DOWN:
binding.more.setImageState(new int[]{android.R.attr.state_active},false);
binding.trash.setImageState(new int[]{android.R.attr.state_active},false);
binding.setIsHovered(true);
return false;

Expand All @@ -204,35 +200,45 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
});
binding.more.setOnHoverListener(mIconHoverListener);
binding.more.setOnTouchListener((view, motionEvent) -> {
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;
});
Expand Down Expand Up @@ -324,19 +330,19 @@ 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,
ICON_ANIMATION_DURATION);
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public class HistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder

private int mMinPadding;
private int mMaxPadding;
private int mIconColorHover;
private int mIconNormalColor;
private boolean mIsNarrowLayout;

@Nullable
Expand All @@ -54,9 +52,6 @@ public HistoryAdapter(@Nullable HistoryItemCallback clickCallback, Context aCont
mMinPadding = WidgetPlacement.pixelDimension(aContext, R.dimen.library_icon_padding_min);
mMaxPadding = WidgetPlacement.pixelDimension(aContext, R.dimen.library_icon_padding_max);

mIconColorHover = aContext.getResources().getColor(R.color.white, aContext.getTheme());
mIconNormalColor = aContext.getResources().getColor(R.color.rhino, aContext.getTheme());

mIsNarrowLayout = false;

setHasStableIds(true);
Expand Down Expand Up @@ -163,6 +158,8 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
return false;

case MotionEvent.ACTION_DOWN:
binding.more.setImageState(new int[]{android.R.attr.state_active},false);
binding.trash.setImageState(new int[]{android.R.attr.state_active},false);
binding.setIsHovered(true);
return false;

Expand All @@ -174,18 +171,23 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
});
binding.more.setOnHoverListener(mIconHoverListener);
binding.more.setOnTouchListener((view, motionEvent) -> {
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;
});
Expand All @@ -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;
});
Expand Down Expand Up @@ -261,19 +268,19 @@ 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,
ICON_ANIMATION_DURATION);
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;
}

Expand Down
72 changes: 29 additions & 43 deletions app/src/main/res/layout/bookmark_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@
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">

<LinearLayout
android:id="@+id/title_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/time_buttons"
android:gravity="center_vertical"
android:orientation="@{isNarrow ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}">

Expand Down Expand Up @@ -85,52 +84,39 @@
android:visibility="visible"/>
</LinearLayout>

<FrameLayout
android:id="@+id/time_buttons"
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:visibility="visible">
android:layout_gravity="end"
android:orientation="horizontal"
app:visibleInvisible="@{isHovered}"
android:addStatesFromChildren="true">

<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal"
app:visibleInvisible="@{isHovered}">
<ImageView
android:id="@+id/trash"
android:layout_width="@dimen/library_item_row_height"
android:layout_height="@dimen/library_item_row_height"
android:layout_gravity="center_vertical|end"
android:padding="@dimen/library_icon_padding_max"
android:soundEffectsEnabled="false"
android:src="@drawable/ic_icon_trash"
android:tint="@color/library_panel_icon_color"
app:srcCompat="@drawable/ic_icon_trash" />

<ImageView
android:id="@+id/trash"
android:layout_width="@dimen/library_item_row_height"
android:layout_height="@dimen/library_item_row_height"
android:layout_gravity="center_vertical|end"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="@dimen/library_icon_padding_max"
android:soundEffectsEnabled="false"
android:src="@drawable/ic_icon_trash"
android:tint="@color/library_panel_icon_color"
android:visibility="visible"
app:srcCompat="@drawable/ic_icon_trash" />

<ImageView
android:id="@+id/more"
android:layout_width="@dimen/library_item_row_height"
android:layout_height="@dimen/library_item_row_height"
android:layout_gravity="center_vertical|end"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="@dimen/library_icon_padding_max"
android:soundEffectsEnabled="false"
android:src="@drawable/ic_icon_more_options"
android:tint="@color/library_panel_icon_color"
android:visibility="visible"
app:srcCompat="@drawable/ic_icon_more_options" />
</LinearLayout>
</FrameLayout>
<ImageView
android:id="@+id/more"
android:layout_width="@dimen/library_item_row_height"
android:layout_height="@dimen/library_item_row_height"
android:layout_gravity="center_vertical|end"
android:padding="@dimen/library_icon_padding_max"
android:soundEffectsEnabled="false"
android:src="@drawable/ic_icon_more_options"
android:tint="@color/library_panel_icon_color"
app:srcCompat="@drawable/ic_icon_more_options" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
</layout>
16 changes: 6 additions & 10 deletions app/src/main/res/layout/history_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<LinearLayout
android:id="@+id/title_url"
Expand Down Expand Up @@ -90,7 +90,8 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:addStatesFromChildren="true">

<TextView
android:id="@+id/time"
Expand All @@ -112,34 +113,29 @@
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal"
app:visibleInvisible="@{isHovered}">
app:visibleInvisible="@{isHovered}"
android:addStatesFromChildren="true">

<ImageView
android:id="@+id/trash"
android:layout_width="@dimen/library_item_row_height"
android:layout_height="@dimen/library_item_row_height"
android:layout_gravity="center_vertical|end"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="@dimen/library_icon_padding_max"
android:soundEffectsEnabled="false"
android:src="@drawable/ic_icon_trash"
android:tint="@color/library_panel_icon_color"
android:visibility="visible"
app:srcCompat="@drawable/ic_icon_trash" />

<ImageView
android:id="@+id/more"
android:layout_width="@dimen/library_item_row_height"
android:layout_height="@dimen/library_item_row_height"
android:layout_gravity="center_vertical|end"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="@dimen/library_icon_padding_max"
android:soundEffectsEnabled="false"
android:src="@drawable/ic_icon_more_options"
android:tint="@color/library_panel_icon_color"
android:visibility="visible"
app:srcCompat="@drawable/ic_icon_more_options" />
</LinearLayout>
</FrameLayout>
Expand Down

0 comments on commit 6d2d0b1

Please sign in to comment.