diff --git a/src/com/timsu/astrid/activities/TaskListAdapter.java b/src/com/timsu/astrid/activities/TaskListAdapter.java index f02b81f48..ba2f137e6 100644 --- a/src/com/timsu/astrid/activities/TaskListAdapter.java +++ b/src/com/timsu/astrid/activities/TaskListAdapter.java @@ -30,6 +30,7 @@ import android.content.DialogInterface; import android.content.res.Resources; import android.graphics.Paint; import android.graphics.Typeface; +import android.util.Log; import android.view.ContextMenu; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -151,16 +152,20 @@ public class TaskListAdapter extends ArrayAdapter { /** Toggle the expanded state of this task */ public void toggleExpanded(View view, TaskModelForList task) { - if(CACHE_TRUE.equals(task.getCachedLabel(KEY_EXPANDED))) { - task.putCachedLabel(KEY_EXPANDED, null); - hooks.setSelectedItem(null); - } else { - task.putCachedLabel(KEY_EXPANDED, CACHE_TRUE); - hooks.setSelectedItem(task.getTaskIdentifier()); - } + try { + if(CACHE_TRUE.equals(task.getCachedLabel(KEY_EXPANDED))) { + task.putCachedLabel(KEY_EXPANDED, null); + hooks.setSelectedItem(null); + } else { + task.putCachedLabel(KEY_EXPANDED, CACHE_TRUE); + hooks.setSelectedItem(task.getTaskIdentifier()); + } - setFieldContentsAndVisibility(view, task); - ((ListView)view.getParent()).setSelection(objects.indexOf(task)); + setFieldContentsAndVisibility(view, task); + ((ListView)view.getParent()).setSelection(objects.indexOf(task)); + } catch (Exception e) { + Log.e("astrid", "Error in toggleExpanded", e); + } } // ---------------------------------------------------------------------- @@ -514,7 +519,7 @@ public class TaskListAdapter extends ArrayAdapter { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - View parent = (View)buttonView.getParent(); + View parent = (View)buttonView.getParent().getParent(); TaskModelForList task = (TaskModelForList)parent.getTag(); int newProgressPercentage; diff --git a/src/com/timsu/astrid/data/task/TaskController.java b/src/com/timsu/astrid/data/task/TaskController.java index 096d4a351..119a873ed 100644 --- a/src/com/timsu/astrid/data/task/TaskController.java +++ b/src/com/timsu/astrid/data/task/TaskController.java @@ -34,6 +34,7 @@ import android.database.sqlite.SQLiteOpenHelper; import com.timsu.astrid.data.AbstractController; import com.timsu.astrid.data.sync.SyncDataController; +import com.timsu.astrid.data.task.AbstractTaskModel.RepeatInfo; import com.timsu.astrid.data.task.AbstractTaskModel.TaskModelDatabaseHelper; import com.timsu.astrid.utilities.Notifications; @@ -239,7 +240,7 @@ public class TaskController extends AbstractController { /** * Called when the task is saved. Perform some processing on the task. - * + * * @param task * @param values */ @@ -250,21 +251,21 @@ public class TaskController extends AbstractController { == AbstractTaskModel.COMPLETE_PERCENTAGE) { onTaskSetCompleted(task, values); } - + // task timer was updated if(values.containsKey(AbstractTaskModel.TIMER_START)) { // show notification bar if timer was started if(values.get(AbstractTaskModel.TIMER_START) != null) { - Notifications.showTimingNotification(context, + Notifications.showTimingNotification(context, task.getTaskIdentifier(), task.getName()); } else { Notifications.clearAllNotifications(context, task.getTaskIdentifier()); } } } - - - /** + + + /** * Called when this task is set to completed. * * @param task task to process @@ -273,7 +274,14 @@ public class TaskController extends AbstractController { private void onTaskSetCompleted(AbstractTaskModel task, ContentValues values) { values.put(AbstractTaskModel.COMPLETION_DATE, System.currentTimeMillis()); - + // handle repeat + Cursor cursor = fetchTaskCursor(task.getTaskIdentifier(), + TaskModelForRepeat.FIELD_LIST); + TaskModelForRepeat repeatModel = new TaskModelForRepeat(cursor, values); + RepeatInfo repeatInfo = repeatModel.getRepeat(); + if(repeatInfo != null) + repeatModel.repeatTaskBy(context, this, repeatInfo); + cursor.close(); } /** Set last notification date */