package com.mokelab.sample.contentprovider.provider.todo;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

/**
 * Content Provider for Todo
 */
public class TodoProvider extends ContentProvider {

    private static final String AUTHORITY = "com.mokelab.todo.provider";

    // region URI type
    private static final int URITYPE_TODO_LIST = 1;
    private static final int URITYPE_TODO = 2;
    // endregion

    private static final UriMatcher sUriMatcher;

    static {
        sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        sUriMatcher.addURI(AUTHORITY, "users/*/todos", URITYPE_TODO_LIST);
        sUriMatcher.addURI(AUTHORITY, "users/*/todos/#", URITYPE_TODO);
    }

    @Override
    public boolean onCreate() {
        return true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        return null;
    }

    @Override
    public String getType(Uri uri) {
        return null;
    }

    @Override
    public Uri insert(Uri uri, ContentValues contentValues) {
        return null;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return 0;
    }

    @Override
    public int update(Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) {
        return 0;
    }
}

@@ -810,49 +810,193 @@
     
-@Override%0A    public boolean onCreate() %7B
+private TodoDB mTodoDB;%0A    private TodoDAO mTodoDAO;%0A%0A    @Override%0A    public boolean onCreate() %7B%0A        mTodoDB = new TodoDB(getContext());%0A        mTodoDAO = new TodoDAO(mTodoDB);
 %0A   
@@ -1329,24 +1329,160 @@
 ntValues) %7B%0A
+        switch (sUriMatcher.match(uri)) %7B%0A        case URITYPE_TODO_LIST:%0A            return insertLocal(uri, contentValues);%0A        %7D%0A
         retu
@@ -1752,11 +1752,604 @@
 0;%0A    %7D
+%0A%0A    private Uri insertLocal(Uri uri, ContentValues contentValues) %7B%0A        // Uri = content://com.mokelab.todo.provider/users/%7BuserId%7D/todos%0A        // pathSegments%5B0%5D = users%0A        // pathSegments%5B1%5D = %7BuserId%7D%0A        // pathSegments%5B2%5D = todos%0A        String userId = uri.getPathSegments().get(1);%0A        String todo = contentValues.getAsString(TodoColumns.TODO);%0A%0A        long id = mTodoDAO.insert(userId, %22%22, System.currentTimeMillis(), 0, todo);%0A        if (id == -1) %7B return null; %7D%0A%0A        return Uri.parse(%22content://%22 + AUTHORITY + %22/users/%22 + userId + %22/todos/%22 + id);%0A    %7D
 %0A%7D%0A

Implement insert method