Simplify edge case handling
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user