use of it.niedermann.owncloud.notes.persistence.entity.Note in project nextcloud-notes by stefan-niedermann.
the class NotesDaoTest method updateStatus_NullConstraint.
@Test(expected = SQLiteConstraintException.class)
public void updateStatus_NullConstraint() {
db.getNoteDao().addNote(new Note(1, 1L, Calendar.getInstance(), "T", "C", "", false, "1", LOCAL_DELETED, account.getId(), "", 0));
db.getNoteDao().updateStatus(1, null);
}
use of it.niedermann.owncloud.notes.persistence.entity.Note in project nextcloud-notes by stefan-niedermann.
the class NotesDaoTest method updateCategory_NullConstraint.
@Test(expected = SQLiteConstraintException.class)
public void updateCategory_NullConstraint() {
db.getNoteDao().addNote(new Note(1, 1L, Calendar.getInstance(), "T", "C", "", false, "1", LOCAL_DELETED, account.getId(), "", 0));
db.getNoteDao().updateCategory(1, null);
}
use of it.niedermann.owncloud.notes.persistence.entity.Note in project nextcloud-notes by stefan-niedermann.
the class NotesDaoTest method getLocalIdByRemoteId.
@Test
public void getLocalIdByRemoteId() {
db.getNoteDao().addNote(new Note(815, 4711L, Calendar.getInstance(), "My-Title", "My-Content", "", false, "1", VOID, account.getId(), "", 0));
db.getNoteDao().addNote(new Note(666, 1234L, Calendar.getInstance(), "My-Title", "My-Content", "", false, "1", LOCAL_EDITED, account.getId(), "", 0));
db.getNoteDao().addNote(new Note(987, 6969L, Calendar.getInstance(), "My-Title", "My-Content", "", false, "1", LOCAL_DELETED, account.getId(), "", 0));
assertEquals(Long.valueOf(815), db.getNoteDao().getLocalIdByRemoteId(account.getId(), 4711));
assertEquals(Long.valueOf(666), db.getNoteDao().getLocalIdByRemoteId(account.getId(), 1234));
assertNull(db.getNoteDao().getLocalIdByRemoteId(account.getId(), 6969));
}
use of it.niedermann.owncloud.notes.persistence.entity.Note in project nextcloud-notes by stefan-niedermann.
the class BaseNoteFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
executor.submit(() -> {
try {
final var ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext().getApplicationContext());
this.localAccount = repo.getAccountByName(ssoAccount.name);
if (savedInstanceState == null) {
final long id = requireArguments().getLong(PARAM_NOTE_ID);
if (id > 0) {
final long accountId = requireArguments().getLong(PARAM_ACCOUNT_ID);
if (accountId > 0) {
/* Switch account if account id has been provided */
this.localAccount = repo.getAccountById(accountId);
SingleAccountHelper.setCurrentAccount(requireContext().getApplicationContext(), localAccount.getAccountName());
}
isNew = false;
note = originalNote = repo.getNoteById(id);
requireActivity().runOnUiThread(() -> onNoteLoaded(note));
requireActivity().invalidateOptionsMenu();
} else {
final var paramNote = (Note) requireArguments().getSerializable(PARAM_NEWNOTE);
final var content = requireArguments().getString(PARAM_CONTENT);
if (paramNote == null) {
if (content == null) {
throw new IllegalArgumentException(PARAM_NOTE_ID + " is not given, argument " + PARAM_NEWNOTE + " is missing and " + PARAM_CONTENT + " is missing.");
} else {
note = new Note(-1, null, Calendar.getInstance(), NoteUtil.generateNoteTitle(content), content, getString(R.string.category_readonly), false, null, DBStatus.VOID, -1, "", 0);
requireActivity().runOnUiThread(() -> onNoteLoaded(note));
requireActivity().invalidateOptionsMenu();
}
} else {
paramNote.setStatus(DBStatus.LOCAL_EDITED);
note = repo.addNote(localAccount.getId(), paramNote);
originalNote = null;
requireActivity().runOnUiThread(() -> onNoteLoaded(note));
requireActivity().invalidateOptionsMenu();
}
}
} else {
note = (Note) savedInstanceState.getSerializable(SAVEDKEY_NOTE);
originalNote = (Note) savedInstanceState.getSerializable(SAVEDKEY_ORIGINAL_NOTE);
requireActivity().runOnUiThread(() -> onNoteLoaded(note));
requireActivity().invalidateOptionsMenu();
}
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
}
});
setHasOptionsMenu(true);
}
use of it.niedermann.owncloud.notes.persistence.entity.Note in project nextcloud-notes by stefan-niedermann.
the class EditNoteActivity method launchNewNote.
/**
* Starts the {@link NoteEditFragment} with a new note.
* Content ("share" functionality), category and favorite attribute can be preset.
*/
private void launchNewNote() {
final var intent = getIntent();
String categoryTitle = "";
boolean favorite = false;
if (intent.hasExtra(PARAM_CATEGORY)) {
final NavigationCategory categoryPreselection = (NavigationCategory) Objects.requireNonNull(intent.getSerializableExtra(PARAM_CATEGORY));
final String category = categoryPreselection.getCategory();
if (category != null) {
categoryTitle = category;
}
favorite = categoryPreselection.getType() == FAVORITES;
}
String content = "";
if (intent.hasExtra(Intent.EXTRA_TEXT) && MIMETYPE_TEXT_PLAIN.equals(intent.getType()) && (Intent.ACTION_SEND.equals(intent.getAction()) || INTENT_GOOGLE_ASSISTANT.equals(intent.getAction()))) {
content = ShareUtil.extractSharedText(intent);
} else if (intent.hasExtra(PARAM_CONTENT)) {
content = intent.getStringExtra(PARAM_CONTENT);
}
if (content == null) {
content = "";
}
final var newNote = new Note(null, Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(content, this), content, categoryTitle, favorite, null);
fragment = NoteEditFragment.newInstanceWithNewNote(newNote);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_view, fragment).commit();
}
Aggregations