Fixed up alarm service to read/write, and tried to make tags stick around afte rotate. but it works pretty poorly :|

pull/14/head
Tim Su 16 years ago
parent 8fee29ef55
commit 65da23a6bf

@ -26,11 +26,6 @@ import com.todoroo.astrid.model.Task;
*/ */
public final class AlarmControlSet implements TaskEditControlSet { public final class AlarmControlSet implements TaskEditControlSet {
// --- constants
/** Number of alarms a task can have */
static final int MAX_ALARMS = 10;
// --- instance variables // --- instance variables
private final LinearLayout alertsContainer; private final LinearLayout alertsContainer;
@ -51,14 +46,13 @@ public final class AlarmControlSet implements TaskEditControlSet {
@Override @Override
public void readFromTask(Task task) { public void readFromTask(Task task) {
if(alertsContainer.getChildCount() == 0) { alertsContainer.removeAllViews();
TodorooCursor<Metadata> cursor = AlarmService.getInstance().getAlarms(task.getId()); TodorooCursor<Metadata> cursor = AlarmService.getInstance().getAlarms(task.getId());
try { try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
addAlarm(new Date(cursor.get(Alarm.TIME))); addAlarm(new Date(cursor.get(Alarm.TIME)));
} finally { } finally {
cursor.close(); cursor.close();
}
} }
} }
@ -77,9 +71,6 @@ public final class AlarmControlSet implements TaskEditControlSet {
} }
private boolean addAlarm(Date alert) { 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); final View alertItem = LayoutInflater.from(activity).inflate(R.layout.alarm_edit_row, null);
alertsContainer.addView(alertItem); alertsContainer.addView(alertItem);

@ -17,7 +17,6 @@ import com.todoroo.astrid.service.MetadataService;
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
@SuppressWarnings("nls")
public class AlarmService { public class AlarmService {
// --- singleton // --- singleton

@ -174,6 +174,8 @@ public final class ReminderService {
scheduler.createAlarm(task, whenDueDate, TYPE_DUE); scheduler.createAlarm(task, whenDueDate, TYPE_DUE);
else if(whenOverdue != NO_ALARM) else if(whenOverdue != NO_ALARM)
scheduler.createAlarm(task, whenOverdue, TYPE_OVERDUE); scheduler.createAlarm(task, whenOverdue, TYPE_OVERDUE);
else
scheduler.createAlarm(task, 0, 0);
} }
/** /**
@ -286,14 +288,6 @@ public final class ReminderService {
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public void createAlarm(Task task, long time, int type) { 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(); Context context = ContextManager.getContext();
Intent intent = new Intent(context, Notifications.class); Intent intent = new Intent(context, Notifications.class);
intent.setType(Long.toString(task.getId())); intent.setType(Long.toString(task.getId()));
@ -305,9 +299,18 @@ public final class ReminderService {
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intent, 0); intent, 0);
Log.e("Astrid", "Alarm (" + task.getId() + ", " + type + if(time == 0 || time == NO_ALARM)
") set for " + new Date(time)); am.cancel(pendingIntent);
am.set(AlarmManager.RTC_WAKEUP, time, 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);
}
} }
} }

@ -3,10 +3,9 @@ package com.todoroo.astrid.tags;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import android.app.Activity; import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.ImageButton; import android.widget.ImageButton;
@ -29,11 +28,6 @@ import com.todoroo.astrid.tags.TagService.Tag;
*/ */
public final class TagsControlSet implements TaskEditControlSet { public final class TagsControlSet implements TaskEditControlSet {
// --- constants
/** Number of tags a task can have */
static final int MAX_TAGS = 5;
// --- instance variables // --- instance variables
private final TagService tagService = TagService.getInstance(); private final TagService tagService = TagService.getInstance();
@ -47,24 +41,29 @@ public final class TagsControlSet implements TaskEditControlSet {
this.tagsContainer = (LinearLayout) activity.findViewById(tagsContainer); this.tagsContainer = (LinearLayout) activity.findViewById(tagsContainer);
} }
@SuppressWarnings("nls")
@Override @Override
public void readFromTask(Task task) { public void readFromTask(Task task) {
// tags (only configure if not already set) System.err.println("TAGS loading... old size = " + tagsContainer.getChildCount());
if(tagsContainer.getChildCount() == 0) { tagsContainer.removeAllViews();
TodorooCursor<Metadata> cursor = tagService.getTags(task.getId());
try { TodorooCursor<Metadata> cursor = tagService.getTags(task.getId());
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) try {
addTag(cursor.get(TagService.TAG)); for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
} finally { addTag(cursor.get(TagService.TAG));
cursor.close(); } finally {
} cursor.close();
addTag("");
} }
if(tagsContainer.getChildCount() == 0)
addTag(""); //$NON-NLS-1$
System.err.println("TAGS loaded ");
} }
@Override @Override
public void writeToModel(Task task) { 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<String> tags = new LinkedHashSet<String>(); LinkedHashSet<String> tags = new LinkedHashSet<String>();
for(int i = 0; i < tagsContainer.getChildCount(); i++) { for(int i = 0; i < tagsContainer.getChildCount(); i++) {
@ -75,14 +74,12 @@ public final class TagsControlSet implements TaskEditControlSet {
} }
tagService.synchronizeTags(task.getId(), tags); tagService.synchronizeTags(task.getId(), tags);
System.err.println("TAGS saved " + tags);
} }
/** Adds a tag to the tag field */ /** Adds a tag to the tag field */
boolean addTag(String tagName) { boolean addTag(String tagName) {
if (tagsContainer.getChildCount() >= MAX_TAGS) { System.err.println("TAG ADDING ui " + tagName);
return false;
}
LayoutInflater inflater = activity.getLayoutInflater(); LayoutInflater inflater = activity.getLayoutInflater();
final View tagItem = inflater.inflate(R.layout.tag_edit_row, null); final View tagItem = inflater.inflate(R.layout.tag_edit_row, null);
tagsContainer.addView(tagItem); tagsContainer.addView(tagItem);
@ -94,33 +91,40 @@ public final class TagsControlSet implements TaskEditControlSet {
new ArrayAdapter<Tag>(activity, new ArrayAdapter<Tag>(activity,
android.R.layout.simple_dropdown_item_1line, allTags); android.R.layout.simple_dropdown_item_1line, allTags);
textView.setAdapter(tagsAdapter); 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$
}
} }
});
/*textView.setOnEditorActionListener(new OnEditorActionListener() {
public void beforeTextChanged(CharSequence s, int start, int count, @Override
int after) { 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; ImageButton reminderRemoveButton;
reminderRemoveButton = (ImageButton)tagItem.findViewById(R.id.button1); reminderRemoveButton = (ImageButton)tagItem.findViewById(R.id.button1);
reminderRemoveButton.setOnClickListener(new View.OnClickListener() { reminderRemoveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
if(textView.getText().length() > 0) if(tagsContainer.getChildCount() > 0)
tagsContainer.removeView(tagItem); tagsContainer.removeView(tagItem);
else
textView.setText(""); //$NON-NLS-1$
} }
}); });

Loading…
Cancel
Save