mirror of https://github.com/tasks/tasks
Moved filter by tag to the tag plugin, created an api for task context menu actions
parent
0b753d3532
commit
8d8db3e1d8
@ -0,0 +1,59 @@
|
||||
package com.todoroo.astrid.reminders;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.astrid.api.TaskContextActionExposer;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.reminders.ReminderService.AlarmScheduler;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class ReminderDebugContextActions {
|
||||
|
||||
public static class WhenReminder implements TaskContextActionExposer {
|
||||
|
||||
@Override
|
||||
public Object getLabel(Task task) {
|
||||
if (Constants.DEBUG)
|
||||
return "when alarm?";
|
||||
return null;
|
||||
}
|
||||
|
||||
public void invoke(Task task) {
|
||||
AlarmScheduler original = ReminderService.getInstance().getScheduler();
|
||||
ReminderService.getInstance().setScheduler(new AlarmScheduler() {
|
||||
@Override
|
||||
public void createAlarm(Task theTask, long time, int type) {
|
||||
if(time == 0 || time == Long.MAX_VALUE)
|
||||
return;
|
||||
|
||||
Toast.makeText(ContextManager.getContext(), "Scheduled Alarm: " +
|
||||
new Date(time), Toast.LENGTH_LONG).show();
|
||||
ReminderService.getInstance().setScheduler(null);
|
||||
}
|
||||
});
|
||||
ReminderService.getInstance().scheduleAlarm(task);
|
||||
if(ReminderService.getInstance().getScheduler() != null)
|
||||
Toast.makeText(ContextManager.getContext(), "No alarms", Toast.LENGTH_LONG).show();
|
||||
ReminderService.getInstance().setScheduler(original);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MakeNotification implements TaskContextActionExposer {
|
||||
|
||||
public Object getLabel(Task task) {
|
||||
if (Constants.DEBUG)
|
||||
return "when alarm?"; //$NON-NLS-1$
|
||||
return null;
|
||||
}
|
||||
|
||||
public void invoke(Task task) {
|
||||
new Notifications().showTaskNotification(task.getId(),
|
||||
ReminderService.TYPE_SNOOZE, "test reminder");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.todoroo.astrid.tags;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ContentValues;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.data.TodorooCursor;
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.andlib.sql.Criterion;
|
||||
import com.todoroo.andlib.sql.QueryTemplate;
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.astrid.activity.TaskListActivity;
|
||||
import com.todoroo.astrid.api.Filter;
|
||||
import com.todoroo.astrid.api.TaskContextActionExposer;
|
||||
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
||||
import com.todoroo.astrid.data.Metadata;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.tags.TagService.Tag;
|
||||
|
||||
public class FilterByTagContextAction implements TaskContextActionExposer {
|
||||
|
||||
@Override
|
||||
public Object getLabel(Task task) {
|
||||
TodorooCursor<Metadata> cursor = TagService.getInstance().getTags(task.getId());
|
||||
try {
|
||||
if(cursor.getCount() > 0)
|
||||
return R.string.TAd_contextFilterByTag;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void invoke(Task task) {
|
||||
final TodorooCursor<Metadata> cursor = TagService.getInstance().getTags(
|
||||
task.getId());
|
||||
final List<String> tags;
|
||||
try {
|
||||
if (!cursor.moveToFirst())
|
||||
return;
|
||||
tags = new ArrayList<String>();
|
||||
do {
|
||||
tags.add(cursor.get(TagService.TAG));
|
||||
} while (cursor.moveToNext());
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
Collator collator = Collator.getInstance();
|
||||
collator.setStrength(Collator.PRIMARY);
|
||||
Collections.sort(tags, collator);
|
||||
|
||||
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Tag tag = new Tag(tags.get(which), 0);
|
||||
|
||||
String listTitle = tag.tag;
|
||||
String title = ContextManager.getString(
|
||||
R.string.tag_FEx_name, tag.tag);
|
||||
Criterion criterion = TaskCriteria.activeAndVisible();
|
||||
QueryTemplate tagTemplate = tag.queryTemplate(criterion);
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(Metadata.KEY.name, TagService.KEY);
|
||||
contentValues.put(TagService.TAG.name, tag.tag);
|
||||
|
||||
Filter tagFilter = new Filter(listTitle, title,
|
||||
tagTemplate, contentValues);
|
||||
Intent tagIntent = new Intent(ContextManager.getContext(),
|
||||
TaskListActivity.class);
|
||||
tagIntent.putExtra(TaskListActivity.TOKEN_FILTER, tagFilter);
|
||||
|
||||
ContextManager.getContext().startActivity(tagIntent);
|
||||
AndroidUtilities.callApiMethod(5,
|
||||
this,
|
||||
"overridePendingTransition", //$NON-NLS-1$
|
||||
new Class<?>[] { Integer.TYPE, Integer.TYPE },
|
||||
R.anim.slide_left_in, R.anim.slide_left_out);
|
||||
}
|
||||
};
|
||||
|
||||
if (tags.size() == 1) {
|
||||
listener.onClick(null, 0);
|
||||
} else {
|
||||
new AlertDialog.Builder(ContextManager.getContext()).setTitle(
|
||||
R.string.TAd_contextFilterByTag).setAdapter(
|
||||
new ArrayAdapter<String>(ContextManager.getContext(),
|
||||
android.R.layout.select_dialog_item, tags),
|
||||
listener).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.todoroo.astrid.api;
|
||||
|
||||
import com.todoroo.astrid.data.Task;
|
||||
|
||||
|
||||
/**
|
||||
* API for exposing context menu items associated with a task.
|
||||
*
|
||||
* Due to the limitations of the Android platform, this is currently
|
||||
* internal-use only, though if it can be done well, I would be open to creating
|
||||
* an external API. Internal API for exposing task decorations
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public interface TaskContextActionExposer {
|
||||
|
||||
public class TaskContextAction{
|
||||
public int labelResource;
|
||||
public Runnable action;
|
||||
|
||||
public TaskContextAction(int labelResource, Runnable action) {
|
||||
super();
|
||||
this.labelResource = labelResource;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose context menu item label, or null if item should not be shown
|
||||
* @param task
|
||||
*
|
||||
* @return null if no item should be displayed, or string or id
|
||||
*/
|
||||
public Object getLabel(Task task);
|
||||
|
||||
/**
|
||||
* Call context menu action
|
||||
* @param task
|
||||
*/
|
||||
public void invoke(Task task);
|
||||
|
||||
}
|
Loading…
Reference in New Issue