-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUiExt.kt
More file actions
22 lines (16 loc) · 839 Bytes
/
UiExt.kt
File metadata and controls
22 lines (16 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package voiedev
import android.app.Activity
import android.content.Context
import android.view.View
import android.widget.Toast
import com.google.android.material.snackbar.Snackbar
val Activity.rootView: View
get() = findViewById(android.R.id.content)
fun Context.toast(message: String) = toastInternal(message, Toast.LENGTH_LONG)
fun Context.toastShort(message: String) = toastInternal(message, Toast.LENGTH_SHORT)
private fun Context.toastInternal(message: String, duration: Int) =
Toast.makeText(this, message, duration).show()
fun Activity.snack(message: String) = snackInternal(message, Snackbar.LENGTH_LONG)
fun Activity.snackShort(message: String) = snackInternal(message, Snackbar.LENGTH_SHORT)
private fun Activity.snackInternal(message: String, duration: Int) =
Snackbar.make(rootView, message, duration).show()