Merge pull request #219 from TouchInstinct/add/extension-browser-intent

MOBILE-1144
This commit is contained in:
sousnein 2021-09-13 17:01:07 +03:00 committed by GitHub
commit a1db8b8ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import ru.touchin.roboswag.core.log.Lc
import android.provider.Browser
fun Context.safeStartActivity(intent: Intent, options: Bundle? = null) =
try {
@ -18,6 +19,18 @@ fun Context.openBrowser(url: String) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(url))
.let { intent -> safeStartActivity(intent) }
fun Context.openBrowserWithHeaders(url: String, headersMap: Map<String, String>) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(url))
.let { intent ->
val bundle = Bundle().apply {
headersMap.forEach { (key, value) ->
putString(key, value)
}
}
intent.putExtra(Browser.EXTRA_HEADERS, bundle)
safeStartActivity(intent)
}
fun Context.callToPhoneNumber(phoneNumber: String) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("tel:$phoneNumber"))
.let { intent -> safeStartActivity(intent) }