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 {
// --- 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<Metadata> 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<Metadata> 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);

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

@ -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);
}
}
}

@ -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<Metadata> 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<Metadata> 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<String> tags = new LinkedHashSet<String>();
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<Tag>(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$
}
});

Loading…
Cancel
Save