Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1bf9057

Browse files
committed
Merge pull request #270 from code-troopers/fix/269
Fix/269 : looks ok to me
2 parents aebc2ae + 48362d5 commit 1bf9057

File tree

4 files changed

+62
-58
lines changed

4 files changed

+62
-58
lines changed

library/src/main/java/com/codetroopers/betterpickers/recurrencepicker/EventRecurrenceFormatter.java

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ public class EventRecurrenceFormatter {
3131
private static int[] mMonthRepeatByDayOfWeekIds;
3232
private static String[][] mMonthRepeatByDayOfWeekStrs;
3333

34-
public static String getRepeatString(Context context, Resources r, EventRecurrence recurrence,
35-
boolean includeEndString) {
34+
public static String getRepeatString(Context context, Resources r, EventRecurrence recurrence, boolean includeEndString) {
3635
String endString = "";
3736
if (includeEndString) {
3837
StringBuilder sb = new StringBuilder();
3938
if (recurrence.until != null) {
4039
try {
41-
Time t = new Time();
42-
t.parse(recurrence.until);
43-
final String dateStr = DateUtils.formatDateTime(context,
44-
t.toMillis(false), DateUtils.FORMAT_NUMERIC_DATE);
40+
Time time = new Time();
41+
time.parse(recurrence.until);
42+
final String dateStr = DateUtils.formatDateTime(context, time.toMillis(false), DateUtils.FORMAT_NUMERIC_DATE);
4543
sb.append(r.getString(R.string.endByDate, dateStr));
4644
} catch (TimeFormatException e) {
4745
}
@@ -98,32 +96,23 @@ public static String getRepeatString(Context context, Resources r, EventRecurren
9896
int day = EventRecurrence.timeDay2Day(recurrence.startDate.weekDay);
9997
string = dayToString(day, DateUtils.LENGTH_LONG);
10098
}
101-
return r.getQuantityString(R.plurals.weekly, interval, interval, string)
102-
+ endString;
99+
return r.getQuantityString(R.plurals.weekly, interval, interval, string) + endString;
103100
}
104101
}
105102
case EventRecurrence.MONTHLY: {
106-
if (recurrence.bydayCount == 1) {
107-
int weekday;
108-
if (recurrence.startDate == null) {
109-
return null;
110-
}
111-
weekday = recurrence.startDate.weekDay;
103+
String details = "";
104+
if (recurrence.byday != null) {
105+
int weekday = EventRecurrence.day2CalendarDay(recurrence.byday[0]) - 1;
106+
int dayNumber = recurrence.bydayNum[0];
112107
// Cache this stuff so we won't have to redo work again later.
113108
cacheMonthRepeatStrings(r, weekday);
114-
int dayNumber = (recurrence.startDate.monthDay - 1) / 7;
115-
StringBuilder sb = new StringBuilder();
116-
sb.append(r.getString(R.string.monthly));
117-
sb.append(" (");
118-
sb.append(mMonthRepeatByDayOfWeekStrs[weekday][dayNumber]);
119-
sb.append(")");
120-
sb.append(endString);
121-
return sb.toString();
109+
110+
details = mMonthRepeatByDayOfWeekStrs[weekday][dayNumber - 1];
122111
}
123-
return r.getString(R.string.monthly) + endString;
112+
return r.getQuantityString(R.plurals.monthly, interval, interval, details) + endString;
124113
}
125114
case EventRecurrence.YEARLY:
126-
return r.getString(R.string.yearly_plain) + endString;
115+
return r.getQuantityString(R.plurals.yearly_plain, interval, interval, "") + endString;
127116
}
128117

129118
return null;
@@ -144,8 +133,7 @@ private static void cacheMonthRepeatStrings(Resources r, int weekday) {
144133
mMonthRepeatByDayOfWeekStrs = new String[7][];
145134
}
146135
if (mMonthRepeatByDayOfWeekStrs[weekday] == null) {
147-
mMonthRepeatByDayOfWeekStrs[weekday] =
148-
r.getStringArray(mMonthRepeatByDayOfWeekIds[weekday]);
136+
mMonthRepeatByDayOfWeekStrs[weekday] = r.getStringArray(mMonthRepeatByDayOfWeekIds[weekday]);
149137
}
150138
}
151139

library/src/main/java/com/codetroopers/betterpickers/recurrencepicker/RecurrencePickerDialogFragment.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -561,19 +561,19 @@ static private void copyEventRecurrenceToModel(final EventRecurrence er,
561561
}
562562
}
563563

564-
static private void copyModelToEventRecurrence(final RecurrenceModel model, EventRecurrence er) {
564+
static private void copyModelToEventRecurrence(final RecurrenceModel model, EventRecurrence eventRecurrence) {
565565
if (model.recurrenceState == RecurrenceModel.STATE_NO_RECURRENCE) {
566566
throw new IllegalStateException("There's no recurrence");
567567
}
568568

569569
// Freq
570-
er.freq = mFreqModelToEventRecurrence[model.freq];
570+
eventRecurrence.freq = mFreqModelToEventRecurrence[model.freq];
571571

572572
// Interval
573573
if (model.interval <= 1) {
574-
er.interval = 0;
574+
eventRecurrence.interval = 0;
575575
} else {
576-
er.interval = model.interval;
576+
eventRecurrence.interval = model.interval;
577577
}
578578

579579
// End
@@ -582,52 +582,52 @@ static private void copyModelToEventRecurrence(final RecurrenceModel model, Even
582582
if (model.endDate != null) {
583583
model.endDate.switchTimezone(Time.TIMEZONE_UTC);
584584
model.endDate.normalize(false);
585-
er.until = model.endDate.format2445();
586-
er.count = 0;
585+
eventRecurrence.until = model.endDate.format2445();
586+
eventRecurrence.count = 0;
587587
} else {
588588
throw new IllegalStateException("end = END_BY_DATE but endDate is null");
589589
}
590590
break;
591591
case RecurrenceModel.END_BY_COUNT:
592-
er.count = model.endCount;
593-
er.until = null;
594-
if (er.count <= 0) {
595-
throw new IllegalStateException("count is " + er.count);
592+
eventRecurrence.count = model.endCount;
593+
eventRecurrence.until = null;
594+
if (eventRecurrence.count <= 0) {
595+
throw new IllegalStateException("count is " + eventRecurrence.count);
596596
}
597597
break;
598598
default:
599-
er.count = 0;
600-
er.until = null;
599+
eventRecurrence.count = 0;
600+
eventRecurrence.until = null;
601601
break;
602602
}
603603

604604
// Weekly && monthly repeat patterns
605-
er.bydayCount = 0;
606-
er.bymonthdayCount = 0;
605+
eventRecurrence.bydayCount = 0;
606+
eventRecurrence.bymonthdayCount = 0;
607607

608608
switch (model.freq) {
609609
case RecurrenceModel.FREQ_MONTHLY:
610610
if (model.monthlyRepeat == RecurrenceModel.MONTHLY_BY_DATE) {
611611
if (model.monthlyByMonthDay > 0) {
612-
if (er.bymonthday == null || er.bymonthdayCount < 1) {
613-
er.bymonthday = new int[1];
612+
if (eventRecurrence.bymonthday == null || eventRecurrence.bymonthdayCount < 1) {
613+
eventRecurrence.bymonthday = new int[1];
614614
}
615-
er.bymonthday[0] = model.monthlyByMonthDay;
616-
er.bymonthdayCount = 1;
615+
eventRecurrence.bymonthday[0] = model.monthlyByMonthDay;
616+
eventRecurrence.bymonthdayCount = 1;
617617
}
618618
} else if (model.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) {
619619
if (!isSupportedMonthlyByNthDayOfWeek(model.monthlyByNthDayOfWeek)) {
620620
throw new IllegalStateException("month repeat by nth week but n is "
621621
+ model.monthlyByNthDayOfWeek);
622622
}
623623
int count = 1;
624-
if (er.bydayCount < count || er.byday == null || er.bydayNum == null) {
625-
er.byday = new int[count];
626-
er.bydayNum = new int[count];
624+
if (eventRecurrence.bydayCount < count || eventRecurrence.byday == null || eventRecurrence.bydayNum == null) {
625+
eventRecurrence.byday = new int[count];
626+
eventRecurrence.bydayNum = new int[count];
627627
}
628-
er.bydayCount = count;
629-
er.byday[0] = EventRecurrence.timeDay2Day(model.monthlyByDayOfWeek);
630-
er.bydayNum[0] = model.monthlyByNthDayOfWeek;
628+
eventRecurrence.bydayCount = count;
629+
eventRecurrence.byday[0] = EventRecurrence.timeDay2Day(model.monthlyByDayOfWeek);
630+
eventRecurrence.bydayNum[0] = model.monthlyByNthDayOfWeek;
631631
}
632632
break;
633633
case RecurrenceModel.FREQ_WEEKLY:
@@ -638,24 +638,24 @@ static private void copyModelToEventRecurrence(final RecurrenceModel model, Even
638638
}
639639
}
640640

641-
if (er.bydayCount < count || er.byday == null || er.bydayNum == null) {
642-
er.byday = new int[count];
643-
er.bydayNum = new int[count];
641+
if (eventRecurrence.bydayCount < count || eventRecurrence.byday == null || eventRecurrence.bydayNum == null) {
642+
eventRecurrence.byday = new int[count];
643+
eventRecurrence.bydayNum = new int[count];
644644
}
645-
er.bydayCount = count;
645+
eventRecurrence.bydayCount = count;
646646

647647
for (int i = 6; i >= 0; i--) {
648648
if (model.weeklyByDayOfWeek[i]) {
649-
er.bydayNum[--count] = 0;
650-
er.byday[count] = EventRecurrence.timeDay2Day(i);
649+
eventRecurrence.bydayNum[--count] = 0;
650+
eventRecurrence.byday[count] = EventRecurrence.timeDay2Day(i);
651651
}
652652
}
653653
break;
654654
}
655655

656-
if (!canHandleRecurrenceRule(er)) {
656+
if (!canHandleRecurrenceRule(eventRecurrence)) {
657657
throw new IllegalStateException("UI generated recurrence that it can't handle. ER:"
658-
+ er.toString() + " Model: " + model.toString());
658+
+ eventRecurrence.toString() + " Model: " + model.toString());
659659
}
660660
}
661661

library/src/main/res/values-fr/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,16 @@
155155
<!-- The common portion of a string describing how often an event repeats,
156156
example: 'Monthly (on day 2)' -->
157157
<string name="monthly">Mensuel</string>
158+
<plurals name="monthly">
159+
<item quantity="one">Mensuel <xliff:g id="days_of_month">%2$s</xliff:g></item>
160+
<item quantity="other">Tous les <xliff:g id="number">%1$d</xliff:g> mois <xliff:g id="days_of_month">%2$s</xliff:g></item>
161+
</plurals>
158162
<!-- Calendar spinner item, to select that an event recurs every year. -->
159163
<string name="yearly_plain">Annuel</string>
164+
<plurals name="yearly_plain">
165+
<item quantity="one">Annuel <xliff:g id="days_of_month">%2$s</xliff:g></item>
166+
<item quantity="other">Tous les <xliff:g id="number">%1$d</xliff:g> ans <xliff:g id="days_of_month">%2$s</xliff:g></item>
167+
</plurals>
160168

161169
<string name="switch_on">ON</string>
162170
<string name="switch_off">OFF</string>

library/src/main/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,16 @@
183183
<!-- The common portion of a string describing how often an event repeats,
184184
example: 'Monthly (on day 2)' -->
185185
<string name="monthly">Monthly</string>
186+
<plurals name="monthly">
187+
<item quantity="one">Monthly <xliff:g id="days_of_month">%2$s</xliff:g></item>
188+
<item quantity="other">Every <xliff:g id="number">%1$d</xliff:g> months <xliff:g id="days_of_month">%2$s</xliff:g></item>
189+
</plurals>
186190
<!-- Calendar spinner item, to select that an event recurs every year. -->
187191
<string name="yearly_plain">Yearly</string>
192+
<plurals name="yearly_plain">
193+
<item quantity="one">Yearly <xliff:g id="days_of_month">%2$s</xliff:g></item>
194+
<item quantity="other">Every <xliff:g id="number">%1$d</xliff:g> years <xliff:g id="days_of_month">%2$s</xliff:g></item>
195+
</plurals>
188196

189197
<!-- Hint text to encourage the user to enter a country name to find a time zone
190198
[CHAR LIMIT=25] -->

0 commit comments

Comments
 (0)