Skip to content

Commit

Permalink
Added new option by month last and others updates
Browse files Browse the repository at this point in the history
Updated to support API 27, build tools 28.0.3, removed allowBackup, added new BYMONTHLAST option, updated MAX interval to 999, added MINUTELY and HOURLY, AM/PM corrections
  • Loading branch information
chrisonline committed Oct 13, 2018
1 parent 666f83f commit 20d2115
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 52 deletions.
1 change: 1 addition & 0 deletions sublimepickerlibrary/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
*.iml
25 changes: 15 additions & 10 deletions sublimepickerlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ ext {
}

android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
compileSdkVersion 27
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 27
versionCode 4
versionName "2.1.4"
}

lintOptions {
disable 'Instantiatable'
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -64,15 +69,15 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:gridlayout-v7:23.2.1'
compile 'com.android.support:support-annotations:23.2.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:gridlayout-v7:27.1.0'
implementation 'com.android.support:support-annotations:27.1.0'

// For IconicDrawable - No download needed (see https://github.com/mikepenz/Android-Iconics)
compile "com.mikepenz:iconics-core:2.8.2@aar"
compile 'com.mikepenz:community-material-typeface:1.7.22.1@aar'
implementation "com.mikepenz:iconics-core:2.8.2@aar"
implementation 'com.mikepenz:community-material-typeface:1.7.22.1@aar'
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
Expand Down
7 changes: 2 additions & 5 deletions sublimepickerlibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appeaser.sublimepickerlibrary">
<manifest package="com.appeaser.sublimepickerlibrary">

<application android:allowBackup="true">

</application>
<application />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.appeaser.sublimepickerlibrary.common.ButtonHandler;
import com.appeaser.sublimepickerlibrary.datepicker.SelectedDate;
Expand Down Expand Up @@ -618,6 +620,22 @@ private void processOptions() {
mTimePicker.setIs24HourView(mOptions.is24HourView());
mTimePicker.setValidationCallback(this);

// if AM/PM we need to move the icon to the left, because we don't have enough space
// to show it on the right
if(ivRecurrenceOptionsTP.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ivRecurrenceOptionsTP.getLayoutParams();
if (!mOptions.is24HourView()) {
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
} else {
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
if (SUtils.isApi_17_OrHigher()) {
params.addRule(RelativeLayout.ALIGN_PARENT_END);
}
}
ivRecurrenceOptionsTP.setLayoutParams(params); //causes layout update
}


ivRecurrenceOptionsTP.setVisibility(mRecurrencePickerEnabled ?
View.VISIBLE : View.GONE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.appeaser.sublimepickerlibrary.datepicker;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
Expand All @@ -32,7 +33,7 @@
* Indicator used for selected year in YearPickerView
* Needs fixing.
*/
class CircularIndicatorTextView extends TextView {
public class CircularIndicatorTextView extends TextView {
private static final int SELECTED_CIRCLE_ALPHA = 60;

private final Paint mCirclePaint = new Paint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class EventRecurrence {
public int bymonthCount;
public int[] bysetpos;
public int bysetposCount;
public int[] bymonthLast;
public int bymonthLastCount;

/**
* maps a part string to a parser object
Expand All @@ -96,6 +98,7 @@ public class EventRecurrence {
sParsePartMap.put("BYMONTH", new ParseByMonth());
sParsePartMap.put("BYSETPOS", new ParseBySetPos());
sParsePartMap.put("WKST", new ParseWkst());
sParsePartMap.put("BYMONTHLAST", new ParseByMonthLast());
}

/* values for bit vector that keeps track of what we have already seen */
Expand All @@ -113,6 +116,7 @@ public class EventRecurrence {
private static final int PARSED_BYMONTH = 1 << 11;
private static final int PARSED_BYSETPOS = 1 << 12;
private static final int PARSED_WKST = 1 << 13;
private static final int PARSED_BYMONTH_LAST = 1 << 14;

/**
* maps a FREQ value to an integer constant
Expand Down Expand Up @@ -392,6 +396,7 @@ public String toString() {
appendNumbers(s, ";BYWEEKNO=", this.byweeknoCount, this.byweekno);
appendNumbers(s, ";BYMONTH=", this.bymonthCount, this.bymonth);
appendNumbers(s, ";BYSETPOS=", this.bysetposCount, this.bysetpos);
appendNumbers(s, ";BYMONTHLAST=", this.bymonthLastCount, this.bymonthLast);

return s.toString();
}
Expand Down Expand Up @@ -490,6 +495,7 @@ public boolean equals(Object obj) {
arraysEqual(byyearday, byyeardayCount, er.byyearday, er.byyeardayCount) &&
arraysEqual(byweekno, byweeknoCount, er.byweekno, er.byweeknoCount) &&
arraysEqual(bymonth, bymonthCount, er.bymonth, er.bymonthCount) &&
arraysEqual(bymonthLast, bymonthLastCount, er.bymonthLast, er.bymonthLastCount) &&
arraysEqual(bysetpos, bysetposCount, er.bysetpos, er.bysetposCount);
}

Expand All @@ -512,7 +518,7 @@ private void resetFields() {
until = null;
freq = count = interval = bysecondCount = byminuteCount = byhourCount =
bydayCount = bymonthdayCount = byyeardayCount = byweeknoCount = bymonthCount =
bysetposCount = 0;
bymonthLastCount = bysetposCount = 0;
}

/**
Expand Down Expand Up @@ -833,7 +839,7 @@ public int parsePart(String value, EventRecurrence er) {
int[] bydayNum;
int bydayCount;

if (value.indexOf(",") < 0) {
if (value.indexOf(",") < 0) {
/* only one entry, skip split() overhead */
bydayCount = 1;
byday = new int[1];
Expand Down Expand Up @@ -932,6 +938,18 @@ public int parsePart(String value, EventRecurrence er) {
}
}

/**
* parses BYMONTHLAST=bymolist
*/
private static class ParseByMonthLast extends PartParser {
@Override
public int parsePart(String value, EventRecurrence er) {
int[] bymonthLast = parseNumberList(value, 1, 12, false);
er.bymonthLast = bymonthLast;
er.bymonthLastCount = bymonthLast.length;
return PARSED_BYMONTH_LAST;
}
}
/**
* parses BYSETPOS=bysplist
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ public static String getRepeatString(Context context, Resources r, EventRecurren
return sb.toString();
}

if(recurrence.bymonthLastCount == 1) {
StringBuilder sb = new StringBuilder();
sb.append(monthlyStart);
sb.append(" (");
sb.append(r.getString(R.string.on_the_last_day_each_month));
sb.append(")");
sb.append(endString);
return sb.toString();
}

return monthlyStart + endString;
}
case EventRecurrence.YEARLY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private enum CurrentView {
}

// Update android:maxLength in EditText as needed
private static final int INTERVAL_MAX = 99;
private static final int INTERVAL_MAX = 999;
private static final int INTERVAL_DEFAULT = 1;
// Update android:maxLength in EditText as needed
private static final int COUNT_MAX = 730;
Expand Down Expand Up @@ -175,6 +175,7 @@ private enum CurrentView {
private RadioGroup mMonthRepeatByRadioGroup;
private RadioButton mRepeatMonthlyByNthDayOfWeek;
private RadioButton mRepeatMonthlyByNthDayOfMonth;
private RadioButton mRepeatMonthlyByLastDyOfMonth;
private String mMonthRepeatByDayOfWeekStr;

private OnRecurrenceSetListener mRecurrenceSetListener;
Expand Down Expand Up @@ -241,6 +242,7 @@ private class RecurrenceModel implements Parcelable {

static final int MONTHLY_BY_DATE = 0;
static final int MONTHLY_BY_NTH_DAY_OF_WEEK = 1;
static final int MONTHLY_BY_LAST_DAY_OF_MONTH = 2;

static final int STATE_NO_RECURRENCE = 0;
static final int STATE_RECURRENCE = 1;
Expand Down Expand Up @@ -289,6 +291,12 @@ private class RecurrenceModel implements Parcelable {
*/
int monthlyByMonthDay;

/**
* Day of the month to repeat. Used when monthlyRepeat ==
* MONTHLY_BY_LAST_DAY_OF_MONTH
*/
int monthlyByLastDayOfMonth;

/**
* Day of the week to repeat. Used when monthlyRepeat ==
* MONTHLY_BY_NTH_DAY_OF_WEEK
Expand All @@ -313,7 +321,8 @@ public String toString() {
+ endDate + ", endCount=" + endCount + ", weeklyByDayOfWeek="
+ Arrays.toString(weeklyByDayOfWeek) + ", monthlyRepeat=" + monthlyRepeat
+ ", monthlyByMonthDay=" + monthlyByMonthDay + ", monthlyByDayOfWeek="
+ monthlyByDayOfWeek + ", monthlyByNthDayOfWeek=" + monthlyByNthDayOfWeek + "]";
+ monthlyByDayOfWeek + ", monthlyByNthDayOfWeek=" + monthlyByNthDayOfWeek
+ ", monthlyByLastDayOfMonth=" + monthlyByLastDayOfMonth +"]";
}

@Override
Expand All @@ -340,6 +349,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeBooleanArray(weeklyByDayOfWeek);
dest.writeInt(monthlyRepeat);
dest.writeInt(monthlyByMonthDay);
dest.writeInt(monthlyByLastDayOfMonth);
dest.writeInt(monthlyByDayOfWeek);
dest.writeInt(monthlyByNthDayOfWeek);
dest.writeInt(recurrenceState);
Expand All @@ -357,6 +367,7 @@ private void readFromParcel(Parcel in) {
in.readBooleanArray(weeklyByDayOfWeek);
monthlyRepeat = in.readInt();
monthlyByMonthDay = in.readInt();
monthlyByLastDayOfMonth = in.readInt();
monthlyByDayOfWeek = in.readInt();
monthlyByNthDayOfWeek = in.readInt();
recurrenceState = in.readInt();
Expand Down Expand Up @@ -511,6 +522,10 @@ static private void copyEventRecurrenceToModel(final EventRecurrence er,
break;
case EventRecurrence.MONTHLY:
model.freq = RecurrenceModel.FREQ_MONTHLY;
if(er.bymonthLastCount == 1) {
model.monthlyRepeat = RecurrenceModel.MONTHLY_BY_LAST_DAY_OF_MONTH;
model.monthlyByLastDayOfMonth = er.bymonthLastCount;
}
break;
case EventRecurrence.YEARLY:
model.freq = RecurrenceModel.FREQ_YEARLY;
Expand Down Expand Up @@ -647,6 +662,7 @@ static private void copyModelToEventRecurrence(final RecurrenceModel model,
// Weekly && monthly repeat patterns
er.bydayCount = 0;
er.bymonthdayCount = 0;
er.bymonthLastCount = 0;

switch (model.freq) {
case RecurrenceModel.FREQ_MONTHLY:
Expand All @@ -671,6 +687,10 @@ static private void copyModelToEventRecurrence(final RecurrenceModel model,
er.bydayCount = count;
er.byday[0] = EventRecurrence.timeDay2Day(model.monthlyByDayOfWeek);
er.bydayNum[0] = model.monthlyByNthDayOfWeek;
} else if(model.monthlyRepeat == RecurrenceModel.MONTHLY_BY_LAST_DAY_OF_MONTH) {
er.bymonthLastCount = 1;
er.bymonthLast = new int[1];
er.bymonthLast[0] = model.monthlyByLastDayOfMonth;
}
break;
case RecurrenceModel.FREQ_WEEKLY:
Expand Down Expand Up @@ -910,6 +930,8 @@ void onChange(int v) {
findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
mRepeatMonthlyByNthDayOfMonth = (RadioButton)
findViewById(R.id.repeatMonthlyByNthDayOfMonth);
mRepeatMonthlyByLastDyOfMonth = (RadioButton)
findViewById(R.id.repeatMonthlyByLastDayOfMonth);
}

public void initializeData(long currentlyChosenTime,
Expand Down Expand Up @@ -976,6 +998,7 @@ private void togglePickerOptions() {
mEndDateTextView.setEnabled(false);
mRepeatMonthlyByNthDayOfWeek.setEnabled(false);
mRepeatMonthlyByNthDayOfMonth.setEnabled(false);
mRepeatMonthlyByLastDyOfMonth.setEnabled(false);
for (Button button : mWeekByDayButtons) {
button.setEnabled(false);
}
Expand All @@ -992,6 +1015,7 @@ private void togglePickerOptions() {
mEndDateTextView.setEnabled(true);
mRepeatMonthlyByNthDayOfWeek.setEnabled(true);
mRepeatMonthlyByNthDayOfMonth.setEnabled(true);
mRepeatMonthlyByLastDyOfMonth.setEnabled(true);
for (Button button : mWeekByDayButtons) {
button.setEnabled(true);
}
Expand Down Expand Up @@ -1176,8 +1200,13 @@ public void updateDialog() {

if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_DATE) {
mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfMonth);
mModel.monthlyByLastDayOfMonth = 0;
} else if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) {
mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfTheWeek);
mModel.monthlyByLastDayOfMonth = 0;
} else if(mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_LAST_DAY_OF_MONTH) {
mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByLastDayOfMonth);
mModel.monthlyByLastDayOfMonth = 1;
}

if (mMonthRepeatByDayOfWeekStr == null) {
Expand Down Expand Up @@ -1379,6 +1408,8 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
mModel.monthlyRepeat = RecurrenceModel.MONTHLY_BY_DATE;
} else if (checkedId == R.id.repeatMonthlyByNthDayOfTheWeek) {
mModel.monthlyRepeat = RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK;
} else if (checkedId == R.id.repeatMonthlyByLastDayOfMonth) {
mModel.monthlyRepeat = RecurrenceModel.MONTHLY_BY_LAST_DAY_OF_MONTH;
}
updateDialog();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class SublimeRecurrencePicker extends FrameLayout
// format. Choosing 'CUSTOM' takes the user
// to 'RecurrenceOptionCreator'.
public enum RecurrenceOption {
DOES_NOT_REPEAT("DOES NOT REPEAT"),
DOES_NOT_REPEAT("DOES NOT REPEAT"), MINUTELY("MINUTELY"), HOURLY("HOURLY"),
DAILY("DAILY"), WEEKLY("WEEKLY"), MONTHLY("MONTHLY"),
YEARLY("YEARLY"), CUSTOM("CUSTOM...");

Expand Down Expand Up @@ -197,6 +197,10 @@ void initializeLayout() {
(TextView) findViewById(R.id.tvChosenCustomOption));
mRepeatOptionTextViews.add(
(TextView) findViewById(R.id.tvDoesNotRepeat));
mRepeatOptionTextViews.add(
(TextView) findViewById(R.id.tvMinutely));
mRepeatOptionTextViews.add(
(TextView) findViewById(R.id.tvHourly));
mRepeatOptionTextViews.add(
(TextView) findViewById(R.id.tvDaily));
mRepeatOptionTextViews.add(
Expand Down Expand Up @@ -264,6 +268,12 @@ void updateFlowLayout(RecurrenceOption recurrenceOption) {
case DOES_NOT_REPEAT:
viewIdToSelect = R.id.tvDoesNotRepeat;
break;
case MINUTELY:
viewIdToSelect = R.id.tvMinutely;
break;
case HOURLY:
viewIdToSelect = R.id.tvHourly;
break;
case DAILY:
viewIdToSelect = R.id.tvDaily;
break;
Expand Down Expand Up @@ -342,6 +352,10 @@ public void onClick(View v) {
return;
} else if (v.getId() == R.id.tvDoesNotRepeat) {
mCurrentRecurrenceOption = RecurrenceOption.DOES_NOT_REPEAT;
} else if (v.getId() == R.id.tvMinutely) {
mCurrentRecurrenceOption = RecurrenceOption.MINUTELY;
} else if (v.getId() == R.id.tvHourly) {
mCurrentRecurrenceOption = RecurrenceOption.HOURLY;
} else if (v.getId() == R.id.tvDaily) {
mCurrentRecurrenceOption = RecurrenceOption.DAILY;
} else if (v.getId() == R.id.tvWeekly) {
Expand Down
Loading

0 comments on commit 20d2115

Please sign in to comment.