mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
修复:定时任务
的Cron表达式
输入非法时导致FC #407
This commit is contained in:
parent
117a2e42d9
commit
132dcd808c
@ -72,6 +72,7 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
private val yearList: List<String> = (2020..2099).map { String.format("%d", it) }
|
||||
private var selectedYearList = ""
|
||||
|
||||
private val regexNum = Regex("\\d+")
|
||||
private var second = "*"
|
||||
private var minute = "*"
|
||||
private var hour = "*"
|
||||
@ -355,10 +356,6 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
expression = "$second $minute $hour $day $month $week $year"
|
||||
Log.d(TAG, "afterSecondChanged expression:$expression")
|
||||
CronExpression.validateExpression(expression)
|
||||
} catch (e: Exception) {
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
second == "*" -> {
|
||||
@ -387,16 +384,24 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
binding!!.rbSecondTypeCyclic.isChecked = true
|
||||
}
|
||||
|
||||
secondsList.indexOf(String.format("%02d", second.toInt())) != -1 -> {
|
||||
regexNum.matches(second) && secondsList.indexOf(String.format("%02d", second.toInt())) != -1 -> {
|
||||
binding!!.flowlayoutMultiSelectSecond.setSelectedItems(String.format("%02d", second.toInt()))
|
||||
binding!!.rbSecondTypeAssigned.isChecked = true
|
||||
selectedSecondList = second
|
||||
}
|
||||
|
||||
else -> {
|
||||
second = "*"
|
||||
binding!!.etSecond.setText(second)
|
||||
binding!!.rbSecondTypeAll.isChecked = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
second = "*"
|
||||
binding!!.etSecond.setText(second)
|
||||
binding!!.rbSecondTypeAll.isChecked = true
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
//初始化输入提示--分
|
||||
@ -518,10 +523,6 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
expression = "$second $minute $hour $day $month $week $year"
|
||||
Log.d(TAG, "afterMinuteChanged expression:$expression")
|
||||
CronExpression.validateExpression(expression)
|
||||
} catch (e: Exception) {
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
minute == "*" -> {
|
||||
@ -550,16 +551,24 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
binding!!.rbMinuteTypeCyclic.isChecked = true
|
||||
}
|
||||
|
||||
minutesList.indexOf(String.format("%02d", minute.toInt())) != -1 -> {
|
||||
regexNum.matches(minute) && minutesList.indexOf(String.format("%02d", minute.toInt())) != -1 -> {
|
||||
binding!!.flowlayoutMultiSelectMinute.setSelectedItems(String.format("%02d", minute.toInt()))
|
||||
binding!!.rbMinuteTypeAssigned.isChecked = true
|
||||
selectedMinuteList = minute
|
||||
}
|
||||
|
||||
else -> {
|
||||
minute = "*"
|
||||
binding!!.etMinute.setText(minute)
|
||||
binding!!.rbMinuteTypeAll.isChecked = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
minute = "*"
|
||||
binding!!.etMinute.setText(minute)
|
||||
binding!!.rbMinuteTypeAll.isChecked = true
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
//初始化输入提示--时
|
||||
@ -681,10 +690,6 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
expression = "$second $minute $hour $day $month $week $year"
|
||||
Log.d(TAG, "afterHourChanged expression:$expression")
|
||||
CronExpression.validateExpression(expression)
|
||||
} catch (e: Exception) {
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
hour == "*" -> {
|
||||
@ -713,16 +718,24 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
binding!!.rbHourTypeCyclic.isChecked = true
|
||||
}
|
||||
|
||||
hoursList.indexOf(String.format("%02d", hour.toInt())) != -1 -> {
|
||||
regexNum.matches(hour) && hoursList.indexOf(String.format("%02d", hour.toInt())) != -1 -> {
|
||||
binding!!.flowlayoutMultiSelectHour.setSelectedItems(String.format("%02d", hour.toInt()))
|
||||
binding!!.rbHourTypeAssigned.isChecked = true
|
||||
selectedHourList = hour
|
||||
}
|
||||
|
||||
else -> {
|
||||
hour = "*"
|
||||
binding!!.etHour.setText(hour)
|
||||
binding!!.rbHourTypeAll.isChecked = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
hour = "*"
|
||||
binding!!.etHour.setText(hour)
|
||||
binding!!.rbHourTypeAll.isChecked = true
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
//初始化输入提示--日
|
||||
@ -871,10 +884,6 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
expression = "$second $minute $hour $day $month $week $year"
|
||||
Log.d(TAG, "afterDayChanged expression:$expression")
|
||||
CronExpression.validateExpression(expression)
|
||||
} catch (e: Exception) {
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
day == "*" -> {
|
||||
@ -922,16 +931,24 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
binding!!.rbDayTypeCyclic.isChecked = true
|
||||
}
|
||||
|
||||
dayList.indexOf(String.format("%d", day.toInt())) != -1 -> {
|
||||
regexNum.matches(day) && dayList.indexOf(String.format("%d", day.toInt())) != -1 -> {
|
||||
binding!!.flowlayoutMultiSelectDay.setSelectedItems(String.format("%d", day.toInt()))
|
||||
binding!!.rbDayTypeAssigned.isChecked = true
|
||||
selectedDayList = day
|
||||
}
|
||||
|
||||
else -> {
|
||||
day = "*"
|
||||
binding!!.etDay.setText(day)
|
||||
binding!!.rbDayTypeAll.isChecked = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
day = "*"
|
||||
binding!!.etDay.setText(day)
|
||||
binding!!.rbDayTypeAll.isChecked = true
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
//初始化输入提示--月
|
||||
@ -1053,10 +1070,6 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
expression = "$second $minute $hour $day $month $week $year"
|
||||
Log.d(TAG, "afterMonthChanged expression:$expression")
|
||||
CronExpression.validateExpression(expression)
|
||||
} catch (e: Exception) {
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
month == "*" -> {
|
||||
@ -1092,9 +1105,17 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
}
|
||||
|
||||
else -> {
|
||||
month = "*"
|
||||
binding!!.etMonth.setText(month)
|
||||
binding!!.rbMonthTypeAll.isChecked = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
month = "*"
|
||||
binding!!.etMonth.setText(month)
|
||||
binding!!.rbMonthTypeAll.isChecked = true
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
//初始化输入提示--周
|
||||
@ -1252,10 +1273,6 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
expression = "$second $minute $hour $day $month $week $year"
|
||||
Log.d(TAG, "afterWeekChanged expression:$expression")
|
||||
CronExpression.validateExpression(expression)
|
||||
} catch (e: Exception) {
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
week == "*" -> {
|
||||
@ -1300,9 +1317,17 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
}
|
||||
|
||||
else -> {
|
||||
week = "*"
|
||||
binding!!.etWeek.setText(week)
|
||||
binding!!.rbWeekTypeAll.isChecked = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
week = "*"
|
||||
binding!!.etWeek.setText(week)
|
||||
binding!!.rbWeekTypeAll.isChecked = true
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
//初始化输入提示--年
|
||||
@ -1424,10 +1449,6 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
expression = "$second $minute $hour $day $month $week $year"
|
||||
Log.d(TAG, "afterYearChanged expression:$expression")
|
||||
CronExpression.validateExpression(expression)
|
||||
} catch (e: Exception) {
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
year == "*" -> {
|
||||
@ -1467,9 +1488,17 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||
}
|
||||
|
||||
else -> {
|
||||
year = "*"
|
||||
binding!!.etYear.setText(year)
|
||||
binding!!.rbYearTypeAll.isChecked = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
year = "*"
|
||||
binding!!.etYear.setText(year)
|
||||
binding!!.rbYearTypeAll.isChecked = true
|
||||
XToastUtils.error("Cron表达式无效:" + e.message, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
//获取选中的项目
|
||||
|
Loading…
x
Reference in New Issue
Block a user