修改“姨妈走了”按钮的逻辑

一、需求
整改“姨妈走了”按钮的逻辑
之前:按钮一开,删除所有姨妈日期,重新填写新的姨妈日期
现在:按钮一开,添加姨妈表里面没有的日期,其他姨妈日期保留;还有就是删除姨妈表里有的日期
之前的方法,没有考虑到姨妈量和姨妈痛的保存,所以需要整改
二、完成步骤
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)
                            }
                        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值