|
|
|
@ -5,6 +5,7 @@ package io.legado.app.utils |
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
import android.app.Activity |
|
|
|
|
import android.app.PendingIntent |
|
|
|
|
import android.app.PendingIntent.* |
|
|
|
|
import android.app.Service |
|
|
|
|
import android.content.* |
|
|
|
|
import android.content.pm.PackageManager |
|
|
|
@ -43,6 +44,7 @@ inline fun <reified T : Service> Context.stopService() { |
|
|
|
|
stopService(Intent(this, T::class.java)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("UnspecifiedImmutableFlag") |
|
|
|
|
inline fun <reified T : Service> Context.servicePendingIntent( |
|
|
|
|
action: String, |
|
|
|
|
configIntent: Intent.() -> Unit = {} |
|
|
|
@ -50,7 +52,29 @@ inline fun <reified T : Service> Context.servicePendingIntent( |
|
|
|
|
val intent = Intent(this, T::class.java) |
|
|
|
|
intent.action = action |
|
|
|
|
configIntent.invoke(intent) |
|
|
|
|
return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
return getService(this, 0, intent, FLAG_UPDATE_CURRENT) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("UnspecifiedImmutableFlag") |
|
|
|
|
inline fun <reified T : Activity> Context.activityPendingIntent( |
|
|
|
|
action: String, |
|
|
|
|
configIntent: Intent.() -> Unit = {} |
|
|
|
|
): PendingIntent? { |
|
|
|
|
val intent = Intent(this, T::class.java) |
|
|
|
|
intent.action = action |
|
|
|
|
configIntent.invoke(intent) |
|
|
|
|
return getActivity(this, 0, intent, FLAG_UPDATE_CURRENT) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("UnspecifiedImmutableFlag") |
|
|
|
|
inline fun <reified T : BroadcastReceiver> Context.broadcastPendingIntent( |
|
|
|
|
action: String, |
|
|
|
|
configIntent: Intent.() -> Unit = {} |
|
|
|
|
): PendingIntent? { |
|
|
|
|
val intent = Intent(this, T::class.java) |
|
|
|
|
intent.action = action |
|
|
|
|
configIntent.invoke(intent) |
|
|
|
|
return getBroadcast(this, 0, intent, FLAG_CANCEL_CURRENT) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun Context.toastOnUi(message: Int) { |
|
|
|
|