一、需求
之前:“姨妈来了”按钮打开后,修改第一天姨妈的日期以及天数,然后删除与其相关的姨妈信息,重新加入其他天的姨妈日期,这样就出现一个问题,之前保存的流量和痛感被重置了
修改后:保留之前的姨妈信息,修改第一天姨妈日期以及天数,在其他姨妈的表添加新增的日期
二、实现步骤
1.首先算出点击的日期与第一天日期相差多少天
differ = indexCalendar.differ(selectCalendar)
2.修改持续天数和第一天日期,记得当数据库有修改就得重新刷新获取数据库内容的数组
val newKeep = differ + replaceObjectList[index].menKeep!!
val findDate = replaceObjectList[index].menFirstDate
firstMenDao.modifyFirstKeepDay(newKeep,findDate)
firstMenDao.modifyMenFirstDateByDate(selectDay,findDate)
resetReplaceObjectList()
private fun resetReplaceObjectList() {
replaceObjectList.clear()
replaceObjectList = firstMenDao.getAllMenFirst() as MutableList<FirstMenses>
}
3.向普通姨妈表加入新增的日期,然后刷新获取普通姨妈表数据的数组
//向普通姨妈表计入新的数据
var tempYear = iSelectYear
var tempMonth = iSelectMonth
var tempDay = iSelectDay
for(i in 1 .. differ){
tempDay = iSelectDay + i
val nearMonthDays: Int =
CustomDateFormat.getDays(tempYear, tempMonth - 1);
if(tempDay > nearMonthDays){
tempDay -= nearMonthDays
tempMonth = iSelectMonth + 1
if(tempMonth == 13){
tempMonth = 1
tempYear += 1
}
}
val tempDate = "$tempYear-$tempMonth-$tempDay"
Timber.d("修改第一天后需要加入的日期:$tempDate")
menDao.insert(
Menses(null,replaceObjectList[index].menFirstId,
tempDate,0,0))
}
}
resetOtherObjectList()
private fun resetOtherObjectList(){
otherObjectList.clear()
otherObjectList = menDao.getAllMenses() as MutableList<Menses>
}