2016-03-19 10:39:19 -04:00
|
|
|
package eu.kanade.tachiyomi.util
|
|
|
|
|
2016-04-09 18:59:12 -04:00
|
|
|
import android.graphics.Color
|
2016-03-19 10:39:19 -04:00
|
|
|
import android.graphics.Point
|
2016-04-09 18:59:12 -04:00
|
|
|
import android.support.design.widget.Snackbar
|
2016-03-19 10:39:19 -04:00
|
|
|
import android.view.View
|
2016-04-09 18:59:12 -04:00
|
|
|
import android.widget.TextView
|
2016-03-19 10:39:19 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns coordinates of view.
|
|
|
|
* Used for animation
|
|
|
|
*
|
|
|
|
* @return coordinates of view
|
|
|
|
*/
|
2016-04-09 18:59:12 -04:00
|
|
|
fun View.getCoordinates() = Point((left + right) / 2, (top + bottom) / 2)
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2016-04-09 18:59:12 -04: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.
|
|
|
|
*/
|
|
|
|
inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) {
|
|
|
|
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()
|
|
|
|
}
|