Simplify edge case handling

This commit is contained in:
Kirill Kamakin
2022-11-05 10:40:15 +01:00
parent 33bdaf9726
commit b7bb6c8566
4 changed files with 60 additions and 48 deletions

View File

@@ -1,5 +1,7 @@
package gq.kirmanak.mealient.extensions
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
@@ -19,4 +21,12 @@ fun Fragment.launchWhenViewResumed(
fun <T> Flow<T>.launchIn(lifecycleOwner: LifecycleOwner) {
launchIn(lifecycleOwner.lifecycleScope)
}
}
fun Fragment.showLongToast(@StringRes text: Int) = showLongToast(getString(text))
fun Fragment.showLongToast(text: String) = showToast(text, Toast.LENGTH_LONG)
private fun Fragment.showToast(text: String, length: Int): Boolean {
return context?.let { Toast.makeText(it, text, length).show() } != null
}