mirror of https://github.com/tasks/tasks
Convert TagDataDao to Room
parent
c2255296d7
commit
5bee730f1c
@ -0,0 +1,110 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 40,
|
||||
"identityHash": "522b606947ecd5beebfb95d548aef0c4",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "notification",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `type` INTEGER NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "uid",
|
||||
"columnName": "uid",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "taskId",
|
||||
"columnName": "task",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"uid"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_notification_task",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"task"
|
||||
],
|
||||
"createSql": "CREATE UNIQUE INDEX `index_notification_task` ON `${TABLE_NAME}` (`task`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "tagdata",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `name` TEXT, `color` INTEGER, `tagOrdering` TEXT, `deleted` INTEGER)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "_id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "remoteId",
|
||||
"columnName": "remoteId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "tagOrdering",
|
||||
"columnName": "tagOrdering",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "deleted",
|
||||
"columnName": "deleted",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"_id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"522b606947ecd5beebfb95d548aef0c4\")"
|
||||
]
|
||||
}
|
||||
}
|
@ -1,121 +1,180 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.data;
|
||||
|
||||
import android.arch.persistence.room.ColumnInfo;
|
||||
import android.arch.persistence.room.Entity;
|
||||
import android.arch.persistence.room.Ignore;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import org.tasks.backup.XmlReader;
|
||||
import org.tasks.backup.XmlWriter;
|
||||
|
||||
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;
|
||||
@Entity(tableName = "tagdata")
|
||||
public final class TagData implements Parcelable {
|
||||
|
||||
/**
|
||||
* Data Model which represents a collaboration space for users / tasks.
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public final class TagData extends RemoteModel {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "_id")
|
||||
private Long id;
|
||||
|
||||
// --- table and uri
|
||||
@ColumnInfo(name = "remoteId")
|
||||
private String remoteId = RemoteModel.NO_UUID;
|
||||
|
||||
/** table for this model */
|
||||
public static final Table TABLE = new Table("tagdata", TagData.class);
|
||||
@ColumnInfo(name = "name")
|
||||
private String name = "";
|
||||
|
||||
// --- properties
|
||||
@ColumnInfo(name = "color")
|
||||
private Integer color = -1;
|
||||
|
||||
/** ID */
|
||||
public static final LongProperty ID = new LongProperty(
|
||||
TABLE, ID_PROPERTY_NAME);
|
||||
@ColumnInfo(name = "tagOrdering")
|
||||
private String tagOrdering = "[]";
|
||||
|
||||
/** Remote goal id */
|
||||
public static final StringProperty UUID = new StringProperty(
|
||||
TABLE, UUID_PROPERTY_NAME);
|
||||
@Deprecated
|
||||
@ColumnInfo(name = "deleted")
|
||||
private Long deleted = 0L;
|
||||
|
||||
/** Name of Tag */
|
||||
public static final StringProperty NAME = new StringProperty(
|
||||
TABLE, "name");
|
||||
public TagData() {
|
||||
}
|
||||
|
||||
public static final IntegerProperty COLOR = new IntegerProperty(
|
||||
TABLE, "color");
|
||||
@Ignore
|
||||
public TagData(XmlReader reader) {
|
||||
reader.readString("remoteId", this::setRemoteId);
|
||||
reader.readString("name", this::setName);
|
||||
reader.readInteger("color", this::setColor);
|
||||
reader.readString("tagOrdering", this::setTagOrdering);
|
||||
reader.readLong("deleted", this::setDeleted);
|
||||
}
|
||||
|
||||
/** Unixtime Project was deleted. 0 means not deleted */
|
||||
@Deprecated
|
||||
public static final LongProperty DELETION_DATE = new LongProperty(
|
||||
TABLE, "deleted", Property.PROP_FLAG_DATE);
|
||||
@Ignore
|
||||
private TagData(Parcel parcel) {
|
||||
id = parcel.readLong();
|
||||
remoteId = parcel.readString();
|
||||
name = parcel.readString();
|
||||
color = parcel.readInt();
|
||||
tagOrdering = parcel.readString();
|
||||
deleted = parcel.readLong();
|
||||
}
|
||||
|
||||
/** Tag ordering */
|
||||
@Deprecated
|
||||
public static final StringProperty TAG_ORDERING = new StringProperty(
|
||||
TABLE, "tagOrdering");
|
||||
public void writeToXml(XmlWriter writer) {
|
||||
writer.writeString("remoteId", remoteId);
|
||||
writer.writeString("name", name);
|
||||
writer.writeInteger("color", color);
|
||||
writer.writeString("tagOrdering", tagOrdering);
|
||||
writer.writeLong("deleted", deleted);
|
||||
}
|
||||
|
||||
/** List of all properties for this model */
|
||||
public static final Property<?>[] PROPERTIES = generateProperties(TagData.class);
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
// --- defaults
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/** Default values container */
|
||||
private static final ContentValues defaultValues = new ContentValues();
|
||||
public String getRemoteId() {
|
||||
return remoteId;
|
||||
}
|
||||
|
||||
static {
|
||||
defaultValues.put(UUID.name, NO_UUID);
|
||||
defaultValues.put(NAME.name, "");
|
||||
defaultValues.put(DELETION_DATE.name, 0);
|
||||
defaultValues.put(TAG_ORDERING.name, "[]");
|
||||
defaultValues.put(COLOR.name, -1);
|
||||
public void setRemoteId(String remoteId) {
|
||||
this.remoteId = remoteId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentValues getDefaultValues() {
|
||||
return defaultValues;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return getIdHelper(ID);
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return getUuidHelper(UUID);
|
||||
public String getTagOrdering() {
|
||||
return tagOrdering;
|
||||
}
|
||||
|
||||
// --- parcelable helpers
|
||||
public void setTagOrdering(String tagOrdering) {
|
||||
this.tagOrdering = tagOrdering;
|
||||
}
|
||||
|
||||
public static final Creator<TagData> CREATOR = new ModelCreator<>(TagData.class);
|
||||
public Integer getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
// --- data access methods
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return getValue(NAME);
|
||||
public Long getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
setValue(NAME, name);
|
||||
public void setDeleted(long deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
public String getTagOrdering() {
|
||||
return getValue(TAG_ORDERING);
|
||||
public static final Creator<TagData> CREATOR = new Creator<TagData>() {
|
||||
@Override
|
||||
public TagData createFromParcel(Parcel source) {
|
||||
return new TagData(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagData[] newArray(int size) {
|
||||
return new TagData[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
setValue(COLOR, color);
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(id);
|
||||
dest.writeString(remoteId);
|
||||
dest.writeString(name);
|
||||
dest.writeInt(color);
|
||||
dest.writeString(tagOrdering);
|
||||
dest.writeLong(deleted);
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return getValue(COLOR);
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TagData tagData = (TagData) o;
|
||||
|
||||
if (id != null ? !id.equals(tagData.id) : tagData.id != null) return false;
|
||||
if (remoteId != null ? !remoteId.equals(tagData.remoteId) : tagData.remoteId != null)
|
||||
return false;
|
||||
if (name != null ? !name.equals(tagData.name) : tagData.name != null) return false;
|
||||
if (color != null ? !color.equals(tagData.color) : tagData.color != null) return false;
|
||||
if (tagOrdering != null ? !tagOrdering.equals(tagData.tagOrdering) : tagData.tagOrdering != null)
|
||||
return false;
|
||||
return deleted != null ? deleted.equals(tagData.deleted) : tagData.deleted == null;
|
||||
}
|
||||
|
||||
// TODO: remove?
|
||||
public String getUUID() {
|
||||
return getValue(UUID);
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id != null ? id.hashCode() : 0;
|
||||
result = 31 * result + (remoteId != null ? remoteId.hashCode() : 0);
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (color != null ? color.hashCode() : 0);
|
||||
result = 31 * result + (tagOrdering != null ? tagOrdering.hashCode() : 0);
|
||||
result = 31 * result + (deleted != null ? deleted.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setUUID(String uuid) {
|
||||
setValue(UUID, uuid);
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TagData{" +
|
||||
"id=" + id +
|
||||
", remoteId='" + remoteId + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", color=" + color +
|
||||
", tagOrdering='" + tagOrdering + '\'' +
|
||||
", deleted=" + deleted +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package org.tasks.backup;
|
||||
|
||||
import com.todoroo.astrid.backup.TasksXmlExporter;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class XmlReader {
|
||||
|
||||
public interface ValueWriter<T> {
|
||||
void write(T value);
|
||||
}
|
||||
|
||||
private final XmlPullParser xpp;
|
||||
|
||||
public XmlReader(XmlPullParser xpp) {
|
||||
this.xpp = xpp;
|
||||
}
|
||||
|
||||
public void readLong(String name, ValueWriter<Long> writer) {
|
||||
String value = xpp.getAttributeValue(null, name);
|
||||
if(value != null) {
|
||||
writer.write(TasksXmlExporter.XML_NULL.equals(value) ?
|
||||
null : Long.parseLong(value));
|
||||
}
|
||||
}
|
||||
|
||||
public void readInteger(String name, ValueWriter<Integer> writer) {
|
||||
String value = xpp.getAttributeValue(null, name);
|
||||
if(value != null) {
|
||||
writer.write(TasksXmlExporter.XML_NULL.equals(value) ?
|
||||
null : Integer.parseInt(value));
|
||||
}
|
||||
}
|
||||
|
||||
public void readString(String name, ValueWriter<String> writer) {
|
||||
String value = xpp.getAttributeValue(null, name);
|
||||
if (value != null) {
|
||||
writer.write(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package org.tasks.backup;
|
||||
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.todoroo.astrid.backup.TasksXmlExporter.XML_NULL;
|
||||
|
||||
public class XmlWriter {
|
||||
private final XmlSerializer xml;
|
||||
|
||||
public XmlWriter(XmlSerializer xml) {
|
||||
this.xml = xml;
|
||||
}
|
||||
|
||||
public void writeLong(String name, Long value) {
|
||||
try {
|
||||
String valueString = (value == null) ? XML_NULL : value.toString();
|
||||
xml.attribute(null, name, valueString);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// didn't read this value, do nothing
|
||||
Timber.e(e, e.getMessage());
|
||||
} catch (IllegalArgumentException | IOException | IllegalStateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeString(String name, String value) {
|
||||
try {
|
||||
if(value != null) {
|
||||
xml.attribute(null, name, value);
|
||||
}
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// didn't read this value, do nothing
|
||||
Timber.v(e, e.getMessage());
|
||||
} catch (IllegalArgumentException | IOException | IllegalStateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeInteger(String name, Integer value) {
|
||||
try {
|
||||
String valueString = (value == null) ? XML_NULL : value.toString();
|
||||
xml.attribute(null, name, valueString);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// didn't read this value, do nothing
|
||||
Timber.e(e, e.getMessage());
|
||||
} catch (IllegalArgumentException | IOException | IllegalStateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue