use of com.orgzly.org.OrgHead in project orgzly-android by orgzly.
the class NotesClient method headFromCursor.
private static OrgHead headFromCursor(Cursor cursor) {
OrgHead head = new OrgHead();
String state = cursor.getString(cursor.getColumnIndex(DbNoteView.STATE));
if (NoteStates.Companion.isKeyword(state)) {
head.setState(state);
} else {
head.setState(null);
}
String priority = cursor.getString(cursor.getColumnIndex(DbNoteView.PRIORITY));
if (priority != null) {
head.setPriority(priority);
}
head.setTitle(cursor.getString(cursor.getColumnIndex(DbNoteView.TITLE)));
head.setContent(cursor.getString(cursor.getColumnIndex(DbNoteView.CONTENT)));
if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(DbNoteView.SCHEDULED_RANGE_STRING))))
head.setScheduled(OrgRange.parse(cursor.getString(cursor.getColumnIndex(DbNoteView.SCHEDULED_RANGE_STRING))));
if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(DbNoteView.DEADLINE_RANGE_STRING))))
head.setDeadline(OrgRange.parse(cursor.getString(cursor.getColumnIndex(DbNoteView.DEADLINE_RANGE_STRING))));
if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(DbNoteView.CLOSED_RANGE_STRING))))
head.setClosed(OrgRange.parse(cursor.getString(cursor.getColumnIndex(DbNoteView.CLOSED_RANGE_STRING))));
if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(DbNoteView.CLOCK_RANGE_STRING))))
head.setClock(OrgRange.parse(cursor.getString(cursor.getColumnIndex(DbNoteView.CLOCK_RANGE_STRING))));
// TODO: This is probably slowing UI down when scrolling fast, use strings from db directly?
String tags = cursor.getString(cursor.getColumnIndex(DbNoteView.TAGS));
if (!TextUtils.isEmpty(tags)) {
head.setTags(DbNote.dbDeSerializeTags(tags));
}
return head;
}
use of com.orgzly.org.OrgHead in project orgzly-android by orgzly.
the class NotesClient method fromCursor.
public static Note fromCursor(Cursor cursor, boolean withExtras) {
long id = idFromCursor(cursor);
long createdAt = cursor.getLong(cursor.getColumnIndex(DbNoteView.CREATED_AT));
int contentLines = cursor.getInt(cursor.getColumnIndex(DbNoteView.CONTENT_LINE_COUNT));
OrgHead head = headFromCursor(cursor);
NotePosition position = DbNote.positionFromCursor(cursor);
Note note = new Note();
note.setHead(head);
note.setId(id);
note.setCreatedAt(createdAt);
note.setPosition(position);
note.setContentLines(contentLines);
if (withExtras) {
String inheritedTags = cursor.getString(cursor.getColumnIndex(DbNoteView.INHERITED_TAGS));
if (!TextUtils.isEmpty(inheritedTags)) {
note.setInheritedTags(DbNote.dbDeSerializeTags(inheritedTags));
}
}
return note;
}
use of com.orgzly.org.OrgHead in project orgzly-android by orgzly.
the class Shelf method reParseNotesStateAndTitles.
/**
* Using current states configuration, update states and titles for all notes.
* Keywords that were part of the title can become states and vice versa.
*/
public void reParseNotesStateAndTitles() throws IOException {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
/* Get all notes. */
Cursor cursor = mContext.getContentResolver().query(ProviderContract.Notes.ContentUri.notes(), null, null, null, null);
try {
OrgParser.Builder parserBuilder = new OrgParser.Builder().setTodoKeywords(AppPreferences.todoKeywordsSet(mContext)).setDoneKeywords(AppPreferences.doneKeywordsSet(mContext));
OrgParserWriter parserWriter = new OrgParserWriter();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
/* Get current heading string. */
Note note = NotesClient.fromCursor(cursor);
/* Skip root node. */
if (note.getPosition().getLevel() == 0) {
continue;
}
OrgHead head = note.getHead();
String headString = parserWriter.whiteSpacedHead(head, note.getPosition().getLevel(), false);
/* Re-parse heading using current setting of keywords. */
OrgParsedFile file = parserBuilder.setInput(headString).build().parse();
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, "Note " + note + " parsed has " + file.getHeadsInList().size() + " notes");
if (file.getHeadsInList().size() != 1) {
throw new IOException("Got " + file.getHeadsInList().size() + " notes after parsing \"" + headString + "\"");
}
OrgHead newHead = file.getHeadsInList().get(0).getHead();
ContentValues values = new ContentValues();
/* Update if state, title or priority are different. */
if (!TextUtils.equals(newHead.getState(), head.getState()) || !TextUtils.equals(newHead.getTitle(), head.getTitle()) || !TextUtils.equals(newHead.getPriority(), head.getPriority())) {
values.put(ProviderContract.Notes.UpdateParam.TITLE, newHead.getTitle());
values.put(ProviderContract.Notes.UpdateParam.STATE, newHead.getState());
values.put(ProviderContract.Notes.UpdateParam.PRIORITY, newHead.getPriority());
}
if (values.size() > 0) {
ops.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(ProviderContract.Notes.ContentUri.notes(), cursor.getLong(0))).withValues(values).build());
}
}
} finally {
cursor.close();
}
/*
* Apply batch.
*/
try {
mContext.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
notifyDataChanged(mContext);
}
use of com.orgzly.org.OrgHead in project orgzly-android by orgzly.
the class NoteFragment method onDateTimeCleared.
@Override
public /* TimestampDialog */
void onDateTimeCleared(int id, TreeSet<Long> noteIds) {
if (mNote == null) {
return;
}
OrgHead head = mNote.getHead();
switch(id) {
case R.id.fragment_note_scheduled_button:
updateTimestampView(TimeType.SCHEDULED, mScheduledButton, null);
head.setScheduled(null);
break;
case R.id.fragment_note_deadline_button:
updateTimestampView(TimeType.DEADLINE, mDeadlineButton, null);
head.setDeadline(null);
break;
case R.id.fragment_note_closed_button:
updateTimestampView(TimeType.CLOSED, mClosedButton, null);
head.setClosed(null);
break;
}
}
use of com.orgzly.org.OrgHead in project orgzly-android by orgzly.
the class NoteFragment method updateNoteFromViews.
/**
* Views -> Note (Only those fields which are not updated when views are.)
*/
private void updateNoteFromViews() {
OrgHead head = mNote.getHead();
head.setState(mState.getTag() != null ? (String) mState.getTag() : null);
head.setPriority(mPriority.getTag() != null ? (String) mPriority.getTag() : null);
/* Replace new lines with spaces, in case multi-line text has been pasted. */
head.setTitle(mTitleView.getText().toString().replaceAll("\n", " ").trim());
head.setTags(mTagsView.getText().toString().split("\\s+"));
/* Add properties. */
head.removeProperties();
for (int i = 0; i < propertyList.getChildCount(); i++) {
View property = propertyList.getChildAt(i);
CharSequence name = ((TextView) property.findViewById(R.id.name)).getText();
CharSequence value = ((TextView) property.findViewById(R.id.value)).getText();
if (!TextUtils.isEmpty(name)) {
// Ignore property with no name
head.addProperty(name.toString(), value.toString());
}
}
head.setContent(bodyEdit.getText().toString());
}
Aggregations