Skip to content

Commit

Permalink
修复标记的日期无法移除的bug,新增removeSchemeDate,clearSchemeDate API
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Mar 26, 2018
1 parent 7e64dc8 commit c10dc6f
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 25 deletions.
32 changes: 32 additions & 0 deletions app/src/main/java/com/haibin/calendarviewproject/TestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import android.support.v4.widget.NestedScrollView;
import android.view.View;

import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarView;
import com.haibin.calendarviewproject.base.activity.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
* 测试
* Created by huanghaibin on 2018/1/28.
Expand Down Expand Up @@ -38,6 +42,34 @@ protected void initData() {

}

/**
* 全部假设calendars1 != null, 传入calendars1,合并calendars2,返回calendars1,有多少个集合则调用多少次
*/
private List<Calendar> merge(List<Calendar> calendars1, List<Calendar> calendars2) {
if (calendars2 == null || calendars2.size() == 0)
return calendars1;
for (Calendar calendar : calendars2) {
if (calendars1.contains(calendar)) {
Calendar mergeCalendar = calendars1.get(calendars1.indexOf(calendar));
mergeCalendar(mergeCalendar, calendar);
} else {
calendars1.add(calendar);
}
}
return calendars1;
}


private void mergeCalendar(Calendar calendar1, Calendar calendar2) {
if (calendar2.getSchemes() == null || calendar2.getSchemes().size() == 0)
return;
if (calendar1.getSchemes() == null) {
calendar1.setSchemes(new ArrayList<Calendar.Scheme>());
}
calendar1.getSchemes().addAll(calendar2.getSchemes());
}


public void onClick(View view) {
mCalendarView.showSelectLayout(mCalendarView.getCurYear());
}
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 327
versionName "3.2.7"
versionCode 328
versionName "3.2.8"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void scrollToCurrent(boolean smoothScroll) {
return;
}
mDelegate.mSelectedCalendar = mDelegate.createCurrentDate();
mWeekBar.onDateSelected(mDelegate.mSelectedCalendar,false);
mWeekBar.onDateSelected(mDelegate.mSelectedCalendar, false);
mWeekPager.scrollToCurrent(smoothScroll);
mMonthPager.scrollToCurrent(smoothScroll);
mSelectLayout.scrollToYear(mDelegate.getCurrentDay().getYear(), smoothScroll);
Expand Down Expand Up @@ -557,6 +557,35 @@ public void setSchemeDate(List<Calendar> mSchemeDate) {
mWeekPager.updateScheme();
}


/**
* 清空日期标记
*/
public void clearSchemeDate() {
this.mDelegate.mSchemeDate = null;
mMonthPager.updateScheme();
mWeekPager.updateScheme();
}


/**
* 移除某天的标记
* 这个API是安全的,无效try cache
* @param calendar calendar
*/
public void removeSchemeDate(Calendar calendar) {
if (mDelegate.mSchemeDate == null ||
mDelegate.mSchemeDate.size() == 0 ||
calendar == null) {
return;
}
if (mDelegate.mSchemeDate.contains(calendar)) {
mDelegate.mSchemeDate.remove(calendar);
}
mMonthPager.updateScheme();
mWeekPager.updateScheme();
}

/**
* 设置背景色
*
Expand Down Expand Up @@ -622,12 +651,13 @@ public void setSchemeColor(int schemeColor, int schemeTextColor, int schemeLunar

/**
* 设置年视图的颜色
*
* @param yearViewMonthTextColor 年视图月份颜色
* @param yearViewDayTextColor 年视图天的颜色
* @param yearViewDayTextColor 年视图天的颜色
* @param yarViewSchemeTextColor 年视图标记颜色
*/
public void setYearViewTextColor(int yearViewMonthTextColor, int yearViewDayTextColor, int yarViewSchemeTextColor){
mDelegate.setYearViewTextColor(yearViewMonthTextColor,yearViewDayTextColor,yarViewSchemeTextColor);
public void setYearViewTextColor(int yearViewMonthTextColor, int yearViewDayTextColor, int yarViewSchemeTextColor) {
mDelegate.setYearViewTextColor(yearViewMonthTextColor, yearViewDayTextColor, yarViewSchemeTextColor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,24 @@ final class CustomCalendarViewDelegate {
@SuppressWarnings("unused")
static final int MODE_FIT_MONTH = 2;


/**
* 月份显示模式
*/
private int mMonthViewShowMode;


// /**
// * 默认选择模式
// */
// static final int SELECT_MODE_DEFAULT = 0;
//
// /**
// * 单选模式
// */
// static final int SELECT_MODE_SINGLE = 1;
//
// private int mSelectMode;

/**
* 支持转换的最小农历年份
*/
Expand Down Expand Up @@ -204,6 +216,11 @@ final class CustomCalendarViewDelegate {
*/
Calendar mSelectedCalendar;

// /**
// * 保存标记位置
// */
// Calendar mIndexCalendar;

CustomCalendarViewDelegate(Context context, @Nullable AttributeSet attrs) {
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CalendarView);

Expand All @@ -223,6 +240,7 @@ final class CustomCalendarViewDelegate {
mSchemeText = "记";
}
mMonthViewShowMode = array.getInt(R.styleable.CalendarView_month_view_show_mode, MODE_ALL_MONTH);
//mSelectMode = array.getInt(R.styleable.CalendarView_select_mode, SELECT_MODE_DEFAULT);

mWeekBackground = array.getColor(R.styleable.CalendarView_week_background, Color.WHITE);
mWeekLineBackground = array.getColor(R.styleable.CalendarView_week_line_background, Color.TRANSPARENT);
Expand Down Expand Up @@ -427,6 +445,10 @@ int getMonthViewShowMode() {
return mMonthViewShowMode;
}

// int getSelectMode() {
// return mSelectMode;
// }

void setTextColor(int curDayTextColor, int curMonthTextColor, int otherMonthTextColor, int curMonthLunarTextColor, int otherMonthLunarTextColor) {
mCurDayTextColor = curDayTextColor;
mOtherMonthTextColor = otherMonthTextColor;
Expand Down
26 changes: 18 additions & 8 deletions calendarview/src/main/java/com/haibin/calendarview/MonthView.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,28 @@ private void initCalendar() {

@Override
void update() {
if (mDelegate.mSchemeDate != null) {
if (mDelegate.mSchemeDate == null || mDelegate.mSchemeDate.size() == 0) {//清空操作
for (Calendar a : mItems) {
for (Calendar d : mDelegate.mSchemeDate) {
if (d.equals(a)) {
a.setScheme(TextUtils.isEmpty(d.getScheme()) ? mDelegate.getSchemeText() : d.getScheme());
a.setSchemeColor(d.getSchemeColor());
a.setSchemes(d.getSchemes());
}
}
a.setScheme("");
a.setSchemeColor(0);
a.setSchemes(null);
}
invalidate();
return;
}
for (Calendar a : mItems) {//添加操作
if(mDelegate.mSchemeDate.contains(a)){
Calendar d = mDelegate.mSchemeDate.get(mDelegate.mSchemeDate.indexOf(a));
a.setScheme(TextUtils.isEmpty(d.getScheme()) ? mDelegate.getSchemeText() : d.getScheme());
a.setSchemeColor(d.getSchemeColor());
a.setSchemes(d.getSchemes());
}else {
a.setScheme("");
a.setSchemeColor(0);
a.setSchemes(null);
}
}
invalidate();
}


Expand Down
26 changes: 18 additions & 8 deletions calendarview/src/main/java/com/haibin/calendarview/WeekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,28 @@ void setup(Calendar calendar) {
* 更新界面
*/
void update() {
if (mDelegate.mSchemeDate != null) {
if (mDelegate.mSchemeDate == null || mDelegate.mSchemeDate.size() == 0) {//清空操作
for (Calendar a : mItems) {
for (Calendar d : mDelegate.mSchemeDate) {
if (d.equals(a)) {
a.setScheme(TextUtils.isEmpty(d.getScheme()) ? mDelegate.getSchemeText() : d.getScheme());
a.setSchemeColor(d.getSchemeColor());
a.setSchemes(d.getSchemes());
}
}
a.setScheme("");
a.setSchemeColor(0);
a.setSchemes(null);
}
invalidate();
return;
}
for (Calendar a : mItems) {//添加操作
if(mDelegate.mSchemeDate.contains(a)){
Calendar d = mDelegate.mSchemeDate.get(mDelegate.mSchemeDate.indexOf(a));
a.setScheme(TextUtils.isEmpty(d.getScheme()) ? mDelegate.getSchemeText() : d.getScheme());
a.setSchemeColor(d.getSchemeColor());
a.setSchemes(d.getSchemes());
}else {
a.setScheme("");
a.setSchemeColor(0);
a.setSchemes(null);
}
}
invalidate();
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions calendarview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<enum name="mode_fix" value="2" />
</attr>

<!--<attr name="select_mode">-->
<!--<enum name="default_mode" value="0"/>-->
<!--<enum name="single_mode" value="1"/>-->
<!--</attr>-->
</declare-styleable>


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.2.7
VERSION_CODE=3.2.7
VERSION_NAME=3.2.8
VERSION_CODE=3.2.8
POM_BINTRAY_PRPO=maven
POM_PACKAGING=aar
POM_NAME=calendarview
Expand Down

0 comments on commit c10dc6f

Please sign in to comment.