From 65da23a6bf033787e5d26a194ebd8952527d369a Mon Sep 17 00:00:00 2001 From: Tim Su Date: Fri, 6 Aug 2010 18:48:17 -0700 Subject: [PATCH] Fixed up alarm service to read/write, and tried to make tags stick around afte rotate. but it works pretty poorly :| --- .../astrid/alarms/AlarmControlSet.java | 23 ++---- .../todoroo/astrid/alarms/AlarmService.java | 1 - .../astrid/reminders/ReminderService.java | 25 +++--- .../todoroo/astrid/tags/TagsControlSet.java | 82 ++++++++++--------- 4 files changed, 64 insertions(+), 67 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmControlSet.java b/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmControlSet.java index b9c54eb82..f03ed0aac 100644 --- a/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmControlSet.java @@ -26,11 +26,6 @@ import com.todoroo.astrid.model.Task; */ public final class AlarmControlSet implements TaskEditControlSet { - // --- constants - - /** Number of alarms a task can have */ - static final int MAX_ALARMS = 10; - // --- instance variables private final LinearLayout alertsContainer; @@ -51,14 +46,13 @@ public final class AlarmControlSet implements TaskEditControlSet { @Override public void readFromTask(Task task) { - if(alertsContainer.getChildCount() == 0) { - TodorooCursor cursor = AlarmService.getInstance().getAlarms(task.getId()); - try { - for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) - addAlarm(new Date(cursor.get(Alarm.TIME))); - } finally { - cursor.close(); - } + alertsContainer.removeAllViews(); + TodorooCursor cursor = AlarmService.getInstance().getAlarms(task.getId()); + try { + for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) + addAlarm(new Date(cursor.get(Alarm.TIME))); + } finally { + cursor.close(); } } @@ -77,9 +71,6 @@ public final class AlarmControlSet implements TaskEditControlSet { } private boolean addAlarm(Date alert) { - if(alertsContainer.getChildCount() >= MAX_ALARMS) - return false; - final View alertItem = LayoutInflater.from(activity).inflate(R.layout.alarm_edit_row, null); alertsContainer.addView(alertItem); diff --git a/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java b/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java index 6ae73b15e..abe6d3f69 100644 --- a/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java +++ b/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java @@ -17,7 +17,6 @@ import com.todoroo.astrid.service.MetadataService; * @author Tim Su * */ -@SuppressWarnings("nls") public class AlarmService { // --- singleton diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java index 4625bd814..3fe029a8a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java @@ -174,6 +174,8 @@ public final class ReminderService { scheduler.createAlarm(task, whenDueDate, TYPE_DUE); else if(whenOverdue != NO_ALARM) scheduler.createAlarm(task, whenOverdue, TYPE_OVERDUE); + else + scheduler.createAlarm(task, 0, 0); } /** @@ -286,14 +288,6 @@ public final class ReminderService { */ @SuppressWarnings("nls") public void createAlarm(Task task, long time, int type) { - if(time == 0 || time == NO_ALARM) - return; - - if(time < DateUtilities.now()) { - time = DateUtilities.now() + (long)((0.5f + - 4 * random.nextFloat()) * DateUtilities.ONE_HOUR); - } - Context context = ContextManager.getContext(); Intent intent = new Intent(context, Notifications.class); intent.setType(Long.toString(task.getId())); @@ -305,9 +299,18 @@ public final class ReminderService { PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); - Log.e("Astrid", "Alarm (" + task.getId() + ", " + type + - ") set for " + new Date(time)); - am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent); + if(time == 0 || time == NO_ALARM) + am.cancel(pendingIntent); + else { + if(time < DateUtilities.now()) { + time = DateUtilities.now() + (long)((0.5f + + 4 * random.nextFloat()) * DateUtilities.ONE_HOUR); + } + + Log.e("Astrid", "Alarm (" + task.getId() + ", " + type + + ") set for " + new Date(time)); + am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent); + } } } diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java index 469b6c03d..da7a11926 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java @@ -3,10 +3,9 @@ package com.todoroo.astrid.tags; import java.util.LinkedHashSet; import android.app.Activity; -import android.text.Editable; -import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.ImageButton; @@ -29,11 +28,6 @@ import com.todoroo.astrid.tags.TagService.Tag; */ public final class TagsControlSet implements TaskEditControlSet { - // --- constants - - /** Number of tags a task can have */ - static final int MAX_TAGS = 5; - // --- instance variables private final TagService tagService = TagService.getInstance(); @@ -47,24 +41,29 @@ public final class TagsControlSet implements TaskEditControlSet { this.tagsContainer = (LinearLayout) activity.findViewById(tagsContainer); } - @SuppressWarnings("nls") @Override public void readFromTask(Task task) { - // tags (only configure if not already set) - if(tagsContainer.getChildCount() == 0) { - TodorooCursor cursor = tagService.getTags(task.getId()); - try { - for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) - addTag(cursor.get(TagService.TAG)); - } finally { - cursor.close(); - } - addTag(""); + System.err.println("TAGS loading... old size = " + tagsContainer.getChildCount()); + tagsContainer.removeAllViews(); + + TodorooCursor cursor = tagService.getTags(task.getId()); + try { + for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) + addTag(cursor.get(TagService.TAG)); + } finally { + cursor.close(); } + if(tagsContainer.getChildCount() == 0) + addTag(""); //$NON-NLS-1$ + System.err.println("TAGS loaded "); } @Override public void writeToModel(Task task) { + // this is a case where we're asked to save but the UI was not yet populated + if(tagsContainer.getChildCount() == 0) + return; + LinkedHashSet tags = new LinkedHashSet(); for(int i = 0; i < tagsContainer.getChildCount(); i++) { @@ -75,14 +74,12 @@ public final class TagsControlSet implements TaskEditControlSet { } tagService.synchronizeTags(task.getId(), tags); + System.err.println("TAGS saved " + tags); } /** Adds a tag to the tag field */ boolean addTag(String tagName) { - if (tagsContainer.getChildCount() >= MAX_TAGS) { - return false; - } - + System.err.println("TAG ADDING ui " + tagName); LayoutInflater inflater = activity.getLayoutInflater(); final View tagItem = inflater.inflate(R.layout.tag_edit_row, null); tagsContainer.addView(tagItem); @@ -94,33 +91,40 @@ public final class TagsControlSet implements TaskEditControlSet { new ArrayAdapter(activity, android.R.layout.simple_dropdown_item_1line, allTags); textView.setAdapter(tagsAdapter); - textView.addTextChangedListener(new TextWatcher() { - @SuppressWarnings("nls") - public void onTextChanged(CharSequence s, int start, int before, - int count) { - if(start == 0 && tagsContainer.getChildAt( - tagsContainer.getChildCount()-1) == tagItem) { - addTag(""); - } - } - public void afterTextChanged(Editable s) { - // + textView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + View lastItem = tagsContainer.getChildAt(tagsContainer.getChildCount()-1); + TextView lastText = (TextView) lastItem.findViewById(R.id.text1); + if(lastText.getText().length() != 0) { + addTag(""); //$NON-NLS-1$ + } } + }); - - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - // + /*textView.setOnEditorActionListener(new OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView arg0, int actionId, KeyEvent arg2) { + if(actionId != EditorInfo.IME_NULL) + return false; + View lastItem = tagsContainer.getChildAt(tagsContainer.getChildCount()-1); + TextView lastText = (TextView) lastItem.findViewById(R.id.text1); + if(lastText.getText().length() != 0) { + addTag(""); //$NON-NLS-1$ + } + return true; } - }); + });*/ ImageButton reminderRemoveButton; reminderRemoveButton = (ImageButton)tagItem.findViewById(R.id.button1); reminderRemoveButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - if(textView.getText().length() > 0) + if(tagsContainer.getChildCount() > 0) tagsContainer.removeView(tagItem); + else + textView.setText(""); //$NON-NLS-1$ } });