Commit 50c4ee94 authored by Ricki Hirner's avatar Ricki Hirner

Handle unresolvable ACTION_VIEW intents; update gradle, Kotlin

parent 2c5cdf81
......@@ -156,6 +156,7 @@ class CalendarSyncManager(
events = Event.fromReader(reader)
} catch (e: InvalidCalendarException) {
Logger.log.log(Level.SEVERE, "Received invalid iCalendar, ignoring", e)
// TODO show notification
return
}
......
......@@ -350,7 +350,10 @@ class ContactsSyncManager(
private fun processVCard(fileName: String, eTag: String, reader: Reader, downloader: Contact.Downloader) {
Logger.log.info("Processing CardDAV resource $fileName")
// TODO catch and show notification on CannotParseException
val contacts = Contact.fromReader(reader, downloader)
if (contacts.isEmpty()) {
Logger.log.warning("Received VCard without data, ignoring")
return
......
......@@ -136,6 +136,7 @@ class TasksSyncManager(
tasks = Task.fromReader(reader)
} catch (e: InvalidCalendarException) {
Logger.log.log(Level.SEVERE, "Received invalid iCalendar, ignoring", e)
// TODO show notification
return
}
......
......@@ -9,7 +9,6 @@
package at.bitfire.davdroid.ui
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
......@@ -61,9 +60,7 @@ class AboutActivity: AppCompatActivity() {
}
fun showWebsite(item: MenuItem) {
val intent = Intent(Intent.ACTION_VIEW, App.homepageUrl(this))
if (intent.resolveActivity(packageManager) != null)
startActivity(intent)
UiUtils.launchUri(this, App.homepageUrl(this))
}
......
......@@ -36,27 +36,24 @@ class DefaultAccountsDrawerHandler: IAccountsDrawerHandler {
activity.startActivity(Intent(activity, AboutActivity::class.java))
R.id.nav_app_settings ->
activity.startActivity(Intent(activity, AppSettingsActivity::class.java))
R.id.nav_beta_feedback -> {
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse(BETA_FEEDBACK_URI))
if (activity.packageManager.resolveActivity(intent, 0) != null)
activity.startActivity(intent)
}
R.id.nav_beta_feedback ->
UiUtils.launchUri(activity, Uri.parse(BETA_FEEDBACK_URI), Intent.ACTION_SENDTO)
R.id.nav_twitter ->
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/davdroidapp")))
UiUtils.launchUri(activity, Uri.parse("https://twitter.com/davdroidapp"))
R.id.nav_website ->
activity.startActivity(Intent(Intent.ACTION_VIEW, App.homepageUrl(activity)))
UiUtils.launchUri(activity, App.homepageUrl(activity))
R.id.nav_manual ->
activity.startActivity(Intent(Intent.ACTION_VIEW, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("manual/").build()))
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("manual/").build())
R.id.nav_faq ->
activity.startActivity(Intent(Intent.ACTION_VIEW, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("faq/").build()))
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("faq/").build())
R.id.nav_forums ->
activity.startActivity(Intent(Intent.ACTION_VIEW, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("forums/").build()))
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("forums/").build())
R.id.nav_donate ->
activity.startActivity(Intent(Intent.ACTION_VIEW, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("donate/").build()))
UiUtils.launchUri(activity, App.homepageUrl(activity)
.buildUpon().appendEncodedPath("donate/").build())
else ->
return false
}
......
......@@ -13,7 +13,6 @@ import android.annotation.TargetApi
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.net.Uri
......@@ -133,10 +132,8 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
.setTitle(R.string.startup_autostart_permission)
.setMessage(getString(R.string.startup_autostart_permission_message, WordUtils.capitalize(Build.MANUFACTURER.toLowerCase())))
.setPositiveButton(R.string.startup_more_info) { _, _ ->
val intent = Intent(Intent.ACTION_VIEW, App.homepageUrl(requireActivity()).buildUpon()
UiUtils.launchUri(requireActivity(), App.homepageUrl(requireActivity()).buildUpon()
.appendPath("faq").appendEncodedPath("synchronization-is-not-run-as-expected/").build())
if (intent.resolveActivity(activity.packageManager) != null)
activity.startActivity(intent)
}
.setNeutralButton(R.string.startup_not_now) { _, _ -> }
.setNegativeButton(R.string.startup_dont_show_again) { _, _ ->
......@@ -150,10 +147,8 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
.setTitle(R.string.startup_battery_optimization)
.setMessage(R.string.startup_battery_optimization_message)
.setPositiveButton(R.string.startup_battery_optimization_disable) @TargetApi(Build.VERSION_CODES.M) { _, _ ->
val intent = Intent(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + BuildConfig.APPLICATION_ID))
if (intent.resolveActivity(activity.packageManager) != null)
activity.startActivity(intent)
UiUtils.launchUri(requireActivity(), Uri.parse("package:" + BuildConfig.APPLICATION_ID),
android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
}
.setNeutralButton(R.string.startup_not_now) { _, _ -> }
.setNegativeButton(R.string.startup_dont_show_again) { _: DialogInterface, _: Int ->
......@@ -173,10 +168,8 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
.setTitle(R.string.startup_google_play_accounts_removed)
.setMessage(R.string.startup_google_play_accounts_removed_message)
.setPositiveButton(R.string.startup_more_info) { _, _ ->
val intent = Intent(Intent.ACTION_VIEW, App.homepageUrl(requireActivity()).buildUpon()
UiUtils.launchUri(requireActivity(), App.homepageUrl(requireActivity()).buildUpon()
.appendPath("faq").appendEncodedPath("accounts-gone-after-reboot-or-update/").build())
if (intent.resolveActivity(activity.packageManager) != null)
activity.startActivity(intent)
}
.setNeutralButton(R.string.startup_not_now) { _, _ -> }
.setNegativeButton(R.string.startup_dont_show_again) { _, _ ->
......@@ -194,10 +187,7 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
.setTitle(R.string.startup_opentasks_not_installed)
.setMessage(builder.toString())
.setPositiveButton(R.string.startup_opentasks_not_installed_install) { _, _ ->
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=org.dmfs.tasks"))
if (intent.resolveActivity(activity.packageManager) != null)
activity.startActivity(intent)
else
if (!UiUtils.launchUri(requireActivity(), Uri.parse("market://details?id=org.dmfs.tasks")))
Logger.log.warning("No market app available, can't install OpenTasks")
}
.setNeutralButton(R.string.startup_not_now) { _, _ -> }
......@@ -213,10 +203,9 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
.setTitle(R.string.startup_donate)
.setMessage(R.string.startup_donate_message)
.setPositiveButton(R.string.startup_donate_now) { _, _ ->
val uri = App.homepageUrl(requireActivity()).buildUpon()
UiUtils.launchUri(requireActivity(), App.homepageUrl(requireActivity()).buildUpon()
.appendEncodedPath("donate/")
.build()
startActivity(Intent(Intent.ACTION_VIEW, uri))
.build())
settings?.putLong(SETTING_NEXT_DONATION_POPUP, System.currentTimeMillis() + 30 * 86400000L) // 30 days
}
.setNegativeButton(R.string.startup_donate_later) { _, _ ->
......
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.ui
import android.content.Context
import android.content.Intent
import android.net.Uri
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.
*/
fun launchUri(context: Context, uri: Uri, action: String = Intent.ACTION_VIEW): Boolean {
val intent = Intent(action, uri)
if (intent.resolveActivity(context.packageManager) != null) {
context.startActivity(intent)
return true
}
return false
}
}
\ No newline at end of file
......@@ -8,13 +8,13 @@
package at.bitfire.davdroid.ui.setup
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import at.bitfire.davdroid.App
import at.bitfire.davdroid.R
import at.bitfire.davdroid.ui.UiUtils
import java.util.*
/**
......@@ -60,9 +60,9 @@ class LoginActivity: AppCompatActivity() {
fun showHelp(item: MenuItem) {
startActivity(Intent(Intent.ACTION_VIEW, App.homepageUrl(this).buildUpon()
UiUtils.launchUri(this, App.homepageUrl(this).buildUpon()
.appendEncodedPath("tested-with/")
.build()))
.build())
}
}
......@@ -8,14 +8,14 @@
buildscript {
ext.dokka_version = '0.9.17'
ext.kotlin_version = '1.2.71'
ext.kotlin_version = '1.3.0'
  • The submodules should be updated as well. Atm, this triggers lots of lint warnings like this:

    w: Runtime JAR files in the classpath have the version 1.2, which is older than the API version 1.3. Consider using the runtime of version 1.3, or pass '-api-version 1.2' explicitly to restrict the available APIs to the runtime of version 1.2. You can also pass '-language-version 1.2' instead, which will restrict not only the APIs to the specified version, but also the language features
    
Please register or sign in to reply
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
}
......
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