mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 21:06:09 +03:00
Use automatic title generation for v0.2 APIs
This commit is contained in:
parent
310df67fdc
commit
cfb501c4e0
4 changed files with 16 additions and 14 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue