mihon/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt

46 lines
1.1 KiB
Kotlin
Raw Normal View History

@file:Suppress("NOTHING_TO_INLINE")
2016-03-19 15:39:19 +01:00
package eu.kanade.tachiyomi.util
import android.graphics.Color
2016-03-19 15:39:19 +01:00
import android.graphics.Point
import android.support.design.widget.Snackbar
2016-03-19 15:39:19 +01:00
import android.view.View
import android.widget.TextView
2016-03-19 15:39:19 +01:00
/**
* Returns coordinates of view.
* Used for animation
*
* @return coordinates of view
*/
fun View.getCoordinates() = Point((left + right) / 2, (top + bottom) / 2)
2016-03-19 15:39:19 +01:00
/**
* Shows a snackbar in this view.
*
* @param message the message to show.
* @param length the duration of the snack.
* @param f a function to execute in the snack, allowing for example to define a custom action.
*/
2017-01-08 18:12:19 +01:00
inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit): Snackbar {
val snack = Snackbar.make(this, message, length)
val textView = snack.view.findViewById(android.support.design.R.id.snackbar_text) as TextView
textView.setTextColor(Color.WHITE)
snack.f()
snack.show()
2017-01-08 18:12:19 +01:00
return snack
}
inline fun View.visible() {
visibility = View.VISIBLE
}
inline fun View.invisible() {
visibility = View.INVISIBLE
}
inline fun View.gone() {
visibility = View.GONE
}