mirror of https://github.com/tasks/tasks
done reading/display-side of producteev-dashboard in the TaskDetailExposer
at least the reading/displaying part is ready for testing, the part where dashboard-infos are written into metadata-db and dataservice-cache is missing and should be done by tim, i think.pull/14/head
parent
1b5a1f9d79
commit
78e6107ce0
@ -1,79 +1,95 @@
|
|||||||
/**
|
/**
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
* See the file "LICENSE" for the full license governing this code.
|
||||||
*/
|
*/
|
||||||
package com.todoroo.astrid.producteev;
|
package com.todoroo.astrid.producteev;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.todoroo.andlib.data.TodorooCursor;
|
import com.timsu.astrid.R;
|
||||||
import com.todoroo.astrid.adapter.TaskAdapter;
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
import com.todoroo.astrid.api.AstridApiConstants;
|
import com.todoroo.astrid.adapter.TaskAdapter;
|
||||||
import com.todoroo.astrid.api.DetailExposer;
|
import com.todoroo.astrid.api.AstridApiConstants;
|
||||||
import com.todoroo.astrid.model.Metadata;
|
import com.todoroo.astrid.api.DetailExposer;
|
||||||
import com.todoroo.astrid.producteev.sync.ProducteevDataService;
|
import com.todoroo.astrid.model.Metadata;
|
||||||
import com.todoroo.astrid.producteev.sync.ProducteevNote;
|
import com.todoroo.astrid.producteev.sync.ProducteevDataService;
|
||||||
|
import com.todoroo.astrid.producteev.sync.ProducteevNote;
|
||||||
/**
|
import com.todoroo.astrid.producteev.sync.ProducteevTask;
|
||||||
* Exposes Task Details for Producteev:
|
|
||||||
* - notes
|
/**
|
||||||
*
|
* Exposes Task Details for Producteev:
|
||||||
* @author Tim Su <tim@todoroo.com>
|
* - notes
|
||||||
*
|
*
|
||||||
*/
|
* @author Tim Su <tim@todoroo.com>
|
||||||
public class ProducteevDetailExposer extends BroadcastReceiver implements DetailExposer{
|
*
|
||||||
|
*/
|
||||||
@Override
|
public class ProducteevDetailExposer extends BroadcastReceiver implements DetailExposer{
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
// if we aren't logged in, don't expose features
|
@Override
|
||||||
if(!ProducteevUtilities.INSTANCE.isLoggedIn())
|
public void onReceive(Context context, Intent intent) {
|
||||||
return;
|
// if we aren't logged in, don't expose features
|
||||||
|
if(!ProducteevUtilities.INSTANCE.isLoggedIn())
|
||||||
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
return;
|
||||||
if(taskId == -1)
|
|
||||||
return;
|
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
||||||
|
if(taskId == -1)
|
||||||
boolean extended = intent.getBooleanExtra(AstridApiConstants.EXTRAS_EXTENDED, false);
|
return;
|
||||||
String taskDetail = getTaskDetails(context, taskId, extended);
|
|
||||||
if(taskDetail == null)
|
boolean extended = intent.getBooleanExtra(AstridApiConstants.EXTRAS_EXTENDED, false);
|
||||||
return;
|
String taskDetail = getTaskDetails(context, taskId, extended);
|
||||||
|
if(taskDetail == null)
|
||||||
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_DETAILS);
|
return;
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ProducteevUtilities.IDENTIFIER);
|
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_DETAILS);
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_EXTENDED, extended);
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ProducteevUtilities.IDENTIFIER);
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, taskDetail);
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
||||||
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_EXTENDED, extended);
|
||||||
}
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, taskDetail);
|
||||||
|
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||||
@Override
|
}
|
||||||
public String getTaskDetails(Context context, long id, boolean extended) {
|
|
||||||
|
@Override
|
||||||
if(!extended)
|
public String getTaskDetails(Context context, long id, boolean extended) {
|
||||||
return null;
|
Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(id);
|
||||||
|
if(metadata == null)
|
||||||
StringBuilder builder = new StringBuilder();
|
return null;
|
||||||
TodorooCursor<Metadata> notesCursor = ProducteevDataService.getInstance().getTaskNotesCursor(id);
|
|
||||||
try {
|
StringBuilder builder = new StringBuilder();
|
||||||
Metadata metadata = new Metadata();
|
|
||||||
for(notesCursor.moveToFirst(); !notesCursor.isAfterLast(); notesCursor.moveToNext()) {
|
if(!extended) {
|
||||||
metadata.readFromCursor(notesCursor);
|
long dashboardId = metadata.getValue(ProducteevTask.DASHBOARD_ID);
|
||||||
builder.append(metadata.getValue(ProducteevNote.MESSAGE)).append(TaskAdapter.DETAIL_SEPARATOR);
|
String dashboardName = ProducteevDataService.getInstance().getDashboardName(dashboardId);
|
||||||
}
|
// Prod dashboard is out of date. don't display Producteev stuff
|
||||||
} finally {
|
if(dashboardName == null)
|
||||||
notesCursor.close();
|
return null;
|
||||||
}
|
|
||||||
|
if(dashboardId > 0) {
|
||||||
if(builder.length() == 0)
|
builder.append(context.getString(R.string.producteev_TLA_dashboard,
|
||||||
return null;
|
dashboardId)).append(TaskAdapter.DETAIL_SEPARATOR);
|
||||||
String result = builder.toString();
|
}
|
||||||
return result.substring(0, result.length() - TaskAdapter.DETAIL_SEPARATOR.length());
|
|
||||||
}
|
} else {
|
||||||
|
TodorooCursor<Metadata> notesCursor = ProducteevDataService.getInstance().getTaskNotesCursor(id);
|
||||||
@Override
|
try {
|
||||||
public String getPluginIdentifier() {
|
for(notesCursor.moveToFirst(); !notesCursor.isAfterLast(); notesCursor.moveToNext()) {
|
||||||
return ProducteevUtilities.IDENTIFIER;
|
metadata.readFromCursor(notesCursor);
|
||||||
}
|
builder.append(metadata.getValue(ProducteevNote.MESSAGE)).append(TaskAdapter.DETAIL_SEPARATOR);
|
||||||
|
}
|
||||||
}
|
} finally {
|
||||||
|
notesCursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(builder.length() == 0)
|
||||||
|
return null;
|
||||||
|
String result = builder.toString();
|
||||||
|
return result.substring(0, result.length() - TaskAdapter.DETAIL_SEPARATOR.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPluginIdentifier() {
|
||||||
|
return ProducteevUtilities.IDENTIFIER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* See the file "LICENSE" for the full license governing this code.
|
||||||
|
*/
|
||||||
|
package com.todoroo.astrid.producteev.sync;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.AbstractModel;
|
||||||
|
import com.todoroo.andlib.data.Property;
|
||||||
|
import com.todoroo.andlib.data.Table;
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.andlib.data.Property.LongProperty;
|
||||||
|
import com.todoroo.andlib.data.Property.StringProperty;
|
||||||
|
import com.todoroo.astrid.model.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data Model which represents a dashboard in Producteev
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
public class ProducteevDashboard extends AbstractModel {
|
||||||
|
|
||||||
|
// --- table
|
||||||
|
|
||||||
|
public static final Table TABLE = new Table("dashboards", ProducteevDashboard.class);
|
||||||
|
|
||||||
|
// --- properties
|
||||||
|
|
||||||
|
/** ID (corresponds to RTM ID) */
|
||||||
|
public static final LongProperty ID = new LongProperty(
|
||||||
|
TABLE, ID_PROPERTY_NAME);
|
||||||
|
|
||||||
|
/** Name */
|
||||||
|
public static final StringProperty NAME = new StringProperty(
|
||||||
|
TABLE, "name");
|
||||||
|
|
||||||
|
/** List of all properties for this model */
|
||||||
|
public static final Property<?>[] PROPERTIES = generateProperties(ProducteevDashboard.class);
|
||||||
|
|
||||||
|
// --- defaults
|
||||||
|
|
||||||
|
/** Default values container */
|
||||||
|
private static final ContentValues defaultValues = new ContentValues();
|
||||||
|
|
||||||
|
// static {
|
||||||
|
// defaultValues.put(POSITION.name, 0);
|
||||||
|
// defaultValues.put(ARCHIVED.name, 0);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentValues getDefaultValues() {
|
||||||
|
return defaultValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- data access boilerplate
|
||||||
|
|
||||||
|
public ProducteevDashboard() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProducteevDashboard(TodorooCursor<ProducteevDashboard> cursor) {
|
||||||
|
this();
|
||||||
|
readPropertiesFromCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromCursor(TodorooCursor<ProducteevDashboard> cursor) {
|
||||||
|
super.readPropertiesFromCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getId() {
|
||||||
|
return getIdHelper(ID);
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- parcelable helpers
|
||||||
|
|
||||||
|
private static final Creator<Task> CREATOR = new ModelCreator<Task>(Task.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Creator<? extends AbstractModel> getCreator() {
|
||||||
|
return CREATOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,196 +1,235 @@
|
|||||||
/**
|
/**
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
* See the file "LICENSE" for the full license governing this code.
|
||||||
*/
|
*/
|
||||||
package com.todoroo.astrid.producteev.sync;
|
package com.todoroo.astrid.producteev.sync;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
import android.content.Context;
|
import java.util.Random;
|
||||||
|
|
||||||
import com.todoroo.andlib.data.Property;
|
import android.content.Context;
|
||||||
import com.todoroo.andlib.data.TodorooCursor;
|
|
||||||
import com.todoroo.andlib.service.Autowired;
|
import com.todoroo.andlib.data.GenericDao;
|
||||||
import com.todoroo.andlib.service.ContextManager;
|
import com.todoroo.andlib.data.Property;
|
||||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
import com.todoroo.andlib.sql.Criterion;
|
import com.todoroo.andlib.service.Autowired;
|
||||||
import com.todoroo.andlib.sql.Join;
|
import com.todoroo.andlib.service.ContextManager;
|
||||||
import com.todoroo.andlib.sql.Query;
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||||
import com.todoroo.astrid.dao.MetadataDao;
|
import com.todoroo.andlib.sql.Criterion;
|
||||||
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
|
import com.todoroo.andlib.sql.Join;
|
||||||
import com.todoroo.astrid.dao.TaskDao;
|
import com.todoroo.andlib.sql.Query;
|
||||||
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
import com.todoroo.andlib.utility.SoftHashMap;
|
||||||
import com.todoroo.astrid.model.Metadata;
|
import com.todoroo.astrid.dao.MetadataDao;
|
||||||
import com.todoroo.astrid.model.Task;
|
import com.todoroo.astrid.dao.TaskDao;
|
||||||
import com.todoroo.astrid.producteev.ProducteevUtilities;
|
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
|
||||||
import com.todoroo.astrid.rmilk.data.MilkNote;
|
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
||||||
import com.todoroo.astrid.tags.TagService;
|
import com.todoroo.astrid.model.Metadata;
|
||||||
|
import com.todoroo.astrid.model.Task;
|
||||||
public final class ProducteevDataService {
|
import com.todoroo.astrid.producteev.ProducteevUtilities;
|
||||||
|
import com.todoroo.astrid.rmilk.data.MilkNote;
|
||||||
// --- constants
|
import com.todoroo.astrid.tags.TagService;
|
||||||
|
|
||||||
/** Utility for joining tasks with metadata */
|
public final class ProducteevDataService {
|
||||||
public static final Join METADATA_JOIN = Join.left(Metadata.TABLE, Task.ID.eq(Metadata.TASK));
|
|
||||||
|
// --- constants
|
||||||
// --- singleton
|
|
||||||
|
/** Utility for joining tasks with metadata */
|
||||||
private static ProducteevDataService instance = null;
|
public static final Join METADATA_JOIN = Join.left(Metadata.TABLE, Task.ID.eq(Metadata.TASK));
|
||||||
|
|
||||||
public static synchronized ProducteevDataService getInstance() {
|
// --- singleton
|
||||||
if(instance == null)
|
|
||||||
instance = new ProducteevDataService(ContextManager.getContext());
|
private static ProducteevDataService instance = null;
|
||||||
return instance;
|
|
||||||
}
|
public static synchronized ProducteevDataService getInstance() {
|
||||||
|
if(instance == null)
|
||||||
// --- instance variables
|
instance = new ProducteevDataService(ContextManager.getContext());
|
||||||
|
return instance;
|
||||||
protected final Context context;
|
}
|
||||||
|
|
||||||
@Autowired
|
// --- instance variables
|
||||||
private TaskDao taskDao;
|
|
||||||
|
protected final Context context;
|
||||||
@Autowired
|
|
||||||
private MetadataDao metadataDao;
|
private final ProducteevDatabase prodDatabase = new ProducteevDatabase();
|
||||||
|
|
||||||
private final ProducteevUtilities preferences = ProducteevUtilities.INSTANCE;
|
private final GenericDao<ProducteevDashboard> prodDashboardDao;
|
||||||
|
|
||||||
static final Random random = new Random();
|
@Autowired
|
||||||
|
private TaskDao taskDao;
|
||||||
private ProducteevDataService(Context context) {
|
|
||||||
this.context = context;
|
@Autowired
|
||||||
DependencyInjectionService.getInstance().inject(this);
|
private MetadataDao metadataDao;
|
||||||
}
|
|
||||||
|
private final ProducteevUtilities preferences = ProducteevUtilities.INSTANCE;
|
||||||
// --- task and metadata methods
|
|
||||||
|
static final Random random = new Random();
|
||||||
/**
|
|
||||||
* Clears RTM metadata information. Used when user logs out of RTM
|
private ProducteevDataService(Context context) {
|
||||||
*/
|
this.context = context;
|
||||||
public void clearMetadata() {
|
DependencyInjectionService.getInstance().inject(this);
|
||||||
metadataDao.deleteWhere(Metadata.KEY.eq(ProducteevTask.METADATA_KEY));
|
prodDashboardDao = new GenericDao<ProducteevDashboard>(ProducteevDashboard.class, prodDatabase);
|
||||||
metadataDao.deleteWhere(Metadata.KEY.eq(ProducteevNote.METADATA_KEY));
|
}
|
||||||
}
|
|
||||||
|
// --- task and metadata methods
|
||||||
/**
|
|
||||||
* Gets tasks that were created since last sync
|
/**
|
||||||
* @param properties
|
* Clears RTM metadata information. Used when user logs out of RTM
|
||||||
* @return
|
*/
|
||||||
*/
|
public void clearMetadata() {
|
||||||
public TodorooCursor<Task> getLocallyCreated(Property<?>[] properties) {
|
metadataDao.deleteWhere(Metadata.KEY.eq(ProducteevTask.METADATA_KEY));
|
||||||
return
|
metadataDao.deleteWhere(Metadata.KEY.eq(ProducteevNote.METADATA_KEY));
|
||||||
taskDao.query(Query.select(properties).join(ProducteevDataService.METADATA_JOIN).where(Criterion.and(
|
}
|
||||||
Criterion.not(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).
|
|
||||||
where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY), ProducteevTask.ID.gt(0))))),
|
/**
|
||||||
TaskCriteria.isActive())).groupBy(Task.ID));
|
* Gets tasks that were created since last sync
|
||||||
}
|
* @param properties
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Gets tasks that were modified since last sync
|
public TodorooCursor<Task> getLocallyCreated(Property<?>[] properties) {
|
||||||
* @param properties
|
return
|
||||||
* @return null if never sync'd
|
taskDao.query(Query.select(properties).join(ProducteevDataService.METADATA_JOIN).where(Criterion.and(
|
||||||
*/
|
Criterion.not(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).
|
||||||
public TodorooCursor<Task> getLocallyUpdated(Property<?>[] properties) {
|
where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY), ProducteevTask.ID.gt(0))))),
|
||||||
long lastSyncDate = preferences.getLastSyncDate();
|
TaskCriteria.isActive())).groupBy(Task.ID));
|
||||||
if(lastSyncDate == 0)
|
}
|
||||||
return taskDao.query(Query.select(Task.ID).where(Criterion.none));
|
|
||||||
return
|
/**
|
||||||
taskDao.query(Query.select(properties).join(ProducteevDataService.METADATA_JOIN).
|
* Gets tasks that were modified since last sync
|
||||||
where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
* @param properties
|
||||||
Task.MODIFICATION_DATE.gt(lastSyncDate))).groupBy(Task.ID));
|
* @return null if never sync'd
|
||||||
}
|
*/
|
||||||
|
public TodorooCursor<Task> getLocallyUpdated(Property<?>[] properties) {
|
||||||
/**
|
long lastSyncDate = preferences.getLastSyncDate();
|
||||||
* Searches for a local task with same remote id, updates this task's id
|
if(lastSyncDate == 0)
|
||||||
* @param remoteTask
|
return taskDao.query(Query.select(Task.ID).where(Criterion.none));
|
||||||
*/
|
return
|
||||||
public void findLocalMatch(ProducteevTaskContainer remoteTask) {
|
taskDao.query(Query.select(properties).join(ProducteevDataService.METADATA_JOIN).
|
||||||
if(remoteTask.task.getId() != Task.NO_ID)
|
where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
||||||
return;
|
Task.MODIFICATION_DATE.gt(lastSyncDate))).groupBy(Task.ID));
|
||||||
TodorooCursor<Task> cursor = taskDao.query(Query.select(Task.ID).
|
}
|
||||||
join(ProducteevDataService.METADATA_JOIN).where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
|
||||||
ProducteevTask.ID.eq(remoteTask.pdvTask.getValue(ProducteevTask.ID)))));
|
/**
|
||||||
try {
|
* Searches for a local task with same remote id, updates this task's id
|
||||||
if(cursor.getCount() == 0)
|
* @param remoteTask
|
||||||
return;
|
*/
|
||||||
cursor.moveToFirst();
|
public void findLocalMatch(ProducteevTaskContainer remoteTask) {
|
||||||
remoteTask.task.setId(cursor.get(Task.ID));
|
if(remoteTask.task.getId() != Task.NO_ID)
|
||||||
} finally {
|
return;
|
||||||
cursor.close();
|
TodorooCursor<Task> cursor = taskDao.query(Query.select(Task.ID).
|
||||||
}
|
join(ProducteevDataService.METADATA_JOIN).where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
||||||
}
|
ProducteevTask.ID.eq(remoteTask.pdvTask.getValue(ProducteevTask.ID)))));
|
||||||
|
try {
|
||||||
/**
|
if(cursor.getCount() == 0)
|
||||||
* Saves a task and its metadata
|
return;
|
||||||
* @param task
|
cursor.moveToFirst();
|
||||||
*/
|
remoteTask.task.setId(cursor.get(Task.ID));
|
||||||
public void saveTaskAndMetadata(ProducteevTaskContainer task) {
|
} finally {
|
||||||
taskDao.save(task.task, true);
|
cursor.close();
|
||||||
|
}
|
||||||
metadataDao.deleteWhere(Criterion.and(MetadataCriteria.byTask(task.task.getId()),
|
}
|
||||||
Criterion.or(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
|
||||||
MetadataCriteria.withKey(ProducteevNote.METADATA_KEY),
|
/**
|
||||||
MetadataCriteria.withKey(TagService.KEY))));
|
* Saves a task and its metadata
|
||||||
task.metadata.add(task.pdvTask);
|
* @param task
|
||||||
task.pdvTask.setValue(Metadata.KEY, ProducteevTask.METADATA_KEY);
|
*/
|
||||||
for(Metadata metadata : task.metadata) {
|
public void saveTaskAndMetadata(ProducteevTaskContainer task) {
|
||||||
metadata.setValue(Metadata.TASK, task.task.getId());
|
taskDao.save(task.task, true);
|
||||||
metadataDao.createNew(metadata);
|
|
||||||
}
|
metadataDao.deleteWhere(Criterion.and(MetadataCriteria.byTask(task.task.getId()),
|
||||||
}
|
Criterion.or(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
||||||
|
MetadataCriteria.withKey(ProducteevNote.METADATA_KEY),
|
||||||
/**
|
MetadataCriteria.withKey(TagService.KEY))));
|
||||||
* Reads a task and its metadata
|
task.metadata.add(task.pdvTask);
|
||||||
* @param task
|
task.pdvTask.setValue(Metadata.KEY, ProducteevTask.METADATA_KEY);
|
||||||
* @return
|
for(Metadata metadata : task.metadata) {
|
||||||
*/
|
metadata.setValue(Metadata.TASK, task.task.getId());
|
||||||
public ProducteevTaskContainer readTaskAndMetadata(TodorooCursor<Task> taskCursor) {
|
metadataDao.createNew(metadata);
|
||||||
Task task = new Task(taskCursor);
|
}
|
||||||
|
}
|
||||||
// read tags, notes, etc
|
|
||||||
ArrayList<Metadata> metadata = new ArrayList<Metadata>();
|
/**
|
||||||
TodorooCursor<Metadata> metadataCursor = metadataDao.query(Query.select(Metadata.PROPERTIES).
|
* Reads a task and its metadata
|
||||||
where(Criterion.and(MetadataCriteria.byTask(task.getId()),
|
* @param task
|
||||||
Criterion.or(MetadataCriteria.withKey(TagService.KEY),
|
* @return
|
||||||
MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
*/
|
||||||
MetadataCriteria.withKey(MilkNote.METADATA_KEY),
|
public ProducteevTaskContainer readTaskAndMetadata(TodorooCursor<Task> taskCursor) {
|
||||||
MetadataCriteria.withKey(ProducteevNote.METADATA_KEY)))));
|
Task task = new Task(taskCursor);
|
||||||
try {
|
|
||||||
for(metadataCursor.moveToFirst(); !metadataCursor.isAfterLast(); metadataCursor.moveToNext()) {
|
// read tags, notes, etc
|
||||||
metadata.add(new Metadata(metadataCursor));
|
ArrayList<Metadata> metadata = new ArrayList<Metadata>();
|
||||||
}
|
TodorooCursor<Metadata> metadataCursor = metadataDao.query(Query.select(Metadata.PROPERTIES).
|
||||||
} finally {
|
where(Criterion.and(MetadataCriteria.byTask(task.getId()),
|
||||||
metadataCursor.close();
|
Criterion.or(MetadataCriteria.withKey(TagService.KEY),
|
||||||
}
|
MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
|
||||||
|
// FIXME: Constant from other plugin shouldnt be used
|
||||||
return new ProducteevTaskContainer(task, metadata);
|
MetadataCriteria.withKey(MilkNote.METADATA_KEY),
|
||||||
}
|
MetadataCriteria.withKey(ProducteevNote.METADATA_KEY)))));
|
||||||
|
try {
|
||||||
/**
|
for(metadataCursor.moveToFirst(); !metadataCursor.isAfterLast(); metadataCursor.moveToNext()) {
|
||||||
* Reads metadata out of a task
|
metadata.add(new Metadata(metadataCursor));
|
||||||
* @return null if no metadata found
|
}
|
||||||
*/
|
} finally {
|
||||||
public Metadata getTaskMetadata(long taskId) {
|
metadataCursor.close();
|
||||||
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(
|
}
|
||||||
ProducteevTask.ID, ProducteevTask.DASHBOARD_ID).where(
|
|
||||||
MetadataCriteria.byTaskAndwithKey(taskId, ProducteevTask.METADATA_KEY)));
|
return new ProducteevTaskContainer(task, metadata);
|
||||||
try {
|
}
|
||||||
if(cursor.getCount() == 0)
|
|
||||||
return null;
|
/**
|
||||||
cursor.moveToFirst();
|
* Reads metadata out of a task
|
||||||
return new Metadata(cursor);
|
* @return null if no metadata found
|
||||||
} finally {
|
*/
|
||||||
cursor.close();
|
public Metadata getTaskMetadata(long taskId) {
|
||||||
}
|
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(
|
||||||
}
|
ProducteevTask.ID, ProducteevTask.DASHBOARD_ID).where(
|
||||||
|
MetadataCriteria.byTaskAndwithKey(taskId, ProducteevTask.METADATA_KEY)));
|
||||||
/**
|
try {
|
||||||
* Reads task notes out of a task
|
if(cursor.getCount() == 0)
|
||||||
*/
|
return null;
|
||||||
public TodorooCursor<Metadata> getTaskNotesCursor(long taskId) {
|
cursor.moveToFirst();
|
||||||
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES).
|
return new Metadata(cursor);
|
||||||
where(MetadataCriteria.byTaskAndwithKey(taskId, ProducteevNote.METADATA_KEY)));
|
} finally {
|
||||||
return cursor;
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Reads task notes out of a task
|
||||||
|
*/
|
||||||
|
public TodorooCursor<Metadata> getTaskNotesCursor(long taskId) {
|
||||||
|
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES).
|
||||||
|
where(MetadataCriteria.byTaskAndwithKey(taskId, ProducteevNote.METADATA_KEY)));
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- list methods
|
||||||
|
|
||||||
|
private final Map<Long, String> dashboardCache =
|
||||||
|
Collections.synchronizedMap(new SoftHashMap<Long, String>());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get dashboard name by dashboard id
|
||||||
|
* @param dashboardId
|
||||||
|
* @return null if no dashboard by this id exists, otherwise dashboard name
|
||||||
|
*/
|
||||||
|
public String getDashboardName(long dashboardId) {
|
||||||
|
if(dashboardCache.containsKey(dashboardId))
|
||||||
|
return dashboardCache.get(dashboardId);
|
||||||
|
|
||||||
|
TodorooCursor<ProducteevDashboard> cursor = prodDashboardDao.query(Query.select(
|
||||||
|
ProducteevDashboard.NAME).where(ProducteevDashboard.ID.eq(dashboardId)));
|
||||||
|
try {
|
||||||
|
if(cursor.getCount() == 0) {
|
||||||
|
dashboardCache.put(dashboardId, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
cursor.moveToFirst();
|
||||||
|
String name = cursor.get(ProducteevDashboard.NAME);
|
||||||
|
dashboardCache.put(dashboardId, name);
|
||||||
|
return name;
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009, Todoroo Inc
|
||||||
|
* All Rights Reserved
|
||||||
|
* http://www.todoroo.com
|
||||||
|
*/
|
||||||
|
package com.todoroo.astrid.producteev.sync;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.AbstractDatabase;
|
||||||
|
import com.todoroo.andlib.data.GenericDao;
|
||||||
|
import com.todoroo.andlib.data.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database wrapper
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
public class ProducteevDatabase extends AbstractDatabase {
|
||||||
|
|
||||||
|
// --- constants
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database version number. This variable must be updated when database
|
||||||
|
* tables are updated, as it determines whether a database needs updating.
|
||||||
|
*/
|
||||||
|
public static final int VERSION = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database name (must be unique)
|
||||||
|
*/
|
||||||
|
private static final String NAME = "producteev";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of table/ If you're adding a new table, add it to this list and
|
||||||
|
* also make sure that our SQLite helper does the right thing.
|
||||||
|
*/
|
||||||
|
public static final Table[] TABLES = new Table[] {
|
||||||
|
ProducteevDashboard.TABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- implementation
|
||||||
|
|
||||||
|
private final GenericDao<ProducteevDashboard> dao = new GenericDao<ProducteevDashboard>(ProducteevDashboard.class, this);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getName() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getVersion() {
|
||||||
|
return VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Table[] getTables() {
|
||||||
|
return TABLES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericDao<ProducteevDashboard> getDao() {
|
||||||
|
return dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreateTables() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean onUpgrade(int oldVersion, int newVersion) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,24 @@
|
|||||||
package com.todoroo.astrid.producteev.sync;
|
package com.todoroo.astrid.producteev.sync;
|
||||||
|
|
||||||
import com.todoroo.andlib.data.Property.LongProperty;
|
import com.todoroo.andlib.data.Property.LongProperty;
|
||||||
import com.todoroo.astrid.model.Metadata;
|
import com.todoroo.astrid.model.Metadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metadata entries for a Remember The Milk Task
|
* Metadata entries for a Producteev Task
|
||||||
* @author Tim Su <tim@todoroo.com>
|
* @author Tim Su <tim@todoroo.com>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ProducteevTask {
|
public class ProducteevTask {
|
||||||
|
|
||||||
/** metadata key */
|
/** metadata key */
|
||||||
public static final String METADATA_KEY = "producteev"; //$NON-NLS-1$
|
public static final String METADATA_KEY = "producteev"; //$NON-NLS-1$
|
||||||
|
|
||||||
/** task id in producteev */
|
/** task id in producteev */
|
||||||
public static final LongProperty ID = new LongProperty(Metadata.TABLE,
|
public static final LongProperty ID = new LongProperty(Metadata.TABLE,
|
||||||
Metadata.VALUE1.name);
|
Metadata.VALUE1.name);
|
||||||
|
|
||||||
/** dashboard id */
|
/** dashboard id */
|
||||||
public static final LongProperty DASHBOARD_ID = new LongProperty(Metadata.TABLE,
|
public static final LongProperty DASHBOARD_ID = new LongProperty(Metadata.TABLE,
|
||||||
Metadata.VALUE2.name);
|
Metadata.VALUE2.name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- See the file "LICENSE" for the full license governing this code. -->
|
<!-- See the file "LICENSE" for the full license governing this code. -->
|
||||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<!-- ==================================================== Preferences == -->
|
<!-- ====================== Plugin Boilerplate ========================= -->
|
||||||
|
|
||||||
<!-- Preferences Title: Producteev -->
|
<!-- task detail showing Producteev dashboard information -->
|
||||||
<string name="producteev_PPr_header">Producteev</string>
|
<string name="producteev_TLA_dashboard">Producteev dashboard: %s</string>
|
||||||
|
|
||||||
<!-- ================================================ Synchronization == -->
|
<!-- ==================================================== Preferences == -->
|
||||||
|
|
||||||
<!-- title for notification tray when synchronizing -->
|
<!-- Preferences Title: Producteev -->
|
||||||
<string name="producteev_notification_title">Astrid: Producteev</string>
|
<string name="producteev_PPr_header">Producteev</string>
|
||||||
|
|
||||||
<!-- Error msg when io exception -->
|
<!-- ================================================ Synchronization == -->
|
||||||
<string name="producteev_ioerror">Connection Error! Check your Internet connection.</string>
|
|
||||||
|
<!-- title for notification tray when synchronizing -->
|
||||||
<!-- Prod Login email not specified-->
|
<string name="producteev_notification_title">Astrid: Producteev</string>
|
||||||
<string name="producteev_MLA_email_empty">E-Mail was not specified!</string>
|
|
||||||
|
<!-- Error msg when io exception -->
|
||||||
<!-- Prod Login password not specified-->
|
<string name="producteev_ioerror">Connection Error! Check your Internet connection.</string>
|
||||||
<string name="producteev_MLA_password_empty">Password was not specified!</string>
|
|
||||||
|
<!-- Prod Login email not specified-->
|
||||||
</resources>
|
<string name="producteev_MLA_email_empty">E-Mail was not specified!</string>
|
||||||
|
|
||||||
|
<!-- Prod Login password not specified-->
|
||||||
|
<string name="producteev_MLA_password_empty">Password was not specified!</string>
|
||||||
|
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue