101Loop / DatePickerTimeline

Android Date Picker Library that provides a calendar as a horizontal timeline
Apache License 2.0
123 stars 37 forks source link

Move to specified date (code included) #12

Open Snow4DV opened 4 years ago

Snow4DV commented 4 years ago

Hello! Great library! Used it in my project but there are some features that i'm missing so i had to implement them myself.

1) I used a calendar date-picker also to move quickly to specified date that is far away from today so in the same time with setting active date it would be great if focus moved to the date that is set to be active like this: `public void setActiveDate(Calendar activeDate) { try { Date initialDate = new SimpleDateFormat("yyyy-MM-dd") .parse(year + "-" + (month + 1) + "-" + this.date); long diff = activeDate.getTime().getTime() - initialDate.getTime(); int position = (int) (diff / (1000 60 60 * 24)); adapter.setSelectedPosition(position); int scrollPosition = position - 2; if(scrollPosition < 0){ scrollPosition = 0; } linLayMan.scrollToPosition(scrollPosition); invalidate(); } catch (ParseException e) { e.printStackTrace(); }

}

`

linear layout manager should be initialized in init() func: 'linLayMan = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); setLayoutManager(linLayMan);' 2) Also missing a function to change the color of picked date background - i just created xml that is used in night mode (that's the purpose of it) but it'd be easier using a func

Thanks! 👍