Giter VIP home page Giter VIP logo

Comments (12)

ShamylZakariya avatar ShamylZakariya commented on July 18, 2024 1

Yilzer

I'm implementing saved state for the StickyHeaderLayoutManager. It likely won't be completely automatic, though. You'll still need to explicitly pack and restore state in your activity's onSaveInstanceState, etc. See here: http://stackoverflow.com/questions/28236390/recyclerview-store-restore-state-between-activities -- I'll report when I've got this working.

Regarding your first point, about jumping to position, this is an interesting quandary. When you request smoothScrollToPosition or scrollToPosition, you're passing an adapter position, which includes headers (and "ghost headers", used internally by the library). This means that if you're looking at the first item of the first section, your adapter position would actually be 3.

I think your best bet there is to ask the adapter for the adapter position, e.g.:

showItem(int clickedIndex) {
    int section = ... // you need to determine which section you're dealing with
    int adapterPosition = adapter.getAdapterPositionForSectionItem(section, clickedIndex)
    recyclerView.scrollToPosition(adapterPosition)
}

from stickyheaders.

ShamylZakariya avatar ShamylZakariya commented on July 18, 2024

I was away on vacation until yesterday - sorry for the delay.

After doing some research, it's clear that scrollToPosition is implemented in the LayoutManager, not RecyclerView. I'll get cracking on it, as well as smoothScrollToPosition.

from stickyheaders.

arkinaforlife avatar arkinaforlife commented on July 18, 2024

Thx for your response,

When you're working on scrollToPosition it may also be important to save the scroll position in onsaveInstance. You can do this by calling: currPosition = recyclerView.findFirstVisibleItemPosition();
The findFirstVisibleItemPosition() method is also an method in the linearlayout manager. I think it's important to have this part also in your stickylayout manager.

Keep up the good work!

from stickyheaders.

ShamylZakariya avatar ShamylZakariya commented on July 18, 2024

yilzer,

I've implemented scrollToPosition and smoothScrollToPosition in the adapter, and they appear to work though I will be testing them further. That being said, I have a serious performance issue with HUGE datasets (hundreds of sections, thousands of items) which I want to tackle before I push an update to bintray. I expect to have that taken care of in a couple days, and I'll let you know and close this issue.

from stickyheaders.

ShamylZakariya avatar ShamylZakariya commented on July 18, 2024

37859b0

I've also fixed a huge performance problem, so I'll be posting an update to bintray tonight, or so.

from stickyheaders.

arkinaforlife avatar arkinaforlife commented on July 18, 2024

Great work man, i've just two more questions for you:

  • if i have 20 items with sticky header in my adapter, when i press on item 3 in grid. I want to show item 3 in adapter, but it shows item 1. Do you have an solution for this, so that it scrolls to the exact item.
    (What i do now to achieve this is multiply the pressed item with 3, i don't know if this is the recommended solution)
  • If i leave my activity or fragment i want to save the item that is visible to the user when leaving, so i can scroll back in onsaveinstance to the last visible item how does this works in your stickylayoutmanager?

Thanks in advance!

from stickyheaders.

arkinaforlife avatar arkinaforlife commented on July 18, 2024

Thanks man!

int section = ... // you need to determine which section you're dealing with

How do i determine the section index? , because the only value that i have at that moment is the value that i want to show to the user in the adapter.

from stickyheaders.

ShamylZakariya avatar ShamylZakariya commented on July 18, 2024

First, I've implemented saved state and it appears to work.

dc63a98

Now, regarding your question, I guess I need to understand the problem. I'm parsing your usage as having one recyclerview -- and when users tap an item in it, the recycler scrolls that item to top of the viewport?

That being said, I've realized the fix is easier than I thoguht: as you have a reference to the ViewHolder, just use RecyclerView.ViewHolder::getAdapterPosition().

from stickyheaders.

arkinaforlife avatar arkinaforlife commented on July 18, 2024

Great work man, I have an fragment with grid images , when the user taps on one of the images he goes to an new activity with your adapter (sticky layout manager). Inside this activity the images are displayed like an feed ( large images instagram style). So if the user taps on item 3 i want to show item 3 in feed with large images.

So i retrieve the current item position from the grid fragment and want to determine the scroll position to show that item to the user.

showItem(int clickedIndex) { int section = ... // you need to determine which section you're dealing with int adapterPosition = adapter.getAdapterPositionForSectionItem(section, clickedIndex) recyclerView.scrollToPosition(adapterPosition) }

How should i determine the section(int section = ... // you need to determine which section you're dealing with) if the only item that i have is the item position from the gridfragment.

I hope you understand my issue better now.

from stickyheaders.

ShamylZakariya avatar ShamylZakariya commented on July 18, 2024

So, if I understand correctly, what you have is a grid of items, indexed 0..N. Clicking on an item opens a list-like recyclerview detail using StickyHeaderLayoutManager where you have all those items, (0..N] but each is presented with its own header, where (presumably) the header is showing the item title/date/other-metadata. In your SectioningAdapter, each item gets its own section, with an associated header. So you have a list mapping like so:

[Header 0,(GhostHeader 0),Item 0],[Header 1,(Ghost Header 1), Item 1]...[Header N, (Ghost Header N),Item N]

(Ghost headers are created by the adapter as part of the layout process)

In this case, the need to multiply item index by 3 makes perfect sense. However: there's a semantically meaningful and forward-compatible way to handle this: instead of trying to scroll to the item, what you want is to scroll to the item's header. The header is indexed by section. So, here's what you will want to do:

void scrollToItem(int itemIndex) {
    int adapterPosition = adapter.getAdapterPositionForSectionHeader(itemIndex)
    recyclerView.scrollToPosition(adapterPosition);
}

from stickyheaders.

arkinaforlife avatar arkinaforlife commented on July 18, 2024

Great work again! This solved all my issues for now. This item can be closed!

from stickyheaders.

ShamylZakariya avatar ShamylZakariya commented on July 18, 2024

Fantastic, glad I could help.

from stickyheaders.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.