Giter Site home page Giter Site logo

How can I add sections? about timeline-view HOT 4 CLOSED

vipulasri avatar vipulasri commented on September 13, 2024
How can I add sections?

from timeline-view.

Comments (4)

vidia avatar vidia commented on September 13, 2024 1

I made a sectioned version of this locally that seems to work pretty well. The main codebased is closed source, but here is the relevant adapter. Hopefully it can help @vipulasri implement an update as well.

Some context before you look, my goal for this was to display a calendar where the headings are days of the week (represented by DayHeaderScheduleEntry) and Events are displayed using the timeline (represented by ScheduleEntry) Both of these entries are a subclass of the abstract class ScheduleViewHolder which is a ViewHolder.

The only abstract method on ScheduleEntry is setScheduleEntry() which takes a ScheduleEntry and uses it to populate the view on that holder.

Finally, note that keySet() does not retain any ordering. So this is not complete. But its a start and I thought I'd share it anyway.

/**
 * Created by David Tschida (@vidia) on 3/23/16.
 */
public class ScheduleRecyclerAdapter extends RecyclerView.Adapter<ScheduleViewHolder> {
    private static int HEADERVIEWTYPE = 124124; //arbitrary number, not 1-4.

    private Map<DayHeaderScheduleEntry, List<ScheduleEntry>> mWeekSchedule;

    List<ScheduleEntry> mAllEntries;

    public ScheduleRecyclerAdapter(Map<DayHeaderScheduleEntry, List<ScheduleEntry>> weekSchedule) {
        this.mWeekSchedule = weekSchedule;

        //flatten the map.
        mAllEntries = new ArrayList<>();
        for(DayHeaderScheduleEntry hme : mWeekSchedule.keySet()) {
            mAllEntries.add(hme);
            for(ScheduleEntry se : mWeekSchedule.get(hme)) {
                mAllEntries.add(se);
            }
        }
    }

    @Override
    public int getItemViewType(int position) {

        if(mAllEntries.get(position) instanceof DayHeaderScheduleEntry) {
            return HEADERVIEWTYPE;
        } else {
            //get position in sublist...
            int prevHeader = -1;
            for (int i = position; i >= 0; i--) {
                if(mAllEntries.get(i) instanceof DayHeaderScheduleEntry) {
                    prevHeader = i;
                    break;
                }
            }

            int postHeader = -1;
            for (int i = position; i < mAllEntries.size(); i++) {
                if(mAllEntries.get(i) instanceof DayHeaderScheduleEntry) {
                    postHeader = i;
                    break;
                }
            }
            if(postHeader == -1) {
                //we are at the end of the list
                postHeader = mAllEntries.size();
            }

            //Pass the position in the "sublist" to the library to init properly.
            //Library has an error in this implementation. See PR https://github.com/vipulasri/Timeline-View/pull/7
            //on upstream.
            return VidiaTimelineView.getTimeLineViewType(position - prevHeader - 1, postHeader - prevHeader - 1);
        }

    }

    @Override
    public ScheduleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType == HEADERVIEWTYPE) {
            View view = View.inflate(parent.getContext(), R.layout.schedule_day_heading, null);
            return new DayHeadingViewHolder(view);
        } else {
            View view = View.inflate(parent.getContext(), R.layout.item_timeline, null);
            return new TimeLineViewHolder(view, viewType);
        }
    }

    @Override
    public void onBindViewHolder(ScheduleViewHolder holder, int position) {
        holder.setScheduleEntry(mAllEntries.get(position));
    }

    @Override
    public int getItemCount() {
        return mAllEntries.size();
    }
}

from timeline-view.

vipulasri avatar vipulasri commented on September 13, 2024

@RiinaV Nice input. I will try to implement it in next update. Till now you can implement it like Sectioned Recycler View. Checkout code of this library you will be able to implement it. https://github.com/afollestad/sectioned-recyclerview

from timeline-view.

rinav avatar rinav commented on September 13, 2024

@vipulasri Thanks for the tip.
I'll look into the lib and implement

from timeline-view.

vipulasri avatar vipulasri commented on September 13, 2024

After actually understanding this issue, it's totally out of scope for this library. If you still think this applies please open a new bug and provide supporting documents for that.

from timeline-view.

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.