Skip to content

Commit

Permalink
Added minDate and maxDate from xxjy (pull request ApplikeySolutions#36
Browse files Browse the repository at this point in the history
…from original)
  • Loading branch information
grenoshka committed Oct 1, 2021
1 parent c1c9f7c commit 46d985d
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,29 @@ public void setWeekendDays(Set<Long> weekendDays) {
setDaysAccordingToSet(weekendDays, DayFlag.WEEKEND);
}

//minDate or maxDate by xxjy pull request #36
public void setMinDate(Calendar minDate){
for (Month month : months) {
for (Day day : month.getDays()) {
if(!day.isDisabled()){
day.setDisabled(CalendarUtils.isDayDisabledByMinDate(day, minDate));
}
}
}
notifyDataSetChanged();
}

public void setMaxDate(Calendar maxDate){
for (Month month : months) {
for (Day day : month.getDays()) {
if(!day.isDisabled()){
day.setDisabled(CalendarUtils.isDayDisabledByMaxDate(day, maxDate));
}
}
}
notifyDataSetChanged();
}

public void setDisabledDays(Set<Long> disabledDays) {
setDaysAccordingToSet(disabledDays, DayFlag.DISABLED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.applikeysolutions.cosmocalendar.settings.selection.SelectionInterface;
import com.applikeysolutions.cosmocalendar.view.CalendarView;

import java.util.Calendar;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -342,6 +343,16 @@ public void setShowDaysOfWeek(boolean showDaysOfWeek) {
public void setShowDaysOfWeekTitle(boolean showDaysOfWeekTitle) {
calendarView.setShowDaysOfWeekTitle(showDaysOfWeekTitle);
}
//minDate or maxDate by xxjy pull request #36
@Override
public Calendar getMinDate() {
return calendarView.getMinDate();
}

@Override
public Calendar getMaxDate() {
return calendarView.getMaxDate();
}

@Override
public Set<Long> getDisabledDays() {
Expand All @@ -363,6 +374,17 @@ public DisabledDaysCriteria getDisabledDaysCriteria() {
return calendarView.getDisabledDaysCriteria();
}

//minDate or maxDate by xxjy pull request #36
@Override
public void setMinDate(Calendar minDate) {
calendarView.setMinDate(minDate);
}

@Override
public void setMaxDate(Calendar maxDate) {
calendarView.setMaxDate(maxDate);
}

@Override
public void setDisabledDays(Set<Long> disabledDays) {
calendarView.setDisabledDays(disabledDays);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ public void setShowDaysOfWeekTitle(boolean showDaysOfWeekTitle) {
appearanceModel.setShowDaysOfWeekTitle(showDaysOfWeekTitle);
}

//minDate or maxDate by xxjy pull request #36
@Override
public Calendar getMinDate() {
return calendarListsModel.getMinDate();
}

@Override
public Calendar getMaxDate() {
return calendarListsModel.getMaxDate();
}

@Override
public Set<Long> getDisabledDays() {
return calendarListsModel.getDisabledDays();
Expand Down Expand Up @@ -331,4 +342,15 @@ public int getFirstDayOfWeek() {
public void setFirstDayOfWeek(int firstDayOfWeek) {
dateModel.setFirstDayOfWeek(firstDayOfWeek);
}

//minDate or maxDate by xxjy pull request #36
@Override
public void setMinDate(Calendar minDate) {
calendarListsModel.setMinDate(minDate);
}

@Override
public void setMaxDate(Calendar maxDate) {
calendarListsModel.setMaxDate(maxDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import com.applikeysolutions.cosmocalendar.settings.lists.connected_days.ConnectedDays;
import com.applikeysolutions.cosmocalendar.settings.lists.connected_days.ConnectedDaysManager;

import java.util.Calendar;
import java.util.Set;

public interface CalendarListsInterface {

//minDate or maxDate by xxjy pull request #36
Calendar getMinDate();

Calendar getMaxDate();

Set<Long> getDisabledDays();

ConnectedDaysManager getConnectedDaysManager();
Expand All @@ -15,6 +21,11 @@ public interface CalendarListsInterface {

DisabledDaysCriteria getDisabledDaysCriteria();

//minDate or maxDate by xxjy pull request #36
void setMinDate(Calendar minDate);

void setMaxDate(Calendar maxDate);

void setDisabledDays(Set<Long> disabledDays);

void setWeekendDays(Set<Long> weekendDays);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

public class CalendarListsModel implements CalendarListsInterface {

//minDate or maxDate by xxjy pull request #36
private Calendar minDate;

private Calendar maxDate;

//Disabled days cannot be selected
private Set<Long> disabledDays = new TreeSet<>();

Expand All @@ -22,6 +27,17 @@ public class CalendarListsModel implements CalendarListsInterface {
add(Calendar.SUNDAY);
}};

//minDate or maxDate by xxjy pull request #36
@Override
public Calendar getMinDate() {
return minDate;
}

@Override
public Calendar getMaxDate() {
return maxDate;
}

@Override
public Set<Long> getDisabledDays() {
return disabledDays;
Expand All @@ -42,6 +58,17 @@ public DisabledDaysCriteria getDisabledDaysCriteria() {
return disabledDaysCriteria;
}

//minDate or maxDate by xxjy pull request #36
@Override
public void setMinDate(Calendar minDate) {
this.minDate = minDate;
}

@Override
public void setMaxDate(Calendar maxDate) {
this.maxDate = maxDate;
}

@Override
public void setDisabledDays(Set<Long> disabledDays) {
this.disabledDays = disabledDays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,21 @@ public static void setDay(Day day, SettingsManager settingsManager) {
day.setWeekend(settingsManager.getWeekendDays().contains(day.getCalendar().get(Calendar.DAY_OF_WEEK)));
}

//minDate or maxDate by xxjy pull request #36
if (settingsManager.getMinDate() != null) {
day.setDisabled(isDayDisabledByMinDate(day, settingsManager.getMinDate()));
}

if (settingsManager.getMaxDate() != null) {
if (!day.isDisabled()) {
day.setDisabled(isDayDisabledByMaxDate(day, settingsManager.getMaxDate()));
}
}

if (settingsManager.getDisabledDays() != null) {
day.setDisabled(isDayInSet(day, settingsManager.getDisabledDays()));
if(!day.isDisabled()) {
day.setDisabled(isDayInSet(day, settingsManager.getDisabledDays()));
}
}

if (settingsManager.getDisabledDaysCriteria() != null) {
Expand All @@ -182,6 +195,18 @@ public static boolean isDayInSet(Day day, Set<Long> daysInSet) {
}
return false;
}
//minDate or maxDate by xxjy pull request #36
public static boolean isDayDisabledByMinDate(Day day, Calendar minDate) {
return day.getCalendar().get(Calendar.YEAR) < minDate.get(Calendar.YEAR)
|| day.getCalendar().get(Calendar.YEAR) == minDate.get(Calendar.YEAR)
&& day.getCalendar().get(Calendar.DAY_OF_YEAR) < minDate.get(Calendar.DAY_OF_YEAR);
}

public static boolean isDayDisabledByMaxDate(Day day, Calendar maxDate) {
return day.getCalendar().get(Calendar.YEAR) > maxDate.get(Calendar.YEAR)
|| day.getCalendar().get(Calendar.YEAR) == maxDate.get(Calendar.YEAR)
&& day.getCalendar().get(Calendar.DAY_OF_YEAR) > maxDate.get(Calendar.DAY_OF_YEAR);
}

public static boolean isDayDisabledByCriteria(Day day, DisabledDaysCriteria criteria) {
int field = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public class CalendarView extends RelativeLayout implements OnDaySelectedListene
private FetchMonthsAsyncTask asyncTask;

public CalendarView(Context context) {
super(context);
init();
this(context, null);
}

public CalendarView(Context context, @Nullable AttributeSet attrs) {
Expand Down Expand Up @@ -511,6 +510,16 @@ private void loadAsyncMonths(final boolean future){

asyncTask.execute(new FetchMonthsAsyncTask.FetchParams(future, month, settingsManager, monthAdapter, SettingsManager.DEFAULT_MONTH_COUNT));
}
//minDate or maxDate by xxjy pull request #36
@Override
public Calendar getMinDate() {
return settingsManager.getMinDate();
}

@Override
public Calendar getMaxDate() {
return settingsManager.getMaxDate();
}

@Override
public Set<Long> getDisabledDays() {
Expand All @@ -531,6 +540,18 @@ public Set<Long> getWeekendDays() {
public DisabledDaysCriteria getDisabledDaysCriteria() {
return settingsManager.getDisabledDaysCriteria();
}
//minDate or maxDate by xxjy pull request #36
@Override
public void setMinDate(Calendar minDate) {
settingsManager.setMinDate(minDate);
monthAdapter.setMinDate(minDate);
}

@Override
public void setMaxDate(Calendar maxDate) {
settingsManager.setMaxDate(maxDate);
monthAdapter.setMaxDate(maxDate);
}

public void setDisabledDays(Set<Long> disabledDays) {
settingsManager.setDisabledDays(disabledDays);
Expand Down

0 comments on commit 46d985d

Please sign in to comment.