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

Commit

Permalink
Adjust the removing animation of the first and the last item.
Browse files Browse the repository at this point in the history
  • Loading branch information
pharspher authored and idiotmax committed Apr 13, 2018
1 parent 92cd479 commit e2bb2b6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
Expand Down Expand Up @@ -418,9 +417,6 @@ private void initRecyclerViewStyle(RecyclerView recyclerView) {
recyclerView.setLayoutManager(layoutManager = new LinearLayoutManager(context,
LinearLayoutManager.VERTICAL, false));

recyclerView.addItemDecoration(new ItemSpaceDecoration(context));
recyclerView.addItemDecoration(new TabTrayPaddingDecoration(context, this));

RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
Expand Down Expand Up @@ -616,40 +612,4 @@ private void onSlide(float slideOffset) {
}
}
}

public static class ItemSpaceDecoration extends RecyclerView.ItemDecoration {
private int margin;

ItemSpaceDecoration(Context context) {
this.margin = context.getResources().getDimensionPixelSize(R.dimen.tab_tray_item_space);
}

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int itemPosition = parent.getChildAdapterPosition(view);
outRect.top = itemPosition == 0 ? 0 : margin;
}
}

public static class TabTrayPaddingDecoration extends RecyclerView.ItemDecoration {
private TabTrayFragment fragment;
private int padding;

TabTrayPaddingDecoration(Context context, TabTrayFragment fragment) {
this.fragment = fragment;
this.padding = context.getResources().getDimensionPixelSize(R.dimen.tab_tray_padding);
}

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int itemPosition = parent.getChildAdapterPosition(view);
outRect.left = outRect.right = padding;

if (itemPosition == 0) {
outRect.top = padding;
} else if (itemPosition == fragment.adapter.getItemCount() - 1) {
outRect.bottom = fragment.newTabBtn.getMeasuredHeight() + padding;
}
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/layout/fragment_tab_tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
android:layout_height="match_parent"
android:background="@color/tabTrayForeground"
android:clipToPadding="false"
android:paddingStart="@dimen/tab_tray_padding"
android:paddingTop="@dimen/tab_tray_padding"
android:paddingEnd="@dimen/tab_tray_padding"
android:paddingBottom="@dimen/tab_tray_new_tab_btn_height"
app:layout_behavior="org.mozilla.focus.tabs.tabtray.InterceptBehavior"
app:behavior_hideable="true"
app:behavior_peekHeight="@dimen/tab_tray_peekHeight"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_tab_tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:background="@drawable/tab_tray_item_bkg"
android:outlineProvider="background"
android:elevation="1dp"
android:layout_marginBottom="@dimen/tab_tray_item_space"
tools:ignore="contentDescription">
<ImageView
android:id="@+id/website_icon"
Expand Down

0 comments on commit e2bb2b6

Please sign in to comment.