ariane/app/src/main/java/oppen/Extensions.kt

48 lines
1.3 KiB
Kotlin
Raw Normal View History

2020-08-15 21:12:17 +00:00
package oppen
2020-11-13 09:22:36 +00:00
import android.annotation.SuppressLint
2020-08-20 17:24:23 +00:00
import android.content.Context
2020-08-20 13:52:24 +00:00
import android.os.CountDownTimer
2020-08-16 21:30:24 +00:00
import android.view.View
2020-08-20 17:24:23 +00:00
import android.view.inputmethod.InputMethodManager
import androidx.core.content.ContextCompat.getSystemService
2020-11-09 22:02:23 +00:00
import java.net.URI
2020-08-15 21:12:17 +00:00
2020-08-20 13:52:24 +00:00
2020-08-16 21:30:24 +00:00
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
2020-08-20 13:52:24 +00:00
}
2020-08-20 17:24:23 +00:00
fun View.hideKeyboard(){
val imm: InputMethodManager? = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
imm?.hideSoftInputFromWindow(windowToken, 0)
}
2020-11-09 22:02:23 +00:00
fun String.toURI(): URI {
return URI.create(this)
}
2020-11-13 09:22:36 +00:00
@SuppressLint("DefaultLocale")
fun String.endsWithImage(): Boolean{
return this.toLowerCase().endsWith(".png") ||
this.toLowerCase().endsWith(".jpg") ||
this.toLowerCase().endsWith(".jpeg") ||
this.toLowerCase().endsWith(".gif")
}
2020-08-20 13:52:24 +00:00
fun delay(ms: Long, action: () -> Unit){
object : CountDownTimer(ms, ms/2) {
override fun onTick(millisUntilFinished: Long) {}
override fun onFinish() {
action.invoke()
}
}.start()
2020-08-15 21:12:17 +00:00
}