diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-06-07 12:46:45 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-06-07 12:46:45 +0300 |
commit | cfb501c4e08ff2bd772dbe5fed81a863ad345ea7 (patch) | |
tree | fe0a1213a4c87278fcacc98bf3ecdd1ad8fe3481 /app/src/main | |
parent | 310df67fdceb1259c049a0dc67a085fcaf051649 (diff) |
Use automatic title generation for v0.2 APIs
Diffstat (limited to 'app/src/main')
4 files changed, 16 insertions, 14 deletions
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(); |