一、需求
整改“姨妈走了”按钮的逻辑
之前:按钮一开,删除所有姨妈日期,重新填写新的姨妈日期
现在:按钮一开,添加姨妈表里面没有的日期,其他姨妈日期保留;还有就是删除姨妈表里有的日期
之前的方法,没有考虑到姨妈量和姨妈痛的保存,所以需要整改
二、完成步骤
1.设置临时变量存储需要加入姨妈表的新日期
首先判断原先姨妈持续天数与后面新更改的姨妈天数的大小,如果新的持续天数大于之前的持续天数,这时候就需要往姨妈表加入新的姨妈日期;如果新的持续天数小于之前的持续天数,这时候就需要将多余的姨妈日期删除。
代码如下:
if(keepDay > firstKeepDay){
for(i in 0 until keepDay - firstKeepDay){
val tempAddDay = firstKeepDay + i
tempDay = iIndexDateDay + tempAddDay
val nearMonthDays: Int =
CustomDateFormat.getDays(iIndexDateYear, iIndexDateMonth - 1);
if (tempDay > nearMonthDays) {
tempDay -= nearMonthDays;
tempMonth = iIndexDateMonth + 1
if (tempMonth == 13) {
tempMonth = 1;
tempYear += 1
}
}
val tempDate = "$tempYear-$tempMonth-$tempDay"
Timber.d("需要加入数据库的数据:$tempDate")
menDao.insert(Menses(null,firstId,tempDate,0,0))
}else if(keepDay < firstKeepDay){
for(i in 0 until firstKeepDay - keepDay){
val tempAddDay = firstKeepDay - (i+1)
tempDay = iIndexDateDay + tempAddDay
val nearMonthDays: Int =
CustomDateFormat.getDays(iIndexDateYear, iIndexDateMonth - 1);
if (tempDay > nearMonthDays) {
tempDay -= nearMonthDays;
tempMonth += 1
if (tempMonth == 13) {
tempMonth = 1;
tempYear += 1
}
}else {
tempMonth = iIndexDateMonth
}
val tempDate = "$tempYear-$tempMonth-$tempDay"
Timber.d("需要从数据库删除的数据:$tempDate")
menDao.deleteOneMenses(tempDate)
}
}