Merge lp:~salgado/tomdroid/sync-ui into lp:~tomdroid-dev/tomdroid/sync-ui
- sync-ui
- Merge into sync-ui
Status: | Merged |
---|---|
Merged at revision: | 239 |
Proposed branch: | lp:~salgado/tomdroid/sync-ui |
Merge into: | lp:~tomdroid-dev/tomdroid/sync-ui |
Diff against target: |
289 lines (+149/-9) 7 files modified
.classpath (+1/-0) AndroidManifest.xml (+3/-0) src/org/tomdroid/Note.java (+17/-1) src/org/tomdroid/NoteManager.java (+15/-6) src/org/tomdroid/NoteProvider.java (+4/-2) tests/org/tomdroid/NoteManagerTest.java (+74/-0) tests/org/tomdroid/NoteTest.java (+35/-0) |
To merge this branch: | bzr merge lp:~salgado/tomdroid/sync-ui |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rodja (community) | Approve | ||
Olivier Bilodeau | Pending | ||
Review via email: mp+32509@code.launchpad.net |
Commit message
Description of the change
This branch excludes notebook templates from the list of notes.
To do that it parses the tags of all notes looking for a "system:template" and when found it flags that note as a notebook template. Right now this only happens when syncing notes from the web, but it could easily be done when syncing from SD as well.
That flag is then stored in the DB and used later to filter out the notebook templates from the notes list. One thing I'm not sure about is whether or not we want to have this flag stored in the DB or computed at run-time.
Oh, and I also started writing unit tests for the some things -- right now only for the things I've changed, but I plan to write more of them to help us feel more confident when doing refactorings.
- 237. By Guilherme Salgado
-
Get rid of lots of unnecessary boilerplate created by Eclipse when I created a separate test project
- 238. By Guilherme Salgado
-
Fix a Null pointer error when loading a note JSON with no tags.
Olivier Bilodeau (plaxx) wrote : | # |
Rodja (trappe) wrote : | # |
It is great to get rid of the templates but...
1. The tests are not passing if there are already notes in the database (see two-way-branch for an setUp/tearDown example).
2. Rather then introducing a new member to flag a note as "template" I would suggest to seach for the template tag each time isNotebookTempl
3. Similar to the second remark, I would sooner see a row for all the tags changing the database when ever we feel about supporting a new tag.
Guilherme Salgado (salgado) wrote : | # |
On Wed, 2010-08-25 at 20:26 +0000, Rodja wrote:
> It is great to get rid of the templates but...
>
> 1. The tests are not passing if there are already notes in the
> database (see two-way-branch for an setUp/tearDown example).
>
So, IIUC, you suggest that I just reset the database as part of
setUp/tearDown? That sounds fine to me, but the sync-ui branch doesn't
have LocalStorage (which you use in the two-way-sync branch to reset the
DB), so I'd have to do it manually for now. Something like:
activity.
Preferences.
Is that ok with you?
> 2. Rather then introducing a new member to flag a note as "template" I
> would suggest to seach for the template tag each time
> isNotebookTempl
> refactorings will be harder with each new member variable.
It's not because of performance that I made it a flag -- it's because I
think we should avoid spending processor cycles unnecessarily, to not
drain people's batteries.
My thinking was that if you have a long list of notes and you're
switching back and forth between any note and the notes list, tomdroid
would be doing a good job at draining your battery. To be honest I have
no idea how much power it'd spend while doing that, but it's easily
avoidable so I thought it was worth it. I'd be OK with dropping the new
flag as you suggest, if you feel it's not worth.
>
> 3. Similar to the second remark, I would sooner see a row for all the
> tags changing the database when ever we feel about supporting a new
> tag.
Do you mean you think we shouldn't be changing the DB schema often? I
don't think that's a problem (thanks to the framework's ability of
detecting when schema upgrades are needed and doing the migration
semi-automatically for us), specially when it's as early in the
lifecycle of the project as we are now.
--
Guilherme Salgado <https:/
Rodja (trappe) wrote : | # |
> On Wed, 2010-08-25 at 20:26 +0000, Rodja wrote:
> > It is great to get rid of the templates but...
> >
> > 1. The tests are not passing if there are already notes in the
> > database (see two-way-branch for an setUp/tearDown example).
> >
>
> So, IIUC, you suggest that I just reset the database as part of
> setUp/tearDown? That sounds fine to me, but the sync-ui branch doesn't
> have LocalStorage (which you use in the two-way-sync branch to reset the
> DB), so I'd have to do it manually for now. Something like:
>
> activity.
> Preferences.
>
> Is that ok with you?
Yes.
> > 2. Rather then introducing a new member to flag a note as "template" I
> > would suggest to seach for the template tag each time
> > isNotebookTempl
> > refactorings will be harder with each new member variable.
>
> It's not because of performance that I made it a flag -- it's because I
> think we should avoid spending processor cycles unnecessarily, to not
> drain people's batteries.
>
> My thinking was that if you have a long list of notes and you're
> switching back and forth between any note and the notes list, tomdroid
> would be doing a good job at draining your battery.
Is it? Have you tested? I would expect Android to keep the notes list Activity running while showing a Note; and calling onResume when switching back. But guessing is never good when talking about optimizations.
> To be honest I have
> no idea how much power it'd spend while doing that, but it's easily
> avoidable so I thought it was worth it. I'd be OK with dropping the new
> flag as you suggest, if you feel it's not worth.
Power consumtion is not easily measureable. But when looking on the battery usage graph from my Motorola Droid the big consumers are wifi, display, Maps and phone. I prefer having a clean code base which is easier to change in the future than "pollute" it with optimizations.
> > 3. Similar to the second remark, I would sooner see a row for all the
> > tags changing the database when ever we feel about supporting a new
> > tag.
>
> Do you mean you think we shouldn't be changing the DB schema often? I
> don't think that's a problem (thanks to the framework's ability of
> detecting when schema upgrades are needed and doing the migration
> semi-automatically for us), specially when it's as early in the
> lifecycle of the project as we are now.
True. I'm not against changing the data base scheme in general. But sooner or later we will introduce a column to store the tags of a note. Should we remove the system:template tag befor putting the others into that column?
I've no insights about Tomboy server API decisions of having "open-on-startup" and "pinned" as extra flags and "system:template" inside the tag list, but would recommend to stick as close as possible with the already provided scheme to avoid complicated data renderings and difficulties for other Tomboy developers.
Guilherme Salgado (salgado) wrote : | # |
On Sat, 2010-08-28 at 08:10 +0000, Rodja wrote:
> > On Wed, 2010-08-25 at 20:26 +0000, Rodja wrote:
> > > It is great to get rid of the templates but...
> > >
> > > 1. The tests are not passing if there are already notes in the
> > > database (see two-way-branch for an setUp/tearDown example).
> > >
> >
> > So, IIUC, you suggest that I just reset the database as part of
> > setUp/tearDown? That sounds fine to me, but the sync-ui branch doesn't
> > have LocalStorage (which you use in the two-way-sync branch to reset the
> > DB), so I'd have to do it manually for now. Something like:
> >
> > activity.
> > Preferences.
> >
> > Is that ok with you?
>
> Yes.
>
Cool, I've done that.
> > > 2. Rather then introducing a new member to flag a note as "template" I
> > > would suggest to seach for the template tag each time
> > > isNotebookTempl
> > > refactorings will be harder with each new member variable.
> >
One issue with the solution you suggest is that, in the current
implementation, we only have access to the tags (which is in the JSON
representation sent by the server) when creating a new Note row in the
database, so I'd have to store all the tags in the DB somehow. Probably
in a custom format as the web sync gives me JSON and the file sync gives
XML.
Does that sound ok to you? Do you have any suggestions as to which
format to use for the tags in the DB? Ideally I think it should be in a
separate table (linked to the Note table) with one column for the key
and another for the value.
> > It's not because of performance that I made it a flag -- it's because I
> > think we should avoid spending processor cycles unnecessarily, to not
> > drain people's batteries.
> >
> > My thinking was that if you have a long list of notes and you're
> > switching back and forth between any note and the notes list, tomdroid
> > would be doing a good job at draining your battery.
>
> Is it? Have you tested? I would expect Android to keep the notes list
> Activity running while showing a Note; and calling onResume when
> switching back. But guessing is never good when talking about
> optimizations.
You're most likely right here. I didn't know this could happen as I
don't know much about Android and this is the first time I write some
code for it.
>
> > To be honest I have
> > no idea how much power it'd spend while doing that, but it's easily
> > avoidable so I thought it was worth it. I'd be OK with dropping the new
> > flag as you suggest, if you feel it's not worth.
>
> Power consumtion is not easily measureable. But when looking on the
> battery usage graph from my Motorola Droid the big consumers are wifi,
> display, Maps and phone. I prefer having a clean code base which is
> easier to change in the future than "pollute" it with optimizations.
Fair enough.
- 239. By Guilherme Salgado
-
A couple tweaks suggested by reviewer
- 240. By Guilherme Salgado
Olivier Bilodeau (plaxx) wrote : | # |
Hi guys,
I'm a bit concerned when hearing about the XML vs JSON tags.. In the end, aren't they both strings (ex: system:template or system:
- A multi to multi SQL approach would be ugly as hell (one entry per <bookname>) but then what about nested xml in the tag or attributes in the xml node.. where would they end up?
- A list of enabled/disabled tags represented in a row of a note as a packed binary would not handle additional data either.. and would be more coupled with Tomdroid's version..
What do we do here? <buzzword>
On the performance / potential power-saving topic:
Until we have benchmark evidence showing it's not efficient I would opt for simpler code and less db maintenance. I don't plan to do auto db upgrade for 0.4 but just drop the db because no notes can be created locally yet. Someone could work on that if required though.
However, related to your concern Guilherme, to improve things we should save and restore the list of notes from the main activity whenever we can in the lifecycle. This would improve a case or two where it is dropped. Actually I should write that down in doc/dev/TODO...
Thanks for the work guys!
Rodja (trappe) wrote : | # |
I'm by no means a database guy, so i've no clue how to solve the tag storing problem. But a quick Google search (http://
I suggest to use the simplest possible approach for a start (this may be storing all tags comma seperated in a single column) and optimizing it in a seperate branch. This merge is about removing the templates from the main list, not getting a high performance tag storage.
Guilherme Salgado (salgado) wrote : | # |
On Fri, 2010-09-03 at 04:29 +0000, Olivier Bilodeau wrote:
> Hi guys,
>
> I'm a bit concerned when hearing about the XML vs JSON tags.. In the
> end, aren't they both strings (ex: system:template or
> system:
Yes, they're the same thing; I don't know what I had in mind when I
wrote that.
> <bookname> related to the notebook addin) I see tons of potential
> problems with a rigid SQL approach..
Well, that could be extrapolated to the rest of tomdroid, no? I mean,
is a relational database the right thing to store tomboy notes?
>
> - A multi to multi SQL approach would be ugly as hell (one entry per
> <bookname>) but then what about nested xml in the tag or attributes in
> the xml node.. where would they end up?
> - A list of enabled/disabled tags represented in a row of a note as a
> packed binary would not handle additional data either.. and would be
> more coupled with Tomdroid's version..
>
> What do we do here? <buzzword>
> let you guys think about that. Do not hesitate to bring this to the
> -dev list if you feel it deserves to.
We could use CouchDB (http://
not for previous versions. Do you know of any alternatives?
> On the performance / potential power-saving topic:
> Until we have benchmark evidence showing it's not efficient I would
> opt for simpler code and less db maintenance. I don't plan to do auto
> db upgrade for 0.4 but just drop the db because no notes can be
> created locally yet. Someone could work on that if required though.
IMHO, that's not necessary as long as notes are read-only in tomdroid.
I'd really like to keep working on this and do some experiments, but I
won't be able to do that before November as I'm recovering from a
surgery and have my left arm in a sling, so unless anybody else wants to
move this forward, I think it won't be included in 0.4
--
Guilherme Salgado <https:/
- 241. By Guilherme Salgado
-
Store all tags in the DB rather than storing just a flag telling whether or not a note is a notebook template
- 242. By Guilherme Salgado
-
Add a comment explaining why the test will fail in some cases
Guilherme Salgado (salgado) wrote : | # |
Actually, it was fairly easy to do what Rodja suggested, so maybe this can still be included in 0.4
Rodja (trappe) wrote : | # |
Works fine and is defenitly a good thing to have in the 0.4 release featuring 'web sync'.
Preview Diff
1 | === modified file '.classpath' | |||
2 | --- .classpath 2010-08-31 21:00:35 +0000 | |||
3 | +++ .classpath 2010-09-17 21:12:56 +0000 | |||
4 | @@ -6,4 +6,5 @@ | |||
5 | 6 | <classpathentry kind="lib" path="lib/signpost-core-1.2.1.1.jar"/> | 6 | <classpathentry kind="lib" path="lib/signpost-core-1.2.1.1.jar"/> |
6 | 7 | <classpathentry kind="lib" path="lib/signpost-commonshttp4-1.2.1.1.jar"/> | 7 | <classpathentry kind="lib" path="lib/signpost-commonshttp4-1.2.1.1.jar"/> |
7 | 8 | <classpathentry kind="output" path="bin"/> | 8 | <classpathentry kind="output" path="bin"/> |
8 | 9 | <classpathentry kind="src" path="tests"/> | ||
9 | 9 | </classpath> | 10 | </classpath> |
10 | 10 | 11 | ||
11 | === modified file 'AndroidManifest.xml' | |||
12 | --- AndroidManifest.xml 2010-05-24 07:27:14 +0000 | |||
13 | +++ AndroidManifest.xml 2010-09-17 21:12:56 +0000 | |||
14 | @@ -48,7 +48,10 @@ | |||
15 | 48 | 48 | ||
16 | 49 | </activity> | 49 | </activity> |
17 | 50 | 50 | ||
18 | 51 | <uses-library android:name="android.test.runner" /> | ||
19 | 51 | </application> | 52 | </application> |
20 | 52 | 53 | ||
21 | 53 | <uses-permission android:name="android.permission.INTERNET" /> | 54 | <uses-permission android:name="android.permission.INTERNET" /> |
22 | 55 | <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="org.tomdroid"></instrumentation> | ||
23 | 56 | |||
24 | 54 | </manifest> | 57 | </manifest> |
25 | 55 | 58 | ||
26 | === modified file 'src/org/tomdroid/Note.java' | |||
27 | --- src/org/tomdroid/Note.java 2010-08-30 16:33:02 +0000 | |||
28 | +++ src/org/tomdroid/Note.java 2010-09-17 21:12:56 +0000 | |||
29 | @@ -28,6 +28,7 @@ | |||
30 | 28 | import java.util.regex.Pattern; | 28 | import java.util.regex.Pattern; |
31 | 29 | 29 | ||
32 | 30 | import org.json.JSONObject; | 30 | import org.json.JSONObject; |
33 | 31 | import org.json.JSONArray; | ||
34 | 31 | import org.tomdroid.util.NoteContentBuilder; | 32 | import org.tomdroid.util.NoteContentBuilder; |
35 | 32 | import org.tomdroid.util.XmlUtils; | 33 | import org.tomdroid.util.XmlUtils; |
36 | 33 | 34 | ||
37 | @@ -46,6 +47,7 @@ | |||
38 | 46 | public static final String MODIFIED_DATE = "modified_date"; | 47 | public static final String MODIFIED_DATE = "modified_date"; |
39 | 47 | public static final String URL = "url"; | 48 | public static final String URL = "url"; |
40 | 48 | public static final String FILE = "file"; | 49 | public static final String FILE = "file"; |
41 | 50 | public static final String TAGS = "tags"; | ||
42 | 49 | public static final String NOTE_CONTENT = "content"; | 51 | public static final String NOTE_CONTENT = "content"; |
43 | 50 | 52 | ||
44 | 51 | // Logging info | 53 | // Logging info |
45 | @@ -65,6 +67,7 @@ | |||
46 | 65 | private String url; | 67 | private String url; |
47 | 66 | private String fileName; | 68 | private String fileName; |
48 | 67 | private String title; | 69 | private String title; |
49 | 70 | private String tags; | ||
50 | 68 | private Time lastChangeDate; | 71 | private Time lastChangeDate; |
51 | 69 | private int dbId; | 72 | private int dbId; |
52 | 70 | private UUID guid; | 73 | private UUID guid; |
53 | @@ -85,8 +88,21 @@ | |||
54 | 85 | setGuid(json.optString("guid")); | 88 | setGuid(json.optString("guid")); |
55 | 86 | setLastChangeDate(json.optString("last-change-date")); | 89 | setLastChangeDate(json.optString("last-change-date")); |
56 | 87 | setXmlContent(json.optString("note-content")); | 90 | setXmlContent(json.optString("note-content")); |
57 | 91 | JSONArray jtags = json.optJSONArray("tags"); | ||
58 | 92 | String tag; | ||
59 | 93 | tags = new String(); | ||
60 | 94 | if (jtags != null) { | ||
61 | 95 | for (int i = 0; i < jtags.length(); i++ ) { | ||
62 | 96 | tag = jtags.optString(i); | ||
63 | 97 | tags += tag + ","; | ||
64 | 98 | } | ||
65 | 99 | } | ||
66 | 88 | } | 100 | } |
67 | 89 | 101 | ||
68 | 102 | public String getTags() { | ||
69 | 103 | return tags; | ||
70 | 104 | } | ||
71 | 105 | |||
72 | 90 | public String getUrl() { | 106 | public String getUrl() { |
73 | 91 | return url; | 107 | return url; |
74 | 92 | } | 108 | } |
75 | @@ -150,7 +166,7 @@ | |||
76 | 150 | public void setGuid(String guid) { | 166 | public void setGuid(String guid) { |
77 | 151 | this.guid = UUID.fromString(guid); | 167 | this.guid = UUID.fromString(guid); |
78 | 152 | } | 168 | } |
80 | 153 | 169 | ||
81 | 154 | // TODO: should this handler passed around evolve into an observer pattern? | 170 | // TODO: should this handler passed around evolve into an observer pattern? |
82 | 155 | public SpannableStringBuilder getNoteContent(Handler handler) { | 171 | public SpannableStringBuilder getNoteContent(Handler handler) { |
83 | 156 | 172 | ||
84 | 157 | 173 | ||
85 | === modified file 'src/org/tomdroid/NoteManager.java' | |||
86 | --- src/org/tomdroid/NoteManager.java 2010-03-21 18:38:49 +0000 | |||
87 | +++ src/org/tomdroid/NoteManager.java 2010-09-17 21:12:56 +0000 | |||
88 | @@ -96,6 +96,7 @@ | |||
89 | 96 | // Notice that we store the date in UTC because sqlite doesn't handle RFC3339 timezone information | 96 | // Notice that we store the date in UTC because sqlite doesn't handle RFC3339 timezone information |
90 | 97 | values.put(Note.MODIFIED_DATE, note.getLastChangeDate().format3339(false)); | 97 | values.put(Note.MODIFIED_DATE, note.getLastChangeDate().format3339(false)); |
91 | 98 | values.put(Note.NOTE_CONTENT, note.getXmlContent()); | 98 | values.put(Note.NOTE_CONTENT, note.getXmlContent()); |
92 | 99 | values.put(Note.TAGS, note.getTags()); | ||
93 | 99 | 100 | ||
94 | 100 | if (managedCursor.getCount() == 0) { | 101 | if (managedCursor.getCount() == 0) { |
95 | 101 | 102 | ||
96 | @@ -127,18 +128,26 @@ | |||
97 | 127 | return false; | 128 | return false; |
98 | 128 | } | 129 | } |
99 | 129 | 130 | ||
100 | 131 | public static Cursor getAllNotes(Activity activity, Boolean includeNotebookTemplates) { | ||
101 | 132 | // get a cursor representing all notes from the NoteProvider | ||
102 | 133 | Uri notes = Tomdroid.CONTENT_URI; | ||
103 | 134 | String where = null; | ||
104 | 135 | if (!includeNotebookTemplates) { | ||
105 | 136 | where = Note.TAGS + " NOT LIKE '%" + "system:template" + "%'"; | ||
106 | 137 | } | ||
107 | 138 | return activity.managedQuery(notes, LIST_PROJECTION, where, null, null); | ||
108 | 139 | } | ||
109 | 140 | |||
110 | 141 | |||
111 | 130 | public static ListAdapter getListAdapter(Activity activity) { | 142 | public static ListAdapter getListAdapter(Activity activity) { |
116 | 131 | 143 | Cursor notesCursor = getAllNotes(activity, false); | |
113 | 132 | // get a cursor representing all notes from the NoteProvider | ||
114 | 133 | Uri notes = Tomdroid.CONTENT_URI; | ||
115 | 134 | Cursor notesCursor = activity.managedQuery(notes, LIST_PROJECTION, null, null, null); | ||
117 | 135 | 144 | ||
118 | 136 | // set up an adapter binding the TITLE field of the cursor to the list item | 145 | // set up an adapter binding the TITLE field of the cursor to the list item |
119 | 137 | String[] from = new String[] { Note.TITLE }; | 146 | String[] from = new String[] { Note.TITLE }; |
120 | 138 | int[] to = new int[] { R.id.note_title }; | 147 | int[] to = new int[] { R.id.note_title }; |
121 | 139 | return new SimpleCursorAdapter(activity, R.layout.main_list_item, notesCursor, from, to); | 148 | return new SimpleCursorAdapter(activity, R.layout.main_list_item, notesCursor, from, to); |
122 | 140 | } | 149 | } |
124 | 141 | 150 | ||
125 | 142 | // gets the titles of the notes present in the db, used in ViewNote.buildLinkifyPattern() | 151 | // gets the titles of the notes present in the db, used in ViewNote.buildLinkifyPattern() |
126 | 143 | public static Cursor getTitles(Activity activity) { | 152 | public static Cursor getTitles(Activity activity) { |
127 | 144 | 153 | ||
128 | @@ -149,7 +158,7 @@ | |||
129 | 149 | // gets the ids of the notes present in the db, used in SyncService.deleteNotes() | 158 | // gets the ids of the notes present in the db, used in SyncService.deleteNotes() |
130 | 150 | public static Cursor getGuids(Activity activity) { | 159 | public static Cursor getGuids(Activity activity) { |
131 | 151 | 160 | ||
133 | 152 | // get a cursor containing the notes titles | 161 | // get a cursor containing the notes guids |
134 | 153 | return activity.managedQuery(Tomdroid.CONTENT_URI, GUID_PROJECTION, null, null, null); | 162 | return activity.managedQuery(Tomdroid.CONTENT_URI, GUID_PROJECTION, null, null, null); |
135 | 154 | } | 163 | } |
136 | 155 | 164 | ||
137 | 156 | 165 | ||
138 | === modified file 'src/org/tomdroid/NoteProvider.java' | |||
139 | --- src/org/tomdroid/NoteProvider.java 2010-08-30 16:33:02 +0000 | |||
140 | +++ src/org/tomdroid/NoteProvider.java 2010-09-17 21:12:56 +0000 | |||
141 | @@ -69,7 +69,7 @@ | |||
142 | 69 | // -- | 69 | // -- |
143 | 70 | private static final String DATABASE_NAME = "tomdroid-notes.db"; | 70 | private static final String DATABASE_NAME = "tomdroid-notes.db"; |
144 | 71 | private static final String DB_TABLE_NOTES = "notes"; | 71 | private static final String DB_TABLE_NOTES = "notes"; |
146 | 72 | private static final int DB_VERSION = 2; | 72 | private static final int DB_VERSION = 3; |
147 | 73 | private static final String DEFAULT_SORT_ORDER = Note.MODIFIED_DATE + " DESC"; | 73 | private static final String DEFAULT_SORT_ORDER = Note.MODIFIED_DATE + " DESC"; |
148 | 74 | 74 | ||
149 | 75 | private static HashMap<String, String> notesProjectionMap; | 75 | private static HashMap<String, String> notesProjectionMap; |
150 | @@ -100,7 +100,8 @@ | |||
151 | 100 | + Note.TITLE + " TEXT," | 100 | + Note.TITLE + " TEXT," |
152 | 101 | + Note.FILE + " TEXT," | 101 | + Note.FILE + " TEXT," |
153 | 102 | + Note.NOTE_CONTENT + " TEXT," | 102 | + Note.NOTE_CONTENT + " TEXT," |
155 | 103 | + Note.MODIFIED_DATE + " STRING" | 103 | + Note.MODIFIED_DATE + " STRING," |
156 | 104 | + Note.TAGS + " STRING" | ||
157 | 104 | + ");"); | 105 | + ");"); |
158 | 105 | } | 106 | } |
159 | 106 | 107 | ||
160 | @@ -297,6 +298,7 @@ | |||
161 | 297 | notesProjectionMap.put(Note.TITLE, Note.TITLE); | 298 | notesProjectionMap.put(Note.TITLE, Note.TITLE); |
162 | 298 | notesProjectionMap.put(Note.FILE, Note.FILE); | 299 | notesProjectionMap.put(Note.FILE, Note.FILE); |
163 | 299 | notesProjectionMap.put(Note.NOTE_CONTENT, Note.NOTE_CONTENT); | 300 | notesProjectionMap.put(Note.NOTE_CONTENT, Note.NOTE_CONTENT); |
164 | 301 | notesProjectionMap.put(Note.TAGS, Note.TAGS); | ||
165 | 300 | notesProjectionMap.put(Note.MODIFIED_DATE, Note.MODIFIED_DATE); | 302 | notesProjectionMap.put(Note.MODIFIED_DATE, Note.MODIFIED_DATE); |
166 | 301 | } | 303 | } |
167 | 302 | } | 304 | } |
168 | 303 | 305 | ||
169 | === added directory 'tests' | |||
170 | === added directory 'tests/org' | |||
171 | === added directory 'tests/org/tomdroid' | |||
172 | === added file 'tests/org/tomdroid/NoteManagerTest.java' | |||
173 | --- tests/org/tomdroid/NoteManagerTest.java 1970-01-01 00:00:00 +0000 | |||
174 | +++ tests/org/tomdroid/NoteManagerTest.java 2010-09-17 21:12:56 +0000 | |||
175 | @@ -0,0 +1,74 @@ | |||
176 | 1 | package org.tomdroid; | ||
177 | 2 | |||
178 | 3 | import org.json.JSONObject; | ||
179 | 4 | import org.tomdroid.Note; | ||
180 | 5 | import org.tomdroid.NoteManager; | ||
181 | 6 | import org.tomdroid.ui.Tomdroid; | ||
182 | 7 | import org.tomdroid.util.Preferences; | ||
183 | 8 | |||
184 | 9 | import android.app.Activity; | ||
185 | 10 | import android.content.Intent; | ||
186 | 11 | import android.database.Cursor; | ||
187 | 12 | import android.test.ActivityUnitTestCase; | ||
188 | 13 | |||
189 | 14 | public class NoteManagerTest extends ActivityUnitTestCase<Tomdroid> { | ||
190 | 15 | |||
191 | 16 | public NoteManagerTest() { | ||
192 | 17 | super(Tomdroid.class); | ||
193 | 18 | } | ||
194 | 19 | |||
195 | 20 | public void testGetAllNotes() throws Exception { | ||
196 | 21 | Activity activity = getActivity(); | ||
197 | 22 | putNotes(activity); | ||
198 | 23 | Cursor cursor; | ||
199 | 24 | // Get all notes excluding the notebook template ones. | ||
200 | 25 | cursor = NoteManager.getAllNotes(activity, false); | ||
201 | 26 | assertEquals(1, cursor.getCount()); | ||
202 | 27 | |||
203 | 28 | // Get all notes, including notebook templates this time. | ||
204 | 29 | cursor = NoteManager.getAllNotes(activity, true); | ||
205 | 30 | assertEquals(2, cursor.getCount()); | ||
206 | 31 | } | ||
207 | 32 | |||
208 | 33 | private void putNotes(Activity a) throws Exception { | ||
209 | 34 | // Add a regular note to the content manager. | ||
210 | 35 | JSONObject note = new JSONObject( | ||
211 | 36 | "{'title': 'foo', 'note-content': 'bar', " + | ||
212 | 37 | "'guid': '002e91a2-2e34-4e2d-bf88-21def49a7704', " + | ||
213 | 38 | "'last-change-date': '2009-04-19T21:29:23.2197340-07:00', " + | ||
214 | 39 | "'tags': ['tag1', 'tag2']}"); | ||
215 | 40 | Note n = new Note(note); | ||
216 | 41 | NoteManager.putNote(a, n); | ||
217 | 42 | |||
218 | 43 | // Add a notebook template to the content manager. | ||
219 | 44 | JSONObject template = new JSONObject( | ||
220 | 45 | "{'title': 'foo', 'note-content': 'bar', " + | ||
221 | 46 | "'guid': '992e91a2-2e34-4e2d-bf88-21def49a7712', " + | ||
222 | 47 | "'last-change-date': '2009-04-19T21:29:23.2197340-07:00', " + | ||
223 | 48 | "'tags': ['system:template', 'tag2']}"); | ||
224 | 49 | Note t = new Note(template); | ||
225 | 50 | NoteManager.putNote(a, t); | ||
226 | 51 | } | ||
227 | 52 | |||
228 | 53 | @Override | ||
229 | 54 | public void setUp() throws Exception { | ||
230 | 55 | super.setUp(); | ||
231 | 56 | // XXX: For some reason this will raise an | ||
232 | 57 | // "Unable to add window -- token null is not for an application" | ||
233 | 58 | // error when you run the test after wiping user data from the emulator. | ||
234 | 59 | // The error is actually raised when we try to display the AlertDialog that | ||
235 | 60 | // is shown the first time the user runs tomdroid. | ||
236 | 61 | startActivity(new Intent(), null, null); | ||
237 | 62 | // XXX: Soon we'll be able to replace the two lines below with LocalStorage.resetDatabase(). | ||
238 | 63 | getActivity().getContentResolver().delete(Tomdroid.CONTENT_URI, null, null); | ||
239 | 64 | Preferences.putLong(Preferences.Key.LATEST_SYNC_REVISION, 0); | ||
240 | 65 | } | ||
241 | 66 | |||
242 | 67 | @Override | ||
243 | 68 | public void tearDown() throws Exception { | ||
244 | 69 | // XXX: Soon we'll be able to replace the two lines below with LocalStorage.resetDatabase(). | ||
245 | 70 | getActivity().getContentResolver().delete(Tomdroid.CONTENT_URI, null, null); | ||
246 | 71 | Preferences.putLong(Preferences.Key.LATEST_SYNC_REVISION, 0); | ||
247 | 72 | super.tearDown(); | ||
248 | 73 | } | ||
249 | 74 | } | ||
250 | 0 | 75 | ||
251 | === added file 'tests/org/tomdroid/NoteTest.java' | |||
252 | --- tests/org/tomdroid/NoteTest.java 1970-01-01 00:00:00 +0000 | |||
253 | +++ tests/org/tomdroid/NoteTest.java 2010-09-17 21:12:56 +0000 | |||
254 | @@ -0,0 +1,35 @@ | |||
255 | 1 | package org.tomdroid; | ||
256 | 2 | |||
257 | 3 | import junit.framework.Assert; | ||
258 | 4 | import junit.framework.TestCase; | ||
259 | 5 | |||
260 | 6 | import org.tomdroid.Note; | ||
261 | 7 | import org.json.JSONException; | ||
262 | 8 | import org.json.JSONObject; | ||
263 | 9 | |||
264 | 10 | |||
265 | 11 | public class NoteTest extends TestCase { | ||
266 | 12 | |||
267 | 13 | public void testConstructorForNoteWithTags() throws JSONException { | ||
268 | 14 | JSONObject json = new JSONObject( | ||
269 | 15 | "{'title': 'foo', 'note-content': 'bar', " + | ||
270 | 16 | "'guid': '002e91a2-2e34-4e2d-bf88-21def49a7705', " + | ||
271 | 17 | "'last-change-date': '2009-04-19T21:29:23.2197340-07:00', " + | ||
272 | 18 | "'tags': ['tag1', 'tag2']}"); | ||
273 | 19 | Note n = new Note(json); | ||
274 | 20 | Assert.assertEquals("foo", n.getTitle()); | ||
275 | 21 | Assert.assertEquals("002e91a2-2e34-4e2d-bf88-21def49a7705", n.getGuid().toString()); | ||
276 | 22 | Assert.assertEquals("bar", n.getXmlContent()); | ||
277 | 23 | Assert.assertEquals("tag1,tag2,", n.getTags()); | ||
278 | 24 | } | ||
279 | 25 | |||
280 | 26 | public void testConstructorForNoteWithNoTags() throws JSONException { | ||
281 | 27 | JSONObject json = new JSONObject( | ||
282 | 28 | "{'title': 'foo', 'note-content': 'bar', " + | ||
283 | 29 | "'guid': '002e91a2-2e34-4e2d-bf88-21def49a7705', " + | ||
284 | 30 | "'last-change-date': '2009-04-19T21:29:23.2197340-07:00'}"); | ||
285 | 31 | Note n = new Note(json); | ||
286 | 32 | Assert.assertEquals("foo", n.getTitle()); | ||
287 | 33 | Assert.assertEquals("", n.getTags()); | ||
288 | 34 | } | ||
289 | 35 | } |
Rodja, please review this and integrate it in sync-ui if you don't see any problems with it.