diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 2bac567b3..a828f305e 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -16,6 +16,7 @@ * 更新到SDK31,android 12 * 修复在线朗读引擎新建会替换之前已有的bug * 修复目录界面自动跳转到顶部bug +* 修复阿里云在线朗读引擎模板中获取时间的兼容性问题 **2021/11/20** diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 964708b48..0897a5989 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -15,7 +15,6 @@ import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking -import org.apache.commons.lang3.time.DateFormatUtils import org.jsoup.Connection import org.jsoup.Jsoup import splitties.init.appCtx @@ -25,6 +24,7 @@ import java.io.ByteArrayOutputStream import java.io.File import java.net.URLEncoder import java.nio.charset.Charset +import java.text.SimpleDateFormat import java.util.* import java.util.zip.ZipEntry import java.util.zip.ZipInputStream @@ -233,7 +233,10 @@ interface JsExtensions { */ fun timeFormatUTC(time: Long, format: String, sh: Int): String? { val utc = SimpleTimeZone(sh, "UTC") - return DateFormatUtils.format(Date(time), format, utc, null) + return SimpleDateFormat(format, Locale.getDefault()).run { + timeZone = utc + format(Date(time)) + } } /** diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 6562c98e9..f04eba50c 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -54,7 +54,12 @@ inline fun Context.servicePendingIntent( val intent = Intent(this, T::class.java) intent.action = action configIntent.invoke(intent) - return getService(this, 0, intent, FLAG_UPDATE_CURRENT) + val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + FLAG_UPDATE_CURRENT or FLAG_MUTABLE + } else { + FLAG_UPDATE_CURRENT + } + return getService(this, 0, intent, flags) } @SuppressLint("UnspecifiedImmutableFlag") @@ -65,7 +70,12 @@ inline fun Context.activityPendingIntent( val intent = Intent(this, T::class.java) intent.action = action configIntent.invoke(intent) - return getActivity(this, 0, intent, FLAG_UPDATE_CURRENT) + val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + FLAG_UPDATE_CURRENT or FLAG_MUTABLE + } else { + FLAG_UPDATE_CURRENT + } + return getActivity(this, 0, intent, flags) } @SuppressLint("UnspecifiedImmutableFlag") @@ -76,7 +86,12 @@ inline fun Context.broadcastPendingIntent( val intent = Intent(this, T::class.java) intent.action = action configIntent.invoke(intent) - return getBroadcast(this, 0, intent, FLAG_CANCEL_CURRENT) + val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + FLAG_UPDATE_CURRENT or FLAG_MUTABLE + } else { + FLAG_UPDATE_CURRENT + } + return getBroadcast(this, 0, intent, flags) } val Context.defaultSharedPreferences: SharedPreferences