File attachments quick action

pull/14/head
Sam Bosley 13 years ago
parent 5e6209fee9
commit 8bb5f2d405

@ -26,6 +26,8 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.api.TaskAction; import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration; import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.files.FileMetadata;
import com.todoroo.astrid.files.FilesAction;
import com.todoroo.astrid.notes.NotesAction; import com.todoroo.astrid.notes.NotesAction;
/** /**
@ -51,7 +53,9 @@ public class LinkActionExposer {
Linkify.addLinks(titleSpan, Linkify.ALL); Linkify.addLinks(titleSpan, Linkify.ALL);
URLSpan[] urlSpans = titleSpan.getSpans(0, titleSpan.length(), URLSpan.class); URLSpan[] urlSpans = titleSpan.getSpans(0, titleSpan.length(), URLSpan.class);
if(urlSpans.length == 0 && TextUtils.isEmpty(notes)) boolean hasAttachments = false;
if(urlSpans.length == 0 && TextUtils.isEmpty(notes) &&
!(hasAttachments = FileMetadata.taskHasAttachments(taskId)))
return result; return result;
pm = context.getPackageManager(); pm = context.getPackageManager();
@ -66,8 +70,14 @@ public class LinkActionExposer {
result.add(taskAction); result.add(taskAction);
} }
Resources r = context.getResources();
if (hasAttachments) {
Bitmap icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_attachments)).getBitmap();
FilesAction filesAction = new FilesAction("", null, icon); //$NON-NLS-1$
result.add(filesAction);
}
if (!TextUtils.isEmpty(notes) && !Preferences.getBoolean(R.string.p_showNotes, false)) { if (!TextUtils.isEmpty(notes) && !Preferences.getBoolean(R.string.p_showNotes, false)) {
Resources r = context.getResources();
Bitmap icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_notes)).getBitmap(); Bitmap icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_notes)).getBitmap();
NotesAction notesAction = new NotesAction("", null, icon); //$NON-NLS-1$ NotesAction notesAction = new NotesAction("", null, icon); //$NON-NLS-1$
result.add(notesAction); result.add(notesAction);

@ -3,6 +3,7 @@ package com.todoroo.astrid.files;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
public class FileMetadata { public class FileMetadata {
@ -51,4 +52,8 @@ public class FileMetadata {
return metadata; return metadata;
} }
public static boolean taskHasAttachments(long taskId) {
return PluginServices.getMetadataByTaskAndWithKey(taskId, METADATA_KEY) != null;
}
} }

@ -0,0 +1,40 @@
package com.todoroo.astrid.files;
import android.app.PendingIntent;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import com.todoroo.astrid.api.TaskAction;
public class FilesAction extends TaskAction {
public FilesAction(String text, PendingIntent intent, Bitmap icon) {
super(text, intent, icon);
}
/**
* Parcelable creator
*/
@SuppressWarnings("hiding")
public static final Parcelable.Creator<FilesAction> CREATOR = new Parcelable.Creator<FilesAction>() {
/**
* {@inheritDoc}
*/
public FilesAction createFromParcel(Parcel source) {
FilesAction action = new FilesAction(source.readString(),
(PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()),
(Bitmap)source.readParcelable(Bitmap.class.getClassLoader()));
action.drawable = source.readInt();
return action;
}
/**
* {@inheritDoc}
*/
public FilesAction[] newArray(int size) {
return new FilesAction[size];
};
};
}

@ -16,6 +16,7 @@ public class NotesAction extends TaskAction {
/** /**
* Parcelable creator * Parcelable creator
*/ */
@SuppressWarnings("hiding")
public static final Parcelable.Creator<NotesAction> CREATOR = new Parcelable.Creator<NotesAction>() { public static final Parcelable.Creator<NotesAction> CREATOR = new Parcelable.Creator<NotesAction>() {
/** /**
* {@inheritDoc} * {@inheritDoc}

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

@ -67,6 +67,8 @@ import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.api.TaskDecorationExposer; import com.todoroo.astrid.api.TaskDecorationExposer;
import com.todoroo.astrid.core.LinkActionExposer; import com.todoroo.astrid.core.LinkActionExposer;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.files.FilesAction;
import com.todoroo.astrid.files.FilesControlSet;
import com.todoroo.astrid.helper.AsyncImageView; import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.TaskAdapterAddOnManager; import com.todoroo.astrid.helper.TaskAdapterAddOnManager;
import com.todoroo.astrid.notes.NotesAction; import com.todoroo.astrid.notes.NotesAction;
@ -592,6 +594,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
TaskAction action = (TaskAction) viewHolder.taskActionIcon.getTag(); TaskAction action = (TaskAction) viewHolder.taskActionIcon.getTag();
if (action instanceof NotesAction) { if (action instanceof NotesAction) {
showEditNotesDialog(viewHolder.task); showEditNotesDialog(viewHolder.task);
} else if (action instanceof FilesAction) {
showFilesDialog(viewHolder.task);
} else if (action != null) { } else if (action != null) {
try { try {
action.intent.send(); action.intent.send();
@ -634,6 +638,13 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
dialog.show(); dialog.show();
} }
private void showFilesDialog(Task task) {
FilesControlSet filesControlSet = new FilesControlSet(fragment.getActivity(), R.layout.control_set_files,
R.layout.control_set_files_display, R.string.TEA_control_files);
filesControlSet.readFromTask(task);
filesControlSet.getDisplayView().performClick();
}
/* ====================================================================== /* ======================================================================
* ============================================================== details * ============================================================== details
* ====================================================================== */ * ====================================================================== */

Loading…
Cancel
Save