Added TaskAttachment data model

pull/14/head
Sam Bosley 13 years ago
parent 204cd8161a
commit 88d5e73d32

@ -0,0 +1,150 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.data;
import android.content.ContentValues;
import android.net.Uri;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.api.AstridApiConstants;
/**
* Data Model which represents a user.
*
* @author Tim Su <tim@todoroo.com>
*
*/
@SuppressWarnings("nls")
public final class TaskAttachment extends RemoteModel {
// --- table and uri
/** table for this model */
public static final Table TABLE = new Table("task_attachments", TaskAttachment.class);
/** content uri for this model */
public static final Uri CONTENT_URI = Uri.parse("content://" + AstridApiConstants.API_PACKAGE + "/" +
TABLE.name);
// --- properties
/** ID */
public static final LongProperty ID = new LongProperty(
TABLE, ID_PROPERTY_NAME);
/** Remote id */
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
/** Pushed at date */
public static final LongProperty PUSHED_AT = new LongProperty(
TABLE, PUSHED_AT_PROPERTY_NAME);
/** Creator user id */
public static final StringProperty USER_UUID = new StringProperty(
TABLE, "user_id");
/** Task uuid */
public static final StringProperty TASK_UUID = new StringProperty(
TABLE, "task_id");
/** File name */
public static final StringProperty NAME = new StringProperty(
TABLE, "name");
/** File url (for downloading) */
public static final StringProperty URL = new StringProperty(
TABLE, "url");
/** File path (on local storage) */
public static final StringProperty FILE_PATH = new StringProperty(
TABLE, "path");
/** File size (in bytes) */
public static final IntegerProperty SIZE = new IntegerProperty(
TABLE, "size");
/** File mimetype */
public static final StringProperty FILETYPE = new StringProperty(
TABLE, "filetype");
/** Attachment creation date */
public static final LongProperty CREATED_AT = new LongProperty(
TABLE, "created_at", Property.PROP_FLAG_DATE);
/** Attachment deletion date */
public static final LongProperty DELETED_AT = new LongProperty(
TABLE, "created_at", Property.PROP_FLAG_DATE);
/** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(TaskAttachment.class);
// --- defaults
/** Default values container */
private static final ContentValues defaultValues = new ContentValues();
static {
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(PUSHED_AT.name, 0);
defaultValues.put(USER_UUID.name, NO_UUID);
defaultValues.put(TASK_UUID.name, NO_UUID);
defaultValues.put(NAME.name, "");
defaultValues.put(URL.name, "");
defaultValues.put(FILE_PATH.name, "");
defaultValues.put(SIZE.name, 0);
defaultValues.put(FILETYPE.name, "");
defaultValues.put(CREATED_AT.name, 0);
defaultValues.put(DELETED_AT.name, 0);
}
@Override
public ContentValues getDefaultValues() {
return defaultValues;
}
// --- data access boilerplate
public TaskAttachment() {
super();
}
public TaskAttachment(TodorooCursor<TaskAttachment> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<TaskAttachment> cursor) {
super.readPropertiesFromCursor(cursor);
}
@Override
public long getId() {
return getIdHelper(ID);
}
@Override
public String getUuid() {
return getUuidHelper(UUID);
}
// --- parcelable helpers
public static final Creator<TaskAttachment> CREATOR = new ModelCreator<TaskAttachment>(TaskAttachment.class);
@Override
protected Creator<? extends AbstractModel> getCreator() {
return CREATOR;
}
}

@ -22,6 +22,7 @@ import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagMetadata;
import com.todoroo.astrid.data.TagOutstanding;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskAttachment;
import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.User;
@ -68,6 +69,7 @@ public class Database extends AbstractDatabase {
ABTestEvent.TABLE,
TagMetadata.TABLE,
History.TABLE,
TaskAttachment.TABLE,
TaskOutstanding.TABLE,
TagOutstanding.TABLE,
@ -342,6 +344,7 @@ public class Database extends AbstractDatabase {
database.execSQL(createTableSql(visitor, UserActivity.TABLE.name, UserActivity.PROPERTIES));
database.execSQL(createTableSql(visitor, UserActivityOutstanding.TABLE.name, UserActivityOutstanding.PROPERTIES));
database.execSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES));
database.execSQL(createTableSql(visitor, TaskAttachment.TABLE.name, TaskAttachment.PROPERTIES));
database.execSQL(addColumnSql(Task.TABLE, Task.PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(Task.TABLE, Task.IS_PUBLIC, visitor, "0"));

Loading…
Cancel
Save