-
-
Notifications
You must be signed in to change notification settings - Fork 945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/weekend days #576
base: master
Are you sure you want to change the base?
Feature/weekend days #576
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon Oct 08 10:18:59 CEST 2018 | ||
#Mon Apr 01 17:09:18 EET 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,6 @@ | |
import android.graphics.Color; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.StringRes; | ||
import androidx.fragment.app.DialogFragment; | ||
import androidx.core.content.ContextCompat; | ||
import androidx.core.content.res.ResourcesCompat; | ||
import android.text.format.DateFormat; | ||
import android.text.format.DateUtils; | ||
import android.view.LayoutInflater; | ||
|
@@ -53,9 +47,17 @@ | |
import java.util.Arrays; | ||
import java.util.Calendar; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.StringRes; | ||
import androidx.core.content.ContextCompat; | ||
import androidx.core.content.res.ResourcesCompat; | ||
import androidx.fragment.app.DialogFragment; | ||
|
||
/** | ||
* Dialog allowing users to select a date. | ||
*/ | ||
|
@@ -871,7 +873,19 @@ public void setDisabledDays(Calendar[] disabledDays) { | |
mDefaultLimiter.setDisabledDays(disabledDays); | ||
if (mDayPickerView != null) mDayPickerView.onChange(); | ||
} | ||
/** | ||
* Sets a list of days id that are not selectable in the picker | ||
* like Calendar.SATURDAY = 7 | ||
* Setting this value will take precedence over using setMinDate() and setMaxDate(), but stacks with setSelectableDays() | ||
* | ||
* @param weekendDays an Array of Calendar Objects containing the disabled dates | ||
*/ | ||
public void setWeekendDays(@NonNull List<Integer> weekendDays) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the naming here. There's nothing about a weekend day which implies that it's disabled. Some people might have the exact opposite requirement. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can use this in the signature? https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html (it has utility methods to convert to a Calendar int later on). That might be a more intuitive signature than int. |
||
|
||
mDefaultLimiter.setWeekendDays(weekendDays); | ||
if (mDayPickerView != null) mDayPickerView.onChange(); | ||
|
||
} | ||
/** | ||
* @return an Array of Calendar objects containing the list of days that are not selectable. null if no restriction is set | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,16 +18,19 @@ | |
|
||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.wdullaer.materialdatetimepicker.Utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.TimeZone; | ||
import java.util.TreeSet; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
class DefaultDateRangeLimiter implements DateRangeLimiter { | ||
private static final int DEFAULT_START_YEAR = 1900; | ||
private static final int DEFAULT_END_YEAR = 2100; | ||
|
@@ -39,8 +42,10 @@ class DefaultDateRangeLimiter implements DateRangeLimiter { | |
private Calendar mMaxDate; | ||
private TreeSet<Calendar> selectableDays = new TreeSet<>(); | ||
private HashSet<Calendar> disabledDays = new HashSet<>(); | ||
private List<Integer> weekendDays = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a set makes more sense than a list? |
||
|
||
DefaultDateRangeLimiter() {} | ||
DefaultDateRangeLimiter() { | ||
} | ||
|
||
@SuppressWarnings({"unchecked", "WeakerAccess"}) | ||
public DefaultDateRangeLimiter(Parcel in) { | ||
|
@@ -50,6 +55,7 @@ public DefaultDateRangeLimiter(Parcel in) { | |
mMaxDate = (Calendar) in.readSerializable(); | ||
selectableDays = (TreeSet<Calendar>) in.readSerializable(); | ||
disabledDays = (HashSet<Calendar>) in.readSerializable(); | ||
in.readList(weekendDays, null); | ||
} | ||
|
||
@Override | ||
|
@@ -60,6 +66,7 @@ public void writeToParcel(Parcel out, int flags) { | |
out.writeSerializable(mMaxDate); | ||
out.writeSerializable(selectableDays); | ||
out.writeSerializable(disabledDays); | ||
out.writeList(weekendDays); | ||
} | ||
|
||
@Override | ||
|
@@ -91,6 +98,11 @@ void setDisabledDays(@NonNull Calendar[] days) { | |
} | ||
} | ||
|
||
void setWeekendDays(@NonNull List<Integer> weekendDays) { | ||
|
||
this.weekendDays = weekendDays; | ||
} | ||
|
||
void setMinDate(@NonNull Calendar calendar) { | ||
mMinDate = Utils.trimToMidnight((Calendar) calendar.clone()); | ||
} | ||
|
@@ -112,22 +124,31 @@ void setYearRange(int startYear, int endYear) { | |
mMaxYear = endYear; | ||
} | ||
|
||
@Nullable Calendar getMinDate() { | ||
@Nullable | ||
Calendar getMinDate() { | ||
return mMinDate; | ||
} | ||
|
||
@Nullable Calendar getMaxDate() { | ||
@Nullable | ||
Calendar getMaxDate() { | ||
return mMaxDate; | ||
} | ||
|
||
@Nullable Calendar[] getSelectableDays() { | ||
return selectableDays.isEmpty() ? null : selectableDays.toArray(new Calendar[0]); | ||
@Nullable | ||
Calendar[] getSelectableDays() { | ||
return selectableDays.isEmpty() ? null : selectableDays.toArray(new Calendar[0]); | ||
} | ||
|
||
@Nullable Calendar[] getDisabledDays() { | ||
@Nullable | ||
Calendar[] getDisabledDays() { | ||
return disabledDays.isEmpty() ? null : disabledDays.toArray(new Calendar[0]); | ||
} | ||
|
||
@Nullable | ||
List<Integer> getWeekendDays() { | ||
return weekendDays; | ||
} | ||
|
||
@Override | ||
public int getMinYear() { | ||
if (!selectableDays.isEmpty()) return selectableDays.first().get(Calendar.YEAR); | ||
|
@@ -143,7 +164,8 @@ public int getMaxYear() { | |
} | ||
|
||
@Override | ||
public @NonNull Calendar getStartDate() { | ||
public @NonNull | ||
Calendar getStartDate() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to make sure the start date is not on a disabled weekday |
||
if (!selectableDays.isEmpty()) return (Calendar) selectableDays.first().clone(); | ||
if (mMinDate != null) return (Calendar) mMinDate.clone(); | ||
TimeZone timeZone = mController == null ? TimeZone.getDefault() : mController.getTimeZone(); | ||
|
@@ -155,7 +177,8 @@ public int getMaxYear() { | |
} | ||
|
||
@Override | ||
public @NonNull Calendar getEndDate() { | ||
public @NonNull | ||
Calendar getEndDate() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to make sure the end date is not on a disabled weekday |
||
if (!selectableDays.isEmpty()) return (Calendar) selectableDays.last().clone(); | ||
if (mMaxDate != null) return (Calendar) mMaxDate.clone(); | ||
TimeZone timeZone = mController == null ? TimeZone.getDefault() : mController.getTimeZone(); | ||
|
@@ -183,7 +206,13 @@ public boolean isOutOfRange(int year, int month, int day) { | |
|
||
private boolean isOutOfRange(@NonNull Calendar calendar) { | ||
Utils.trimToMidnight(calendar); | ||
return isDisabled(calendar) || !isSelectable(calendar); | ||
return isDisabled(calendar) || !isSelectable(calendar) || isWeekend(calendar); | ||
} | ||
|
||
|
||
private boolean isWeekend(@NonNull Calendar calendar) { | ||
int dayId = calendar.get(Calendar.DAY_OF_WEEK); | ||
return weekendDays.contains(dayId); | ||
} | ||
|
||
private boolean isDisabled(@NonNull Calendar c) { | ||
|
@@ -203,7 +232,8 @@ private boolean isAfterMax(@NonNull Calendar calendar) { | |
} | ||
|
||
@Override | ||
public @NonNull Calendar setToNearestDate(@NonNull Calendar calendar) { | ||
public @NonNull | ||
Calendar setToNearestDate(@NonNull Calendar calendar) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setToNearest will need to take the disabled weekdays into account (you don't want to return a date that is disabled) |
||
if (!selectableDays.isEmpty()) { | ||
Calendar newCalendar = null; | ||
Calendar higher = selectableDays.ceiling(calendar); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,35 +2,37 @@ | |
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<LinearLayout | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you remove this? |
||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="16dp"> | ||
|
||
<!-- DatePicker Options --> | ||
<TextView | ||
android:id="@+id/date_textview" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/selected_date"/> | ||
android:text="@string/selected_date" /> | ||
|
||
<Button | ||
android:id="@+id/date_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/pick_date"/> | ||
android:text="@string/pick_date" /> | ||
|
||
<Button | ||
android:id="@+id/original_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/original_button"/> | ||
android:text="@string/original_button" /> | ||
|
||
<CheckBox | ||
android:id="@+id/show_version_2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/show_version_2"/> | ||
android:text="@string/show_version_2" /> | ||
|
||
<CheckBox | ||
android:id="@+id/mode_dark_date" | ||
|
@@ -48,8 +50,8 @@ | |
android:id="@+id/vibrate_date" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/vibrate" | ||
android:checked="true"/> | ||
android:checked="true" | ||
android:text="@string/vibrate" /> | ||
|
||
<CheckBox | ||
android:id="@+id/switch_orientation" | ||
|
@@ -61,36 +63,45 @@ | |
android:id="@+id/dismiss_date" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/dismiss" | ||
android:checked="false"/> | ||
android:checked="false" | ||
android:text="@string/dismiss" /> | ||
|
||
<CheckBox | ||
android:id="@+id/show_year_first" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/show_year_first" | ||
android:checked="false"/> | ||
android:checked="false" | ||
android:text="@string/show_year_first" /> | ||
|
||
<CheckBox | ||
android:id="@+id/title_date" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/title" | ||
android:checked="false"/> | ||
android:checked="false" | ||
android:text="@string/title" /> | ||
|
||
<CheckBox | ||
android:id="@+id/limit_dates" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/limit_dates" | ||
android:checked="false"/> | ||
android:checked="false" | ||
android:text="@string/limit_dates" /> | ||
|
||
<CheckBox | ||
android:id="@+id/highlight_dates" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/highlight_dates" | ||
android:checked="false"/> | ||
android:checked="false" | ||
android:text="@string/highlight_dates" /> | ||
|
||
|
||
<CheckBox | ||
|
||
android:id="@+id/weekend_dates" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:checked="false" | ||
android:text="@string/weekend_dates" /> | ||
|
||
</LinearLayout> | ||
</androidx.core.widget.NestedScrollView> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't update gradle in a feature PR, unless it's required for the functionality you are building.
This avoids merge conflicts if gradle gets upgraded in master before your PR lands