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

commented Mar 8, 2016

+1
I want to get the Full guide.

@inaling

This comment has been minimized.

Copy link

commented Mar 22, 2016

@frosas

This comment has been minimized.

Copy link

commented Jul 4, 2017

Nice. Any chance to have a web API?

@aquatix

This comment has been minimized.

Copy link

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.

@6bytes

This comment has been minimized.

Copy link

commented Feb 15, 2018

+1 for CLI tool

@tophopstop

This comment has been minimized.

Copy link

commented Mar 1, 2018

Another +1 for web API.

@itantrik

This comment has been minimized.

Copy link

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

commented Aug 13, 2018

web api +1

@sdmunozsierra

This comment has been minimized.

Copy link

commented Sep 7, 2018

Tasker fun 😺

@kuzzmi

This comment has been minimized.

Copy link

commented Nov 22, 2018

Web API +1

@walkerofmargins

This comment has been minimized.

Copy link

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

commented Jan 3, 2019

Joining the club of Web API fans

@braydenhouston

This comment has been minimized.

Copy link

commented Jan 13, 2019

Web API please! +1

@adiroiban

This comment has been minimized.

Copy link

commented Feb 8, 2019

Web API please :)

@aliasgarlabs

This comment has been minimized.

Copy link

commented Feb 11, 2019

REST APIs please :)

@vbifonixor

This comment has been minimized.

Copy link

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

commented Feb 26, 2019

Web API pls k thanx bye

@SimonKapl

This comment has been minimized.

Copy link

commented Apr 15, 2019

REST API pls

@akosipax

This comment has been minimized.

Copy link

commented Apr 20, 2019

+1 on Web/REST API

@svenkapudija

This comment has been minimized.

Copy link

commented May 15, 2019

+1 on REST API

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.