show an error if fetching google events fails

This commit is contained in:
tibbi 2017-07-28 20:39:30 +02:00
parent 617c56cefd
commit dc5846f268
17 changed files with 31 additions and 2 deletions

View File

@ -37,7 +37,7 @@ android {
} }
dependencies { dependencies {
compile 'com.simplemobiletools:commons:2.22.8' compile 'com.simplemobiletools:commons:2.23.0'
compile 'joda-time:joda-time:2.9.1' compile 'joda-time:joda-time:2.9.1'
compile 'com.facebook.stetho:stetho:1.4.1' compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

@ -4,13 +4,18 @@ import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.os.AsyncTask import android.os.AsyncTask
import android.util.SparseIntArray import android.util.SparseIntArray
import android.widget.Toast
import com.google.api.client.googleapis.json.GoogleJsonResponseException
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.* import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.interfaces.GoogleSyncListener import com.simplemobiletools.calendar.interfaces.GoogleSyncListener
import com.simplemobiletools.calendar.models.* import com.simplemobiletools.calendar.models.*
import com.simplemobiletools.commons.extensions.isOnMainThread
import com.simplemobiletools.commons.extensions.toast
import org.joda.time.DateTime import org.joda.time.DateTime
import java.util.* import java.util.*
@ -24,6 +29,7 @@ class FetchGoogleEventsTask(val context: Context, val googleSyncListener: Google
private var eventTypes = ArrayList<EventType>() private var eventTypes = ArrayList<EventType>()
private var eventColors = SparseIntArray() private var eventColors = SparseIntArray()
private var service = context.getGoogleSyncService() private var service = context.getGoogleSyncService()
private var parseError: Exception? = null
override fun doInBackground(vararg params: Void): String { override fun doInBackground(vararg params: Void): String {
if (!context.isGoogleSyncActive() || !context.isOnline()) if (!context.isGoogleSyncActive() || !context.isOnline())
@ -56,12 +62,20 @@ class FetchGoogleEventsTask(val context: Context, val googleSyncListener: Google
getColors() getColors()
getDataFromApi() getDataFromApi()
} catch (e: Exception) { } catch (e: Exception) {
cancel(true) parseError = e
} }
googleSyncListener?.syncCompleted() googleSyncListener?.syncCompleted()
return "" return ""
} }
override fun onPostExecute(result: String?) {
super.onPostExecute(result)
if (context.isOnMainThread() && parseError != null && parseError is GoogleJsonResponseException) {
val msg = String.format(context.getString(R.string.google_sync_error_fetch), parseError!!.getGoogleMessageError())
context.toast(msg, Toast.LENGTH_LONG)
}
}
private fun getColors() { private fun getColors() {
val colors = service.colors().get().execute() val colors = service.colors().get().execute()
for ((id, color) in colors.event.entries) { for ((id, color) in colors.event.entries) {

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minuto</item> <item quantity="one">%1$d minuto</item>

View File

@ -211,6 +211,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d минута</item> <item quantity="one">%1$d минута</item>

View File

@ -204,6 +204,7 @@
<string name="google_sync_disabling">Vypnutie Google synchonizácie odstráni všetky synchronizované udalosti zo zariadenia, no v oblakoch ostanú nedotknuté.</string> <string name="google_sync_disabling">Vypnutie Google synchonizácie odstráni všetky synchronizované udalosti zo zariadenia, no v oblakoch ostanú nedotknuté.</string>
<string name="google_sync_error_insert">Chyba pri nahrávaní udalosti na Google: %1$s</string> <string name="google_sync_error_insert">Chyba pri nahrávaní udalosti na Google: %1$s</string>
<string name="google_sync_error_update">Chyba pri úprave udalosti na Googli: %1$s</string> <string name="google_sync_error_update">Chyba pri úprave udalosti na Googli: %1$s</string>
<string name="google_sync_error_fetch">Chyba pri čítaní Google udalostí: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minútu</item> <item quantity="one">%1$d minútu</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minut</item> <item quantity="one">%1$d minut</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -197,6 +197,7 @@
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event to Google: %1$s</string> <string name="google_sync_error_insert">Error uploading event to Google: %1$s</string>
<string name="google_sync_error_update">Error updating event at Google: %1$s</string> <string name="google_sync_error_update">Error updating event at Google: %1$s</string>
<string name="google_sync_error_fetch">Error fetching Google events: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>