Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A utility class to work with TickTick's Content Provider. A full guide is available at https://docs.google.com/document/d/1zo0JdIWnQWi-D0v7xikknEnsLj4RmrzOuqzScdR_tm8
/**
* This class provides the URI, const values and some methods to work with TickTick's Content Provider.
*
* A guide is available on https://docs.google.com/document/d/1zo0JdIWnQWi-D0v7xikknEnsLj4RmrzOuqzScdR_tm8
*/
public class TickTickProviderHelper {
private static final Uri TASK_URI = Uri.parse("content://com.ticktick.task.data/tasks");
private static final Uri PROJECT_URI = Uri.parse("content://com.ticktick.task.data/tasklist");
private static final String TASK_CONTENT_ITEM_TYPE = "vnd.android.cursor.item/ticktick.task.task";
enum TaskColumns {
ID, LIST_ID, TITLE, DUEDATE, SORT_ORDER, COMPLETED, PRIORITY, REMINDER_TIME, REPEAT_FLAG
}
enum ProjectColumns {
ID, NAME, COLOR
}
public static final class PriorityLevel {
public final static int Level0 = 0;// none
public final static int Level1 = 1;// low
public final static int Level2 = 2;
public final static int Level3 = 3;// medium
public final static int Level4 = 4;
public final static int Level5 = 5;// high
}
/**
* Return all Projects of current TickTick account
*
* @param context
* @return
*/
public static List<TickTickProject> getAllProjects(Context context) {
List<TickTickProject> projects = new ArrayList<TickTickProject>();
ContentResolver resolver = context.getContentResolver();
Cursor cursor = null;
try {
cursor = resolver.query(PROJECT_URI, null, null, null, null);
if (cursor.moveToFirst()) {
do {
TickTickProject project = cursorToProject(cursor);
projects.add(project);
} while (cursor.moveToNext());
}
return projects;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
/**
* Return all tasks (With completed tasks) of current TickTick account
*
* @param context
* @return
*/
public static List<TickTickTask> getAllTasks(Context context) {
List<TickTickTask> tasks = new ArrayList<TickTickTask>();
ContentResolver resolver = context.getContentResolver();
Cursor cursor = null;
try {
cursor = resolver.query(TASK_URI, null, null, new String[] {
"-1", "true"
}, null);
if (cursor.moveToFirst()) {
do {
TickTickTask task = cursorToTask(cursor);
tasks.add(task);
} while (cursor.moveToNext());
}
return tasks;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
/**
* Add a new task to TickTick
*
* @param projectId
* , the task will be add to this project
* @param context
*/
public static void insertTask(long projectId, Context context) {
Intent editIntent;
editIntent = new Intent(Intent.ACTION_INSERT);
editIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
editIntent.setDataAndType(TASK_URI.buildUpon().appendEncodedPath(projectId + "").build(),
TASK_CONTENT_ITEM_TYPE);
context.startActivity(editIntent);
}
/**
* View a task of TickTick
*
* @param projectId
* , the Project
* @param taskId
* , the task
* @param context
*/
public static void viewTask(long projectId, long taskId, Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("tasklist_id", projectId);
intent.setDataAndType(ContentUris.withAppendedId(TASK_URI, taskId), TASK_CONTENT_ITEM_TYPE);
context.startActivity(intent);
}
private static TickTickTask cursorToTask(Cursor cursor) {
TickTickTask task = new TickTickTask();
task.id = cursor.getLong(TaskColumns.ID.ordinal());
task.projectId = cursor.getLong(TaskColumns.LIST_ID.ordinal());
task.title = cursor.getString(TaskColumns.TITLE.ordinal());
task.dueDate = cursor.getLong(TaskColumns.DUEDATE.ordinal());
task.sortOrder = cursor.getLong(TaskColumns.SORT_ORDER.ordinal());
task.completedTime = cursor.getLong(TaskColumns.COMPLETED.ordinal());
task.priority = cursor.getInt(TaskColumns.PRIORITY.ordinal());
task.reminderTime = cursor.getLong(TaskColumns.REMINDER_TIME.ordinal());
return task;
}
private static TickTickProject cursorToProject(Cursor cursor) {
TickTickProject project = new TickTickProject();
project.id = cursor.getLong(ProjectColumns.ID.ordinal());
project.name = cursor.getString(ProjectColumns.NAME.ordinal());
project.color = cursor.getString(ProjectColumns.COLOR.ordinal());
return project;
}
public static class TickTickTask {
public long id;
public long projectId;
public String title;
public long dueDate;
public long sortOrder;
public long completedTime;
public int priority;
public long reminderTime;
}
public static class TickTickProject {
public long id;
public String name;
public String color;
}
}
@samarth-math

This comment has been minimized.

@axsann

This comment has been minimized.

Copy link

axsann commented Mar 8, 2016

+1
I want to get the Full guide.

@inaling

This comment has been minimized.

Copy link

inaling commented Mar 22, 2016

@frosas

This comment has been minimized.

Copy link

frosas commented Jul 4, 2017

Nice. Any chance to have a web API?

@aquatix

This comment has been minimized.

Copy link

aquatix commented Jan 5, 2018

I would really like to have a web API too, if only for reading. I'd like to create a CLI tool listing my current upcoming todo's.

@ctrl-b

This comment has been minimized.

Copy link

ctrl-b commented Feb 15, 2018

+1 for CLI tool

@tophopstop

This comment has been minimized.

Copy link

tophopstop commented Mar 1, 2018

Another +1 for web API.

@itantrik

This comment has been minimized.

Copy link

itantrik commented Apr 5, 2018

Yes. I think a REST API will work wonders. Or in a shorter term something along the lines of slack/zapier integration.

@htkcodes

This comment has been minimized.

Copy link

htkcodes commented Aug 13, 2018

web api +1

@sdmunozsierra

This comment has been minimized.

Copy link

sdmunozsierra commented Sep 7, 2018

Tasker fun 😺

@kuzzmi

This comment has been minimized.

Copy link

kuzzmi commented Nov 22, 2018

Web API +1

@walkerofmargins

This comment has been minimized.

Copy link

walkerofmargins commented Dec 20, 2018

Web API +2

Will move over to Tick Tick from Todoist as soon as this is available.

@SpadarShut

This comment has been minimized.

Copy link

SpadarShut commented Jan 3, 2019

Joining the club of Web API fans

@braydenhouston

This comment has been minimized.

Copy link

braydenhouston commented Jan 13, 2019

Web API please! +1

@adiroiban

This comment has been minimized.

Copy link

adiroiban commented Feb 8, 2019

Web API please :)

@aliasgarlabs

This comment has been minimized.

Copy link

aliasgarlabs commented Feb 11, 2019

REST APIs please :)

@vbifonixor

This comment has been minimized.

Copy link

vbifonixor commented Feb 21, 2019

+1 for web api. Wanna create some cool cli dashboard for my day

@tinskanix

This comment has been minimized.

Copy link

tinskanix commented Feb 26, 2019

Web API pls k thanx bye

@SimonKapl

This comment has been minimized.

Copy link

SimonKapl commented Apr 15, 2019

REST API pls

@paxcodes

This comment has been minimized.

Copy link

paxcodes commented Apr 20, 2019

+1 on Web/REST API

@svenkapudija

This comment has been minimized.

Copy link

svenkapudija commented May 15, 2019

+1 on REST API

@Jedliu

This comment has been minimized.

Copy link

Jedliu commented Jun 12, 2019

+1 on REST API

@sigurdmm

This comment has been minimized.

Copy link

sigurdmm commented Jul 24, 2019

+1 on REST API

@tigattack

This comment has been minimized.

Copy link

tigattack commented Aug 27, 2019

+1 on REST API

@rppig42

This comment has been minimized.

Copy link

rppig42 commented Aug 27, 2019

+1 on REST API

@silasabbott

This comment has been minimized.

Copy link

silasabbott commented Aug 27, 2019

+1 on REST API

@A-ezzat1997

This comment has been minimized.

Copy link

A-ezzat1997 commented Aug 28, 2019

+1 on REST API

@jackaaron

This comment has been minimized.

Copy link

jackaaron commented Sep 5, 2019

+1 on REST API

@kadaliao

This comment has been minimized.

Copy link

kadaliao commented Sep 14, 2019

+1 on REST API

@aadilayub

This comment has been minimized.

Copy link

aadilayub commented Oct 9, 2019

+1 on REST API. You guys have built an amazing product. The only thing keeping me from shifting completely from Todoist is API availability (needed for linux integration)

@c01nd01r

This comment has been minimized.

Copy link

c01nd01r commented Oct 10, 2019

+1. I am planing to use it for my browser extension.

@eHorlyck

This comment has been minimized.

Copy link

eHorlyck commented Oct 15, 2019

+1 REST API

@Kdkulakov

This comment has been minimized.

Copy link

Kdkulakov commented Nov 1, 2019

+1 REST API

@aadilayub

This comment has been minimized.

Copy link

aadilayub commented Nov 1, 2019

Also, the documentation linked in the description is not viewable

@velansalis

This comment has been minimized.

Copy link

velansalis commented Nov 16, 2019

+1 REST API

@szymczakk

This comment has been minimized.

Copy link

szymczakk commented Nov 24, 2019

+1 REST API PLS! The only thing that keep me with todoist is API. Come on! If you need help with it ping me, will be happy to help you 😉

@pavel-alay

This comment has been minimized.

Copy link

pavel-alay commented Nov 28, 2019

+1 for REST API

@wieli99

This comment has been minimized.

Copy link

wieli99 commented Nov 30, 2019

+1 REST API would be awesome!

@rvsosn

This comment has been minimized.

Copy link

rvsosn commented Dec 3, 2019

+1 REST API

@jackperry

This comment has been minimized.

Copy link

jackperry commented Dec 3, 2019

+1 for REST API. Really the only holdover keeping me from committing to a move from Todoist.

@trevorlang

This comment has been minimized.

Copy link

trevorlang commented Dec 17, 2019

+1 for REST API. That would be fantastic. Like others, this is the only concern I have in moving over from Todoist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.