pref: 一键签到失败时不中断
This commit is contained in:
parent
90cebdb90d
commit
70e6522a98
|
|
@ -36,6 +36,8 @@ class OKSignService : IntentService(TAG), CoroutineScope, ProgressListener {
|
|||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.Main + job
|
||||
|
||||
private var lastSignData: SignDataBean? = null
|
||||
|
||||
private val notificationManager: NotificationManagerCompat by lazy {
|
||||
NotificationManagerCompat.from(this)
|
||||
}
|
||||
|
|
@ -165,6 +167,7 @@ class OKSignService : IntentService(TAG), CoroutineScope, ProgressListener {
|
|||
}
|
||||
|
||||
override fun onProgressStart(signDataBean: SignDataBean, current: Int, total: Int) {
|
||||
lastSignData = signDataBean
|
||||
updateNotification(
|
||||
getString(
|
||||
R.string.title_signing_progress,
|
||||
|
|
@ -217,8 +220,22 @@ class OKSignService : IntentService(TAG), CoroutineScope, ProgressListener {
|
|||
}
|
||||
|
||||
override fun onFailure(current: Int, total: Int, errorCode: Int, errorMsg: String) {
|
||||
lastSignData.let {
|
||||
if (it == null) {
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_DETACH)
|
||||
updateNotification(getString(R.string.title_oksign_fail), errorMsg)
|
||||
} else {
|
||||
updateNotification(
|
||||
getString(
|
||||
R.string.title_signing_progress,
|
||||
it.userName,
|
||||
current + 1,
|
||||
total
|
||||
),
|
||||
getString(R.string.text_singing_progress_fail, it.forumName, errorMsg)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -436,6 +436,7 @@
|
|||
<string name="text_stat_fans">粉丝</string>
|
||||
<string name="title_custom_font_size">字体大小</string>
|
||||
<string name="text_singing_progress">%1$s吧 ✓</string>
|
||||
<string name="text_singing_progress_fail">%1$s吧 × %2$s</string>
|
||||
<string name="text_singing_progress_exp">%1$s吧 ✓ 经验 +%2$s</string>
|
||||
<string name="title_start_sign">即将开始签到</string>
|
||||
<string name="toast_oksign_start">签到已开始,可在通知栏查看进度</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue