mirror of https://git.sr.ht/~oppen/ariane
40 lines
997 B
Kotlin
40 lines
997 B
Kotlin
package oppen
|
|
|
|
import android.content.Context
|
|
import android.os.CountDownTimer
|
|
import android.view.View
|
|
import android.view.inputmethod.InputMethodManager
|
|
import androidx.core.content.ContextCompat.getSystemService
|
|
|
|
|
|
fun View.visible(visible: Boolean) = when {
|
|
visible -> this.visibility = View.VISIBLE
|
|
else -> this.visibility = View.GONE
|
|
}
|
|
|
|
fun View.visibleRetainingSpace(visible: Boolean) = when {
|
|
visible -> this.visibility = View.VISIBLE
|
|
else -> this.visibility = View.INVISIBLE
|
|
}
|
|
|
|
fun View.hideKeyboard(){
|
|
val imm: InputMethodManager? = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
|
|
imm?.hideSoftInputFromWindow(windowToken, 0)
|
|
}
|
|
|
|
fun View.showKeyboard(){
|
|
delay(200){
|
|
this.callOnClick()
|
|
}
|
|
}
|
|
|
|
fun delay(ms: Long, action: () -> Unit){
|
|
object : CountDownTimer(ms, ms/2) {
|
|
override fun onTick(millisUntilFinished: Long) {}
|
|
|
|
override fun onFinish() {
|
|
action.invoke()
|
|
}
|
|
}.start()
|
|
|
|
} |