Skip to content

Commit

Permalink
修复scrollToCalendar在周视图模式下月视图高度不正确的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Jun 26, 2018
1 parent 51fb362 commit c8c6b77
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Android上一个优雅、高度自定义、性能高效的日历控件,完美

### Gradle
```
compile 'com.haibin:calendarview:3.3.3'
compile 'com.haibin:calendarview:3.3.4'
```
```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>
<type>pom</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ This widget has obvious advantages of memory and efficiency, adapt to many scene

### Gradle
```
compile 'com.haibin:calendarview:3.3.3'
compile 'com.haibin:calendarview:3.3.4'
```
```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>
<type>pom</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions calendarview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
minSdkVersion 15
//noinspection OldTargetApi
targetSdkVersion 23
versionCode 333
versionName "3.3.3"
versionCode 334
versionName "3.3.4"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ public void scrollToCurrent(boolean smoothScroll) {
}
mDelegate.mSelectedCalendar = mDelegate.createCurrentDate();
mWeekBar.onDateSelected(mDelegate.mSelectedCalendar, mDelegate.getWeekStart(), false);
mWeekPager.scrollToCurrent(smoothScroll);

mMonthPager.scrollToCurrent(smoothScroll);
if (mMonthPager.getVisibility() == VISIBLE) {
mMonthPager.scrollToCurrent(smoothScroll);
} else {
mWeekPager.scrollToCurrent(smoothScroll);
}
mSelectLayout.scrollToYear(mDelegate.getCurrentDay().getYear(), smoothScroll);
}

Expand Down Expand Up @@ -485,8 +487,9 @@ public void scrollToYear(int year) {
* @param smoothScroll smoothScroll
*/
public void scrollToYear(int year, boolean smoothScroll) {
mMonthPager.setCurrentItem(12 * (year - mDelegate.getMinYear()) +
mDelegate.getCurrentDay().getMonth() - mDelegate.getMinYearMonth(), smoothScroll);
if (mSelectLayout.getVisibility() != VISIBLE) {
return;
}
mSelectLayout.scrollToYear(year, smoothScroll);
}

Expand Down Expand Up @@ -561,9 +564,10 @@ public void setOnDateLongClickListener(OnDateLongClickListener listener, boolean

/**
* 视图改变事件
*
* @param listener listener
*/
public void setOnViewChangeListener(OnViewChangeListener listener){
public void setOnViewChangeListener(OnViewChangeListener listener) {
this.mDelegate.mViewChangeListener = listener;
}

Expand Down Expand Up @@ -903,6 +907,7 @@ public interface OnDateLongClickListener {
public interface OnViewChangeListener {
/**
* 视图改变事件
*
* @param isMonthView isMonthView是否是月视图
*/
void onViewChange(boolean isMonthView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void init(Context context) {
private static String[] SPECIAL_FESTIVAL_STR = null;

/**
* 特殊节日、母亲节和父亲节
* 特殊节日、母亲节和父亲节,感恩节等
*/
@SuppressLint("UseSparseArrays")
private static final Map<Integer, String[]> SPECIAL_FESTIVAL = new HashMap<>();
Expand Down Expand Up @@ -254,6 +254,7 @@ private static String getLunarText(int year, int month, int day) {
/**
* 获取特殊计算方式的节日
* 如:每年五月的第二个星期日为母亲节,六月的第三个星期日为父亲节
* 每年11月第四个星期四定为"感恩节"
*
* @param year year
* @param month month
Expand All @@ -278,13 +279,14 @@ private static String getSpecialFestival(int year, int month, int day) {


/**
* 获取每年的母亲节和父亲节
* 获取每年的母亲节和父亲节和感恩节
* 特殊计算方式的节日
*
* @param year 年
* @return 获取每年的母亲节和父亲节
* @return 获取每年的母亲节和父亲节、感恩节
*/
private static String[] getSpecialFestivals(int year) {
String[] festivals = new String[2];
String[] festivals = new String[3];
java.util.Calendar date = java.util.Calendar.getInstance();
date.set(year, 4, 1);
int week = date.get(java.util.Calendar.DAY_OF_WEEK);
Expand All @@ -302,6 +304,15 @@ private static String[] getSpecialFestivals(int year) {
} else {
festivals[1] = dateToString(year, 6, startDiff + 7 + 7 + 1) + SPECIAL_FESTIVAL_STR[1];
}

date.set(year, 10, 1);
week = date.get(java.util.Calendar.DAY_OF_WEEK);
startDiff = 7 - week + 1;
if (startDiff <= 2) {
festivals[2] = dateToString(year, 11, startDiff + 21 + 5) + SPECIAL_FESTIVAL_STR[2];
} else {
festivals[2] = dateToString(year, 11, startDiff + 14 + 5) + SPECIAL_FESTIVAL_STR[2];
}
return festivals;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ public void onPageScrollStateChanged(int state) {
*/
private void updateMonthViewHeight(int year, int month) {

if (mDelegate.getMonthViewShowMode() == CalendarViewDelegate.MODE_ALL_MONTH) {
if (mDelegate.getMonthViewShowMode() == CalendarViewDelegate.MODE_ALL_MONTH) {//非动态高度就不需要了
mCurrentViewHeight = 6 * mDelegate.getCalendarItemHeight();
return;
}

if (mParentLayout != null) {
if (getVisibility() != VISIBLE) {//如果已经显示周视图,则需要动态改变月视图高度
if (getVisibility() != VISIBLE) {//如果已经显示周视图,则需要动态改变月视图高度,否则显示就有bug
ViewGroup.LayoutParams params = getLayoutParams();
params.height = CalendarUtil.getMonthViewHeight(year, month, mDelegate.getCalendarItemHeight(), mDelegate.getWeekStart());
setLayoutParams(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ void scrollToCalendar(int year, int month, int day, boolean smoothScroll) {
if (mDelegate.mDateSelectedListener != null) {
mDelegate.mDateSelectedListener.onDateSelected(calendar, false);
}
int i = CalendarUtil.getWeekFromDayInMonth(calendar, mDelegate.getWeekStart());
mParentLayout.setSelectWeek(i);
}

/**
Expand All @@ -149,6 +151,11 @@ void scrollToCurrent(boolean smoothScroll) {
if (mDelegate.mDateSelectedListener != null && getVisibility() == VISIBLE) {
mDelegate.mDateSelectedListener.onDateSelected(mDelegate.createCurrentDate(), false);
}
if(getVisibility() == VISIBLE){
mDelegate.mInnerListener.onWeekDateSelected(mDelegate.getCurrentDay(),false);
}
int i = CalendarUtil.getWeekFromDayInMonth(mDelegate.getCurrentDay(), mDelegate.getWeekStart());
mParentLayout.setSelectWeek(i);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions calendarview/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<item>0312植树节</item>
<item>0315消权日</item>
<item>0401愚人节</item>
<item>0422地球日</item>
<item>0501劳动节</item>
<item>0504青年节</item>
<item>0601儿童节</item>
Expand Down Expand Up @@ -108,6 +109,7 @@
<string-array name="special_festivals">
<item>母亲节</item>
<item>父亲节</item>
<item>感恩节</item>
</string-array>

<string name="sun">日</string>
Expand Down
2 changes: 2 additions & 0 deletions calendarview/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<item>0312植树节</item>
<item>0315消权日</item>
<item>0401愚人节</item>
<item>0422地球日</item>
<item>0501劳动节</item>
<item>0504青年节</item>
<item>0601儿童节</item>
Expand Down Expand Up @@ -108,6 +109,7 @@
<string-array name="special_festivals">
<item>母亲节</item>
<item>父亲节</item>
<item>感恩节</item>
</string-array>

<string name="sun">Sun</string>
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ org.gradle.jvmargs=-Xmx1536m
POM_BINTRAY_NAME=com.haibin:calendarview
POM_DESCRIPTION=A very good CalendarView for Android.
POM_ARTIFACT_ID=calendarview
VERSION_NAME=3.3.3
VERSION_CODE=3.3.3
VERSION_NAME=3.3.4
VERSION_CODE=3.3.4
POM_BINTRAY_PRPO=maven
POM_PACKAGING=aar
POM_NAME=calendarview
Expand Down

0 comments on commit c8c6b77

Please sign in to comment.