2016-02-16 19:44:21 -05:00
|
|
|
package eu.kanade.tachiyomi.util
|
|
|
|
|
|
|
|
import android.app.AlarmManager
|
|
|
|
import android.app.Notification
|
2016-02-23 08:51:18 -05:00
|
|
|
import android.app.NotificationManager
|
2016-02-16 19:44:21 -05:00
|
|
|
import android.content.Context
|
|
|
|
import android.support.annotation.StringRes
|
|
|
|
import android.support.v4.app.NotificationCompat
|
|
|
|
import android.widget.Toast
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a toast in this context.
|
|
|
|
* @param resource the text resource.
|
|
|
|
* @param duration the duration of the toast. Defaults to short.
|
|
|
|
*/
|
|
|
|
fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT) {
|
|
|
|
Toast.makeText(this, resource, duration).show()
|
|
|
|
}
|
|
|
|
|
2016-03-13 17:06:32 -04:00
|
|
|
/**
|
|
|
|
* Display a toast in this context.
|
|
|
|
* @param text the text to display.
|
|
|
|
* @param duration the duration of the toast. Defaults to short.
|
|
|
|
*/
|
|
|
|
fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT) {
|
|
|
|
Toast.makeText(this, text, duration).show()
|
|
|
|
}
|
|
|
|
|
2016-02-16 19:44:21 -05:00
|
|
|
/**
|
|
|
|
* Helper method to create a notification.
|
|
|
|
* @param func the function that will execute inside the builder.
|
|
|
|
* @return a notification to be displayed or updated.
|
|
|
|
*/
|
|
|
|
inline fun Context.notification(func: NotificationCompat.Builder.() -> Unit): Notification {
|
|
|
|
val builder = NotificationCompat.Builder(this)
|
|
|
|
builder.func()
|
|
|
|
return builder.build()
|
|
|
|
}
|
|
|
|
|
2016-02-23 08:51:18 -05:00
|
|
|
/**
|
|
|
|
* Property to get the notification manager from the context.
|
|
|
|
*/
|
|
|
|
val Context.notificationManager : NotificationManager
|
|
|
|
get() = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
|
2016-02-16 19:44:21 -05:00
|
|
|
/**
|
|
|
|
* Property to get the alarm manager from the context.
|
|
|
|
* @return the alarm manager.
|
|
|
|
*/
|
|
|
|
val Context.alarmManager: AlarmManager
|
|
|
|
get() = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|