Search in sources :

Example 11 with Note

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);
}
Also used : Note(it.niedermann.owncloud.notes.persistence.entity.Note) Test(org.junit.Test)

Example 12 with Note

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);
}
Also used : Note(it.niedermann.owncloud.notes.persistence.entity.Note) Test(org.junit.Test)

Example 13 with Note

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));
}
Also used : Note(it.niedermann.owncloud.notes.persistence.entity.Note) Test(org.junit.Test)

Example 14 with Note

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);
}
Also used : Note(it.niedermann.owncloud.notes.persistence.entity.Note) NoCurrentAccountSelectedException(com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException)

Example 15 with Note

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();
}
Also used : NavigationCategory(it.niedermann.owncloud.notes.shared.model.NavigationCategory) Note(it.niedermann.owncloud.notes.persistence.entity.Note)

Aggregations

Note (it.niedermann.owncloud.notes.persistence.entity.Note)21 Test (org.junit.Test)13 Account (it.niedermann.owncloud.notes.persistence.entity.Account)5 Intent (android.content.Intent)3 NonNull (androidx.annotation.NonNull)3 NextcloudFilesAppAccountNotFoundException (com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException)3 Capabilities (it.niedermann.owncloud.notes.shared.model.Capabilities)3 NavigationCategory (it.niedermann.owncloud.notes.shared.model.NavigationCategory)3 Before (org.junit.Before)3 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)2 Bundle (android.os.Bundle)2 InstantTaskExecutorRule (androidx.arch.core.executor.testing.InstantTaskExecutorRule)2 Room (androidx.room.Room)2 ApplicationProvider (androidx.test.core.app.ApplicationProvider)2 NextcloudHttpRequestFailedException (com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException)2 TokenMismatchException (com.nextcloud.android.sso.exceptions.TokenMismatchException)2 CategoryWithNotesCount (it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount)2 DBStatus (it.niedermann.owncloud.notes.shared.model.DBStatus)2 LOCAL_DELETED (it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_DELETED)2 LOCAL_EDITED (it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_EDITED)2