Search in sources :

Example 1 with OrgHead

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;
}
Also used : OrgHead(com.orgzly.org.OrgHead)

Example 2 with OrgHead

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;
}
Also used : OrgHead(com.orgzly.org.OrgHead) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) DbNote(com.orgzly.android.provider.models.DbNote)

Example 3 with OrgHead

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);
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) OrgHead(com.orgzly.org.OrgHead) CircularArrayList(com.orgzly.android.util.CircularArrayList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Cursor(android.database.Cursor) OrgParserWriter(com.orgzly.org.parser.OrgParserWriter) OrgParsedFile(com.orgzly.org.parser.OrgParsedFile) OrgParser(com.orgzly.org.parser.OrgParser) DbNote(com.orgzly.android.provider.models.DbNote) RemoteException(android.os.RemoteException) OperationApplicationException(android.content.OperationApplicationException)

Example 4 with OrgHead

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;
    }
}
Also used : OrgHead(com.orgzly.org.OrgHead)

Example 5 with OrgHead

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());
}
Also used : OrgHead(com.orgzly.org.OrgHead) MultiAutoCompleteTextView(android.widget.MultiAutoCompleteTextView) TextView(android.widget.TextView) MultiAutoCompleteTextView(android.widget.MultiAutoCompleteTextView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView)

Aggregations

OrgHead (com.orgzly.org.OrgHead)14 Note (com.orgzly.android.Note)4 Cursor (android.database.Cursor)2 DbNote (com.orgzly.android.provider.models.DbNote)2 OrgRange (com.orgzly.org.datetime.OrgRange)2 OrgParserWriter (com.orgzly.org.parser.OrgParserWriter)2 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 OperationApplicationException (android.content.OperationApplicationException)1 RemoteException (android.os.RemoteException)1 View (android.view.View)1 MultiAutoCompleteTextView (android.widget.MultiAutoCompleteTextView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 AppIntent (com.orgzly.android.AppIntent)1 Book (com.orgzly.android.Book)1 NotePosition (com.orgzly.android.NotePosition)1 OrgzlyTest (com.orgzly.android.OrgzlyTest)1 CircularArrayList (com.orgzly.android.util.CircularArrayList)1