use of com.orgzly.android.db.entity.Note in project orgzly-android by orgzly.
the class MainActivity method setupViewModel.
private void setupViewModel() {
sharedMainActivityViewModel.getDrawerLockState().observe(this, isLocked -> {
DrawerLayout layout = mDrawerLayout;
if (layout != null) {
if (isLocked == null || !isLocked) {
layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
} else {
layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
}
});
sharedMainActivityViewModel.getFragmentState().observe(this, state -> {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, "Observed fragment state: " + state);
if (state != null) {
getSupportActionBar().setTitle(state.getTitle());
// Clean up whitespace for multi-line query
CharSequence subTitle = state.getSubTitle();
if (subTitle != null) {
subTitle = subTitle.toString().replaceAll("\\s{2,}", " ");
}
getSupportActionBar().setSubtitle(subTitle);
drawerNavigationView.updateActiveFragment(state.getTag());
/* Update floating action button. */
MainFab.updateFab(this, state.getTag(), state.getSelectionCount());
}
});
viewModel.getOpenNoteWithPropertyRequestEvent().observeSingle(this, pair -> {
if (pair != null) {
UseCase action = pair.getFirst();
UseCaseResult result = pair.getSecond();
if (action instanceof NoteFindWithProperty) {
NoteFindWithProperty thisAction = (NoteFindWithProperty) action;
if (result.getUserData() != null) {
NoteDao.NoteIdBookId note = (NoteDao.NoteIdBookId) result.getUserData();
DisplayManager.displayExistingNote(getSupportFragmentManager(), note.getBookId(), note.getNoteId());
} else {
showSnackbar(getString(R.string.no_such_link_target, thisAction.getName(), thisAction.getValue()));
}
}
}
});
viewModel.getOpenFileLinkRequestEvent().observeSingle(this, result -> {
if (result != null && result.getUserData() != null) {
Object userData = result.getUserData();
if (userData instanceof Book) {
Book book = (Book) userData;
Intent intent = new Intent(AppIntent.ACTION_OPEN_BOOK);
intent.putExtra(AppIntent.EXTRA_BOOK_ID, book.getId());
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, "sending intent", intent);
} else if (userData instanceof File) {
File file = (File) userData;
openFileIfExists(file);
}
}
});
viewModel.getOpenNoteRequestEvent().observeSingle(this, note -> MainActivity.openSpecificNote(note.getPosition().getBookId(), note.getId()));
viewModel.getSetBookLinkRequestEvent().observeSingle(this, result -> {
Book book = result.getBook();
List<Repo> links = result.getLinks();
CharSequence[] urls = result.getUrls();
int checked = result.getSelected();
if (links.isEmpty()) {
showSnackbarWithReposLink(getString(R.string.no_repos));
} else {
ArrayAdapter<Repo> adapter = new ArrayAdapter<>(this, R.layout.item_repo, R.id.item_repo_url);
adapter.addAll(links);
dialog = new AlertDialog.Builder(this).setTitle(R.string.book_link).setSingleChoiceItems(urls, checked, (d, which) -> {
mSyncFragment.run(new BookLinkUpdate(book.getId(), links.get(which)));
dialog.dismiss();
dialog = null;
}).setNeutralButton(R.string.remove_notebook_link, (dialog, which) -> {
mSyncFragment.run(new BookLinkUpdate(book.getId()));
}).setNegativeButton(R.string.cancel, null).show();
}
});
viewModel.getSavedSearchedExportEvent().observeSingle(this, count -> {
showSnackbar(getResources().getQuantityString(R.plurals.exported_searches, count, count));
});
viewModel.getSavedSearchedImportEvent().observeSingle(this, count -> {
showSnackbar(getResources().getQuantityString(R.plurals.imported_searches, count, count));
});
viewModel.getErrorEvent().observeSingle(this, error -> {
if (error != null) {
showSnackbar(error.getLocalizedMessage());
}
});
}
use of com.orgzly.android.db.entity.Note in project orgzly-android by orgzly.
the class TitleGenerator method generateTitle.
public CharSequence generateTitle(NoteView noteView) {
Note note = noteView.getNote();
SpannableStringBuilder builder = new SpannableStringBuilder();
/* State. */
if (note.getState() != null) {
builder.append(generateState(note));
}
/* Priority. */
if (note.getPriority() != null) {
if (builder.length() > 0) {
builder.append(TITLE_SEPARATOR);
}
builder.append(generatePriority(note));
}
/* Bold everything up until now. */
if (builder.length() > 0) {
builder.setSpan(new StyleSpan(Typeface.BOLD), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
/* Space before title, unless there's nothing added. */
if (builder.length() > 0) {
builder.append(TITLE_SEPARATOR);
}
/* Title. */
builder.append(OrgFormatter.parse(note.getTitle(), mContext, true, false));
/* Append note ID. */
// builder.append(TITLE_SEPARATOR).append("#").append(String.valueOf(note.getId()));
int mark = builder.length();
boolean hasPostTitleText = false;
/* Tags. */
if (note.hasTags()) {
builder.append(TITLE_SEPARATOR).append(generateTags(note.getTagsList()));
hasPostTitleText = true;
}
/* Inherited tags in search results. */
if (!inBook && noteView.hasInheritedTags() && AppPreferences.inheritedTagsInSearchResults(mContext)) {
if (note.hasTags()) {
builder.append(INHERITED_TAGS_SEPARATOR);
} else {
builder.append(TITLE_SEPARATOR);
}
builder.append(generateTags(noteView.getInheritedTagsList()));
hasPostTitleText = true;
}
/* Content line number. */
if (note.hasContent() && AppPreferences.contentLineCountDisplayed(mContext)) {
if (!shouldDisplayContent(note)) {
builder.append(TITLE_SEPARATOR).append(String.valueOf(note.getContentLineCount()));
hasPostTitleText = true;
}
}
/* Change font style of text after title. */
if (hasPostTitleText) {
builder.setSpan(attributes.postTitleTextSize, mark, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(attributes.postTitleTextColor, mark, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return builder;
}
use of com.orgzly.android.db.entity.Note in project orgzly-android by orgzly.
the class MainActivity method onNoteCreated.
@Override
public void onNoteCreated(Note note) {
finishActionMode();
popBackStackAndCloseKeyboard();
// Display Snackbar with an action (create new note below just created one)
View view = findViewById(R.id.main_content);
if (view != null) {
showSnackbar(Snackbar.make(view, R.string.message_note_created, Snackbar.LENGTH_LONG).setAction(R.string.new_below, v -> {
NotePlace notePlace = new NotePlace(note.getPosition().getBookId(), note.getId(), Place.BELOW);
DisplayManager.displayNewNote(getSupportFragmentManager(), notePlace);
}));
}
}
use of com.orgzly.android.db.entity.Note in project orgzly-android by orgzly.
the class DataRepositoryTest method testRootNodeInNewBook.
@Test
public void testRootNodeInNewBook() throws IOException {
BookView book = dataRepository.createBook("booky");
Note note = dataRepository.getRootNode(book.getBook().getId());
assertEquals(1, note.getPosition().getLft());
assertEquals(2, note.getPosition().getRgt());
assertEquals(0, note.getPosition().getLevel());
assertEquals("", note.getTitle());
}
Aggregations