diff --git a/src/com/timsu/astrid/activities/TagListSubActivity.java b/src/com/timsu/astrid/activities/TagListSubActivity.java index 9ff6a1937..61912dee2 100644 --- a/src/com/timsu/astrid/activities/TagListSubActivity.java +++ b/src/com/timsu/astrid/activities/TagListSubActivity.java @@ -30,6 +30,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.database.Cursor; +import android.database.StaleDataException; import android.os.Bundle; import android.os.Handler; import android.util.Log; @@ -121,7 +122,7 @@ public class TagListSubActivity extends SubActivity { abstract int compareTo(TagListSubActivity self, TagModelForView arg0, TagModelForView arg1); }; - private void sortTagArray() { + private synchronized void sortTagArray() { // get all tasks Cursor taskCursor = getTaskController().getActiveTaskListCursor(); startManagingCursor(taskCursor); @@ -161,10 +162,15 @@ public class TagListSubActivity extends SubActivity { // --- fill data /** Fill in the Tag List with our tags */ - private void fillData() { + private synchronized void fillData() { try { tagArray = getTagController().getAllTags(getParent()); sortTagArray(); + } catch (StaleDataException e) { + // happens when you rotate the screen while the thread is + // still running. i don't think it's avoidable? + Log.w("astrid", "StaleDataException", e); + return; } catch (Exception e) { Log.e("astrid", "Error loading list", e); } @@ -352,7 +358,7 @@ public class TagListSubActivity extends SubActivity { // --------------------------------------------------- tag list adapter - private class TagListAdapter extends ArrayAdapter { + class TagListAdapter extends ArrayAdapter { private List objects; private int resource; @@ -377,23 +383,30 @@ public class TagListSubActivity extends SubActivity { if(view == null) { view = inflater.inflate(resource, parent, false); } - setupView(view, objects.get(position)); + setupView(view, objects.get(position), false); return view; } - public void setupView(View view, final TagModelForView tag) { + public void setupView(View view, final TagModelForView tag, boolean retry) { Resources r = getResources(); view.setTag(tag); final TextView name = ((TextView)view.findViewById(android.R.id.text1)); - name.setText(new StringBuilder(tag.getName()). - append(" (").append(tagCount.get(tag)).append(")")); + try { + if(tagCount == null) + tagCount = tagToTaskCount; + + name.setText(new StringBuilder(tag.getName()). + append(" (").append(tagCount.get(tag)).append(")")); - if(tagCount.get(tag) == 0) - name.setTextColor(r.getColor(R.color.task_list_done)); - else - name.setTextColor(r.getColor(android.R.color.white)); + if(tagCount.get(tag) == 0) + name.setTextColor(r.getColor(R.color.task_list_done)); + else + name.setTextColor(r.getColor(android.R.color.white)); + } catch (Exception e) { + Log.e("astrid", "Error loading tag list", e); + } } } diff --git a/src/com/timsu/astrid/activities/TaskListAdapter.java b/src/com/timsu/astrid/activities/TaskListAdapter.java index 53fdf75da..fdbbfacbe 100644 --- a/src/com/timsu/astrid/activities/TaskListAdapter.java +++ b/src/com/timsu/astrid/activities/TaskListAdapter.java @@ -494,7 +494,7 @@ public class TaskListAdapter extends ArrayAdapter { String cachedResult = task.getCachedLabel(KEY_TAGS); if(cachedResult == null) { String tagString = hooks.getTagsFor(task); - if(!tagString.equals("")) + if(tagString != null && !tagString.equals("")) cachedResult = r.getString(R.string.taskList_tagsPrefix) + " " + tagString; else diff --git a/src/com/timsu/astrid/activities/TaskListSubActivity.java b/src/com/timsu/astrid/activities/TaskListSubActivity.java index 02f30bf47..406fa82b6 100644 --- a/src/com/timsu/astrid/activities/TaskListSubActivity.java +++ b/src/com/timsu/astrid/activities/TaskListSubActivity.java @@ -507,6 +507,16 @@ public class TaskListSubActivity extends SubActivity { // still running. i don't think it's avoidable? Log.w("astrid", "StaleDataException", e); return; + } catch (IllegalStateException e) { + // happens when you run out of memory usually + Log.e("astrid", "Error loading task list", e); + handler.post(new Runnable() { + @Override + public void run() { + DialogUtilities.okDialog(getParent(), "Ran out of memory! " + + "Try restarting Astrid...", null); + } + }); } catch (final Exception e) { Log.e("astrid", "Error loading task list", e); return; diff --git a/src/com/timsu/astrid/data/AbstractModel.java b/src/com/timsu/astrid/data/AbstractModel.java index cee1b2075..35a941a19 100644 --- a/src/com/timsu/astrid/data/AbstractModel.java +++ b/src/com/timsu/astrid/data/AbstractModel.java @@ -225,9 +225,14 @@ public abstract class AbstractModel { // --- retrieving composite objects protected Date retrieveDate(String field) { - Long time = retrieveLong(field); - if(time == null || time == 0) + Long time; + try { + time = retrieveLong(field); + if(time == null || time == 0) + return null; + } catch (NullPointerException e) { return null; + } return new Date(time); } diff --git a/src/com/timsu/astrid/sync/RTMSyncService.java b/src/com/timsu/astrid/sync/RTMSyncService.java index 0d1c8d160..5904589b2 100644 --- a/src/com/timsu/astrid/sync/RTMSyncService.java +++ b/src/com/timsu/astrid/sync/RTMSyncService.java @@ -448,7 +448,7 @@ public class RTMSyncService extends SynchronizationService { // --- helper classes /** SynchronizeHelper for remember the milk */ - private class RtmSyncHelper implements SynchronizeHelper { + class RtmSyncHelper implements SynchronizeHelper { private String timeline; private String lastCreatedTask = null; diff --git a/src/com/timsu/astrid/sync/SynchronizationService.java b/src/com/timsu/astrid/sync/SynchronizationService.java index 761190cf3..ef4367419 100644 --- a/src/com/timsu/astrid/sync/SynchronizationService.java +++ b/src/com/timsu/astrid/sync/SynchronizationService.java @@ -390,7 +390,7 @@ public abstract class SynchronizationService { // --- helper classes /** data structure builder */ - private class SyncData { + class SyncData { HashSet mappings; HashSet activeTasks; HashSet allTasks; diff --git a/src/com/timsu/astrid/utilities/Notifications.java b/src/com/timsu/astrid/utilities/Notifications.java index d52767b5c..8c19198df 100644 --- a/src/com/timsu/astrid/utilities/Notifications.java +++ b/src/com/timsu/astrid/utilities/Notifications.java @@ -82,7 +82,8 @@ public class Notifications extends BroadcastReceiver { reminder = getRandomReminder(r); long repeatInterval = intent.getLongExtra(REPEAT_KEY, 0); - Log.e("ALARM", "Alarm triggered id " + id +", flags " + flags + + if(Constants.DEBUG) + Log.e("ALARM", "Alarm triggered id " + id +", flags " + flags + ", repeat " + repeatInterval); if(!showNotification(context, id, flags, repeatInterval, reminder)) { @@ -292,7 +293,8 @@ public class Notifications extends BroadcastReceiver { PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, createAlarmIntent(context, id, flags), 0); - Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " + new Date(when)); + if(Constants.DEBUG) + Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " + new Date(when)); am.set(AlarmManager.RTC_WAKEUP, when, pendingIntent); } @@ -308,7 +310,8 @@ public class Notifications extends BroadcastReceiver { PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); - Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " + + if(Constants.DEBUG) + Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " + new Date(when) + " every " + interval/1000 + " s"); am.setRepeating(AlarmManager.RTC_WAKEUP, when, interval, pendingIntent); } @@ -456,7 +459,8 @@ public class Notifications extends BroadcastReceiver { } } - Log.w("Astrid", "Logging notification: " + reminder); + if(Constants.DEBUG) + Log.w("Astrid", "Logging notification: " + reminder); nm.notify((int)id, notification); return true; @@ -502,7 +506,8 @@ public class Notifications extends BroadcastReceiver { Notification.FLAG_NO_CLEAR; notification.flags &= ~Notification.FLAG_AUTO_CANCEL; - Log.w("Astrid", "Logging timing notification: " + text); + if(Constants.DEBUG) + Log.w("Astrid", "Logging timing notification: " + text); nm.notify((int)taskId.getId(), notification); return true; diff --git a/src/com/timsu/astrid/widget/NumberPicker.java b/src/com/timsu/astrid/widget/NumberPicker.java index 18bdd1aa2..3bd5add02 100644 --- a/src/com/timsu/astrid/widget/NumberPicker.java +++ b/src/com/timsu/astrid/widget/NumberPicker.java @@ -345,7 +345,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener, private NumberPickerButton mIncrementButton; private NumberPickerButton mDecrementButton; - private class NumberPickerInputFilter implements InputFilter { + class NumberPickerInputFilter implements InputFilter { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if (mDisplayedValues == null) { @@ -367,7 +367,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener, } } - private class NumberRangeKeyListener extends NumberKeyListener { + class NumberRangeKeyListener extends NumberKeyListener { @Override protected char[] getAcceptedChars() {