在数据表中加入新字段,修改“姨妈走了”逻辑

一、需求
1.在第一天表里加入新的字段:最后一天的日期
2.修改“姨妈走了”按钮的bug
二、实现步骤
1.在表中加入新字段

@ColumnInfo(name = "men_last_date")
var menLastDate: String?,

2.首先判断点击日期是否为最后一天

//判断点击的天是不是最后一天,是返回1,否返回0
                for(i in 0 until lastDateObjectList.size){
                    val a = lastDateObjectList[i]
//                    Timber.d("selectday == $selectDay====lastdate[i]==$a")
                    if(selectDay == lastDateObjectList[i]){
                        selectDayIsLast =  1
                        break
                    }else if(i == lastDateObjectList.size - 1 && selectDay != lastDateObjectList[i]){
                        selectDayIsLast =  0
                    }
                }

3.如果是最后一天,不做任何动作
不是最后一天,判断在姨妈后五天还是在姨妈期间

 if(selectDayIsLast == 0){
//                    Timber.d("selectdayislast==$selectDayIsLast")
                    //标记选择日期是否在后面五天
                    var selectIsFive = 0
                    val total = replaceObjectList.size * 5
                    var signCycle = 0
                    for(i in 0 until replaceObjectList.size){
                        val dLastDate: Date = dfAll.parse(replaceObjectList[i].menLastDate)
                        val iLastDateYear: Int = dfYear.format(dLastDate).toInt()
                        val iLastDateMonth: Int = dfMonth.format(dLastDate).toInt()
                        val iLastDateDay: Int = dfDay.format(dLastDate).toInt()
                        var tempYear: Int = iLastDateYear
                        var tempMonth: Int = iLastDateMonth
                        var tempDay: Int = iLastDateDay
                        for(a in 1..5){
                            signCycle += 1
                            tempDay += 1
                            val nearMonthDays: Int =
                                CustomDateFormat.getDays(iLastDateYear, iLastDateMonth - 1);
                            if(tempDay > nearMonthDays){
                                tempDay = 1
                                tempMonth += 1
                                if(tempMonth == 13){
                                    tempMonth = 1
                                    tempYear += 1
                                }
                            }
                            val tempDate = "$tempYear-$tempMonth-$tempDay"
                            //选中的日期属于后面五天
                            if(selectDay == tempDate){
                                selectIsFive = 1
                                index = i
                                selectCalendar.year = iSelectYear
                                selectCalendar.month = iSelectMonth
                                selectCalendar.day = iSelectDay

                                val indexDate: String = replaceObjectList[index].menFirstDate!!
                                val dIndexDate: Date = dfAll.parse(indexDate)
                                val iIndexDateYear: Int = dfYear.format(dIndexDate).toInt()
                                val iIndexDateMonth: Int = dfMonth.format(dIndexDate).toInt()
                                val iIndexDateDay: Int = dfDay.format(dIndexDate).toInt()
                                Timber.d("标记的日期:$iIndexDateYear----$iIndexDateMonth----$iIndexDateDay")
                                val indexCalendar: Calendar = Calendar()
                                indexCalendar.year = iIndexDateYear
                                indexCalendar.month = iIndexDateMonth
                                indexCalendar.day = iIndexDateDay
                                if (replaceObjectList.size != 0) {
                                    differ = selectCalendar.differ(indexCalendar)
                                }
                                val keepDay = differ + 1
                                val firstId = firstMenDao.getMensesIdByClick(indexDate)
                                val firstKeepDay = firstMenDao.getFirstMensesKeepDay(firstId)
                                for (b in 0 until keepDay - firstKeepDay) {
                                    val tempAddDay = firstKeepDay + b
                                    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))
                                }
                                resetOtherObjectList()
//                        修改持续天数
                                firstMenDao.modifyFirstKeepDay(keepDay, indexDate)
                                firstMenDao.modifyLastDay(selectDay,indexDate)
                                firstMenDao.modifyLastDay(selectDay,indexDate)
//                        重新获取数据库里的第一天姨妈表里的信息
                                resetReplaceObjectList()

//                        //情况5:后面五天点击姨妈走了
                                showLogcat(replaceObjectList, otherObjectList, 5)
                                break
                            }
                        }
                        Timber.d("signcycle == $signCycle == total == $total")
                        if(selectIsFive == 1){
                            break
                        }else if(signCycle == total){
                            selectIsFive = 0
                        }
                    }
                    Timber.d("selectisfive == $selectIsFive")
                    if(selectIsFive == 0){
                        val length1 = otherObjectList.size
                        Timber.d("循环姨妈期间的长度===length==$length1")
                        for(i in 0 until otherObjectList.size){
                            val length = otherObjectList.size
                            Timber.d("循环姨妈期间的日期i == $i===length==$length")
                            if(selectDay == otherObjectList[i].menDate){
                                val firstMenses = firstMenDao.getFirstMenses(otherObjectList[i].menFirstId!!)
                                selectCalendar.year = iSelectYear
                                selectCalendar.month = iSelectMonth
                                selectCalendar.day = iSelectDay

                                val indexDate: String = firstMenses.menFirstDate!!
                                val dIndexDate: Date = dfAll.parse(indexDate)
                                val iIndexDateYear: Int = dfYear.format(dIndexDate).toInt()
                                val iIndexDateMonth: Int = dfMonth.format(dIndexDate).toInt()
                                val iIndexDateDay: Int = dfDay.format(dIndexDate).toInt()
                                Timber.d("标记的日期:$iIndexDateYear----$iIndexDateMonth----$iIndexDateDay")
                                val indexCalendar: Calendar = Calendar()
                                indexCalendar.year = iIndexDateYear
                                indexCalendar.month = iIndexDateMonth
                                indexCalendar.day = iIndexDateDay

                                if (replaceObjectList.size != 0) {
                                    differ = selectCalendar.differ(indexCalendar)
                                }
                                val keepDay = differ + 1
                                //找到需要改的第一天的id
                                val firstId = firstMenDao.getMensesIdByClick(indexDate)
                                val firstKeepDay = firstMenDao.getFirstMensesKeepDay(firstId)
                                var tempDay: Int
                                var tempMonth = iIndexDateMonth
                                var tempYear = iIndexDateYear

                                for (b in 0 until firstKeepDay - keepDay) {
                                    val tempAddDay = firstKeepDay - (b + 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)
                                }
                                resetOtherObjectList()
//                        修改持续天数
                                firstMenDao.modifyFirstKeepDay(keepDay, indexDate)
                                firstMenDao.modifyLastDay(selectDay,indexDate)
                                firstMenDao.modifyLastDay(selectDay,indexDate)
//                        重新获取数据库里的第一天姨妈表里的信息
                                resetReplaceObjectList()

//                        //情况5:后面五天点击姨妈走了
                                showLogcat(replaceObjectList, otherObjectList, 5)
                                break
                            }
                        }
                    }
                    switch_m_come.isChecked = true
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值