Skip to content

Commit

Permalink
Merge pull request #365 from FuHeJian/master
Browse files Browse the repository at this point in the history
1.毫秒设置成1000,实际上获取出来的时间是下个月的1号0点,改为999,防止出现其他月份。
  • Loading branch information
liyujiang-gzu authored Nov 28, 2024
2 parents 51852c3 + c8f7bfe commit f372f2f
Show file tree
Hide file tree
Showing 7 changed files with 549 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.github.gzuliyujiang.calendarpicker.core.FestivalProvider;
import com.github.gzuliyujiang.calendarpicker.core.ItemViewProvider;
import com.github.gzuliyujiang.calendarpicker.core.OnDateSelectedListener;
import com.github.gzuliyujiang.calendarpicker.listener.OnPageChangeCallback;
import com.github.gzuliyujiang.calendarpicker.listener.ScrollEventAdapter;
import com.github.gzuliyujiang.dialog.DialogConfig;
import com.github.gzuliyujiang.dialog.DialogStyle;
import com.github.gzuliyujiang.dialog.ModalDialog;
Expand All @@ -47,6 +49,7 @@
public class CalendarPicker extends ModalDialog implements OnDateSelectedListener {
private CalendarView calendarView;
private CalendarAdapter calendarAdapter;
private ScrollEventAdapter mScrollEventAdapter;
private ColorScheme colorScheme;
private boolean singleMode = false;
private FestivalProvider festivalProvider;
Expand Down Expand Up @@ -104,8 +107,26 @@ protected void initData() {
maxCalendar.set(Calendar.DAY_OF_MONTH, DateUtils.maxDaysOfMonth(maxCalendar.getTime()));
maxDate = maxCalendar.getTime();
}
if (mScrollEventAdapter == null) {
mScrollEventAdapter = new ScrollEventAdapter(calendarView.getBodyView());
calendarView.getBodyView().addOnScrollListener(mScrollEventAdapter);
}
calendarAdapter = calendarView.getAdapter();
calendarAdapter.setOnCalendarSelectedListener(this);
mScrollEventAdapter.setOnPageChangeCallback(new OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
if (calendarAdapter != null) {
Date cDate = calendarAdapter.getDateValue(position);
if (onSingleDatePickListener != null) {
onSingleDatePickListener.onMonthChanged(cDate);
}
if (onRangeDatePickListener != null) {
onRangeDatePickListener.onMonthChanged(cDate);
}
}
}
});
refreshData();
}

Expand Down Expand Up @@ -331,4 +352,14 @@ public final CalendarView getCalendarView() {
return calendarView;
}

@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mScrollEventAdapter != null && calendarView != null) {
mScrollEventAdapter.setOnPageChangeCallback(null);
calendarView.getBodyView().removeOnScrollListener(mScrollEventAdapter);
mScrollEventAdapter = null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface OnRangeDatePickListener {

void onRangeDatePicked(@NonNull Date startDate, @NonNull Date endDate);

void onMonthChanged(Date date);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface OnSingleDatePickListener {

void onSingleDatePicked(@NonNull Date date);

void onMonthChanged(Date date);

}
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public final int getDatePosition(Date date) {
maxDate.set(Calendar.HOUR_OF_DAY, 23);
maxDate.set(Calendar.MINUTE, 59);
maxDate.set(Calendar.SECOND, 59);
maxDate.set(Calendar.MILLISECOND, 1000);
maxDate.set(Calendar.MILLISECOND, 999);
if (time >= minDate.getTime().getTime() && time <= maxDate.getTime().getTime()) {
return i;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.gzuliyujiang.calendarpicker.listener;

import androidx.annotation.Px;

public abstract class OnPageChangeCallback {
/**
* This method will be invoked when the current page is scrolled, either as part
* of a programmatically initiated smooth scroll or a user initiated touch scroll.
*
* @param position Position index of the first page currently being displayed.
* Page position+1 will be visible if positionOffset is nonzero.
* @param positionOffset Value from [0, 1) indicating the offset from the page at position.
* @param positionOffsetPixels Value in pixels indicating the offset from position.
*/
public void onPageScrolled(int position, float positionOffset,
@Px int positionOffsetPixels) {
}

/**
* This method will be invoked when a new page becomes selected. Animation is not
* necessarily complete.
*
* @param position Position index of the new selected page.
*/
public void onPageSelected(int position) {
}

/**
* Called when the scroll state changes. Useful for discovering when the user begins
* dragging, when a fake drag is started, when the pager is automatically settling to the
* current page, or when it is fully stopped/idle. {@code state} can be one of {@link
*/
public void onPageScrollStateChanged(int state) {
}
}
Loading

0 comments on commit f372f2f

Please sign in to comment.