// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Files implements FilesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_FILES).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = { ID, NAME, FILENAME,
// 			COMMENT, NODE_ID };
// 	public static final String DEFAULT_SORT = NAME + " ASC";
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// 
// 	public static String getFilename(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildFilenameUri(String filename) {
// 		return CONTENT_URI.buildUpon().appendPath(filename)
// 				.appendPath("filename").build();
// 	}
// 
// 	public static Uri buildIdUri(Long fileId) {
// 		return CONTENT_URI.buildUpon().appendPath(fileId.toString()).build();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class OrgData implements OrgDataColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_ORGDATA).build();
// 
// 	public static final Uri CONTENT_URI_TODOS =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 	public static final String DEFAULT_SORT = ID + " ASC";
// 	public static final String NAME_SORT = NAME + " ASC";
// 	public static final String POSITION_SORT = POSITION + " ASC";
// 	public static final String[] DEFAULT_COLUMNS = {ID, NAME, TODO, TAGS, TAGS_INHERITED,
// 			PARENT_ID, PAYLOAD, LEVEL, PRIORITY, FILE_ID, POSITION, SCHEDULED, SCHEDULED_DATE_ONLY, DEADLINE, DEADLINE_DATE_ONLY};
// 
// 	public static String getId(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildIdUri(String id) {
// 		return CONTENT_URI.buildUpon().appendPath(id).build();
// 	}
// 
// 	public static Uri buildIdUri(Long id) {
// 		return buildIdUri(id.toString());
// 	}
// 
// 	public static Uri buildChildrenUri(String parentId) {
// 		return CONTENT_URI.buildUpon().appendPath(parentId).appendPath("children").build();
// 	}
// 
// 	public static Uri buildChildrenUri(long node_id) {
// 		return buildChildrenUri(Long.toString(node_id));
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Priorities implements PrioritiesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_PRIORITIES).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Tags implements TagsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TAGS).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Timestamps implements TimestampsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TIMESTAMPS).build();
// 	public static final String[] DEFAULT_COLUMNS = {NODE_ID, FILE_ID, TYPE, TIMESTAMP, ALL_DAY};
// 
// 	public static Uri buildIdUri(Long id) {
// 		return CONTENT_URI.buildUpon().appendPath(id.toString()).build();
// 	}
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Todos implements TodosColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = {NAME, ID, GROUP, ISDONE};
// }


import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import com.matburt.mobileorg.orgdata.OrgContract.Files;
import com.matburt.mobileorg.orgdata.OrgContract.OrgData;
import com.matburt.mobileorg.orgdata.OrgContract.Priorities;
import com.matburt.mobileorg.orgdata.OrgContract.Tags;
import com.matburt.mobileorg.orgdata.OrgContract.Timestamps;
import com.matburt.mobileorg.orgdata.OrgContract.Todos;
import com.matburt.mobileorg.util.OrgFileNotFoundException;
import com.matburt.mobileorg.util.OrgNodeNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
	public static ArrayList<String> getTodos(ContentResolver resolver) {
		Cursor cursor = resolver.query(Todos.CONTENT_URI, new String[] { Todos.NAME }, null, null, Todos.ID);
		if(cursor==null) return new ArrayList<>();

		ArrayList<String> todos = cursorToArrayList(cursor);

		return todos;
	}
	
	public static void setPriorities(ArrayList<String> priorities, ContentResolver resolver) {
		resolver.delete(Priorities.CONTENT_URI, null, null);

		for (String priority : priorities) {
			ContentValues values = new ContentValues();
			values.put(Priorities.NAME, priority);
			resolver.insert(Priorities.CONTENT_URI, values);
		}
	}

	public static ArrayList<String> getPriorities(ContentResolver resolver) {
		Cursor cursor = resolver.query(Priorities.CONTENT_URI, new String[] { Priorities.NAME },
				null, null, Priorities.ID);
		ArrayList<String> priorities = cursorToArrayList(cursor);

		cursor.close();
		return priorities;
	}
	

	public static void setTags(ArrayList<String> priorities, ContentResolver resolver) {
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Files implements FilesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_FILES).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = { ID, NAME, FILENAME,
// 			COMMENT, NODE_ID };
// 	public static final String DEFAULT_SORT = NAME + " ASC";
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// 
// 	public static String getFilename(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildFilenameUri(String filename) {
// 		return CONTENT_URI.buildUpon().appendPath(filename)
// 				.appendPath("filename").build();
// 	}
// 
// 	public static Uri buildIdUri(Long fileId) {
// 		return CONTENT_URI.buildUpon().appendPath(fileId.toString()).build();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class OrgData implements OrgDataColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_ORGDATA).build();
// 
// 	public static final Uri CONTENT_URI_TODOS =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 	public static final String DEFAULT_SORT = ID + " ASC";
// 	public static final String NAME_SORT = NAME + " ASC";
// 	public static final String POSITION_SORT = POSITION + " ASC";
// 	public static final String[] DEFAULT_COLUMNS = {ID, NAME, TODO, TAGS, TAGS_INHERITED,
// 			PARENT_ID, PAYLOAD, LEVEL, PRIORITY, FILE_ID, POSITION, SCHEDULED, SCHEDULED_DATE_ONLY, DEADLINE, DEADLINE_DATE_ONLY};
// 
// 	public static String getId(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildIdUri(String id) {
// 		return CONTENT_URI.buildUpon().appendPath(id).build();
// 	}
// 
// 	public static Uri buildIdUri(Long id) {
// 		return buildIdUri(id.toString());
// 	}
// 
// 	public static Uri buildChildrenUri(String parentId) {
// 		return CONTENT_URI.buildUpon().appendPath(parentId).appendPath("children").build();
// 	}
// 
// 	public static Uri buildChildrenUri(long node_id) {
// 		return buildChildrenUri(Long.toString(node_id));
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Priorities implements PrioritiesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_PRIORITIES).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Tags implements TagsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TAGS).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Timestamps implements TimestampsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TIMESTAMPS).build();
// 	public static final String[] DEFAULT_COLUMNS = {NODE_ID, FILE_ID, TYPE, TIMESTAMP, ALL_DAY};
// 
// 	public static Uri buildIdUri(Long id) {
// 		return CONTENT_URI.buildUpon().appendPath(id.toString()).build();
// 	}
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Todos implements TodosColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = {NAME, ID, GROUP, ISDONE};
// }


// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgProviderUtils.java
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import com.matburt.mobileorg.orgdata.OrgContract.Files;
import com.matburt.mobileorg.orgdata.OrgContract.OrgData;
import com.matburt.mobileorg.orgdata.OrgContract.Priorities;
import com.matburt.mobileorg.orgdata.OrgContract.Tags;
import com.matburt.mobileorg.orgdata.OrgContract.Timestamps;
import com.matburt.mobileorg.orgdata.OrgContract.Todos;
import com.matburt.mobileorg.util.OrgFileNotFoundException;
import com.matburt.mobileorg.util.OrgNodeNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

	public static ArrayList<String> getTodos(ContentResolver resolver) {
		Cursor cursor = resolver.query(Todos.CONTENT_URI, new String[] { Todos.NAME }, null, null, Todos.ID);
		if(cursor==null) return new ArrayList<>();

		ArrayList<String> todos = cursorToArrayList(cursor);

		return todos;
	}
	
	public static void setPriorities(ArrayList<String> priorities, ContentResolver resolver) {
		resolver.delete(Priorities.CONTENT_URI, null, null);

		for (String priority : priorities) {
			ContentValues values = new ContentValues();
			values.put(Priorities.NAME, priority);
			resolver.insert(Priorities.CONTENT_URI, values);
		}
	}

	public static ArrayList<String> getPriorities(ContentResolver resolver) {
		Cursor cursor = resolver.query(Priorities.CONTENT_URI, new String[] { Priorities.NAME },
				null, null, Priorities.ID);
		ArrayList<String> priorities = cursorToArrayList(cursor);

		cursor.close();
		return priorities;
	}
	

	public static void setTags(ArrayList<String> priorities, ContentResolver resolver) {
		resolver.delete(Tags.CONTENT_URI, null, null);