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/persistence')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java29
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java12
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Account.java16
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryOptions.java4
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java10
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java11
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java8
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java4
8 files changed, 38 insertions, 56 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
index 74589cbc..f69e16fc 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
@@ -653,20 +653,16 @@ public class NotesRepository {
int orderIndex = sortingMethod.getId();
switch (selectedCategory.getType()) {
- case FAVORITES: {
+ case FAVORITES -> {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_favorites), orderIndex);
- break;
}
- case UNCATEGORIZED: {
+ case UNCATEGORIZED -> {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.action_uncategorized), orderIndex);
- break;
}
- case RECENT: {
+ case RECENT -> {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_all_notes), orderIndex);
- break;
}
- case DEFAULT_CATEGORY:
- default: {
+ default -> {
final String category = selectedCategory.getCategory();
if (category != null) {
if (db.getCategoryOptionsDao().modifyCategoryOrder(accountId, category, sortingMethod) == 0) {
@@ -680,7 +676,6 @@ public class NotesRepository {
} else {
throw new IllegalStateException("Tried to modify category order for " + ENavigationCategoryType.DEFAULT_CATEGORY + "but category is null.");
}
- break;
}
}
sp.apply();
@@ -707,20 +702,16 @@ public class NotesRepository {
switch (selectedCategory.getType()) {
// TODO make this account specific
- case RECENT: {
+ case RECENT -> {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_all_notes);
- break;
}
- case FAVORITES: {
+ case FAVORITES -> {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_favorites);
- break;
}
- case UNCATEGORIZED: {
+ case UNCATEGORIZED -> {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.action_uncategorized);
- break;
}
- case DEFAULT_CATEGORY:
- default: {
+ default -> {
final String category = selectedCategory.getCategory();
if (category != null) {
return db.getCategoryOptionsDao().getCategoryOrder(selectedCategory.getAccountId(), category);
@@ -814,9 +805,7 @@ public class NotesRepository {
if (account == null) {
Log.i(TAG, SingleSignOnAccount.class.getSimpleName() + " is null. Is this a local account?");
} else {
- if (syncActive.get(account.getId()) == null) {
- syncActive.put(account.getId(), false);
- }
+ syncActive.putIfAbsent(account.getId(), false);
Log.d(TAG, "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (Boolean.TRUE.equals(syncActive.get(account.getId())) ? "sync active" : "sync NOT active") + ") ...");
if (isSyncPossible() && (!Boolean.TRUE.equals(syncActive.get(account.getId())) || onlyLocalChanges)) {
syncActive.put(account.getId(), true);
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java
index f50dd21e..1ecfdc92 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java
@@ -118,7 +118,7 @@ abstract class NotesServerSyncTask extends Thread {
try {
Note remoteNote;
switch (note.getStatus()) {
- case LOCAL_EDITED:
+ case LOCAL_EDITED -> {
Log.v(TAG, " ...create/edit");
if (note.getRemoteId() != null) {
Log.v(TAG, " ...Note has remoteId → try to edit");
@@ -160,8 +160,8 @@ abstract class NotesServerSyncTask extends Thread {
}
// Please note, that db.updateNote() realized an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
repo.updateIfNotModifiedLocallyDuringSync(note.getId(), remoteNote.getModified().getTimeInMillis(), remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getETag(), remoteNote.getContent(), generateNoteExcerpt(remoteNote.getContent(), remoteNote.getTitle()), note.getContent(), note.getCategory(), note.getFavorite());
- break;
- case LOCAL_DELETED:
+ }
+ case LOCAL_DELETED -> {
if (note.getRemoteId() == null) {
Log.v(TAG, " ...delete (only local, since it has never been synchronized)");
} else {
@@ -177,9 +177,9 @@ abstract class NotesServerSyncTask extends Thread {
}
// Please note, that db.deleteNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
repo.deleteByNoteId(note.getId(), LOCAL_DELETED);
- break;
- default:
- throw new IllegalStateException("Unknown State of Note " + note + ": " + note.getStatus());
+ }
+ default ->
+ throw new IllegalStateException("Unknown State of Note " + note + ": " + note.getStatus());
}
} catch (NextcloudHttpRequestFailedException e) {
if (e.getStatusCode() == HTTP_NOT_MODIFIED) {
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Account.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Account.java
index 05b957f0..04f55738 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Account.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Account.java
@@ -12,6 +12,7 @@ import androidx.room.PrimaryKey;
import java.io.Serializable;
import java.util.Calendar;
+import java.util.Objects;
import it.niedermann.owncloud.notes.shared.model.Capabilities;
@@ -180,9 +181,7 @@ public class Account implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof Account)) return false;
-
- Account account = (Account) o;
+ if (!(o instanceof Account account)) return false;
if (id != account.id) return false;
if (color != account.color) return false;
@@ -190,15 +189,14 @@ public class Account implements Serializable {
if (!url.equals(account.url)) return false;
if (!userName.equals(account.userName)) return false;
if (!accountName.equals(account.accountName)) return false;
- if (eTag != null ? !eTag.equals(account.eTag) : account.eTag != null) return false;
- if (modified != null ? !modified.equals(account.modified) : account.modified != null)
+ if (!Objects.equals(eTag, account.eTag)) return false;
+ if (!Objects.equals(modified, account.modified))
return false;
- if (apiVersion != null ? !apiVersion.equals(account.apiVersion) : account.apiVersion != null)
+ if (!Objects.equals(apiVersion, account.apiVersion))
return false;
- if (capabilitiesETag != null ? !capabilitiesETag.equals(account.capabilitiesETag) : account.capabilitiesETag != null)
+ if (!Objects.equals(capabilitiesETag, account.capabilitiesETag))
return false;
- if (directEditingAvailable != account.directEditingAvailable) return false;
- return true;
+ return directEditingAvailable == account.directEditingAvailable;
}
@Override
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryOptions.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryOptions.java
index da37ee31..35328ca8 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryOptions.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryOptions.java
@@ -74,9 +74,7 @@ public class CategoryOptions implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof CategoryOptions)) return false;
-
- CategoryOptions that = (CategoryOptions) o;
+ if (!(o instanceof CategoryOptions that)) return false;
if (accountId != that.accountId) return false;
if (!category.equals(that.category)) return false;
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java
index 2eb71eb6..139ce5c1 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java
@@ -2,6 +2,8 @@ package it.niedermann.owncloud.notes.persistence.entity;
import androidx.room.Ignore;
+import java.util.Objects;
+
public class CategoryWithNotesCount {
private long accountId;
@@ -46,14 +48,12 @@ public class CategoryWithNotesCount {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof CategoryWithNotesCount)) return false;
-
- CategoryWithNotesCount that = (CategoryWithNotesCount) o;
+ if (!(o instanceof CategoryWithNotesCount that)) return false;
if (accountId != that.accountId) return false;
- if (category != null ? !category.equals(that.category) : that.category != null)
+ if (!Objects.equals(category, that.category))
return false;
- return totalNotes != null ? totalNotes.equals(that.totalNotes) : that.totalNotes == null;
+ return Objects.equals(totalNotes, that.totalNotes);
}
@Override
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java
index e0d0325c..51132720 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java
@@ -14,6 +14,7 @@ import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.Calendar;
+import java.util.Objects;
import it.niedermann.owncloud.notes.shared.model.DBStatus;
import it.niedermann.owncloud.notes.shared.model.Item;
@@ -218,23 +219,21 @@ public class Note implements Serializable, Item {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof Note)) return false;
-
- Note note = (Note) o;
+ if (!(o instanceof Note note)) return false;
if (id != note.id) return false;
if (accountId != note.accountId) return false;
if (favorite != note.favorite) return false;
if (scrollY != note.scrollY) return false;
- if (remoteId != null ? !remoteId.equals(note.remoteId) : note.remoteId != null)
+ if (!Objects.equals(remoteId, note.remoteId))
return false;
if (status != note.status) return false;
if (!title.equals(note.title)) return false;
if (!category.equals(note.category)) return false;
- if (modified != null ? !modified.equals(note.modified) : note.modified != null)
+ if (!Objects.equals(modified, note.modified))
return false;
if (!content.equals(note.content)) return false;
- if (eTag != null ? !eTag.equals(note.eTag) : note.eTag != null) return false;
+ if (!Objects.equals(eTag, note.eTag)) return false;
return excerpt.equals(note.excerpt);
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java
index da784d1d..ff319869 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java
@@ -8,6 +8,8 @@ import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
+import java.util.Objects;
+
import it.niedermann.owncloud.notes.widget.AbstractWidgetData;
@Entity(
@@ -61,13 +63,11 @@ public class NotesListWidgetData extends AbstractWidgetData {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof NotesListWidgetData)) return false;
+ if (!(o instanceof NotesListWidgetData that)) return false;
if (!super.equals(o)) return false;
- NotesListWidgetData that = (NotesListWidgetData) o;
-
if (mode != that.mode) return false;
- return category != null ? category.equals(that.category) : that.category == null;
+ return Objects.equals(category, that.category);
}
@Override
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java
index 3e726242..753d1ed8 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java
@@ -51,9 +51,7 @@ public class SingleNoteWidgetData extends AbstractWidgetData {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof SingleNoteWidgetData)) return false;
-
- SingleNoteWidgetData that = (SingleNoteWidgetData) o;
+ if (!(o instanceof SingleNoteWidgetData that)) return false;
return noteId == that.noteId;
}