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:
authorStefan Niedermann <info@niedermann.it>2020-10-20 16:04:46 +0300
committerStefan Niedermann <info@niedermann.it>2020-10-20 16:04:46 +0300
commit6a3f13b3f2e364b3f2612022a1693e7e7ab818f6 (patch)
treec38f7d01095cee3a92233d984c380cb23b71b089 /app/src/main/java/it
parent717fe55dec4c7cc7c051492def3191298faa687f (diff)
Optimize NOT NULL constraints
Diffstat (limited to 'app/src/main/java/it')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java7
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java6
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java14
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Account.java205
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java36
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java111
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java31
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java23
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java18
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java6
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java4
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java22
13 files changed, 305 insertions, 180 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java
index acfd22de..bd480a56 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java
@@ -30,6 +30,8 @@ import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.nextcloud.android.sso.model.SingleSignOnAccount;
+import java.util.Calendar;
+
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.accountpicker.AccountPickerDialogFragment;
import it.niedermann.owncloud.notes.branding.BrandedFragment;
@@ -68,7 +70,6 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
private static final String SAVEDKEY_ORIGINAL_NOTE = "original_note";
private Account localAccount;
- private SingleSignOnAccount ssoAccount;
protected NoteWithCategory note;
// TODO do we really need this? The reference to note is currently the same
@@ -96,7 +97,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
- this.ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireActivity().getApplicationContext());
+ SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireActivity().getApplicationContext());
this.localAccount = db.getAccountDao().getLocalAccountByAccountName(ssoAccount.name);
if (savedInstanceState == null) {
@@ -117,7 +118,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
if (content == null) {
throw new IllegalArgumentException(PARAM_NOTE_ID + " is not given, argument " + PARAM_NEWNOTE + " is missing and " + PARAM_CONTENT + " is missing.");
} else {
- note = new NoteWithCategory(new Note(-1, -1L, null, NoteUtil.generateNoteTitle(content), content, false, getString(R.string.category_readonly), DBStatus.VOID, -1, "", 0));
+ note = new NoteWithCategory(new Note(-1, -1L, Calendar.getInstance(), NoteUtil.generateNoteTitle(content), content, false, getString(R.string.category_readonly), DBStatus.VOID, -1, "", 0));
}
} else {
final LiveData<NoteWithCategory> createLiveData = db.addNoteAndSync(localAccount, cloudNote);
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
index 8685214e..c751930f 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
@@ -80,6 +80,7 @@ import it.niedermann.owncloud.notes.shared.model.NoteClickListener;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
import static android.os.Build.VERSION.SDK_INT;
+import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.O;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
@@ -484,7 +485,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
binding.headerView.setBackgroundColor(mainColor);
binding.appName.setTextColor(textColor);
- if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ if (SDK_INT >= LOLLIPOP) {
activityBinding.progressCircular.getIndeterminateDrawable().setColorFilter(getSecondaryForegroundColorDependingOnTheme(this, mainColor), PorterDuff.Mode.SRC_IN);
}
@@ -632,7 +633,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
private void updateToolbars(boolean disableSearch) {
activityBinding.homeToolbar.setVisibility(disableSearch ? VISIBLE : GONE);
activityBinding.toolbar.setVisibility(disableSearch ? GONE : VISIBLE);
- if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ if (SDK_INT >= LOLLIPOP) {
activityBinding.appBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(activityBinding.appBar.getContext(),
disableSearch ? R.animator.appbar_elevation_off : R.animator.appbar_elevation_on));
} else {
@@ -641,7 +642,6 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
if (disableSearch) {
activityBinding.searchView.setQuery(null, true);
}
- activityBinding.searchView.setIconified(disableSearch);
}
@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 c0a32fd4..58e7ccb3 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
@@ -175,16 +175,14 @@ public abstract class NotesDatabase extends RoomDatabase {
* Inserts a note directly into the Database.
* No Synchronisation will be triggered! Use addNoteAndSync()!
*
- * @param note Note to be added. Remotely created Notes must be of type CloudNote and locally created Notes must be of Type {@link Note} (with {@link DBStatus#LOCAL_EDITED})!
+ * @param note Note to be added. Locally created Notes must be of Type {@link Note} (with {@link DBStatus#LOCAL_EDITED})!
*/
@NonNull
@WorkerThread
NoteWithCategory addNote(long accountId, NoteWithCategory note) {
Note entity = new Note();
- if (note.getId() != null) {
- if (note.getId() > 0) {
- entity.setId(note.getId());
- }
+ if (note.getId() > 0) {
+ entity.setId(note.getId());
entity.setStatus(note.getStatus());
entity.setAccountId(note.getAccountId());
entity.setExcerpt(note.getExcerpt());
@@ -236,9 +234,9 @@ public abstract class NotesDatabase extends RoomDatabase {
* This method will search in the database to find out the category id in the db.
* If there is no such category existing, this method will create it and search again.
*
- * @param account The single sign on account
- * @param noteId The note which will be updated
- * @param category The category title which should be used to find the category id.
+ * @param account The single sign on account
+ * @param noteId The note which will be updated
+ * @param category The category title which should be used to find the category id.
*/
@AnyThread
public void setCategory(@NonNull Account account, long noteId, @NonNull String category) {
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 c3598cc7..c26dd094 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
@@ -1,5 +1,7 @@
package it.niedermann.owncloud.notes.persistence.entity;
+import android.graphics.Color;
+
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -21,7 +23,6 @@ import java.util.NoSuchElementException;
import it.niedermann.owncloud.notes.persistence.NotesClient;
import it.niedermann.owncloud.notes.shared.model.ApiVersion;
import it.niedermann.owncloud.notes.shared.model.Capabilities;
-import it.niedermann.owncloud.notes.shared.util.ColorUtil;
@Entity(
indices = {
@@ -34,21 +35,35 @@ import it.niedermann.owncloud.notes.shared.util.ColorUtil;
)
public class Account {
@PrimaryKey(autoGenerate = true)
- private Long id;
- private String url;
- private String userName;
- private String accountName;
+ private long id;
+ @NonNull
+ @ColumnInfo(defaultValue = "")
+ private String url = "";
+ @NonNull
+ @ColumnInfo(defaultValue = "")
+ private String userName = "";
+ @NonNull
+ @ColumnInfo(defaultValue = "")
+ private String accountName = "";
+ @Nullable
private String eTag;
+ @Nullable
private Calendar modified;
+ @Nullable
private String apiVersion;
@ColorInt
@ColumnInfo(defaultValue = "-16743735")
- private Integer color;
+ private int color = Color.parseColor("#0082C9");
@ColorInt
@ColumnInfo(defaultValue = "-16777216")
- private Integer textColor;
+ private int textColor = Color.WHITE;
+ @Nullable
private String capabilitiesETag;
+ @Nullable
+ @Ignore
+ private ApiVersion preferredApiVersion;
+
public Account() {
// Default constructor
}
@@ -61,136 +76,130 @@ public class Account {
}
@Nullable
- @Ignore
- private ApiVersion preferredApiVersion;
+ public ApiVersion getPreferredApiVersion() {
+ return preferredApiVersion;
+ }
+
+ /**
+ * @param availableApiVersions <code>["0.2", "1.0", ...]</code>
+ */
+ public void setPreferredApiVersion(@Nullable String availableApiVersions) {
+ // TODO move this logic to NotesClient?
+ try {
+ if (availableApiVersions == null) {
+ this.preferredApiVersion = null;
+ return;
+ }
+ final JSONArray versionsArray = new JSONArray(availableApiVersions);
+ final Collection<ApiVersion> supportedApiVersions = new HashSet<>(versionsArray.length());
+ for (int i = 0; i < versionsArray.length(); i++) {
+ final ApiVersion parsedApiVersion = ApiVersion.of(versionsArray.getString(i));
+ for (ApiVersion temp : NotesClient.SUPPORTED_API_VERSIONS) {
+ if (temp.compareTo(parsedApiVersion) == 0) {
+ supportedApiVersions.add(parsedApiVersion);
+ break;
+ }
+ }
+ }
+ this.preferredApiVersion = Collections.max(supportedApiVersions);
+ } catch (JSONException | NoSuchElementException e) {
+ e.printStackTrace();
+ this.preferredApiVersion = null;
+ }
+ }
+
+ public void setCapabilities(@NonNull Capabilities capabilities) {
+ capabilitiesETag = capabilities.getETag();
+ apiVersion = capabilities.getApiVersion();
+ setColor(capabilities.getColor());
+ setTextColor(capabilities.getTextColor());
+ }
- public Long getId() {
+ public long getId() {
return id;
}
- public void setId(Long id) {
+ public void setId(long id) {
this.id = id;
}
+ @NonNull
public String getUrl() {
return url;
}
- public void setUrl(String url) {
+ public void setUrl(@NonNull String url) {
this.url = url;
}
+ @NonNull
public String getUserName() {
return userName;
}
- public void setUserName(String userName) {
+ public void setUserName(@NonNull String userName) {
this.userName = userName;
}
+ @NonNull
public String getAccountName() {
return accountName;
}
- public void setAccountName(String accountName) {
+ public void setAccountName(@NonNull String accountName) {
this.accountName = accountName;
}
+ @Nullable
public String getETag() {
return eTag;
}
- public void setETag(String eTag) {
+ public void setETag(@Nullable String eTag) {
this.eTag = eTag;
}
+ @Nullable
public Calendar getModified() {
return modified;
}
- public void setModified(Calendar modified) {
+ public void setModified(@Nullable Calendar modified) {
this.modified = modified;
}
+ @Nullable
public String getApiVersion() {
return apiVersion;
}
- public void setApiVersion(String apiVersion) {
+ public void setApiVersion(@Nullable String apiVersion) {
this.apiVersion = apiVersion;
- setPreferredApiVersion(apiVersion);
}
- public String getCapabilitiesETag() {
- return capabilitiesETag;
- }
-
- public void setCapabilitiesETag(String capabilitiesETag) {
- this.capabilitiesETag = capabilitiesETag;
- }
-
- public void setCapabilities(@NonNull Capabilities capabilities) {
- capabilitiesETag = capabilities.getETag();
- apiVersion = capabilities.getApiVersion();
- setColor(capabilities.getColor());
- setTextColor(capabilities.getTextColor());
- }
-
- @Nullable
- public ApiVersion getPreferredApiVersion() {
- return preferredApiVersion;
- }
-
- /**
- * @param availableApiVersions <code>["0.2", "1.0", ...]</code>
- */
- public void setPreferredApiVersion(@Nullable String availableApiVersions) {
- // TODO move this logic to NotesClient?
- try {
- if (availableApiVersions == null) {
- this.preferredApiVersion = null;
- return;
- }
- JSONArray versionsArray = new JSONArray(availableApiVersions);
- Collection<ApiVersion> supportedApiVersions = new HashSet<>(versionsArray.length());
- for (int i = 0; i < versionsArray.length(); i++) {
- ApiVersion parsedApiVersion = ApiVersion.of(versionsArray.getString(i));
- for (ApiVersion temp : NotesClient.SUPPORTED_API_VERSIONS) {
- if (temp.compareTo(parsedApiVersion) == 0) {
- supportedApiVersions.add(parsedApiVersion);
- break;
- }
- }
- }
- this.preferredApiVersion = Collections.max(supportedApiVersions);
- } catch (JSONException | NoSuchElementException e) {
- e.printStackTrace();
- this.preferredApiVersion = null;
- }
- }
-
- public Integer getColor() {
+ public int getColor() {
return color;
}
- public void setColor(Integer color) {
+ public void setColor(int color) {
this.color = color;
}
- public Integer getTextColor() {
+ public int getTextColor() {
return textColor;
}
- public void setTextColor(Integer textColor) {
+ public void setTextColor(int textColor) {
this.textColor = textColor;
}
- @NonNull
- @Override
- public String toString() {
- return "Account{" +
- "accountName='" + accountName + '\'' +
- '}';
+ @Nullable
+ public String getCapabilitiesETag() {
+ return capabilitiesETag;
+ }
+
+ public void setCapabilitiesETag(@Nullable String capabilitiesETag) {
+ this.capabilitiesETag = capabilitiesETag;
}
@Override
@@ -200,20 +209,17 @@ public class Account {
Account account = (Account) o;
- if (id != null ? !id.equals(account.id) : account.id != null) return false;
- if (url != null ? !url.equals(account.url) : account.url != null) return false;
- if (userName != null ? !userName.equals(account.userName) : account.userName != null)
- return false;
- if (accountName != null ? !accountName.equals(account.accountName) : account.accountName != null)
- return false;
+ if (id != account.id) return false;
+ if (color != account.color) return false;
+ if (textColor != account.textColor) return false;
+ 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)
return false;
if (apiVersion != null ? !apiVersion.equals(account.apiVersion) : account.apiVersion != null)
return false;
- if (color != null ? !color.equals(account.color) : account.color != null) return false;
- if (textColor != null ? !textColor.equals(account.textColor) : account.textColor != null)
- return false;
if (capabilitiesETag != null ? !capabilitiesETag.equals(account.capabilitiesETag) : account.capabilitiesETag != null)
return false;
return preferredApiVersion != null ? preferredApiVersion.equals(account.preferredApiVersion) : account.preferredApiVersion == null;
@@ -221,17 +227,34 @@ public class Account {
@Override
public int hashCode() {
- int result = id != null ? id.hashCode() : 0;
- result = 31 * result + (url != null ? url.hashCode() : 0);
- result = 31 * result + (userName != null ? userName.hashCode() : 0);
- result = 31 * result + (accountName != null ? accountName.hashCode() : 0);
+ int result = (int) (id ^ (id >>> 32));
+ result = 31 * result + url.hashCode();
+ result = 31 * result + userName.hashCode();
+ result = 31 * result + accountName.hashCode();
result = 31 * result + (eTag != null ? eTag.hashCode() : 0);
result = 31 * result + (modified != null ? modified.hashCode() : 0);
result = 31 * result + (apiVersion != null ? apiVersion.hashCode() : 0);
- result = 31 * result + (color != null ? color.hashCode() : 0);
- result = 31 * result + (textColor != null ? textColor.hashCode() : 0);
+ result = 31 * result + color;
+ result = 31 * result + textColor;
result = 31 * result + (capabilitiesETag != null ? capabilitiesETag.hashCode() : 0);
result = 31 * result + (preferredApiVersion != null ? preferredApiVersion.hashCode() : 0);
return result;
}
+
+ @Override
+ public String toString() {
+ return "Account{" +
+ "id=" + id +
+ ", url='" + url + '\'' +
+ ", userName='" + userName + '\'' +
+ ", accountName='" + accountName + '\'' +
+ ", eTag='" + eTag + '\'' +
+ ", modified=" + modified +
+ ", apiVersion='" + apiVersion + '\'' +
+ ", color=" + color +
+ ", textColor=" + textColor +
+ ", capabilitiesETag='" + capabilitiesETag + '\'' +
+ ", preferredApiVersion=" + preferredApiVersion +
+ '}';
+ }
} \ No newline at end of file
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java
index 0205e07e..b87b8ea3 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java
@@ -1,5 +1,8 @@
package it.niedermann.owncloud.notes.persistence.entity;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
@@ -30,7 +33,10 @@ public class Category implements Serializable {
@PrimaryKey(autoGenerate = true)
private long id;
private long accountId;
- private String title;
+ @NonNull
+ @ColumnInfo(defaultValue = "")
+ private String title = "";
+ @Nullable
private CategorySortingMethod sortingMethod;
public long getId() {
@@ -49,19 +55,43 @@ public class Category implements Serializable {
this.accountId = accountId;
}
+ @NonNull
public String getTitle() {
return title;
}
- public void setTitle(String title) {
+ public void setTitle(@NonNull String title) {
this.title = title;
}
+ @Nullable
public CategorySortingMethod getSortingMethod() {
return sortingMethod;
}
- public void setSortingMethod(CategorySortingMethod sortingMethod) {
+ public void setSortingMethod(@Nullable CategorySortingMethod sortingMethod) {
this.sortingMethod = sortingMethod;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Category)) return false;
+
+ Category category = (Category) o;
+
+ if (id != category.id) return false;
+ if (accountId != category.accountId) return false;
+ if (!title.equals(category.title)) return false;
+ return sortingMethod == category.sortingMethod;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = (int) (id ^ (id >>> 32));
+ result = 31 * result + (int) (accountId ^ (accountId >>> 32));
+ result = 31 * result + title.hashCode();
+ result = 31 * result + (sortingMethod != null ? sortingMethod.hashCode() : 0);
+ return result;
+ }
} \ No newline at end of file
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 b336b4a9..0dada540 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
@@ -1,7 +1,7 @@
package it.niedermann.owncloud.notes.persistence.entity;
import androidx.annotation.NonNull;
-import androidx.annotation.RestrictTo;
+import androidx.annotation.Nullable;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
@@ -13,7 +13,6 @@ import java.io.Serializable;
import java.util.Calendar;
import it.niedermann.owncloud.notes.shared.model.DBStatus;
-import it.niedermann.owncloud.notes.shared.model.Item;
@Entity(
foreignKeys = {
@@ -40,30 +39,38 @@ import it.niedermann.owncloud.notes.shared.model.Item;
)
public class Note implements Serializable {
@PrimaryKey(autoGenerate = true)
- private Long id;
+ private long id;
+ @Nullable
private Long remoteId;
- private Long accountId;
+ private long accountId;
+ @NonNull
private DBStatus status = DBStatus.VOID;
- private String title;
- @ColumnInfo(defaultValue = "0")
+ @NonNull
+ @ColumnInfo(defaultValue = "")
+ private String title = "";
+ @Nullable
private Calendar modified;
- private String content;
+ @NonNull
+ @ColumnInfo(defaultValue = "")
+ private String content = "";
@ColumnInfo(defaultValue = "0")
- private Boolean favorite;
+ private boolean favorite = false;
+ @Nullable
private Long categoryId;
+ @Nullable
private String eTag;
@NonNull
@ColumnInfo(defaultValue = "")
private String excerpt = "";
@ColumnInfo(defaultValue = "0")
- private Integer scrollY = 0;
+ private int scrollY = 0;
public Note() {
super();
}
@Ignore
- public Note(Long remoteId, Calendar modified, String title, String content, Boolean favorite, String eTag) {
+ public Note(@Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, boolean favorite, @Nullable String eTag) {
this.remoteId = remoteId;
this.title = title;
this.modified = modified;
@@ -73,7 +80,7 @@ public class Note implements Serializable {
}
@Ignore
- public Note(long id, Long remoteId, Calendar modified, String title, String content, boolean favorite, String etag, DBStatus status, long accountId, @NonNull String excerpt, Integer scrollY) {
+ public Note(long id, @Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, boolean favorite, @Nullable String etag, @NonNull DBStatus status, long accountId, @NonNull String excerpt, int scrollY) {
this(remoteId, modified, title, content, favorite, etag);
this.id = id;
this.status = status;
@@ -82,84 +89,90 @@ public class Note implements Serializable {
this.scrollY = scrollY;
}
- public Long getId() {
+ public long getId() {
return id;
}
- public void setId(Long id) {
+ public void setId(long id) {
this.id = id;
}
+ @Nullable
public Long getRemoteId() {
return remoteId;
}
- public void setRemoteId(Long remoteId) {
+ public void setRemoteId(@Nullable Long remoteId) {
this.remoteId = remoteId;
}
- public Long getAccountId() {
+ public long getAccountId() {
return accountId;
}
- public void setAccountId(Long accountId) {
+ public void setAccountId(long accountId) {
this.accountId = accountId;
}
- @RestrictTo(RestrictTo.Scope.TESTS)
- public Long getCategoryId() {
- return categoryId;
- }
-
- public void setCategoryId(Long categoryId) {
- this.categoryId = categoryId;
- }
-
+ @NonNull
public DBStatus getStatus() {
return status;
}
- public void setStatus(DBStatus status) {
+ public void setStatus(@NonNull DBStatus status) {
this.status = status;
}
+ @NonNull
public String getTitle() {
return title;
}
- public void setTitle(String title) {
+ public void setTitle(@NonNull String title) {
this.title = title;
}
+ @Nullable
public Calendar getModified() {
return modified;
}
- public void setModified(Calendar modified) {
+ public void setModified(@Nullable Calendar modified) {
this.modified = modified;
}
+ @NonNull
public String getContent() {
return content;
}
- public void setContent(String content) {
+ public void setContent(@NonNull String content) {
this.content = content;
}
- public Boolean getFavorite() {
+ public boolean getFavorite() {
return favorite;
}
- public void setFavorite(Boolean favorite) {
+ public void setFavorite(boolean favorite) {
this.favorite = favorite;
}
+ @Nullable
+ public Long getCategoryId() {
+ return categoryId;
+ }
+
+ public void setCategoryId(@Nullable Long categoryId) {
+ this.categoryId = categoryId;
+ }
+
+ @Nullable
public String getETag() {
return eTag;
}
- public void setETag(String eTag) {
+ public void setETag(@Nullable String eTag) {
this.eTag = eTag;
}
@@ -172,11 +185,11 @@ public class Note implements Serializable {
this.excerpt = excerpt;
}
- public Integer getScrollY() {
+ public int getScrollY() {
return scrollY;
}
- public void setScrollY(Integer scrollY) {
+ public void setScrollY(int scrollY) {
this.scrollY = scrollY;
}
@@ -187,39 +200,37 @@ public class Note implements Serializable {
Note note = (Note) o;
- if (id != null ? !id.equals(note.id) : note.id != null) 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)
return false;
- if (accountId != null ? !accountId.equals(note.accountId) : note.accountId != null)
- return false;
if (status != note.status) return false;
- if (title != null ? !title.equals(note.title) : note.title != null) return false;
+ if (!title.equals(note.title)) return false;
if (modified != null ? !modified.equals(note.modified) : note.modified != null)
return false;
- if (content != null ? !content.equals(note.content) : note.content != null) return false;
- if (favorite != null ? !favorite.equals(note.favorite) : note.favorite != null)
- return false;
+ if (!content.equals(note.content)) return false;
if (categoryId != null ? !categoryId.equals(note.categoryId) : note.categoryId != null)
return false;
if (eTag != null ? !eTag.equals(note.eTag) : note.eTag != null) return false;
- if (!excerpt.equals(note.excerpt)) return false;
- return scrollY != null ? scrollY.equals(note.scrollY) : note.scrollY == null;
+ return excerpt.equals(note.excerpt);
}
@Override
public int hashCode() {
- int result = id != null ? id.hashCode() : 0;
+ int result = (int) (id ^ (id >>> 32));
result = 31 * result + (remoteId != null ? remoteId.hashCode() : 0);
- result = 31 * result + (accountId != null ? accountId.hashCode() : 0);
- result = 31 * result + (status != null ? status.hashCode() : 0);
- result = 31 * result + (title != null ? title.hashCode() : 0);
+ result = 31 * result + (int) (accountId ^ (accountId >>> 32));
+ result = 31 * result + status.hashCode();
+ result = 31 * result + title.hashCode();
result = 31 * result + (modified != null ? modified.hashCode() : 0);
- result = 31 * result + (content != null ? content.hashCode() : 0);
- result = 31 * result + (favorite != null ? favorite.hashCode() : 0);
+ result = 31 * result + content.hashCode();
+ result = 31 * result + (favorite ? 1 : 0);
result = 31 * result + (categoryId != null ? categoryId.hashCode() : 0);
result = 31 * result + (eTag != null ? eTag.hashCode() : 0);
result = 31 * result + excerpt.hashCode();
- result = 31 * result + (scrollY != null ? scrollY.hashCode() : 0);
+ result = 31 * result + scrollY;
return result;
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java
index ee3a212d..187839bc 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java
@@ -14,7 +14,8 @@ import it.niedermann.owncloud.notes.shared.model.Item;
public class NoteWithCategory implements Serializable, Item {
@Embedded
private Note note;
- private String category;
+ @NonNull
+ private String category = "";
public NoteWithCategory() {
// Default constructor
@@ -22,55 +23,62 @@ public class NoteWithCategory implements Serializable, Item {
@Ignore
public NoteWithCategory(@NonNull Note note) {
- this(note, null);
+ this.note = note;
}
@Ignore
- public NoteWithCategory(@NonNull Note note, @Nullable String category) {
+ public NoteWithCategory(@NonNull Note note, @NonNull String category) {
this.note = note;
this.category = category;
}
+ @NonNull
public Note getNote() {
return note;
}
- public void setNote(Note note) {
+ public void setNote(@NonNull Note note) {
this.note = note;
}
- public Long getId() {
+ public long getId() {
return note.getId();
}
+ @Nullable
public Long getRemoteId() {
return note.getRemoteId();
}
- public Long getAccountId() {
+ public long getAccountId() {
return note.getAccountId();
}
+ @NonNull
public DBStatus getStatus() {
return note.getStatus();
}
+ @NonNull
public String getTitle() {
return note.getTitle();
}
+ @Nullable
public Calendar getModified() {
return note.getModified();
}
+ @NonNull
public String getContent() {
return note.getContent();
}
- public Boolean getFavorite() {
+ public boolean getFavorite() {
return note.getFavorite();
}
+ @Nullable
public String getETag() {
return note.getETag();
}
@@ -80,15 +88,16 @@ public class NoteWithCategory implements Serializable, Item {
return note.getExcerpt();
}
- public Integer getScrollY() {
+ public int getScrollY() {
return note.getScrollY();
}
+ @NonNull
public String getCategory() {
return category;
}
- public void setCategory(String category) {
+ public void setCategory(@NonNull String category) {
this.category = category;
}
@@ -100,13 +109,13 @@ public class NoteWithCategory implements Serializable, Item {
NoteWithCategory that = (NoteWithCategory) o;
if (note != null ? !note.equals(that.note) : that.note != null) return false;
- return category != null ? category.equals(that.category) : that.category == null;
+ return category.equals(that.category);
}
@Override
public int hashCode() {
int result = note != null ? note.hashCode() : 0;
- result = 31 * result + (category != null ? category.hashCode() : 0);
+ result = 31 * result + category.hashCode();
return result;
}
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 8ec12007..a7d95172 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
@@ -3,7 +3,6 @@ package it.niedermann.owncloud.notes.persistence.entity;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
@@ -42,6 +41,7 @@ public class NotesListWidgetData extends AbstractWidgetData {
@IntRange(from = 0, to = 2)
private int mode;
+ @Nullable
private Long categoryId;
@Nullable
@@ -53,14 +53,33 @@ public class NotesListWidgetData extends AbstractWidgetData {
this.categoryId = categoryId;
}
- public void setMode(int mode) {
+ public void setMode(@IntRange(from = 0, to = 2) int mode) {
this.mode = mode;
}
+ @IntRange(from = 0, to = 2)
public int getMode() {
return mode;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof NotesListWidgetData)) return false;
+
+ NotesListWidgetData that = (NotesListWidgetData) o;
+
+ if (mode != that.mode) return false;
+ return categoryId != null ? categoryId.equals(that.categoryId) : that.categoryId == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = mode;
+ result = 31 * result + (categoryId != null ? categoryId.hashCode() : 0);
+ return result;
+ }
+
@NonNull
@Override
public String toString() {
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 d7fad48c..3e726242 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
@@ -1,6 +1,5 @@
package it.niedermann.owncloud.notes.persistence.entity;
-import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
@@ -32,7 +31,7 @@ public class SingleNoteWidgetData extends AbstractWidgetData {
private long noteId;
public SingleNoteWidgetData() {
-
+ // Default constructor
}
@Ignore
@@ -48,4 +47,19 @@ public class SingleNoteWidgetData extends AbstractWidgetData {
public void setNoteId(long noteId) {
this.noteId = noteId;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof SingleNoteWidgetData)) return false;
+
+ SingleNoteWidgetData that = (SingleNoteWidgetData) o;
+
+ return noteId == that.noteId;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) (noteId ^ (noteId >>> 32));
+ }
} \ No newline at end of file
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java
index bff6f181..9f749d86 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java
@@ -37,9 +37,9 @@ public class Migration_19_20 extends Migration {
db.execSQL("DROP INDEX NOTES_CATEGORY_idx");
db.execSQL("DROP INDEX NOTES_MODIFIED_idx");
- db.execSQL("CREATE TABLE `Account` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `url` TEXT, `userName` TEXT, `accountName` TEXT, `eTag` TEXT, `modified` INTEGER, `apiVersion` TEXT, `color` INTEGER DEFAULT -16743735, `textColor` INTEGER DEFAULT -16777216, `capabilitiesETag` TEXT)");
- db.execSQL("CREATE TABLE `Category` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `accountId` INTEGER NOT NULL, `title` TEXT, `sortingMethod` INTEGER, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
- db.execSQL("CREATE TABLE `Note` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` INTEGER, `accountId` INTEGER, `status` TEXT, `title` TEXT, `modified` INTEGER DEFAULT 0, `content` TEXT, `favorite` INTEGER DEFAULT 0, `categoryId` INTEGER, `eTag` TEXT, `excerpt` TEXT NOT NULL DEFAULT '', `scrollY` INTEGER DEFAULT 0, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`categoryId`) REFERENCES `Category`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )");
+ db.execSQL("CREATE TABLE `Account` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL DEFAULT '', `userName` TEXT NOT NULL DEFAULT '', `accountName` TEXT NOT NULL DEFAULT '', `eTag` TEXT, `modified` INTEGER, `apiVersion` TEXT, `color` INTEGER NOT NULL DEFAULT -16743735, `textColor` INTEGER NOT NULL DEFAULT -16777216, `capabilitiesETag` TEXT)");
+ db.execSQL("CREATE TABLE `Category` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `accountId` INTEGER NOT NULL, `title` TEXT NOT NULL DEFAULT '', `sortingMethod` INTEGER, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
+ db.execSQL("CREATE TABLE `Note` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `remoteId` INTEGER, `accountId` INTEGER NOT NULL, `status` TEXT NOT NULL, `title` TEXT NOT NULL DEFAULT '', `modified` INTEGER, `content` TEXT NOT NULL DEFAULT '', `favorite` INTEGER NOT NULL DEFAULT 0, `categoryId` INTEGER, `eTag` TEXT, `excerpt` TEXT NOT NULL DEFAULT '', `scrollY` INTEGER NOT NULL DEFAULT 0, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`categoryId`) REFERENCES `Category`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )");
db.execSQL("CREATE TABLE `NotesListWidgetData` (`mode` INTEGER NOT NULL, `categoryId` INTEGER, `id` INTEGER NOT NULL, `accountId` INTEGER NOT NULL, `themeMode` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`categoryId`) REFERENCES `Category`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
db.execSQL("CREATE TABLE `SingleNoteWidgetData` (`noteId` INTEGER NOT NULL, `id` INTEGER NOT NULL, `accountId` INTEGER NOT NULL, `themeMode` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java
index 35ab8b66..6191bb9e 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java
@@ -4,7 +4,7 @@ public enum CategorySortingMethod {
SORT_MODIFIED_DESC("MODIFIED DESC"),
SORT_LEXICOGRAPHICAL_ASC("TITLE COLLATE NOCASE ASC");
- private String sorder; // sorting method OrderBy for SQL
+ private final String sorder; // sorting method OrderBy for SQL
/***
* Constructor
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java
index 2e0ca30d..fbf94237 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java
@@ -76,7 +76,7 @@ public class ServerResponse {
String content = "";
Calendar modified = null;
boolean favorite = false;
- String category = null;
+ String category = "";
String etag = null;
if (!json.isNull(NotesClient.JSON_ID)) {
id = json.getLong(NotesClient.JSON_ID);
@@ -88,7 +88,7 @@ public class ServerResponse {
content = json.getString(NotesClient.JSON_CONTENT);
}
if (!json.isNull(NotesClient.JSON_MODIFIED)) {
- modified = GregorianCalendar.getInstance();
+ modified = Calendar.getInstance();
modified.setTimeInMillis(json.getLong(NotesClient.JSON_MODIFIED) * 1000);
}
if (!json.isNull(NotesClient.JSON_FAVORITE)) {
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java
index 9873d100..f561f638 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java
@@ -12,7 +12,7 @@ public abstract class AbstractWidgetData {
private int themeMode;
protected AbstractWidgetData() {
-
+ // Default constructor
}
protected AbstractWidgetData(int id, long accountId, @IntRange(from = 0, to = 2) int themeMode) {
@@ -45,4 +45,24 @@ public abstract class AbstractWidgetData {
public void setThemeMode(@IntRange(from = 0, to = 2) int themeMode) {
this.themeMode = themeMode;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof AbstractWidgetData)) return false;
+
+ AbstractWidgetData that = (AbstractWidgetData) o;
+
+ if (id != that.id) return false;
+ if (accountId != that.accountId) return false;
+ return themeMode == that.themeMode;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id;
+ result = 31 * result + (int) (accountId ^ (accountId >>> 32));
+ result = 31 * result + themeMode;
+ return result;
+ }
}