Skip to content

Commit 4f7c76b

Browse files
committed
Fixed recurrence formatting and better preset defaults
1 parent 658be34 commit 4f7c76b

File tree

14 files changed

+169
-171
lines changed

14 files changed

+169
-171
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v1.4.3
2+
- Changed "Every 1 day/month/..." formatting to "Every day/month/...".
3+
- Removed the "Repeats" part of the formatted recurrence.
4+
- Fixed bug where changing start date of dialog didn't update the text of custom defaults in option list.
5+
16
## v1.4.2
27
- Fixed French translation.
38
- Fixed bug where days of the week of weekly recurrence were not checked.

app/src/main/AndroidManifest.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
-->
2222

2323
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
24+
xmlns:tools="http://schemas.android.com/tools"
2425
package="com.maltaisn.recurpickerdemo"
2526
>
2627

@@ -29,8 +30,12 @@
2930
android:label="@string/app_name"
3031
android:supportsRtl="true"
3132
android:theme="@style/AppTheme"
33+
tools:ignore="AllowBackup,GoogleAppIndexingWarning,MissingApplicationIcon"
3234
>
33-
<activity android:name=".MainActivity">
35+
<activity
36+
android:name=".MainActivity"
37+
android:windowSoftInputMode="stateAlwaysHidden"
38+
>
3439
<intent-filter>
3540
<action android:name="android.intent.action.MAIN"/>
3641

app/src/main/java/com/maltaisn/recurpickerdemo/MainActivity.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import android.app.DatePickerDialog;
2525
import android.os.Bundle;
26+
import android.support.annotation.NonNull;
2627
import android.support.v7.app.AppCompatActivity;
2728
import android.text.Editable;
2829
import android.text.TextWatcher;
@@ -145,10 +146,8 @@ public void onDateSet(DatePicker datePicker, int year, int month, int day) {
145146
startDateValue.setText(dateFormatLong.format(startDate.getTimeInMillis()));
146147

147148
// Also needs to update current recurrence
148-
if (recurrence != null) {
149-
recurrence.setStartDate(startDate.getTimeInMillis());
150-
selectRecurrence(recurrence); // Update interface
151-
}
149+
recurrence.setStartDate(startDate.getTimeInMillis());
150+
selectRecurrence(recurrence); // Update interface
152151

153152
// Check if end date is before start date
154153
if (maxEndDate != null && !Recurrence.isOnSameDayOrAfter(maxEndDate, startDate)) {

app/src/main/res/values/styles.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<style name="RecurrencePickerStyleCustom"
3636
parent="RecurrencePickerStyle">
3737
<!--
38-
You can customize the recurrence picker style here ex:
38+
You can customize the recurrence picker style here eg:
3939
<item name="colorHeaderBackground">?attr/colorPrimary</item>
4040
-->
4141
</style>

recurpicker/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ ext {
1414
siteUrl = 'https://github.com/maltaisn/recurpickerlib'
1515
gitUrl = 'https://github.com/maltaisn/recurpickerlib.git'
1616

17-
libraryVersionCode = 14
18-
libraryVersion = '1.4.2'
17+
libraryVersionCode = 15
18+
libraryVersion = '1.4.3'
1919

2020
developerId = 'maltaisn'
2121

recurpicker/src/main/java/com/maltaisn/recurpicker/Recurrence.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,13 @@ public byte[] toByteArray() {
688688
return bb.array();
689689
}
690690

691+
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
691692
@Override
692693
public boolean equals(Object obj) {
694+
return equals(obj, false);
695+
}
696+
697+
boolean equals(Object obj, boolean ignoreStartDate) {
693698
if (obj == this) return true;
694699
if (!(obj instanceof Recurrence)) return false;
695700

@@ -700,7 +705,7 @@ public boolean equals(Object obj) {
700705
r.daySetting == daySetting &&
701706
r.endType == endType &&
702707
(endCount == 0 || r.endCount == endCount) &&
703-
isOnSameDay(r.startDate, startDate) &&
708+
(ignoreStartDate || isOnSameDay(r.startDate, startDate)) &&
704709
(endDate == null || isOnSameDay(r.endDate, endDate));
705710
}
706711

@@ -722,15 +727,15 @@ public String toString() {
722727
recurSb.append(", ");
723728
switch (period) {
724729
case NONE:
725-
recurSb.append("Does not repeat");
730+
recurSb.append("does not repeat");
726731

727732
case DAILY:
728-
recurSb.append("repeats on every ");
733+
recurSb.append("on every ");
729734
recurSb.append(toStringPlural("day", frequency, false));
730735
break;
731736

732737
case WEEKLY:
733-
recurSb.append("repeats on every ");
738+
recurSb.append("on every ");
734739
recurSb.append(toStringPlural("week", frequency, false));
735740
if (!isDefault) {
736741
// Make a list of days of week
@@ -753,7 +758,7 @@ public String toString() {
753758
break;
754759

755760
case Recurrence.MONTHLY:
756-
recurSb.append("repeats on every ");
761+
recurSb.append("on every ");
757762
recurSb.append(toStringPlural("month", frequency, false));
758763
if (!isDefault) {
759764
recurSb.append(" (");
@@ -779,7 +784,7 @@ public String toString() {
779784
break;
780785

781786
case YEARLY:
782-
recurSb.append("repeats on every ");
787+
recurSb.append("on every ");
783788
recurSb.append(toStringPlural("year", frequency, false));
784789
break;
785790
}

recurpicker/src/main/java/com/maltaisn/recurpicker/RecurrenceFormat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public String format(Recurrence r) {
159159
/**
160160
* Get the text for a date to display on a monthly recurrence repeated on the same day of week of same week
161161
* @param date date to get it for
162-
* @return ex: "on third Sunday" or "on last Friday"
162+
* @return eg: "on third Sunday" or "on last Friday"
163163
*/
164164
String getSameDayOfSameWeekString(long date) {
165165
calendar.setTimeInMillis(date);

recurpicker/src/main/java/com/maltaisn/recurpicker/RecurrencePickerSettings.java

+62-58
Original file line numberDiff line numberDiff line change
@@ -47,78 +47,84 @@ public interface RecurrencePickerSettings {
4747
boolean DEFAULT_SHOW_CANCEL_BTN = false;
4848
int DEFAULT_ENABLED_PERIODS = 0b1111;
4949
int DEFAULT_ENABLED_END_TYPES = 0b111;
50-
Recurrence[] DEFAULT_OPTION_LIST_DEFAULTS = null;
50+
51+
Recurrence[] DEFAULT_OPTION_LIST_DEFAULTS = new Recurrence[]{
52+
new Recurrence(0, Recurrence.DAILY),
53+
new Recurrence(0, Recurrence.WEEKLY),
54+
new Recurrence(0, Recurrence.MONTHLY),
55+
new Recurrence(0, Recurrence.YEARLY),
56+
};
5157
CharSequence[] DEFAULT_OPTION_LIST_TITLES = null;
5258

5359
/**
54-
* Set the date format to use
55-
* By default, the system default date format is used
56-
* You should call this method before {@link #setRecurrence(Recurrence, long)}
57-
* @param endDateFormat Date format to use for the end date
58-
* This date should usually be shorter
59-
* @param optionListDateFormat Date format to use for the custom item in the option list
60-
* This date should usually be more verbose
60+
* Set the date format to use.
61+
* By default, the system default date format is used.
62+
* You should call this method before {@link #setRecurrence(Recurrence, long)}.
63+
* @param endDateFormat Date format to use for the end date.
64+
* This date should usually be shorter.
65+
* @param optionListDateFormat Date format to use for the custom item in the option list.
66+
* This date should usually be more verbose.
6167
*/
6268
RecurrencePickerSettings setDateFormat(@NonNull DateFormat endDateFormat, @NonNull DateFormat optionListDateFormat);
6369

6470
/**
65-
* Call this method to initialize the recurrence picker with a recurrence and a date
66-
* @param recurrence Recurrence to display, use null for the default "does not repeat"
67-
* @param startDate Starting date of recurrence to be returned, use 0 for today
71+
* Call this method to initialize the recurrence picker with a recurrence and a date.
72+
* @param recurrence Recurrence to display, use null for the default "does not repeat".
73+
* @param startDate Starting date of recurrence to be returned, use {@code 0} for today.
6874
*/
6975
RecurrencePickerSettings setRecurrence(@Nullable Recurrence recurrence, long startDate);
7076

7177
/**
72-
* Set the maximum event count for a recurrence
73-
* By default, the maximum number of events is 999
74-
* Must be set before showing the creator or the dialog
75-
* @param max Maximum count, set to -1 to allow any number of events
76-
* Even if set to -1, maximum is {@link RecurrencePickerView#MAX_FIELD_VALUE}
78+
* Set the maximum event count for a recurrence.
79+
* By default, the maximum number of events is 999.
80+
* Must be set before showing the creator or the dialog.
81+
* @param max Maximum count, set to {@code -1} to allow any number of events
82+
* Even if set to {@code -1}, maximum is {@link RecurrencePickerView#MAX_FIELD_VALUE}.
7783
*/
7884
RecurrencePickerSettings setMaxEventCount(int max);
7985

8086
/**
81-
* Set the maximum frequency for a period
82-
* By default, maximum frequency is 99
83-
* Must be set before showing the creator or the dialog
84-
* ex: if 10, maximum will be: every 10 days, every 10 weeks, every 10 months...
85-
* @param max Maximum frequency, set to -1 to allow any value
86-
* Even if set to -1, maximum is {@link RecurrencePickerView#MAX_FIELD_VALUE}
87+
* Set the maximum frequency for a period.
88+
* By default, maximum frequency is 99.
89+
* Must be set before showing the creator or the dialog.
90+
* Eg: if {@code 10}, maximum will be: every 10 days, every 10 weeks, every 10 months...
91+
* @param max Maximum frequency, set to {@code -1} to allow any value.
92+
* Even if set to {@code -1}, maximum is {@link RecurrencePickerView#MAX_FIELD_VALUE}.
8793
*/
8894
RecurrencePickerSettings setMaxFrequency(int max);
8995

9096
/**
91-
* Set the maximum end date for a recurrence
92-
* By default, there is no maximum end date
93-
* Must be set before showing the creator or the dialog
94-
* @param time Time in millis for a date, set to -1 for no maximum
97+
* Set the maximum end date for a recurrence.
98+
* By default, there is no maximum end date.
99+
* Must be set before showing the creator or the dialog.
100+
* @param time Time in millis for a date, set to {@code -1} for no maximum.
95101
*/
96102
RecurrencePickerSettings setMaxEndDate(long time);
97103

98104
/**
99-
* Change how the end date is set relative to the start date by default
100-
* By default, default end date is 3 periods after start date
101-
* Must be set before showing the creator or the dialog
102-
* @param usePeriod If true, will use the currently selected period as the unit of the interval
103-
* ex: if repeating weekly and interval is 3, default end date will be 3 weeks after start date
104-
* If false, will use days as the unit of the interval
105-
* @param interval How many periods/days after start date to set default end date
105+
* Change how the end date is set relative to the start date by default.
106+
* By default, default end date is 3 periods after start date.
107+
* Must be set before showing the creator or the dialog.
108+
* @param usePeriod If true, will use the currently selected period as the unit of the interval.
109+
* Eg: if repeating weekly and interval is 3, default end date will be 3 weeks after start date.
110+
* If false, will use days as the unit of the interval.
111+
* @param interval How many periods/days after start date to set default end date.
106112
*/
107113
RecurrencePickerSettings setDefaultEndDate(boolean usePeriod, int interval);
108114

109115
/**
110-
* Set the number of events to show by default
111-
* By default, recurrence ends after 5 events
112-
* Must be set before showing the creator or the dialog
113-
* @param count Number of events to show by default
116+
* Set the number of events to show by default.
117+
* By default, recurrence ends after 5 events.
118+
* Must be set before showing the creator or the dialog.
119+
* @param count Number of events to show by default.
114120
*/
115121
RecurrencePickerSettings setDefaultEndCount(int count);
116122

117123
/**
118-
* Select which modes are enabled: default options list and recurrence creator
119-
* By default, both modes are enabled, and at least one of them should be
120-
* @param optionListEnabled whether to enable the default options list
121-
* @param creatorEnabled whether to enabled the recurrence creator
124+
* Select which modes are enabled: default options list and recurrence creator.
125+
* By default, both modes are enabled, and at least one of them should be.
126+
* @param optionListEnabled whether to enable the default options list.
127+
* @param creatorEnabled whether to enabled the recurrence creator.
122128
*/
123129
RecurrencePickerSettings setEnabledModes(boolean optionListEnabled, boolean creatorEnabled);
124130

@@ -134,47 +140,45 @@ public interface RecurrencePickerSettings {
134140
* Set whether the header should be displayed in the first screen, the list of default recurrence options,
135141
* or not. If you wish to also hide the header in the creator mode, you can change its background color.
136142
* By default, header is shown.
137-
* @param show Whether to show it or not
143+
* @param show Whether to show it or not.
138144
*/
139145
RecurrencePickerSettings setShowHeaderInOptionList(boolean show);
140146

141147
/**
142148
* Set whether to show a cancel button or not. Cancel button is placed at the left side of the done button.
143149
* By default, cancel button is hidden.
144-
* @param show Whether to show it or not
150+
* @param show Whether to show it or not.
145151
*/
146152
RecurrencePickerSettings setShowCancelButton(boolean show);
147153

148154
/**
149-
* Set which periods are available to be used. Note that NONE period cannot be disabled
155+
* Set which periods are available to be used. Note that {@code NONE} period cannot be disabled.
150156
* You must set at least one period.
151157
* Must be set before showing the creator or the dialog
152-
* @param periods bit field of 1 << [Recurrence.DAILY to Recurrence.YEARLY]. Ex:
153-
* periods = (1 << Recurrence.DAILY) | (1 << Recurrence.WEEKLY)
158+
* @param periods bit field of recurrence period constants. ({@code DAILY} to {@code YEARLY})
159+
* Eg: {@code periods = (1 << Recurrence.DAILY) | (1 << Recurrence.YEARLY)}
154160
* Don't forget the parentheses!
155-
* A quicker way would be to use binary literal ex: periods = 0b1111 (all periods)
156161
*/
157162
RecurrencePickerSettings setEnabledPeriods(int periods);
158163

159164
/**
160-
* Set which end types are available to be used. Note that END_BY_DATE_OR_COUNT is not implemented
165+
* Set which end types are available to be used.
161166
* You must set at least one type. If that's the case, end type spinner will be disabled.
162167
* If the only end type set is forever, end type spinner completely disappears.
163-
* Must be set before showing the creator or the dialog
164-
* @param types bit field of 1 << [Recurrence.END_NEVER, END_BY_DATE and END_BY_COUNT]. Ex:
165-
* periods = (1 << Recurrence.END_BY_DATE) | (1 << Recurrence.END_BY_COUNT)
168+
* Must be set before showing the creator or the dialog.
169+
* @param types bit field of recurrence end types.
170+
* Eg: {@code types = (1 << Recurrence.END_BY_DATE) | (1 << Recurrence.END_BY_COUNT)}
166171
* Don't forget the parentheses!
167-
* A quicker way would be to use binary literal ex: types = 0b111 (all types)
168172
*/
169173
RecurrencePickerSettings setEnabledEndTypes(int types);
170174

171175
/**
172-
* Change defaults in option list. Note that "Does not repeat" will always be shown.
173-
* By default, a daily, weekly, monthly and yearly recurrences with frequency of 1 are used
174-
* MUST be set before setting the recurrence if using the view by itself
175-
* @param defaults Array of recurrence to use as defaults, leave null to use default defaults (exactly)
176-
* or leave null to only change the titles
177-
* You can set any start date for these recurrences because it gets changed
176+
* Change defaults in option list. Note that "Does not repeat" will always be shown first.
177+
* By default, a daily, weekly, monthly and yearly recurrences with frequency of 1 are used.
178+
* Must be set before setting the recurrence if using the view by itself.
179+
* @param defaults Array of recurrence to use as defaults, leave null to use default defaults,
180+
* or to only change the titles.
181+
* You can set any start date for these recurrences because it gets changed.
178182
* @param titles Array of titles to use for each recurrence, leave null to use
179183
* {@link RecurrenceFormat#format(Recurrence)} instead. You can also leave
180184
* specific items in array null to only format those.

0 commit comments

Comments
 (0)