try/catch around backup service, get backup update status and save the

summary off.
pull/14/head
Tim Su 16 years ago
parent 2af81f644f
commit 82f3fa4860

@ -465,8 +465,16 @@ Skipped %d tasks.\n
<string name="prefs_deadlineTime_desc"># of days from now to set new deadlines</string> <string name="prefs_deadlineTime_desc"># of days from now to set new deadlines</string>
<string name="prefs_backup_title">Automatic Backups</string> <string name="prefs_backup_title">Automatic Backups</string>
<!-- backup summary when there is no backup message -->
<string name="prefs_backup_desc">Perform daily backups to sdcard.</string> <string name="prefs_backup_desc">Perform daily backups to sdcard.</string>
<!-- backup failure message (%s -> error message) -->
<string name="prefs_backup_desc_failure">Backup failed: %s</string>
<!-- backup success message (%s -> date) -->
<string name="prefs_backup_desc_success">Latest backup: %s</string>
<string name="displayedFields_PrefScreen_Title">Displayed Fields</string> <string name="displayedFields_PrefScreen_Title">Displayed Fields</string>
<string name="displayedFields_PrefScreen_Desc">Select the fields to show in task list</string> <string name="displayedFields_PrefScreen_Desc">Select the fields to show in task list</string>

@ -20,11 +20,13 @@
package com.timsu.astrid.activities; package com.timsu.astrid.activities;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import com.flurry.android.FlurryAgent; import com.flurry.android.FlurryAgent;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.timsu.astrid.utilities.Constants; import com.timsu.astrid.utilities.Constants;
import com.timsu.astrid.utilities.Preferences;
/** /**
* Displays the preference screen for users to edit their preferences * Displays the preference screen for users to edit their preferences
@ -38,6 +40,11 @@ public class EditPreferences extends PreferenceActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
Preference backupPreference = findPreference(getString(R.string.p_backup));
String backupSummary = Preferences.getBackupSummary(this);
if(backupSummary != null && backupPreference != null)
backupPreference.setSummary(backupSummary);
} }
@Override @Override

@ -2,6 +2,7 @@ package com.timsu.astrid.utilities;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.util.Date;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -10,6 +11,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import com.timsu.astrid.R;
/** /**
* Inspired heavily by SynchronizationService * Inspired heavily by SynchronizationService
*/ */
@ -44,10 +47,20 @@ public class BackupService extends Service {
if (!Preferences.isBackupEnabled(ctx)) { if (!Preferences.isBackupEnabled(ctx)) {
return; return;
} }
deleteOldBackups(); try {
TasksXmlExporter exporter = new TasksXmlExporter(true); deleteOldBackups();
exporter.setContext(ctx); TasksXmlExporter exporter = new TasksXmlExporter(true);
exporter.exportTasks(); exporter.setContext(ctx);
exporter.exportTasks();
Preferences.setBackupSummary(ctx,
ctx.getString(R.string.prefs_backup_desc_success,
DateUtilities.getFormattedDate(ctx.getResources(), new Date())));
} catch (Exception e) {
// unable to backup.
Preferences.setBackupSummary(ctx,
ctx.getString(R.string.prefs_backup_desc_failure,
e.getMessage()));
}
} }
public static void scheduleService(Context ctx) { public static void scheduleService(Context ctx) {

@ -1,15 +1,16 @@
package com.timsu.astrid.utilities; package com.timsu.astrid.utilities;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.timsu.astrid.R;
import java.text.SimpleDateFormat; import com.timsu.astrid.R;
import java.util.Date;
public class Preferences { public class Preferences {
@ -24,6 +25,7 @@ public class Preferences {
private static final String P_LOCALE_LAST_NOTIFY = "locnot"; private static final String P_LOCALE_LAST_NOTIFY = "locnot";
private static final String P_DID_ANDROID_AND_ME_SURVEY = "aamsurvey"; private static final String P_DID_ANDROID_AND_ME_SURVEY = "aamsurvey";
private static final String P_TASK_KILLER_HELP = "taskkiller"; private static final String P_TASK_KILLER_HELP = "taskkiller";
private static final String P_BACKUP_ERROR = "backupError";
// pref values // pref values
public static final int ICON_SET_PINK = 0; public static final int ICON_SET_PINK = 0;
@ -62,6 +64,9 @@ public class Preferences {
if (!prefs.contains(r.getString(R.string.p_backup))) { if (!prefs.contains(r.getString(R.string.p_backup))) {
editor.putBoolean(r.getString(R.string.p_backup), true); editor.putBoolean(r.getString(R.string.p_backup), true);
} }
if (!prefs.contains(P_BACKUP_ERROR)) {
editor.putString(P_BACKUP_ERROR, null);
}
setVisibilityPreferences(prefs, editor, r); setVisibilityPreferences(prefs, editor, r);
@ -281,11 +286,26 @@ public class Preferences {
} }
// --- backup preferences // --- backup preferences
public static boolean isBackupEnabled(Context context) { public static boolean isBackupEnabled(Context context) {
Resources r = context.getResources(); Resources r = context.getResources();
return getPrefs(context).getBoolean(r.getString(R.string.p_backup), true); return getPrefs(context).getBoolean(r.getString(R.string.p_backup), true);
} }
/**
* @return error when doing backup, empty string if successful, or null
* if no backup has been attempted
*/
public static String getBackupSummary(Context context) {
return getPrefs(context).getString(P_BACKUP_ERROR, null);
}
public static void setBackupSummary(Context context, String newValue) {
Editor editor = getPrefs(context).edit();
editor.putString(P_BACKUP_ERROR, newValue);
editor.commit();
}
// --- synchronization preferences // --- synchronization preferences
/** RTM authentication token, or null if doesn't exist */ /** RTM authentication token, or null if doesn't exist */

Loading…
Cancel
Save