From 53bdde1168d3f2697ad1726d5f170cafcf30f302 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Wed, 20 May 2020 18:12:17 +0200 Subject: #786 Support API v1.0 Display dialog to edit title --- .../notes/android/fragment/BaseNoteFragment.java | 30 +++++++- .../android/fragment/EditTitleDialogFragment.java | 81 ++++++++++++++++++++++ .../main/res/drawable/ic_title_grey600_24dp.xml | 5 ++ app/src/main/res/layout/dialog_edit_title.xml | 14 ++++ app/src/main/res/menu/menu_note_fragment.xml | 6 ++ app/src/main/res/values/strings.xml | 2 + 6 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/it/niedermann/owncloud/notes/android/fragment/EditTitleDialogFragment.java create mode 100644 app/src/main/res/drawable/ic_title_grey600_24dp.xml create mode 100644 app/src/main/res/layout/dialog_edit_title.xml (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java index 8f5e3ec0..56ba2580 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java @@ -18,6 +18,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.ShareActionProvider; import androidx.core.view.MenuItemCompat; +import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -29,6 +30,8 @@ import com.nextcloud.android.sso.model.SingleSignOnAccount; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.activity.EditNoteActivity; import it.niedermann.owncloud.notes.android.fragment.CategoryDialogFragment.CategoryDialogListener; +import it.niedermann.owncloud.notes.android.fragment.EditTitleDialogFragment.EditTitleListener; +import it.niedermann.owncloud.notes.model.ApiVersion; import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.DBStatus; @@ -40,7 +43,7 @@ import it.niedermann.owncloud.notes.util.NoteUtil; import static androidx.core.content.pm.ShortcutManagerCompat.isRequestPinShortcutSupported; import static it.niedermann.owncloud.notes.android.activity.EditNoteActivity.ACTION_SHORTCUT; -public abstract class BaseNoteFragment extends Fragment implements CategoryDialogListener { +public abstract class BaseNoteFragment extends Fragment implements CategoryDialogListener, EditTitleListener { private static final String TAG = BaseNoteFragment.class.getSimpleName(); @@ -157,6 +160,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo MenuItem itemFavorite = menu.findItem(R.id.menu_favorite); prepareFavoriteOption(itemFavorite); + menu.findItem(R.id.menu_title).setVisible(localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) >= 0); menu.findItem(R.id.menu_delete).setVisible(!isNew); } @@ -191,6 +195,9 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo case R.id.menu_category: showCategorySelector(); return true; + case R.id.menu_title: + showEditTitleDialog(); + return true; case R.id.menu_move: AccountChooserDialogFragment.newInstance().show(requireActivity().getSupportFragmentManager(), BaseNoteFragment.class.getSimpleName()); return true; @@ -311,12 +318,33 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo categoryFragment.show(manager, fragmentId); } + /** + * Opens a dialog in order to chose a category + */ + private void showEditTitleDialog() { + final String fragmentId = "fragment_edit_title"; + FragmentManager manager = requireActivity().getSupportFragmentManager(); + Fragment frag = manager.findFragmentByTag(fragmentId); + if (frag != null) { + manager.beginTransaction().remove(frag).commit(); + } + DialogFragment editTitleFragment = EditTitleDialogFragment.newInstance(note.getTitle()); + editTitleFragment.setTargetFragment(this, 0); + editTitleFragment.show(manager, fragmentId); + } + @Override public void onCategoryChosen(String category) { db.setCategory(ssoAccount, note, category, null); listener.onNoteUpdated(note); } + @Override + public void onTitleEdited(String newTitle) { +// db.setTitle(ssoAccount, note, newTitle); + listener.onNoteUpdated(note); + } + public void moveNote(LocalAccount account) { db.moveNoteToAnotherAccount(ssoAccount, note.getAccountId(), note, account.getId()); listener.close(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/EditTitleDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/EditTitleDialogFragment.java new file mode 100644 index 00000000..db1dbd61 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/EditTitleDialogFragment.java @@ -0,0 +1,81 @@ +package it.niedermann.owncloud.notes.android.fragment; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.databinding.DialogEditTitleBinding; + +public class EditTitleDialogFragment extends DialogFragment { + + static final String PARAM_OLD_TITLE = "old_title"; + + private String oldTitle; + private EditTitleListener listener; + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + final Bundle args = getArguments(); + if (args == null) { + throw new IllegalArgumentException("Provide at least " + PARAM_OLD_TITLE); + } + oldTitle = args.getString(PARAM_OLD_TITLE); + + if (getTargetFragment() instanceof EditTitleListener) { + listener = (EditTitleListener) getTargetFragment(); + } else if (getActivity() instanceof EditTitleListener) { + listener = (EditTitleListener) getActivity(); + } else { + throw new IllegalArgumentException("Calling activity or target fragment must implement " + EditTitleListener.class.getSimpleName()); + } + } + + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + View dialogView = View.inflate(getContext(), R.layout.dialog_edit_title, null); + DialogEditTitleBinding binding = DialogEditTitleBinding.bind(dialogView); + + if (savedInstanceState == null) { + if (requireArguments().containsKey(PARAM_OLD_TITLE)) { + binding.title.setText(requireArguments().getString(PARAM_OLD_TITLE)); + } + } + + return new AlertDialog.Builder(getActivity()) + .setTitle(R.string.change_note_title) + .setView(dialogView) + .setCancelable(true) + .setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString())) + .setNegativeButton(R.string.simple_cancel, null) + .create(); + } + + public static DialogFragment newInstance(String title) { + final DialogFragment fragment = new EditTitleDialogFragment(); + final Bundle args = new Bundle(); + args.putString(PARAM_OLD_TITLE, title); + fragment.setArguments(args); + return fragment; + } + + /** + * Interface that must be implemented by the calling Activity. + */ + public interface EditTitleListener { + /** + * This method is called after the user has changed the title of a note manually. + * + * @param newTitle the new title that a user submitted + */ + void onTitleEdited(String newTitle); + } +} diff --git a/app/src/main/res/drawable/ic_title_grey600_24dp.xml b/app/src/main/res/drawable/ic_title_grey600_24dp.xml new file mode 100644 index 00000000..a4cec0b8 --- /dev/null +++ b/app/src/main/res/drawable/ic_title_grey600_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/dialog_edit_title.xml b/app/src/main/res/layout/dialog_edit_title.xml new file mode 100644 index 00000000..805926bd --- /dev/null +++ b/app/src/main/res/layout/dialog_edit_title.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_note_fragment.xml b/app/src/main/res/menu/menu_note_fragment.xml index 82a9ba2d..025fe57f 100644 --- a/app/src/main/res/menu/menu_note_fragment.xml +++ b/app/src/main/res/menu/menu_note_fragment.xml @@ -16,6 +16,12 @@ android:title="@string/menu_favorite" android:checkable="true" app:showAsAction="ifRoom" /> + Added "%1$s" Shared text was empty Append to note + Change note title + Edit title -- cgit v1.2.3 From 17d3095a03c30cf9c6e2bbafd72267233a74ed52 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Thu, 4 Jun 2020 11:22:38 +0200 Subject: Generate note title from content only when note has not yet been synchronized (aka "new" notes) --- .../owncloud/notes/persistence/NotesClient.java | 6 ++--- .../owncloud/notes/persistence/NotesClientV1.java | 26 +++++++++++++++++----- .../owncloud/notes/persistence/NotesDatabase.java | 2 +- 3 files changed, 25 insertions(+), 9 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java index 69aeae3d..850c5a09 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java @@ -72,9 +72,9 @@ public abstract class NotesClient { if (preferredApiVersion == null) { Log.i(TAG, "apiVersion is null, using " + NotesClientV02.class.getSimpleName()); return new NotesClientV02(appContext); -// } else if (preferredApiVersion.compareTo(SUPPORTED_API_VERSIONS[0]) == 0) { -// Log.i(TAG, "Using " + NotesClient_1_0.class.getSimpleName()); -// return new NotesClient_1_0(appContext); + } else if (preferredApiVersion.compareTo(SUPPORTED_API_VERSIONS[0]) == 0) { + Log.i(TAG, "Using " + NotesClientV1.class.getSimpleName()); + return new NotesClientV1(appContext); } else if (preferredApiVersion.compareTo(SUPPORTED_API_VERSIONS[1]) == 0) { Log.i(TAG, "Using " + NotesClientV02.class.getSimpleName()); return new NotesClientV02(appContext); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java index 449818c9..75da6a56 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java @@ -7,6 +7,11 @@ import androidx.annotation.WorkerThread; import com.nextcloud.android.sso.model.SingleSignOnAccount; +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.Map; + import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.util.ServerResponse.NoteResponse; import it.niedermann.owncloud.notes.util.ServerResponse.NotesResponse; @@ -18,23 +23,34 @@ public class NotesClientV1 extends NotesClient { NotesClientV1(@NonNull Context appContext) { super(appContext); - throw new UnsupportedOperationException("Not implemented yet."); } NotesResponse getNotes(SingleSignOnAccount ssoAccount, long lastModified, String lastETag) throws Exception { - throw new UnsupportedOperationException("Not implemented yet."); + Map parameter = new HashMap<>(); + parameter.put(GET_PARAM_KEY_PRUNE_BEFORE, Long.toString(lastModified)); + return new NotesResponse(requestServer(ssoAccount, "notes", METHOD_GET, parameter, null, lastETag)); + } + + private NoteResponse putNote(SingleSignOnAccount ssoAccount, CloudNote note, String path, String method) throws Exception { + JSONObject paramObject = new JSONObject(); + paramObject.accumulate(JSON_TITLE, note.getTitle()); + paramObject.accumulate(JSON_CONTENT, note.getContent()); + paramObject.accumulate(JSON_MODIFIED, note.getModified().getTimeInMillis() / 1000); + paramObject.accumulate(JSON_FAVORITE, note.isFavorite()); + paramObject.accumulate(JSON_CATEGORY, note.getCategory()); + return new NoteResponse(requestServer(ssoAccount, path, method, null, paramObject, null)); } NoteResponse createNote(SingleSignOnAccount ssoAccount, CloudNote note) throws Exception { - throw new UnsupportedOperationException("Not implemented yet."); + return putNote(ssoAccount, note, "notes", METHOD_POST); } NoteResponse editNote(SingleSignOnAccount ssoAccount, CloudNote note) throws Exception { - throw new UnsupportedOperationException("Not implemented yet."); + return putNote(ssoAccount, note, "notes/" + note.getRemoteId(), METHOD_PUT); } void deleteNote(SingleSignOnAccount ssoAccount, long noteId) throws Exception { - throw new UnsupportedOperationException("Not implemented yet."); + this.requestServer(ssoAccount, "notes/" + noteId, METHOD_DELETE, null, null, null); } @Override diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java index 0e7ab6ff..ac2c3ec5 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java @@ -507,7 +507,7 @@ public class NotesDatabase extends AbstractNotesDatabase { if (newContent == null) { newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, oldNote.getExcerpt()); } else { - newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()), newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(newContent)); + newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), oldNote.getRemoteId() == 0 ? NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()) : oldNote.getTitle(), newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(newContent)); } SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); -- cgit v1.2.3 From 49a0e09a68c228f15b9439018532270fe82a3a63 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Thu, 4 Jun 2020 11:24:17 +0200 Subject: Nullcheck for InputMethodManager --- .../owncloud/notes/android/fragment/NoteEditFragment.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteEditFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteEditFragment.java index ff529277..9caa38a8 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteEditFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteEditFragment.java @@ -44,6 +44,8 @@ import static it.niedermann.owncloud.notes.util.DisplayUtils.searchAndColor; public class NoteEditFragment extends SearchableBaseNoteFragment { + private static final String TAG = NoteEditFragment.class.getSimpleName(); + private static final String LOG_TAG_AUTOSAVE = "AutoSave"; private static final long DELAY = 2000; // Wait for this time after typing before saving @@ -147,10 +149,12 @@ public class NoteEditFragment extends SearchableBaseNoteFragment { requireActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); - InputMethodManager imm = (InputMethodManager) - requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.showSoftInput(getView(), InputMethodManager.SHOW_IMPLICIT); - + InputMethodManager imm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.showSoftInput(getView(), InputMethodManager.SHOW_IMPLICIT); + } else { + Log.w(TAG, "InputMethodManager is null"); + } } // workaround for issue yydcdut/RxMarkdown#41 -- cgit v1.2.3 From b9ccfd41eabd33f16dd03aa2e6a5d235ed0dc373 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Thu, 4 Jun 2020 11:46:45 +0200 Subject: Keep an empty note if the title has been set manually --- .../notes/android/fragment/BaseNoteFragment.java | 8 ++++++-- .../owncloud/notes/persistence/NotesDatabase.java | 20 +++++++++++++++++--- .../it/niedermann/owncloud/notes/util/NoteUtil.java | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java index 41979865..18d56ebb 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java @@ -62,6 +62,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo private DBNote originalNote; protected NotesDatabase db; private NoteFragmentListener listener; + private boolean titleModified = false; protected boolean isNew = true; @@ -242,7 +243,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo } public void onCloseNote() { - if (originalNote == null && getContent().isEmpty()) { + if (!titleModified && originalNote == null && getContent().isEmpty()) { db.deleteNoteAndSync(ssoAccount, note.getId()); } } @@ -261,6 +262,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo } else { note = db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, newContent, callback); listener.onNoteUpdated(note); + requireActivity().invalidateOptionsMenu(); } } else { Log.e(TAG, "note is null"); @@ -327,7 +329,9 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo @Override public void onTitleEdited(String newTitle) { -// db.setTitle(ssoAccount, note, newTitle); + titleModified = true; + note.setTitle(newTitle); + note = db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, note.getContent(), newTitle, null); listener.onNoteUpdated(note); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java index ac2c3ec5..63b71ece 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java @@ -492,22 +492,36 @@ public class NotesDatabase extends AbstractNotesDatabase { return db.insert(table_category, null, values); } + public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable ISyncCallback callback) { + return updateNoteAndSync(ssoAccount, accountId, oldNote, newContent, null, callback); + } + /** * Updates a single Note with a new content. * The title is derived from the new content automatically, and modified date as well as DBStatus are updated, too -- if the content differs to the state in the database. * * @param oldNote Note to be changed * @param newContent New content. If this is null, then oldNote is saved again (useful for undoing changes). + * @param newTitle New title. If this is null, then either the old title is reused (in case the note has been synced before) or a title is generated (in case it is a new note) * @param callback When the synchronization is finished, this callback will be invoked (optional). * @return changed note if differs from database, otherwise the old note. */ - public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable ISyncCallback callback) { - //debugPrintFullDB(); + public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) { DBNote newNote; if (newContent == null) { newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, oldNote.getExcerpt()); } else { - newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), oldNote.getRemoteId() == 0 ? NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()) : oldNote.getTitle(), newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(newContent)); + final String title; + if (newTitle != null) { + title = newTitle; + } else { + if (oldNote.getRemoteId() == 0) { + title = NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()); + } else { + title = oldNote.getTitle(); + } + } + newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(newContent)); } SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java index 0db9b3ea..65a3b445 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java @@ -73,7 +73,7 @@ public class NoteUtil { * @return truncated string */ @NonNull - private static String truncateString(@NonNull String str, int len) { + private static String truncateString(@NonNull String str, @SuppressWarnings("SameParameterValue") int len) { return str.substring(0, Math.min(len, str.length())); } -- cgit v1.2.3 From ddb9b9ae9f8ea0028b17d75d43eca146b7152c36 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Thu, 4 Jun 2020 15:49:29 +0200 Subject: Adjust excerpt generation --- .../notes/persistence/AbstractNotesDatabase.java | 4 ++-- .../owncloud/notes/persistence/NotesDatabase.java | 9 ++++---- .../niedermann/owncloud/notes/util/NoteUtil.java | 25 ++++++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java index c98e8df5..45d58a50 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java @@ -298,10 +298,10 @@ abstract class AbstractNotesDatabase extends SQLiteOpenHelper { } if (oldVersion < 10) { db.execSQL("ALTER TABLE NOTES ADD COLUMN EXCERPT INTEGER NOT NULL DEFAULT ''"); - Cursor cursor = db.query("NOTES", new String[]{"ID", "CONTENT"}, null, null, null, null, null, null); + Cursor cursor = db.query("NOTES", new String[]{"ID", "CONTENT", "TITLE"}, null, null, null, null, null, null); while (cursor.moveToNext()) { ContentValues values = new ContentValues(); - values.put("EXCERPT", NoteUtil.generateNoteExcerpt(cursor.getString(1))); + values.put("EXCERPT", NoteUtil.generateNoteExcerpt(cursor.getString(1), cursor.getString(2))); db.update("NOTES", values, "ID" + " = ? ", new String[]{cursor.getString(0)}); } cursor.close(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java index 63b71ece..63391fc5 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java @@ -56,6 +56,7 @@ import it.niedermann.owncloud.notes.util.NoteUtil; import static it.niedermann.owncloud.notes.android.activity.EditNoteActivity.ACTION_SHORTCUT; import static it.niedermann.owncloud.notes.model.NoteListsWidgetData.MODE_DISPLAY_CATEGORY; +import static it.niedermann.owncloud.notes.util.NoteUtil.generateNoteExcerpt; /** * Helps to add, get, update and delete Notes with the option to trigger a Resync with the Server. @@ -92,7 +93,7 @@ public class NotesDatabase extends AbstractNotesDatabase { * @param note Note */ public long addNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, CloudNote note) { - DBNote dbNote = new DBNote(0, 0, note.getModified(), note.getTitle(), note.getContent(), note.isFavorite(), note.getCategory(), note.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(note.getContent())); + DBNote dbNote = new DBNote(0, 0, note.getModified(), note.getTitle(), note.getContent(), note.isFavorite(), note.getCategory(), note.getEtag(), DBStatus.LOCAL_EDITED, accountId, generateNoteExcerpt(note.getContent(), note.getTitle())); long id = addNote(accountId, dbNote); notifyNotesChanged(); getNoteServerSyncHelper().scheduleSync(ssoAccount, true); @@ -119,7 +120,7 @@ public class NotesDatabase extends AbstractNotesDatabase { } else { values.put(key_status, DBStatus.VOID.getTitle()); values.put(key_account_id, accountId); - values.put(key_excerpt, NoteUtil.generateNoteExcerpt(note.getContent())); + values.put(key_excerpt, generateNoteExcerpt(note.getContent(), note.getTitle())); } if (note.getRemoteId() > 0) { values.put(key_remote_id, note.getRemoteId()); @@ -521,7 +522,7 @@ public class NotesDatabase extends AbstractNotesDatabase { title = oldNote.getTitle(); } } - newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(newContent)); + newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, generateNoteExcerpt(newContent, title)); } SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); @@ -576,7 +577,7 @@ public class NotesDatabase extends AbstractNotesDatabase { values.put(key_favorite, remoteNote.isFavorite()); values.put(key_category, getCategoryIdByTitle(localAccount.getId(), remoteNote.getCategory())); values.put(key_etag, remoteNote.getEtag()); - values.put(key_excerpt, NoteUtil.generateNoteExcerpt(remoteNote.getContent())); + values.put(key_excerpt, generateNoteExcerpt(remoteNote.getContent(), remoteNote.getTitle())); String whereClause; String[] whereArgs; if (forceUnchangedDBNoteState != null) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java index 65a3b445..5546bdcc 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java @@ -1,6 +1,7 @@ package it.niedermann.owncloud.notes.util; import android.content.Context; +import android.text.TextUtils; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -78,17 +79,29 @@ public class NoteUtil { } /** - * Generates an excerpt of a content String (reads second line which is not empty) + * Generates an excerpt of a content that does not match the given title * - * @param content String + * @param content {@link String} + * @param title {@link String} In case the content starts with the title, the excerpt should be generated starting from this point * @return excerpt String */ @NonNull - public static String generateNoteExcerpt(@NonNull String content) { - if (content.contains("\n")) - return truncateString(removeMarkDown(content.replaceFirst("^.*\n", "")), 200).replace("\n", " "); - else + public static String generateNoteExcerpt(@NonNull String content, @Nullable String title) { + content = removeMarkDown(content.trim()); + if(TextUtils.isEmpty(content)) { + return ""; + } + if (!TextUtils.isEmpty(title)) { + final String trimmedTitle = removeMarkDown(title.trim()); + if (content.startsWith(trimmedTitle)) { + content = content.substring(trimmedTitle.length()); + } + } + if (content.contains("\n")) { + return truncateString(content.trim(), 200).replace("\n", " "); + } else { return ""; + } } @NonNull -- cgit v1.2.3 From cfb501c4e08ff2bd772dbe5fed81a863ad345ea7 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Sun, 7 Jun 2020 11:46:45 +0200 Subject: Use automatic title generation for v0.2 APIs --- .../notes/android/activity/AppendToNoteActivity.java | 2 +- .../owncloud/notes/android/fragment/BaseNoteFragment.java | 12 ++++++------ .../it/niedermann/owncloud/notes/model/LocalAccount.java | 2 ++ .../owncloud/notes/persistence/NotesDatabase.java | 14 +++++++------- 4 files changed, 16 insertions(+), 14 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AppendToNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AppendToNoteActivity.java index 2cc72aea..4f5722aa 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AppendToNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AppendToNoteActivity.java @@ -44,7 +44,7 @@ public class AppendToNoteActivity extends NotesListViewActivity { } else { newContent = receivedText; } - db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, newContent, () -> Toast.makeText(this, getString(R.string.added_content, receivedText), Toast.LENGTH_SHORT).show()); + db.updateNoteAndSync(ssoAccount, localAccount, note, newContent, () -> Toast.makeText(this, getString(R.string.added_content, receivedText), Toast.LENGTH_SHORT).show()); } else { Toast.makeText(this, R.string.shared_text_empty, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java index a2fe34cf..9dcfe7ef 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java @@ -18,8 +18,8 @@ import android.view.MenuItem; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; import androidx.core.content.ContextCompat; +import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -32,8 +32,8 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.activity.EditNoteActivity; import it.niedermann.owncloud.notes.android.fragment.CategoryDialogFragment.CategoryDialogListener; import it.niedermann.owncloud.notes.android.fragment.EditTitleDialogFragment.EditTitleListener; -import it.niedermann.owncloud.notes.model.ApiVersion; import it.niedermann.owncloud.notes.branding.BrandedFragment; +import it.niedermann.owncloud.notes.model.ApiVersion; import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.DBStatus; @@ -170,7 +170,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego MenuItem itemFavorite = menu.findItem(R.id.menu_favorite); prepareFavoriteOption(itemFavorite); - menu.findItem(R.id.menu_title).setVisible(localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) >= 0); + menu.findItem(R.id.menu_title).setVisible(localAccount.getPreferredApiVersion() != null && localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) >= 0); menu.findItem(R.id.menu_delete).setVisible(!isNew); } @@ -190,7 +190,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (originalNote == null) { db.deleteNoteAndSync(ssoAccount, note.getId()); } else { - db.updateNoteAndSync(ssoAccount, localAccount.getId(), originalNote, null, null); + db.updateNoteAndSync(ssoAccount, localAccount, originalNote, null, null); } listener.close(); return true; @@ -271,7 +271,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (note.getContent().equals(newContent)) { Log.v(TAG, "... not saving, since nothing has changed"); } else { - note = db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, newContent, callback); + note = db.updateNoteAndSync(ssoAccount, localAccount, note, newContent, callback); listener.onNoteUpdated(note); requireActivity().invalidateOptionsMenu(); } @@ -342,7 +342,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego public void onTitleEdited(String newTitle) { titleModified = true; note.setTitle(newTitle); - note = db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, note.getContent(), newTitle, null); + note = db.updateNoteAndSync(ssoAccount, localAccount, note, note.getContent(), newTitle, null); listener.onNoteUpdated(note); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java b/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java index 6a6c3a5e..bfcb4d74 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java @@ -24,6 +24,7 @@ public class LocalAccount { private String etag; private String capabilitiesETag; private long modified; + @Nullable private ApiVersion preferredApiVersion; @ColorInt private int color; @@ -78,6 +79,7 @@ public class LocalAccount { this.modified = modified; } + @Nullable public ApiVersion getPreferredApiVersion() { return preferredApiVersion; } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java index fe3600e1..99ee0318 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java @@ -495,8 +495,8 @@ public class NotesDatabase extends AbstractNotesDatabase { return db.insert(table_category, null, values); } - public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable ISyncCallback callback) { - return updateNoteAndSync(ssoAccount, accountId, oldNote, newContent, null, callback); + public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, @NonNull LocalAccount localAccount, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable ISyncCallback callback) { + return updateNoteAndSync(ssoAccount, localAccount, oldNote, newContent, null, callback); } /** @@ -509,22 +509,22 @@ public class NotesDatabase extends AbstractNotesDatabase { * @param callback When the synchronization is finished, this callback will be invoked (optional). * @return changed note if differs from database, otherwise the old note. */ - public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) { + public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, @NonNull LocalAccount localAccount, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) { DBNote newNote; if (newContent == null) { - newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, oldNote.getExcerpt()); + newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt()); } else { final String title; if (newTitle != null) { title = newTitle; } else { - if (oldNote.getRemoteId() == 0) { + if (oldNote.getRemoteId() == 0 || localAccount.getPreferredApiVersion() == null || localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) < 0) { title = NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()); } else { title = oldNote.getTitle(); } } - newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, generateNoteExcerpt(newContent, title)); + newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title)); } SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); @@ -535,7 +535,7 @@ public class NotesDatabase extends AbstractNotesDatabase { values.put(key_content, newNote.getContent()); values.put(key_excerpt, newNote.getExcerpt()); int rows = db.update(table_notes, values, key_id + " = ? AND (" + key_content + " != ? OR " + key_category + " != ?)", new String[]{String.valueOf(newNote.getId()), newNote.getContent(), newNote.getCategory()}); - removeEmptyCategory(accountId); + removeEmptyCategory(localAccount.getId()); // if data was changed, set new status and schedule sync (with callback); otherwise invoke callback directly. if (rows > 0) { notifyNotesChanged(); -- cgit v1.2.3 From 2b776cb7506d72271b1f20f38218d75690012fff Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Mon, 8 Jun 2020 22:03:38 +0200 Subject: Merge master --- .../owncloud/notes/persistence/migration/Migration_9_10.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java index 98ddc601..c5bf2c02 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java @@ -15,10 +15,10 @@ public class Migration_9_10 { */ public Migration_9_10(@NonNull SQLiteDatabase db) { db.execSQL("ALTER TABLE NOTES ADD COLUMN EXCERPT INTEGER NOT NULL DEFAULT ''"); - Cursor cursor = db.query("NOTES", new String[]{"ID", "CONTENT"}, null, null, null, null, null, null); + Cursor cursor = db.query("NOTES", new String[]{"ID", "CONTENT", "TITLE"}, null, null, null, null, null, null); while (cursor.moveToNext()) { ContentValues values = new ContentValues(); - values.put("EXCERPT", NoteUtil.generateNoteExcerpt(cursor.getString(1))); + values.put("EXCERPT", NoteUtil.generateNoteExcerpt(cursor.getString(1), cursor.getString(2))); db.update("NOTES", values, "ID" + " = ? ", new String[]{cursor.getString(0)}); } cursor.close(); -- cgit v1.2.3 From 96da811ac4caa6ec045a2e9099abcfe23551ef85 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Sun, 14 Jun 2020 11:49:03 +0200 Subject: Update formatting help code sample --- app/src/main/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2bb3901d..812c2756 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -244,8 +244,8 @@ \\`%1$s\\` ``` \\`\\`\\` - if (isAwesome){ - return true + int getRandom() { + return 4; } \\`\\`\\`javascript ```javascript -- cgit v1.2.3 From cc6c8fd7e61a15b8ce1376bb94418f9a091b7160 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Sun, 14 Jun 2020 15:53:50 +0200 Subject: =?UTF-8?q?Deal=20with=20=C3=84=C3=96=C3=9C=20and=20move=20hardcod?= =?UTF-8?q?ed=20string=20to=20resources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java | 4 ++-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java index 23573d24..19d0a903 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java @@ -98,8 +98,8 @@ public class LoadNotesListTask extends AsyncTask> { for (int i = 0; i < noteList.size(); i++) { DBNote currentNote = noteList.get(i); String initials = currentNote.getTitle().substring(0, 1).toUpperCase(); - if (!initials.matches("[A-Z]")) { - initials = initials.matches("[\\u0250-\\uFFFF]") ? "Other" : "#"; + if (!initials.matches("[A-Z\\u00C0-\\u00DF]")) { + initials = initials.matches("[\\u0250-\\uFFFF]") ? context.getString(R.string.simple_other) : "#"; } if (i > 0 && !initials.equals(lastInitials)) { itemList.add(new SectionItem(initials)); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7ccda8e4..6aa3a1c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -302,4 +302,5 @@ Tables Images If you are interested in contributing support for one of those features, get in contact with us via GitHub or E-Mail. + Other -- cgit v1.2.3 From 0e2c0c4d9b8128914be93bd7cbd941d97d543590 Mon Sep 17 00:00:00 2001 From: korelstar Date: Sun, 14 Jun 2020 15:58:19 +0200 Subject: fix edit title was shown for wrong API --- .../it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java index 3bf49023..69d1b6dc 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java @@ -199,7 +199,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego MenuItem itemFavorite = menu.findItem(R.id.menu_favorite); prepareFavoriteOption(itemFavorite); - menu.findItem(R.id.menu_title).setVisible(localAccount.getPreferredApiVersion() != null && localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) >= 0); + menu.findItem(R.id.menu_title).setVisible(localAccount.getPreferredApiVersion() != null && localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 1, 0)) >= 0); menu.findItem(R.id.menu_delete).setVisible(!isNew); } -- cgit v1.2.3 From ae68495fab7ec02a11662cdea8ad9c4daafb15a7 Mon Sep 17 00:00:00 2001 From: korelstar Date: Sun, 14 Jun 2020 15:58:46 +0200 Subject: fix parsing of API versions header --- .../java/it/niedermann/owncloud/notes/persistence/NotesClient.java | 2 +- .../java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java index 850c5a09..207b4d49 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java @@ -189,7 +189,7 @@ public abstract class NotesClient { String supportedApiVersions = null; final AidlNetworkRequest.PlainHeader supportedApiVersionsHeader = response.getPlainHeader(HEADER_KEY_X_NOTES_API_VERSIONS); if (supportedApiVersionsHeader != null) { - supportedApiVersions = Objects.requireNonNull(supportedApiVersionsHeader.getValue()).replace("\"", ""); + supportedApiVersions = "[" + Objects.requireNonNull(supportedApiVersionsHeader.getValue()) + "]"; } // return these header fields since they should only be saved after successful processing the result! diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java index a8cbb8e6..b5beeecf 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java @@ -861,9 +861,9 @@ public class NotesDatabase extends AbstractNotesDatabase { Log.i(TAG, "Given API version is a valid JSON array but does not contain any valid API versions. Do not update database."); } } catch (NumberFormatException e) { - throw new IllegalArgumentException("API version does contain a non-valid version."); + throw new IllegalArgumentException("API version does contain a non-valid version: " + apiVersion); } catch (JSONException e) { - throw new IllegalArgumentException("API version must contain be a JSON array."); + throw new IllegalArgumentException("API version must contain be a JSON array: " + apiVersion); } } else { Log.v(TAG, "Given API version is null. Do not update database"); -- cgit v1.2.3