mirror of https://github.com/tasks/tasks
Killed extended details. Created NoteMetadata for displaying notes created from plugins.
- migrated PDV and RTM notes to new formatpull/14/head
parent
b99850134e
commit
f161294848
@ -1,51 +0,0 @@
|
|||||||
/**
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.notes;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import com.todoroo.astrid.api.AstridApiConstants;
|
|
||||||
import com.todoroo.astrid.core.PluginServices;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exposes Task Detail for notes
|
|
||||||
*
|
|
||||||
* @author Tim Su <tim@todoroo.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class NoteDetailExposer extends BroadcastReceiver {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
// get tags associated with this task
|
|
||||||
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
|
||||||
if(taskId == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
boolean extended = intent.getBooleanExtra(AstridApiConstants.EXTRAS_EXTENDED, false);
|
|
||||||
String taskDetail = getTaskDetails(taskId, extended);
|
|
||||||
if(taskDetail == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// transmit
|
|
||||||
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_DETAILS);
|
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, NotesPlugin.IDENTIFIER);
|
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, taskDetail);
|
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_EXTENDED, extended);
|
|
||||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
|
||||||
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTaskDetails(long id, boolean extended) {
|
|
||||||
Task task = PluginServices.getTaskService().fetchById(id, Task.NOTES);
|
|
||||||
if(task == null)
|
|
||||||
return null;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.todoroo.astrid.notes;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.Property.StringProperty;
|
||||||
|
import com.todoroo.astrid.data.Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata entry for a note displayed by the Notes plugin.
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NoteMetadata {
|
||||||
|
|
||||||
|
/** metadata key */
|
||||||
|
public static final String METADATA_KEY = "note"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/** note body */
|
||||||
|
public static final StringProperty BODY = Metadata.VALUE1;
|
||||||
|
|
||||||
|
/** note description (title, date, from, etc) */
|
||||||
|
public static final StringProperty TITLE = Metadata.VALUE2;
|
||||||
|
|
||||||
|
/** note thumbnail URL */
|
||||||
|
public static final StringProperty THUMBNAIL = Metadata.VALUE3;
|
||||||
|
|
||||||
|
/** note external provider (use for your own purposes) */
|
||||||
|
public static final StringProperty EXT_PROVIDER = Metadata.VALUE4;
|
||||||
|
|
||||||
|
/** note external id (use for your own purposes) */
|
||||||
|
public static final StringProperty EXT_ID = Metadata.VALUE5;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* See the file "LICENSE" for the full license governing this code.
|
||||||
|
*/
|
||||||
|
package com.todoroo.astrid.notes;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.timsu.astrid.R;
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.andlib.sql.Query;
|
||||||
|
import com.todoroo.andlib.utility.Preferences;
|
||||||
|
import com.todoroo.astrid.api.AstridApiConstants;
|
||||||
|
import com.todoroo.astrid.core.PluginServices;
|
||||||
|
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
|
||||||
|
import com.todoroo.astrid.data.Metadata;
|
||||||
|
import com.todoroo.astrid.data.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposes Task Detail for notes
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NotesDetailExposer extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
// get tags associated with this task
|
||||||
|
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
||||||
|
if(taskId == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String taskDetail = getTaskDetails(taskId);
|
||||||
|
if(taskDetail == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// transmit
|
||||||
|
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_DETAILS);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, NotesPlugin.IDENTIFIER);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, taskDetail);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
||||||
|
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
public String getTaskDetails(long id) {
|
||||||
|
if(!Preferences.getBoolean(R.string.p_showNotes, false))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Task task = PluginServices.getTaskService().fetchById(id, Task.NOTES);
|
||||||
|
if(task == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
StringBuilder notesBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
String notes = task.getValue(Task.NOTES);
|
||||||
|
if(!TextUtils.isEmpty(notes))
|
||||||
|
notesBuilder.append(notesBuilder);
|
||||||
|
|
||||||
|
TodorooCursor<Metadata> cursor = PluginServices.getMetadataService().query(
|
||||||
|
Query.select(Metadata.PROPERTIES).where(
|
||||||
|
MetadataCriteria.byTaskAndwithKey(task.getId(),
|
||||||
|
NoteMetadata.METADATA_KEY)));
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
try {
|
||||||
|
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||||
|
metadata.readFromCursor(cursor);
|
||||||
|
|
||||||
|
if(notesBuilder.length() > 0)
|
||||||
|
notesBuilder.append("\n");
|
||||||
|
notesBuilder.append("<b>").append(metadata.getValue(NoteMetadata.TITLE)).append("</b>\n");
|
||||||
|
notesBuilder.append(metadata.getValue(NoteMetadata.BODY));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(notesBuilder.length() == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return "<img src='silk_note'/> " + notesBuilder; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,50 +0,0 @@
|
|||||||
package com.todoroo.astrid.producteev.sync;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.Property.LongProperty;
|
|
||||||
import com.todoroo.andlib.data.Property.StringProperty;
|
|
||||||
import com.todoroo.astrid.data.Metadata;
|
|
||||||
import com.todoroo.astrid.producteev.api.ApiUtilities;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Metadata entries for a Producteev note. The first Producteev note becomes
|
|
||||||
* Astrid's note field, subsequent notes are stored in metadata in this
|
|
||||||
* format.
|
|
||||||
*
|
|
||||||
* @author Tim Su <tim@todoroo.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ProducteevNote {
|
|
||||||
|
|
||||||
/** metadata key */
|
|
||||||
public static final String METADATA_KEY = "producteev-note"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
/** note id */
|
|
||||||
public static final LongProperty ID = new LongProperty(Metadata.TABLE,
|
|
||||||
Metadata.VALUE1.name);
|
|
||||||
|
|
||||||
/** note message */
|
|
||||||
public static final StringProperty MESSAGE = Metadata.VALUE2;
|
|
||||||
|
|
||||||
/** note creation date */
|
|
||||||
public static final LongProperty CREATED = new LongProperty(Metadata.TABLE,
|
|
||||||
Metadata.VALUE3.name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create metadata from json object
|
|
||||||
* @param note JSON object with params id_note and message
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("nls")
|
|
||||||
public static Metadata create(JSONObject note) {
|
|
||||||
Metadata metadata = new Metadata();
|
|
||||||
metadata.setValue(Metadata.KEY, METADATA_KEY);
|
|
||||||
metadata.setValue(ID, note.optLong("id_note"));
|
|
||||||
metadata.setValue(MESSAGE, ApiUtilities.decode(note.optString("message")));
|
|
||||||
metadata.setValue(CREATED, ApiUtilities.producteevToUnixTime(
|
|
||||||
note.optString("time_create"), 0));
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue