|
@@ -6,10 +6,10 @@ import com.yingyang.workbenches.databinding.FragmentDataMonitorBinding
|
|
|
import com.yingyang.workbenches.entity.DayBean
|
|
|
import com.yingyangfly.baselib.base.BaseFragment
|
|
|
import com.yingyangfly.baselib.utils.RxBusCodes
|
|
|
+import com.yingyangfly.baselib.utils.StringUtil
|
|
|
import com.yingyangfly.baselib.utils.User
|
|
|
import gorden.rxbus2.Subscribe
|
|
|
import gorden.rxbus2.ThreadMode
|
|
|
-import java.text.SimpleDateFormat
|
|
|
import java.util.*
|
|
|
|
|
|
/**
|
|
@@ -58,7 +58,7 @@ class DataMonitorFragment : BaseFragment<FragmentDataMonitorBinding>() {
|
|
|
var weekIndex = calendar!![Calendar.DAY_OF_WEEK] - 1
|
|
|
// 将日期设为上个月
|
|
|
calendar!![Calendar.MONTH] = calendar!![Calendar.MONTH] - 1
|
|
|
- val preMonthDays: Int = getMonth(
|
|
|
+ val preMonthDays: Int = StringUtil.getMonth(
|
|
|
calendar!![Calendar.MONTH] + 1,
|
|
|
calendar!![Calendar.YEAR]
|
|
|
)
|
|
@@ -74,7 +74,8 @@ class DataMonitorFragment : BaseFragment<FragmentDataMonitorBinding>() {
|
|
|
}
|
|
|
// 将日期设为当月
|
|
|
calendar!![Calendar.MONTH] = calendar!![Calendar.MONTH] + 1
|
|
|
- val currentDays = getMonth(calendar!![Calendar.MONTH] + 1, calendar!![Calendar.YEAR])
|
|
|
+ val currentDays =
|
|
|
+ StringUtil.getMonth(calendar!![Calendar.MONTH] + 1, calendar!![Calendar.YEAR])
|
|
|
// 拿到当月的天数
|
|
|
for (i in 0 until currentDays) {
|
|
|
val bean = DayBean()
|
|
@@ -83,16 +84,12 @@ class DataMonitorFragment : BaseFragment<FragmentDataMonitorBinding>() {
|
|
|
bean.day = i + 1
|
|
|
// 当前日期
|
|
|
val nowDate: String =
|
|
|
- getFormatTime("yyyy-M-d", Calendar.getInstance().time)
|
|
|
+ StringUtil.getFormatTime("yyyy-M-d", Calendar.getInstance().time)
|
|
|
// 选择的日期
|
|
|
val selectDate: String =
|
|
|
- getFormatTime("yyyy-M-", calendar!!.time) + (i + 1)
|
|
|
+ StringUtil.getFormatTime("yyyy-M-", calendar!!.time) + (i + 1)
|
|
|
// 假如相等的话,那么就是今天的日期了
|
|
|
- if (nowDate.contentEquals(selectDate)) {
|
|
|
- bean.isCurrentDay = true
|
|
|
- } else {
|
|
|
- bean.isCurrentDay = false
|
|
|
- }
|
|
|
+ bean.isCurrentDay = nowDate.contentEquals(selectDate)
|
|
|
bean.isCurrentMonth = true
|
|
|
dataList.add(bean)
|
|
|
}
|
|
@@ -116,23 +113,4 @@ class DataMonitorFragment : BaseFragment<FragmentDataMonitorBinding>() {
|
|
|
calendar!![Calendar.MONTH] = calendar!![Calendar.MONTH] - 1
|
|
|
}
|
|
|
|
|
|
- // 传入年和月得出当月的天数
|
|
|
- fun getMonth(m: Int, y: Int): Int {
|
|
|
- return when (m) {
|
|
|
- 2 -> if (isRunYear(y)) 29 else 28
|
|
|
- 4, 6, 9, 11 -> 30
|
|
|
- else -> 31
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 判断是否为闰年
|
|
|
- fun isRunYear(y: Int): Boolean {
|
|
|
- return y % 4 == 0 && y % 100 != 0 || y % 400 == 0
|
|
|
- }
|
|
|
-
|
|
|
- // 格式化时间,设置时间很方便,也比较简单,学的很快
|
|
|
- fun getFormatTime(p: String, t: Date?): String {
|
|
|
- return SimpleDateFormat(p, Locale.CHINESE).format(t)
|
|
|
- }
|
|
|
-
|
|
|
}
|