Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new gtasks sync metadata for saving last sync time
- Loading branch information
Tim Su
committed
Nov 8, 2011
1 parent
7ac45fd
commit 07669aa
Showing
4 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksSyncMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.todoroo.astrid.gtasks; | ||
|
||
import com.todoroo.andlib.data.Property; | ||
import com.todoroo.andlib.data.Property.LongProperty; | ||
import com.todoroo.andlib.data.TodorooCursor; | ||
import com.todoroo.andlib.sql.Query; | ||
import com.todoroo.astrid.dao.MetadataDao; | ||
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; | ||
import com.todoroo.astrid.data.Metadata; | ||
|
||
/** | ||
* Metadata entries for synchronizing a GTasks Task | ||
* @author Tim Su <tim@todoroo.com> | ||
* | ||
*/ | ||
public class GtasksSyncMetadata { | ||
|
||
/** metadata key */ | ||
public static final String METADATA_KEY = "gtasks-sync"; //$NON-NLS-1$ | ||
|
||
/** last sync date*/ | ||
public static final LongProperty LAST_SYNC = new LongProperty(Metadata.TABLE, | ||
Metadata.VALUE1.name); | ||
|
||
/** | ||
* Helper to set value | ||
* @param metadataDao | ||
* @param id | ||
* @param property | ||
* @param now | ||
*/ | ||
public static <T> void set(MetadataDao metadataDao, long taskId, | ||
Property<T> property, T value) { | ||
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES). | ||
where(MetadataCriteria.byTaskAndwithKey(taskId, METADATA_KEY))); | ||
Metadata metadata = new Metadata(); | ||
if(cursor.getCount() == 0) { | ||
metadata.setValue(Metadata.TASK, taskId); | ||
metadata.setValue(Metadata.KEY, METADATA_KEY); | ||
} else { | ||
cursor.moveToFirst(); | ||
metadata.readFromCursor(cursor); | ||
} | ||
|
||
metadata.setValue(property, value); | ||
metadataDao.persist(metadata); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 comments
on commit 07669aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sam what do you think of this? unfortunately, it's late so i haven't tested it. i'll do it tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, makes sense to me. I'll give it a try right now.
Shouldn't this be GtasksSyncMetadata.LAST_SYNC.gt(lastSyncDate)? Filter out the ones that have been synced more recently than last sync?