Brought back isOngoing status for sync prefs, started more user friendly last error messages

pull/14/head
Sam Bosley 14 years ago
parent f221bc49f1
commit c59e6104ee

@ -215,6 +215,10 @@
<!-- confirmation dialog for sync log out -->
<string name="sync_forget_confirm">Log out / clear synchronization data?</string>
<!-- Sync error: network connectivity problems. %s-> name of sync service-->
<string name="sync_error_offline">It looks like you had some network connectivity problems
the last time you tried to sync with %s. Please try again later!</string>
<string-array name="sync_SPr_interval_entries">
<!-- sync_SPr_interval_entries: Synchronization Intervals -->
<item>disable</item>

@ -1,6 +1,7 @@
package com.todoroo.astrid.sync;
import java.util.Date;
import java.util.HashMap;
import android.app.AlertDialog;
import android.content.DialogInterface;
@ -174,7 +175,9 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
else if (r.getString(R.string.sync_SPr_key_last_error).equals(preference.getKey())) {
if (getUtilities().getLastError() != null) {
// Display error
final String lastError = getUtilities().getLastError();
final String service = getTitle().toString();
final String lastErrorFull = getUtilities().getLastError();
final String lastErrorDisplay = adjustErrorForDisplay(r, lastErrorFull, service);
preference.setTitle(R.string.sync_SPr_last_error);
preference.setSummary(R.string.sync_SPr_last_error_subtitle);
@ -185,15 +188,15 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
// Show last error
new AlertDialog.Builder(SyncProviderPreferences.this)
.setTitle(R.string.sync_SPr_last_error)
.setMessage(lastError)
.setMessage(lastErrorDisplay)
.setPositiveButton(R.string.sync_SPr_send_report, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text")
.putExtra(Intent.EXTRA_EMAIL, new String[] { "android-bugs@astrid.com"} )
.putExtra(Intent.EXTRA_SUBJECT, getTitle() + " Sync Error")
.putExtra(Intent.EXTRA_TEXT, lastError);
.putExtra(Intent.EXTRA_SUBJECT, service + " Sync Error")
.putExtra(Intent.EXTRA_TEXT, lastErrorFull);
startActivity(Intent.createChooser(emailIntent, r.getString(R.string.sync_SPr_send_report)));
}
})
@ -233,6 +236,28 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
}
}
/**
* We can define exception strings in this map that we want to replace with more user-friendly
* messages. As we discover new exception types, we can expand the map
*/
private static HashMap<String, Integer> exceptionsToDisplayMessages;
@SuppressWarnings("nls")
private static HashMap<String, Integer> getExceptionMap() {
if (exceptionsToDisplayMessages == null) {
exceptionsToDisplayMessages = new HashMap<String, Integer>();
exceptionsToDisplayMessages.put("java.net.ConnectionException", R.string.sync_error_offline);
}
return exceptionsToDisplayMessages;
}
private static final String adjustErrorForDisplay(Resources r, String lastError, String service) {
Integer resource = getExceptionMap().get(lastError);
if (resource == null)
return lastError;
return r.getString(resource.intValue(), service);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LOGIN && resultCode == RESULT_OK) {

@ -123,7 +123,7 @@ abstract public class SyncProviderUtilities {
editor.putLong(getIdentifier() + PREF_LAST_ATTEMPTED_SYNC,
DateUtilities.now());
editor.remove(getIdentifier() + PREF_LAST_ERROR);
// editor.putBoolean(getIdentifier() + PREF_ONGOING, true);
editor.putBoolean(getIdentifier() + PREF_ONGOING, true);
editor.commit();
}

Loading…
Cancel
Save