修复:低版本Android解析Cron表达式会报错,暂时不处理
This commit is contained in:
parent
c7166ae3ba
commit
ba356e63b3
|
@ -305,11 +305,6 @@ dependencies {
|
||||||
//Location 是一个通过 Android 自带的 LocationManager 来实现的定位功能:https://github.com/jenly1314/Location
|
//Location 是一个通过 Android 自带的 LocationManager 来实现的定位功能:https://github.com/jenly1314/Location
|
||||||
implementation 'com.github.pppscn:location:1.0.0'
|
implementation 'com.github.pppscn:location:1.0.0'
|
||||||
|
|
||||||
//crontab解析库:https://github.com/jmrozanec/cron-utils 官网:http://cron-parser.com
|
|
||||||
//implementation 'com.cronutils:cron-utils:9.2.1'
|
|
||||||
//JSR-310 backport for Android:https://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
|
//Partial implementation of Quartz Cron Java for Android: https://github.com/gatewayapps/crondroid
|
||||||
implementation 'gatewayapps.crondroid:crondroid:1.0.0'
|
implementation 'gatewayapps.crondroid:crondroid:1.0.0'
|
||||||
//Java Parser For Cron Expressions: https://github.com/grahamar/cron-parser
|
//Java Parser For Cron Expressions: https://github.com/grahamar/cron-parser
|
||||||
|
@ -317,8 +312,6 @@ dependencies {
|
||||||
|
|
||||||
//侧边栏菜单:https://github.com/yarolegovich/SlidingRootNav
|
//侧边栏菜单:https://github.com/yarolegovich/SlidingRootNav
|
||||||
implementation 'com.yarolegovich:sliding-root-nav:1.1.1'
|
implementation 'com.yarolegovich:sliding-root-nav:1.1.1'
|
||||||
//TabBar:https://github.com/xuexiangjys/JPTabBar
|
|
||||||
// implementation 'com.github.xuexiangjys:JPTabBar:1.0.1'
|
|
||||||
}
|
}
|
||||||
//自动添加X-Library依赖
|
//自动添加X-Library依赖
|
||||||
apply from: 'x-library.gradle'
|
apply from: 'x-library.gradle'
|
||||||
|
|
|
@ -305,3 +305,7 @@
|
||||||
|
|
||||||
# MultiLanguages
|
# MultiLanguages
|
||||||
-keep class com.hjq.language.** {*;}
|
-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.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -161,7 +162,8 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||||
times++
|
times++
|
||||||
}
|
}
|
||||||
binding!!.tvDescription.text = description
|
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.text = String.format(getString(R.string.next_execution_times), times.toString(), nextTimeList.joinToString("\n"))
|
||||||
binding!!.tvNextTimeList.visibility = View.VISIBLE
|
binding!!.tvNextTimeList.visibility = View.VISIBLE
|
||||||
binding!!.separatorCronExpressionCheck.visibility = View.VISIBLE
|
binding!!.separatorCronExpressionCheck.visibility = View.VISIBLE
|
||||||
|
@ -1589,14 +1591,19 @@ class CronFragment : BaseFragment<FragmentTasksConditionCronBinding?>(), View.On
|
||||||
//判断cronExpression是否有效
|
//判断cronExpression是否有效
|
||||||
CronExpression.validateExpression(expression)
|
CronExpression.validateExpression(expression)
|
||||||
|
|
||||||
//生成cron表达式描述
|
//TODO:低版本Android解析Cron表达式会报错,暂时不处理
|
||||||
val options = Options()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
options.isTwentyFourHourTime = true
|
//生成cron表达式描述
|
||||||
//TODO:支持多语言
|
val options = Options()
|
||||||
val locale = Locale.getDefault()
|
options.isTwentyFourHourTime = true
|
||||||
//Chinese, Japanese, Korean and other East Asian languages have no spaces between words
|
//TODO:支持多语言
|
||||||
options.isNeedSpaceBetweenWords = locale == Locale("zh") || locale == Locale("ja") || locale == Locale("ko")
|
val locale = Locale.getDefault()
|
||||||
description = CronExpressionDescriptor.getDescription(expression, options, locale)
|
//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)
|
return CronSetting(description, expression)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue