Skip to content

Commit

Permalink
Updated library version to 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
muraee committed Dec 27, 2017
1 parent 97326e6 commit f1c4e29
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 73 deletions.
72 changes: 55 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}
dependencies {
compile 'devs.mulham.horizontalcalendar:horizontalcalendar:1.2.5'
compile 'devs.mulham.horizontalcalendar:horizontalcalendar:1.3.0'
}
```

Expand Down Expand Up @@ -59,8 +59,7 @@ startDate.add(Calendar.MONTH, -1);

```java
HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
.startDate(startDate.getTime())
.endDate(endDate.getTime())
.range(startDate, endDate)
.datesNumberOnScreen(5)
.build();
```
Expand All @@ -77,7 +76,7 @@ HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(rootView,
```java
horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
@Override
public void onDateSelected(Date date, int position) {
public void onDateSelected(Calendar date, int position) {
//do something
}
});
Expand All @@ -88,7 +87,7 @@ horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
```java
horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
@Override
public void onDateSelected(Date date, int position) {
public void onDateSelected(Calendar date, int position) {

}

Expand All @@ -99,7 +98,7 @@ horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
}

@Override
public boolean onDateLongClicked(Date date, int position) {
public boolean onDateLongClicked(Calendar date, int position) {
return true;
}
});
Expand All @@ -114,19 +113,17 @@ horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:textColorNormal="#bababa"
app:textColorSelected="#FFFF"
app:selectorColor="#c62828" // default to colorAccent.
app:selectedDateBackground="@drawable/myDrwable"/>
app:selectorColor="#c62828" //default to colorAccent
app:selectedDateBackground="@drawable/myDrawable"/>
```

- Or you can do it programmatically in your **Activity** or **Fragment** using `HorizontalCalendar.Builder`:

```java
HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
.startDate(Date startDate)
.endDate(Date endDate)
.range(Calendar startDate, Calendar endDate)
.datesNumberOnScreen(int number) // Number of Dates cells shown on screen (default to 5).
.configure() // starts configuration.
.formatTopText(String dateFormat) // default to "MMM".
Expand Down Expand Up @@ -156,13 +153,49 @@ builder.configure()
.end()
```

## Reconfiguration
HorizontalCalendar configurations can be changed after initialization:

- Change calendar dates range:
```java
horizontalCalendar.setRange(Calendar startDate, Calendar endDate);
```

- Change default(not selected) items style:
```java
horizontalCalendar.getDefaultStyle()
.setColorTopText(int color)
.setColorMiddleText(int color)
.setColorBottomText(int color)
.setBackground(Drawable background);
```

- Change selected item style:
```java
horizontalCalendar.getSelectedItemStyle()
.setColorTopText(int color)
..............
```

- Change formats, text sizes and selector color:
```java
horizontalCalendar.getConfig()
.setSelectorColor(int color)
.setFormatTopText(String format)
.setSizeTopText(float size)
..............
```

#### Important
**Make sure to call `horizontalCalendar.refresh();` when you finish your changes**

## Features

- Disable specific dates with `HorizontalCalendarPredicate`, a unique style for disabled dates can be specified as well with `CalendarItemStyle`:
```java
builder.disableDates(new HorizontalCalendarPredicate() {
@Override
public boolean test(Date date) {
public boolean test(Calendar date) {
return false; // return true if this date should be disabled, false otherwise.
}

Expand All @@ -175,19 +208,24 @@ builder.disableDates(new HorizontalCalendarPredicate() {

- Select a specific **Date** programmatically with the option whether to play the animation or not:
```java
horizontalCalendar.selectDate(Date date, boolean immediate); // set immediate to false to ignore animation.
horizontalCalendar.selectDate(Calendar date, boolean immediate); // set immediate to false to ignore animation.
// or simply
horizontalCalendar.goToday(boolean immediate);
```

- Check if two dates' **days** are equal:
- Check if a date is contained in the Calendar:
```java
horizontalCalendar.isDatesDaysEquals(Date date1, Date date2);
horizontalCalendar.contains(Calendar date);
```

- Check if a date is contained in the Calendar:
- Check if two dates are equal (year, month, day of month):
```java
Utils.isSameDate(Calendar date1, Calendar date2);
```

- Get number of **days** between two dates:
```java
horizontalCalendar.contains(Date date);
Utils.daysBetween(Calendar startInclusive, Calendar endExclusive);
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion horizontalcalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ext {
siteUrl = 'https://github.com/Mulham-Raee/Horizontal-Calendar'
gitUrl = 'https://github.com/Mulham-Raee/Horizontal-Calendar.git'

libraryVersion = '1.2.5'
libraryVersion = '1.3.0'

developerId = 'mulham-raee'
developerName = 'Mulham Raee'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void setRange(Calendar startDate, Calendar endDate){
this.startDate = startDate;
this.endDate = endDate;
if (mCalendarAdapter instanceof DaysAdapter){
((DaysAdapter) mCalendarAdapter).update(startDate, endDate);
((DaysAdapter) mCalendarAdapter).update(startDate, endDate, false);
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ public int positionOfDate(Calendar date) {
}

int position;
if (Utils.isSameDates(date, startDate)) {
if (Utils.isSameDate(date, startDate)) {
position = 0;
} else {
position = Utils.daysBetween(startDate, date);
Expand All @@ -291,14 +291,6 @@ public int positionOfDate(Calendar date) {
return position + shiftCells;
}

/**
/**
* @return <code>true</code> if dates are equal; <code>false</code> otherwise
*/
public boolean isDatesDaysEquals(Calendar date1, Calendar date2) {
return Utils.isSameDates(date1, date2);
}

public static class Builder {

final int viewId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ public Calendar getItem(int position) throws IndexOutOfBoundsException {
return calendar;
}

public void update(Calendar startDate, Calendar endDate){
public void update(Calendar startDate, Calendar endDate, boolean notify){
this.startDate = startDate;
itemsCount = calculateItemsCount(endDate);
notifyDataSetChanged();
if (notify){
notifyDataSetChanged();
}
}

private int calculateItemsCount(Calendar endDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Base class for all adapters for {@link HorizontalCalendarView HorizontalCalendarView}
*
* @author Mulham-Raee
* @since v1.2.7
* @since v1.3.0
*/
public abstract class HorizontalCalendarBaseAdapter<VH extends DateViewHolder, T extends Calendar> extends RecyclerView.Adapter<VH> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,36 @@ public int getColorTopText() {
return colorTopText;
}

public void setColorTopText(int colorTopText) {
public CalendarItemStyle setColorTopText(int colorTopText) {
this.colorTopText = colorTopText;
return this;
}

public int getColorMiddleText() {
return colorMiddleText;
}

public void setColorMiddleText(int colorMiddleText) {
public CalendarItemStyle setColorMiddleText(int colorMiddleText) {
this.colorMiddleText = colorMiddleText;
return this;
}

public int getColorBottomText() {
return colorBottomText;
}

public void setColorBottomText(int colorBottomText) {
public CalendarItemStyle setColorBottomText(int colorBottomText) {
this.colorBottomText = colorBottomText;
return this;
}

public Drawable getBackground() {
return background;
}

public void setBackground(Drawable background) {
public CalendarItemStyle setBackground(Drawable background) {
this.background = background;
return this;
}

public void setupDefaultValues(CalendarItemStyle defaultValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,76 +36,85 @@ public HorizontalCalendarConfig(float sizeTopText, float sizeMiddleText, float s
this.selectorColor = selectorColor;
}

public String getFormatTopText() {
return formatTopText;
public HorizontalCalendarConfig setFormatTopText(String formatTopText) {
this.formatTopText = formatTopText;
return this;
}

public void setFormatTopText(String formatTopText) {
this.formatTopText = formatTopText;
public HorizontalCalendarConfig setFormatMiddleText(String formatMiddleText) {
this.formatMiddleText = formatMiddleText;
return this;
}

public String getFormatMiddleText() {
return formatMiddleText;
public HorizontalCalendarConfig setFormatBottomText(String formatBottomText) {
this.formatBottomText = formatBottomText;
return this;
}

public void setFormatMiddleText(String formatMiddleText) {
this.formatMiddleText = formatMiddleText;
public HorizontalCalendarConfig setSizeTopText(float sizeTopText) {
this.sizeTopText = sizeTopText;
return this;
}

public String getFormatBottomText() {
return formatBottomText;
public HorizontalCalendarConfig setSizeMiddleText(float sizeMiddleText) {
this.sizeMiddleText = sizeMiddleText;
return this;
}

public void setFormatBottomText(String formatBottomText) {
this.formatBottomText = formatBottomText;
public HorizontalCalendarConfig setSizeBottomText(float sizeBottomText) {
this.sizeBottomText = sizeBottomText;
return this;
}

public float getSizeTopText() {
return sizeTopText;
public HorizontalCalendarConfig setSelectorColor(Integer selectorColor) {
this.selectorColor = selectorColor;
return this;
}

public void setSizeTopText(float sizeTopText) {
this.sizeTopText = sizeTopText;
public HorizontalCalendarConfig setShowTopText(boolean showTopText) {
this.showTopText = showTopText;
return this;
}

public float getSizeMiddleText() {
return sizeMiddleText;
public HorizontalCalendarConfig setShowBottomText(boolean showBottomText) {
this.showBottomText = showBottomText;
return this;
}

public void setSizeMiddleText(float sizeMiddleText) {
this.sizeMiddleText = sizeMiddleText;
public String getFormatTopText() {
return formatTopText;
}

public float getSizeBottomText() {
return sizeBottomText;
public String getFormatMiddleText() {
return formatMiddleText;
}

public void setSizeBottomText(float sizeBottomText) {
this.sizeBottomText = sizeBottomText;
public String getFormatBottomText() {
return formatBottomText;
}

public Integer getSelectorColor() {
return selectorColor;
public float getSizeTopText() {
return sizeTopText;
}

public void setSelectorColor(Integer selectorColor) {
this.selectorColor = selectorColor;
public float getSizeMiddleText() {
return sizeMiddleText;
}

public boolean isShowTopText() {
return showTopText;
public float getSizeBottomText() {
return sizeBottomText;
}

public void setShowTopText(boolean showTopText) {
this.showTopText = showTopText;
public Integer getSelectorColor() {
return selectorColor;
}

public boolean isShowBottomText() {
return showBottomText;
public boolean isShowTopText() {
return showTopText;
}

public void setShowBottomText(boolean showBottomText) {
this.showBottomText = showBottomText;
public boolean isShowBottomText() {
return showBottomText;
}

public void setupDefaultValues(HorizontalCalendarConfig defaultConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* @author Mulham-Raee
* @since v1.2.7
* @since v1.3.0
*/
public final class Utils {

Expand Down Expand Up @@ -48,7 +48,10 @@ public static int calculateRelativeCenterPosition(final int position, final int
return relativeCenterPosition;
}

public static boolean isSameDates(Calendar calendar1, Calendar calendar2){
/**
* @return <code>true</code> if dates are equal; <code>false</code> otherwise
*/
public static boolean isSameDate(Calendar calendar1, Calendar calendar2){
int day = calendar1.get(Calendar.DAY_OF_MONTH);
int month = calendar1.get(Calendar.MONTH);
int year = calendar1.get(Calendar.YEAR);
Expand Down

0 comments on commit f1c4e29

Please sign in to comment.