Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java40
1 files changed, 36 insertions, 4 deletions
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 ccdfc6ab..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
@@ -20,6 +20,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
+import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@@ -31,7 +32,9 @@ 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.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;
@@ -48,7 +51,7 @@ import static it.niedermann.owncloud.notes.branding.BrandingUtil.tintMenuIcon;
import static it.niedermann.owncloud.notes.util.ColorUtil.isColorDark;
import static it.niedermann.owncloud.notes.util.Notes.isDarkThemeActive;
-public abstract class BaseNoteFragment extends BrandedFragment implements CategoryDialogListener {
+public abstract class BaseNoteFragment extends BrandedFragment implements CategoryDialogListener, EditTitleListener {
private static final String TAG = BaseNoteFragment.class.getSimpleName();
@@ -70,6 +73,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
private int originalScrollY;
protected NotesDatabase db;
private NoteFragmentListener listener;
+ private boolean titleModified = false;
protected boolean isNew = true;
@@ -195,6 +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", 1, 0)) >= 0);
menu.findItem(R.id.menu_delete).setVisible(!isNew);
}
@@ -214,7 +219,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;
@@ -230,6 +235,9 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
case R.id.menu_category:
showCategorySelector();
return true;
+ case R.id.menu_title:
+ showEditTitleDialog();
+ return true;
case R.id.menu_move:
MoveAccountDialogFragment.newInstance().show(requireActivity().getSupportFragmentManager(), BaseNoteFragment.class.getSimpleName());
return true;
@@ -275,7 +283,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
}
public void onCloseNote() {
- if (originalNote == null && getContent().isEmpty()) {
+ if (!titleModified && originalNote == null && getContent().isEmpty()) {
db.deleteNoteAndSync(ssoAccount, note.getId());
}
}
@@ -297,8 +305,9 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
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();
}
} else {
Log.e(TAG, "note is null");
@@ -326,12 +335,35 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
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) {
+ titleModified = true;
+ note.setTitle(newTitle);
+ note = db.updateNoteAndSync(ssoAccount, localAccount, note, note.getContent(), newTitle, null);
+ listener.onNoteUpdated(note);
+ }
+
public void moveNote(LocalAccount account) {
db.moveNoteToAnotherAccount(ssoAccount, note.getAccountId(), note, account.getId());
listener.close();