修复:低版本Android解析Cron表达式会报错,暂时不处理

pull/408/head
pppscn 5 months ago
parent c7166ae3ba
commit ba356e63b3

@ -305,11 +305,6 @@ dependencies {
//Location Android LocationManager https://github.com/jenly1314/Location
implementation 'com.github.pppscn:location:1.0.0'
//crontabhttps://github.com/jmrozanec/cron-utils http://cron-parser.com
//implementation 'com.cronutils:cron-utils:9.2.1'
//JSR-310 backport for Androidhttps://github.com/JakeWharton/ThreeTenABP
//implementation 'com.jakewharton.threetenabp:threetenabp:1.4.6'
//Partial implementation of Quartz Cron Java for Android: https://github.com/gatewayapps/crondroid
implementation 'gatewayapps.crondroid:crondroid:1.0.0'
//Java Parser For Cron Expressions: https://github.com/grahamar/cron-parser
@ -317,8 +312,6 @@ dependencies {
//https://github.com/yarolegovich/SlidingRootNav
implementation 'com.yarolegovich:sliding-root-nav:1.1.1'
//TabBarhttps://github.com/xuexiangjys/JPTabBar
// implementation 'com.github.xuexiangjys:JPTabBar:1.0.1'
}
//X-Library
apply from: 'x-library.gradle'

@ -305,3 +305,7 @@
# MultiLanguages
-keep class com.hjq.language.** {*;}
# crontab解析
-keep class gatewayapps.crondroid.** { *; }
-keep class net.redhogs.cronparser.** { *; }

@ -2,6 +2,7 @@ package com.idormy.sms.forwarder.fragment.condition
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
@ -161,7 +162,8 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
times++
}
binding!!.tvDescription.text = description
binding!!.tvCronExpressionCheckTips.text = "$expression\n$description"
//TODO低版本Android解析Cron表达式会报错暂时不处理
binding!!.tvCronExpressionCheckTips.text = if (expression == description) expression else "$expression\n$description"
binding!!.tvNextTimeList.text = String.format(getString(R.string.next_execution_times), times.toString(), nextTimeList.joinToString("\n"))
binding!!.tvNextTimeList.visibility = View.VISIBLE
binding!!.separatorCronExpressionCheck.visibility = View.VISIBLE
@ -1589,14 +1591,19 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
//判断cronExpression是否有效
CronExpression.validateExpression(expression)
//生成cron表达式描述
val options = Options()
options.isTwentyFourHourTime = true
//TODO支持多语言
val locale = Locale.getDefault()
//Chinese, Japanese, Korean and other East Asian languages have no spaces between words
options.isNeedSpaceBetweenWords = locale == Locale("zh") || locale == Locale("ja") || locale == Locale("ko")
description = CronExpressionDescriptor.getDescription(expression, options, locale)
//TODO低版本Android解析Cron表达式会报错暂时不处理
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//生成cron表达式描述
val options = Options()
options.isTwentyFourHourTime = true
//TODO支持多语言
val locale = Locale.getDefault()
//Chinese, Japanese, Korean and other East Asian languages have no spaces between words
options.isNeedSpaceBetweenWords = locale == Locale("zh") || locale == Locale("ja") || locale == Locale("ko")
description = CronExpressionDescriptor.getDescription(expression, options, locale)
} else {
description = expression
}
return CronSetting(description, expression)
}

Loading…
Cancel
Save