pull/34/head
parent
1e59df8536
commit
98003f6e08
@ -1,8 +1,54 @@ |
||||
package io.legado.app.service |
||||
|
||||
import android.content.Intent |
||||
import androidx.core.app.NotificationCompat |
||||
import io.legado.app.R |
||||
import io.legado.app.base.BaseService |
||||
import io.legado.app.constant.Action |
||||
import io.legado.app.constant.AppConst |
||||
import io.legado.app.data.entities.BookSource |
||||
import io.legado.app.help.IntentHelp |
||||
import io.legado.app.ui.book.source.manage.BookSourceActivity |
||||
|
||||
class CheckSourceService : BaseService() { |
||||
|
||||
private var sourceList: List<BookSource>? = null |
||||
|
||||
override fun onCreate() { |
||||
super.onCreate() |
||||
} |
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { |
||||
return super.onStartCommand(intent, flags, startId) |
||||
} |
||||
|
||||
override fun onDestroy() { |
||||
super.onDestroy() |
||||
} |
||||
|
||||
/** |
||||
* 更新通知 |
||||
*/ |
||||
private fun updateNotification(state: Int, msg: String) { |
||||
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud) |
||||
.setSmallIcon(R.drawable.ic_network_check) |
||||
.setOngoing(true) |
||||
.setContentTitle(getString(R.string.check_book_source)) |
||||
.setContentText(msg) |
||||
.setContentIntent( |
||||
IntentHelp.servicePendingIntent<BookSourceActivity>(this, "activity") |
||||
) |
||||
.addAction( |
||||
R.drawable.ic_stop_black_24dp, |
||||
getString(R.string.cancel), |
||||
IntentHelp.servicePendingIntent<CheckSourceService>(this, Action.stop) |
||||
) |
||||
sourceList?.let { |
||||
builder.setProgress(it.size, state, false) |
||||
} |
||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) |
||||
val notification = builder.build() |
||||
startForeground(112202, notification) |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue