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
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.support.v7.widget.SnapHelper;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -90,7 +93,7 @@ public class CalendarView extends RelativeLayout implements OnDaySelectedListene
//Helpers
private SettingsManager settingsManager;
private BaseSelectionManager selectionManager;
private GravitySnapHelper snapHelper;
private SnapHelper snapHelper;

//Listeners
private OnMonthChangeListener onMonthChangeListener;
Expand All @@ -100,6 +103,8 @@ public class CalendarView extends RelativeLayout implements OnDaySelectedListene

private FetchMonthsAsyncTask asyncTask;

private boolean swipeSinglePage;

public CalendarView(Context context) {
super(context);
init();
Expand Down Expand Up @@ -174,6 +179,8 @@ private void handleAttributes(TypedArray typedArray) {
int previousMonthIconRes = typedArray.getResourceId(R.styleable.CalendarView_previousMonthIconRes, R.drawable.ic_chevron_left_gray);
int nextMonthIconRes = typedArray.getResourceId(R.styleable.CalendarView_nextMonthIconRes, R.drawable.ic_chevron_right_gray);

swipeSinglePage = typedArray.getBoolean(R.styleable.CalendarView_singlePageSwipe, false);

setBackgroundColor(calendarBackgroundColor);
settingsManager.setCalendarBackgroundColor(calendarBackgroundColor);
settingsManager.setMonthTextColor(monthTextColor);
Expand Down Expand Up @@ -381,6 +388,7 @@ public void update() {

private void createRecyclerView() {
rvMonths = new SlowdownRecyclerView(getContext());

rvMonths.setId(View.generateViewId());
rvMonths.setHasFixedSize(true);
rvMonths.setNestedScrollingEnabled(false);
Expand Down Expand Up @@ -464,8 +472,15 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {

//Hide navigation buttons
boolean show = newState != RecyclerView.SCROLL_STATE_DRAGGING;

ivPrevious.setVisibility(show ? View.VISIBLE : View.GONE);
ivNext.setVisibility(show ? View.VISIBLE : View.GONE);

boolean clickable = newState == RecyclerView.SCROLL_STATE_IDLE;

ivPrevious.setClickable(clickable);
ivNext.setClickable(clickable);

}

super.onScrollStateChanged(recyclerView, newState);
Expand Down Expand Up @@ -603,7 +618,8 @@ public List<Calendar> getSelectedDates() {
* Scroll calendar to previous month
*/
public void goToPreviousMonth() {
int currentVisibleItemPosition = ((GridLayoutManager) rvMonths.getLayoutManager()).findFirstVisibleItemPosition();

int currentVisibleItemPosition = ((GridLayoutManager) rvMonths.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
if (currentVisibleItemPosition != 0) {
rvMonths.smoothScrollToPosition(currentVisibleItemPosition - 1);
}
Expand All @@ -613,7 +629,7 @@ public void goToPreviousMonth() {
* Scroll calendar to next month
*/
public void goToNextMonth() {
int currentVisibleItemPosition = ((GridLayoutManager) rvMonths.getLayoutManager()).findFirstVisibleItemPosition();
int currentVisibleItemPosition = ((GridLayoutManager) rvMonths.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
if (currentVisibleItemPosition != monthAdapter.getData().size() - 1) {
rvMonths.smoothScrollToPosition(currentVisibleItemPosition + 1);
}
Expand Down Expand Up @@ -948,7 +964,7 @@ public void setCalendarOrientation(int calendarOrientation) {

rvMonths.setLayoutManager(new GridLayoutManager(getContext(), 1, getCalendarOrientation(), false));

changeSnapHelper();
//changeSnapHelper();

if (getCalendarOrientation() == LinearLayout.HORIZONTAL) {
if (flNavigationButtons != null) {
Expand Down Expand Up @@ -1042,11 +1058,17 @@ public void setFirstDayOfWeek(int firstDayOfWeek) {

private void changeSnapHelper() {
rvMonths.setOnFlingListener(null);
if (snapHelper == null) {
snapHelper = new GravitySnapHelper(settingsManager.getCalendarOrientation() == LinearLayoutManager.VERTICAL ? Gravity.TOP : Gravity.START, true, this);
if (swipeSinglePage){
snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(rvMonths);
} else {
snapHelper.setGravity(settingsManager.getCalendarOrientation() == LinearLayoutManager.VERTICAL ? Gravity.TOP : Gravity.START);
}else{
if (snapHelper == null) {
snapHelper = new GravitySnapHelper(settingsManager.getCalendarOrientation() == LinearLayoutManager.VERTICAL ? Gravity.TOP : Gravity.START, true, this);
snapHelper.attachToRecyclerView(rvMonths);
} else {
if (snapHelper instanceof GravitySnapHelper)
((GravitySnapHelper)snapHelper).setGravity(settingsManager.getCalendarOrientation() == LinearLayoutManager.VERTICAL ? Gravity.TOP : Gravity.START);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions cosmocalendar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@
<flag name="sunday" value="64" />
</attr>

<attr name="singlePageSwipe" format="boolean"/>

</declare-styleable>
</resources>