Continued improvements for RTM task / notes - now works without crashing

pull/14/head
Tim Su 14 years ago
parent 38ab72af9f
commit 196417deea

@ -4,7 +4,7 @@
<booleanAttribute key="ch.zork.quicklaunch" value="true"/>
<stringAttribute key="ch.zork.quicklaunch.icon" value="14.gif"/>
<intAttribute key="ch.zork.quicklaunch.index" value="0"/>
<stringAttribute key="ch.zork.quicklaunch.mode" value="debug"/>
<stringAttribute key="ch.zork.quicklaunch.mode" value="run"/>
<intAttribute key="com.android.ide.eclipse.adt.action" value="0"/>
<stringAttribute key="com.android.ide.eclipse.adt.avd" value="evo-8-google"/>
<stringAttribute key="com.android.ide.eclipse.adt.commandline" value="-scale 0.7"/>

@ -15,6 +15,7 @@ import android.content.ContentValues;
import android.os.Parcel;
import android.os.Parcelable;
import com.todoroo.andlib.data.Property.DoubleProperty;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.PropertyVisitor;
@ -149,17 +150,28 @@ public abstract class AbstractModel implements Parcelable {
* Reads the given property. Make sure this model has this property!
*/
public <TYPE> TYPE getValue(Property<TYPE> property) {
Object value;
if(setValues != null && setValues.containsKey(property.name))
return (TYPE)setValues.get(property.name);
value = setValues.get(property.name);
if(values != null && values.containsKey(property.name))
return (TYPE)values.get(property.name);
else if(values != null && values.containsKey(property.name))
value = values.get(property.name);
if(getDefaultValues().containsKey(property.name))
return (TYPE)getDefaultValues().get(property.name);
else if(getDefaultValues().containsKey(property.name))
value = getDefaultValues().get(property.name);
throw new UnsupportedOperationException(
else
throw new UnsupportedOperationException(
"Model Error: Did not read property " + property.name); //$NON-NLS-1$
// resolve properties that were retrieved with a different type than accessed
if(value instanceof String && property instanceof LongProperty)
return (TYPE) Long.valueOf((String)value);
else if(value instanceof String && property instanceof IntegerProperty)
return (TYPE) Integer.valueOf((String)value);
if(value instanceof String && property instanceof DoubleProperty)
return (TYPE) Double.valueOf((String)value);
return (TYPE) value;
}
/**

@ -8,10 +8,12 @@ import android.content.Context;
import android.content.Intent;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.TaskDetail;
import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.rmilk.data.MilkDataService;
import com.todoroo.astrid.rmilk.data.MilkNote;
import com.todoroo.astrid.rmilk.data.MilkTask;
/**
@ -57,6 +59,21 @@ public class MilkDetailExposer extends BroadcastReceiver {
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, detail);
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
}
TodorooCursor<Metadata> notesCursor = MilkDataService.getInstance().getTaskNotesCursor(taskId);
try {
if(notesCursor.getCount() == 0)
return;
for(notesCursor.moveToFirst(); !notesCursor.isAfterLast(); notesCursor.moveToNext()) {
metadata.readFromCursor(notesCursor);
TaskDetail detail = new TaskDetail(MilkNote.toTaskDetail(metadata));
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, detail);
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
}
} finally {
notesCursor.close();
}
}
}

@ -197,6 +197,15 @@ public final class MilkDataService {
}
}
/**
* 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, MilkNote.METADATA_KEY)));
return cursor;
}
// --- list methods
/**

@ -86,4 +86,23 @@ public class MilkNote {
return result;
}
/**
* Turn a note's title and text into an HTML string for notes
* @param metadata
* @return
*/
@SuppressWarnings("nls")
public static String toTaskDetail(Metadata metadata) {
String title = metadata.getValue(TITLE);
String text = metadata.getValue(TEXT);
String result;
if(!TextUtils.isEmpty(title))
result = "<b>" + title + "</b> " + text;
else
result = text;
return result;
}
}

Loading…
Cancel
Save