saket / InboxRecyclerView

Build expandable descendant navigation, inspired by Google Inbox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Animation is always on top

teshlya opened this issue · comments

What I did wrong is that my animation is always on top, not from item of recyclerview?
https://drive.google.com/open?id=1WoHwzns25zw7JbkpoBVmlML6FPBuss9Y

`public class MainActivity extends AppCompatActivity {

ExpandablePageLayout expandablePageLayout;
InboxRecyclerView recyclerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recyclerView = findViewById(R.id.rv);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    expandablePageLayout = findViewById(R.id.inbox_email_thread_page);

    recyclerView.setExpandablePage(expandablePageLayout);
    recyclerView.setTintPainter(new CompleteListTintPainter(Color.WHITE, 0.65F));
    recyclerView.setAdapter(new MyAdapter(recyclerView));

}

@Override
public void onBackPressed() {
    if (expandablePageLayout.isExpandedOrExpanding()) {
        recyclerView.collapse();
    } else {
        super.onBackPressed();
    }
}

}

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
Context context;
InboxRecyclerView recyclerView;

public MyAdapter(InboxRecyclerView recyclerView) {
    setHasStableIds(true);
    this.recyclerView = recyclerView;
}

@NonNull
@Override
public Holder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    context = viewGroup.getContext();
    return new Holder(LayoutInflater.from(viewGroup.getContext())
            .inflate(R.layout.item, viewGroup, false));
}

@Override
public void onBindViewHolder(@NonNull Holder holder, int i) {
    holder.bind(i);
}


@Override
public int getItemCount() {
    return 10;
}

class Holder extends RecyclerView.ViewHolder{

    FrameLayout frameLayout;

    public Holder(@NonNull View itemView) {
        super(itemView);
        frameLayout = itemView.findViewById(R.id.click);
    }

    public void bind(final int pos) {
        frameLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                recyclerView.expandItem(pos);

            }
        });
    }
}

}

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<me.saket.inboxrecyclerview.InboxRecyclerView
    android:id="@+id/rv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:background="#ffffff"/>

<me.saket.inboxrecyclerview.page.ExpandablePageLayout
    android:id="@+id/inbox_email_thread_page"
    android:background="#000000"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:paddingVertical="18dp"
    android:text="123456" />

`

@teshlya your adapter isn't providing IDs for the list items, despite using setHasStableIds(true). InboxRecyclerView relies on IDs to uniquely identify items. The default implementation of getItemId() returns NO_ID so all your items are treated as the same.

Thank you very much. Everything works fine. How can I set duration animation, slow speed?

Whoops, completely forgot to document them. I've updated the wiki: https://github.com/saket/InboxRecyclerView/wiki/Item-animations

Thanks!

Thanks. Very good library. I have one more question. Is it possible to go for example - recyclerView.expandItem(5), but return to position - 7?

Hrm, not sure if it'll work as expected, but you can try setting inboxRecyclerView.expandedItem manually. What's the use case for this?

How can I set duration for activity - expandFromTop() or expandFrom(). And how can I set setPullToCollapseEnabled(false) for activity?

There's no way right now. I'll expose the underlying ExpandablePageLayout in a future release to make that happen.

Thanks. Notify me in comments when it well be ready, please

This does not sound related to InboxRecyclerView. Does this work with a normal RecyclerView?

Edit: can you create a separate issue for this? Dumping all answers in a single issue will not help others.

can you create a separate issue for this?

Hi @saket, how should I implement getItemID? Can't the position be the item's own id?

I got it working now, I actually misunderstood expandItem(), now I'm just using position as the parameter for expandItem() and got getItemId() to return the position.