Commit 15f5152a authored by Ricki Hirner's avatar Ricki Hirner 🐑

UiUtils.launchUri: show toast if no browser is installed

parent 03f54f54
Pipeline #105911184 passed with stages
in 9 minutes and 2 seconds
......@@ -14,6 +14,7 @@ import android.content.Intent
import android.net.Uri
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import at.bitfire.davdroid.App
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.R
......@@ -37,27 +38,30 @@ class DefaultAccountsDrawerHandler: IAccountsDrawerHandler {
R.id.nav_app_settings ->
activity.startActivity(Intent(activity, AppSettingsActivity::class.java))
R.id.nav_beta_feedback ->
UiUtils.launchUri(activity, Uri.parse(BETA_FEEDBACK_URI), Intent.ACTION_SENDTO)
if (!UiUtils.launchUri(activity, Uri.parse(BETA_FEEDBACK_URI), Intent.ACTION_SENDTO, false))
Toast.makeText(activity, R.string.install_email_client, Toast.LENGTH_LONG).show()
R.id.nav_twitter ->
UiUtils.launchUri(activity, Uri.parse("https://twitter.com/" + activity.getString(R.string.twitter_handle)))
UiUtils.launchUri(activity,
Uri.parse("https://twitter.com/" + activity.getString(R.string.twitter_handle)))
R.id.nav_website ->
UiUtils.launchUri(activity, App.homepageUrl(activity))
UiUtils.launchUri(activity,
App.homepageUrl(activity))
R.id.nav_manual ->
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendPath("manual").build())
UiUtils.launchUri(activity,
App.homepageUrl(activity).buildUpon().appendPath("manual").build())
R.id.nav_faq ->
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendPath("faq").build())
UiUtils.launchUri(activity,
App.homepageUrl(activity).buildUpon().appendPath("faq").build())
R.id.nav_forums ->
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendPath("forums").build())
UiUtils.launchUri(activity,
App.homepageUrl(activity).buildUpon().appendPath("forums").build())
R.id.nav_donate ->
//if (BuildConfig.FLAVOR != App.FLAVOR_GOOGLE_PLAY)
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendPath("donate").build())
UiUtils.launchUri(activity,
App.homepageUrl(activity).buildUpon().appendPath("donate").build())
R.id.nav_privacy ->
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendPath("privacy").build())
UiUtils.launchUri(activity,
App.homepageUrl(activity).buildUpon().appendPath("privacy").build())
else ->
return false
}
......
......@@ -132,7 +132,7 @@ class StartupDialogFragment: DialogFragment() {
.setTitle(R.string.startup_opentasks_not_installed)
.setMessage(builder.toString())
.setPositiveButton(R.string.startup_opentasks_not_installed_install) { _, _ ->
if (!UiUtils.launchUri(requireActivity(), Uri.parse("market://details?id=org.dmfs.tasks")))
if (!UiUtils.launchUri(requireActivity(), Uri.parse("market://details?id=org.dmfs.tasks"), toastInstallBrowser = false))
Logger.log.warning("No market app available, can't install OpenTasks")
}
.setNeutralButton(R.string.startup_not_now) { _, _ -> }
......
......@@ -11,6 +11,8 @@ package at.bitfire.davdroid.ui
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.widget.Toast
import at.bitfire.davdroid.R
object UiUtils {
......@@ -18,13 +20,20 @@ object UiUtils {
* Starts the [Intent.ACTION_VIEW] intent with the given URL, if possible.
* If the intent can't be resolved (for instance, because there is no browser
* installed), this method does nothing.
*
* @param toastInstallBrowser whether to show "Please install a browser" toast when
* the Intent could not be resolved
*
* @return true on success, false if the Intent could not be resolved (for instance, because
* there is no user agent installed)
*/
fun launchUri(context: Context, uri: Uri, action: String = Intent.ACTION_VIEW): Boolean {
fun launchUri(context: Context, uri: Uri, action: String = Intent.ACTION_VIEW, toastInstallBrowser: Boolean = true): Boolean {
val intent = Intent(action, uri)
if (intent.resolveActivity(context.packageManager) != null) {
context.startActivity(intent)
return true
}
} else if (toastInstallBrowser)
Toast.makeText(context, R.string.install_browser, Toast.LENGTH_LONG).show()
return false
}
......
......@@ -71,9 +71,8 @@ class LoginActivity: AppCompatActivity() {
}
fun showHelp(item: MenuItem) {
UiUtils.launchUri(this, App.homepageUrl(this).buildUpon()
.appendPath("tested-with")
.build())
UiUtils.launchUri(this,
App.homepageUrl(this).buildUpon().appendPath("tested-with").build())
}
}
......@@ -69,6 +69,8 @@
<string name="navigation_drawer_subtitle">CalDAV/CardDAV Sync Adapter</string>
<string name="navigation_drawer_about">About / License</string>
<string name="navigation_drawer_beta_feedback">Beta feedback</string>
<string name="install_email_client">Please install an email client</string>
<string name="install_browser">Please install a Web browser</string>
<string name="navigation_drawer_settings">Settings</string>
<string name="navigation_drawer_news_updates">News &amp; updates</string>
<string name="navigation_drawer_external_links">External links</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment