mirror of https://github.com/tasks/tasks
Remove some intent queries
parent
e6926f5943
commit
63c914b493
@ -0,0 +1,30 @@
|
|||||||
|
package org.tasks.extensions
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import org.tasks.R
|
||||||
|
|
||||||
|
fun Context.safeStartActivity(intent: Intent) {
|
||||||
|
try {
|
||||||
|
startActivity(intent)
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
toast(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Fragment.safeStartActivityForResult(intent: Intent, rc: Int) {
|
||||||
|
try {
|
||||||
|
startActivityForResult(intent, rc)
|
||||||
|
} catch(e: ActivityNotFoundException) {
|
||||||
|
toast(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toast(context: Context?) {
|
||||||
|
context?.let {
|
||||||
|
Toast.makeText(it, R.string.no_application_found, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue