Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,32 @@ Declare a DayPickerView inside your layout XML file:

```

Next, you have to implement `DatePickerController` in your Activity or your Fragment. You will have to set `getMaxYear` and `onDayOfMonthSelected`. The first one is the max year between the current one and this maxYear. The second one is called every time user selects a new date.
Next, you have to implement `DatePickerController` in your Activity or your Fragment.
You will have to set:

- `getMinYear`: starting year
- `getMaxYear`: final year
- `getCurrentYear`: is the current year actually displayed
- `onDayOfMonthSelected`: is called every time user selects a new date

``` java

@Override
public int getMinYear()
{
return 1970;
}

@Override
public int getMaxYear()
{
return 2015;
return 2016;
}

@Override
public int getCurrentYear()
{
return 2016;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.android.tools.build:gradle:2.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Dec 10 14:37:29 CET 2014
#Tue Jun 14 18:01:01 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
package com.andexert.calendarlistview.library;

public interface DatePickerController {
public abstract int getMaxYear();
int getMaxYear();

public abstract void onDayOfMonthSelected(int year, int month, int day);
int getMinYear();

public abstract void onDateRangeSelected(final SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays);
int getCurrentYear();

void onDayOfMonthSelected(int year, int month, int day);

void onDateRangeSelected(final SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays);

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/***********************************************************************************
* The MIT License (MIT)

* <p>
* Copyright (c) 2014 Robin Chutaux

* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:

* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.

* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -29,56 +29,52 @@
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

public class DayPickerView extends RecyclerView
{
public class DayPickerView extends RecyclerView {
protected Context mContext;
protected SimpleMonthAdapter mAdapter;
private DatePickerController mController;
protected SimpleMonthAdapter mAdapter;
private DatePickerController mController;
protected int mCurrentScrollState = 0;
protected long mPreviousScrollPosition;
protected int mPreviousScrollState = 0;
protected long mPreviousScrollPosition;
protected int mPreviousScrollState = 0;
private TypedArray typedArray;
private OnScrollListener onScrollListener;

public DayPickerView(Context context)
{
public DayPickerView(Context context) {
this(context, null);
}

public DayPickerView(Context context, AttributeSet attrs)
{
public DayPickerView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public DayPickerView(Context context, AttributeSet attrs, int defStyle)
{
public DayPickerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (!isInEditMode())
{
if (!isInEditMode()) {
typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
init(context);
}
}

public void setController(DatePickerController mController)
{
public void setController(DatePickerController mController) {
this.mController = mController;
setUpAdapter();
scrollToCurrentYear();
setAdapter(mAdapter);
}

protected void scrollToCurrentYear() {
scrollToMonth(mController.getCurrentYear(), mAdapter.getFirstMonth());
}

public void init(Context paramContext) {
protected void init(Context paramContext) {
setLayoutManager(new LinearLayoutManager(paramContext));
mContext = paramContext;
setUpListView();
mContext = paramContext;
setUpListView();

onScrollListener = new OnScrollListener()
{
onScrollListener = new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
final SimpleMonthView child = (SimpleMonthView) recyclerView.getChildAt(0);
if (child == null) {
Expand All @@ -89,34 +85,46 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy)
mPreviousScrollState = mCurrentScrollState;
}
};
}
}


protected void setUpAdapter() {
if (mAdapter == null) {
mAdapter = new SimpleMonthAdapter(getContext(), mController, typedArray);
protected void setUpAdapter() {
if (mAdapter == null) {
mAdapter = new SimpleMonthAdapter(getContext(), mController, typedArray);
}
mAdapter.notifyDataSetChanged();
}

protected void setUpListView() {
setVerticalScrollBarEnabled(false);
setOnScrollListener(onScrollListener);
setFadingEdgeLength(0);
}
mAdapter.notifyDataSetChanged();
}


protected void setUpListView() {
setVerticalScrollBarEnabled(false);
setOnScrollListener(onScrollListener);
setFadingEdgeLength(0);
}

public void scrollToMonth(int year, int month) {
if (mController != null && mAdapter != null) {
int position = ((year - mController.getMinYear()) * SimpleMonthAdapter.MONTHS_IN_YEAR)
+ (mAdapter.getFirstMonth() - month);
if (position > 0) {
scrollToPosition(position);
}
} else {
throw new UnsupportedOperationException("Do you specified a DatePickerController?");
}
}


public SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> getSelectedDays()
{
public SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> getSelectedDays() {
return mAdapter.getSelectedDays();
}

protected DatePickerController getController()
{
protected DatePickerController getController() {
return mController;
}

protected TypedArray getTypedArray()
{
protected TypedArray getTypedArray() {
return typedArray;
}
}
Loading