Comments (4)
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.
@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.
@vipulasri Thanks for the tip.
I'll look into the lib and implement
from timeline-view.
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)
- Replace marker with Imageview
- Can we have Dark mode? HOT 2
- What the hell is it written about? The documents are unclear
- I WANT TO IN My app like timelineview circle drawable above and ending line are show so how to get disable it i couldn't find any solution i want to hide the top and end posiiton streght line HOT 1
- Space between TimelineView HOT 14
- Horrizontal timeline cards in bottom HOT 1
- Make time line time sensitive HOT 1
- Dynamic Progress Line HOT 2
- Not seeing the line between markers in AndroidX HOT 6
- implement animation HOT 1
- Androidx support
- Marker is invisible when markerInCenter is set to true HOT 2
- Public access to TimelineView.LineType HOT 4
- Not Change the color of the time line view in Java android HOT 6
- My card layout doesn't stretch to the parent width HOT 5
- Overiding getItemiewType to return Timeline.getTimeLineViewType
- line does not show through xml HOT 3
- Can I get a click event in any of the marker?
- How to get click event for marker click?
- StartLineColor 和EndLineColor 不起作用 先排除ViewHolder里是否timeline.initLine(viewType); HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timeline-view.