use of com.orgzly.android.Note in project orgzly-android by orgzly.
the class ListWidgetViewsFactory method setupNoteRow.
private void setupNoteRow(RemoteViews row, Cursor cursor) {
Note note = NotesClient.fromCursor(cursor);
if (isPartitioned) {
Long originalId = originalNoteIDs.get(note.getId()).getNoteId();
note.setId(originalId);
}
OrgHead head = note.getHead();
row.setTextViewText(R.id.item_list_widget_title, titleGenerator.generateTitle(note, head));
/* Closed time. */
if (head.hasClosed() && AppPreferences.displayPlanning(mContext)) {
row.setTextViewText(R.id.item_list_widget_closed_text, userTimeFormatter.formatAll(head.getClosed()));
row.setViewVisibility(R.id.item_list_widget_closed, View.VISIBLE);
} else {
row.setViewVisibility(R.id.item_list_widget_closed, View.GONE);
}
/* Deadline time. */
if (head.hasDeadline() && AppPreferences.displayPlanning(mContext)) {
row.setTextViewText(R.id.item_list_widget_deadline_text, userTimeFormatter.formatAll(head.getDeadline()));
row.setViewVisibility(R.id.item_list_widget_deadline, View.VISIBLE);
} else {
row.setViewVisibility(R.id.item_list_widget_deadline, View.GONE);
}
/* Scheduled time. */
if (head.hasScheduled() && AppPreferences.displayPlanning(mContext)) {
row.setTextViewText(R.id.item_list_widget_scheduled_text, userTimeFormatter.formatAll(head.getScheduled()));
row.setViewVisibility(R.id.item_list_widget_scheduled, View.VISIBLE);
} else {
row.setViewVisibility(R.id.item_list_widget_scheduled, View.GONE);
}
if (AppPreferences.todoKeywordsSet(mContext).contains(head.getState())) {
row.setViewVisibility(R.id.item_list_widget_done, View.VISIBLE);
} else {
row.setViewVisibility(R.id.item_list_widget_done, View.GONE);
}
final Intent openIntent = new Intent();
openIntent.putExtra(AppIntent.EXTRA_CLICK_TYPE, ListWidgetProvider.OPEN_CLICK_TYPE);
openIntent.putExtra(AppIntent.EXTRA_NOTE_ID, note.getId());
openIntent.putExtra(AppIntent.EXTRA_BOOK_ID, note.getPosition().getBookId());
row.setOnClickFillInIntent(R.id.item_list_widget_layout, openIntent);
final Intent doneIntent = new Intent();
doneIntent.putExtra(AppIntent.EXTRA_CLICK_TYPE, ListWidgetProvider.DONE_CLICK_TYPE);
doneIntent.putExtra(AppIntent.EXTRA_NOTE_ID, note.getId());
row.setOnClickFillInIntent(R.id.item_list_widget_done, doneIntent);
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, row, cursor);
}
use of com.orgzly.android.Note in project orgzly-android by orgzly.
the class NotesClient method forEachBookNote.
public static void forEachBookNote(Context context, String bookName, NotesClientInterface notesClientInterface) {
Cursor cursor = NotesClient.getCursorForBook(context, bookName);
try {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
Note note = NotesClient.fromCursor(cursor);
OrgProperties propertiesFromCursor = getNoteProperties(context, note.getId());
note.getHead().setProperties(propertiesFromCursor);
notesClientInterface.onNote(note);
}
} finally {
cursor.close();
}
}
use of com.orgzly.android.Note in project orgzly-android by orgzly.
the class HeadsListViewAdapter method bindView.
@Override
public void bindView(final View view, final Context context, Cursor cursor) {
final Note note = NotesClient.fromCursor(cursor, !inBook);
final OrgHead head = note.getHead();
final ViewHolder holder = (ViewHolder) view.getTag();
/* Attach some often used data to the view to avoid having to query for it later. */
view.setTag(R.id.note_view_state, head.getState());
if (inBook) {
if (note.getPosition().getFoldedUnderId() == 0) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
}
setupIndentContainer(context, holder.indentContainer, inBook ? note.getPosition().getLevel() - 1 : // No indentation unless in book
0);
updateBullet(note, holder);
if (updateFoldingButton(context, note, holder)) {
holder.foldButton.setOnClickListener(v -> toggleFoldedState(context, note.getId()));
holder.bullet.setOnClickListener(v -> toggleFoldedState(context, note.getId()));
} else {
holder.foldButton.setOnClickListener(null);
holder.bullet.setOnClickListener(null);
}
/* Book name. */
if (inBook) {
holder.bookNameUnderNote.setVisibility(View.GONE);
holder.bookNameLeftFromNoteText.setVisibility(View.GONE);
} else {
switch(Integer.valueOf(AppPreferences.bookNameInSearchResults(context))) {
case 0:
holder.bookNameLeftFromNoteText.setVisibility(View.GONE);
holder.bookNameUnderNote.setVisibility(View.GONE);
break;
case 1:
holder.bookNameLeftFromNoteText.setText(cursor.getString(cursor.getColumnIndex(DbNoteView.BOOK_NAME)));
holder.bookNameLeftFromNoteText.setVisibility(View.VISIBLE);
holder.bookNameUnderNote.setVisibility(View.GONE);
break;
case 2:
holder.bookNameUnderNoteText.setText(cursor.getString(cursor.getColumnIndex(DbNoteView.BOOK_NAME)));
holder.bookNameLeftFromNoteText.setVisibility(View.GONE);
holder.bookNameUnderNote.setVisibility(View.VISIBLE);
break;
}
}
/* Title. */
holder.title.setText(titleGenerator.generateTitle(note, head));
/* Content. */
if (head.hasContent() && titleGenerator.shouldDisplayContent(note)) {
if (AppPreferences.isFontMonospaced(context)) {
holder.content.setTypeface(Typeface.MONOSPACE);
}
holder.content.setText(OrgFormatter.INSTANCE.parse(head.getContent(), context));
holder.content.setVisibility(View.VISIBLE);
} else {
holder.content.setVisibility(View.GONE);
}
/* Closed time. */
if (head.hasClosed() && AppPreferences.displayPlanning(context)) {
holder.closedText.setText(userTimeFormatter.formatAll(head.getClosed()));
holder.closed.setVisibility(View.VISIBLE);
} else {
holder.closed.setVisibility(View.GONE);
}
/* Deadline time. */
if (head.hasDeadline() && AppPreferences.displayPlanning(context)) {
holder.deadlineText.setText(userTimeFormatter.formatAll(head.getDeadline()));
holder.deadline.setVisibility(View.VISIBLE);
} else {
holder.deadline.setVisibility(View.GONE);
}
/* Scheduled time. */
if (head.hasScheduled() && AppPreferences.displayPlanning(context)) {
holder.scheduledText.setText(userTimeFormatter.formatAll(head.getScheduled()));
holder.scheduled.setVisibility(View.VISIBLE);
} else {
holder.scheduled.setVisibility(View.GONE);
}
/* Set alpha for done items. */
if (head.getState() != null && AppPreferences.doneKeywordsSet(context).contains(head.getState())) {
holder.payload.setAlpha(0.45f);
} else {
holder.payload.setAlpha(1.0f);
}
quickMenu.updateView(view, note.getId(), holder.menuContainer, holder.menuFlipper);
selection.updateView(view, note.getId());
}
use of com.orgzly.android.Note in project orgzly-android by orgzly.
the class MainActivity method onNoteScrollToRequest.
@Override
public void onNoteScrollToRequest(long noteId) {
// TODO: Avoid using Shelf from activity directly
Shelf shelf = new Shelf(this);
Note note = shelf.getNote(noteId);
if (note != null) {
long bookId = note.getPosition().getBookId();
mSyncFragment.sparseTree(bookId, noteId);
DisplayManager.displayBook(getSupportFragmentManager(), bookId, noteId);
}
}
use of com.orgzly.android.Note in project orgzly-android by orgzly.
the class ProviderTest method testCreatingNotes.
@Test
public void testCreatingNotes() throws IOException {
Book book = shelfTestUtils.setupBook("notebook", "* Note");
NotePosition root, note1, note2;
note1 = NotesClient.getNote(context, 1).getPosition();
root = NotesClient.getNote(context, 2).getPosition();
assertEquals(1, NotesClient.getCount(context, book.getId()));
assertNotNull(root);
assertEquals(1, root.getLft());
assertEquals(6, note1.getLft());
assertEquals(11, note1.getRgt());
assertEquals(16, root.getRgt());
Note note = new Note();
note.getPosition().setBookId(book.getId());
NotesClient.create(context, note, null, System.currentTimeMillis());
note1 = NotesClient.getNote(context, 1).getPosition();
root = NotesClient.getNote(context, 2).getPosition();
note2 = NotesClient.getNote(context, 3).getPosition();
assertEquals(2, NotesClient.getCount(context, book.getId()));
assertNotNull(note2);
assertTrue(root.getLft() < note1.getLft());
assertTrue(note1.getLft() < note1.getRgt());
assertTrue(note1.getRgt() < note2.getLft());
assertTrue(note2.getLft() < note2.getRgt());
assertTrue(note2.getRgt() < root.getRgt());
}
Aggregations