From 1654d3221197cc97d12ce9a3218365f822fc89f0 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Wed, 1 Sep 2021 19:41:45 +0200 Subject: [PATCH] MIgrate Account entity to kotlin --- .../com/readrops/api/services/Credentials.kt | 2 +- .../notifications/sync/SyncResultAnalyser.kt | 2 +- .../readrops/db/entities/account/Account.java | 230 ------------------ .../readrops/db/entities/account/Account.kt | 43 ++++ 4 files changed, 45 insertions(+), 232 deletions(-) delete mode 100644 db/src/main/java/com/readrops/db/entities/account/Account.java create mode 100644 db/src/main/java/com/readrops/db/entities/account/Account.kt diff --git a/api/src/main/java/com/readrops/api/services/Credentials.kt b/api/src/main/java/com/readrops/api/services/Credentials.kt index 38a223f4..a20eacb7 100644 --- a/api/src/main/java/com/readrops/api/services/Credentials.kt +++ b/api/src/main/java/com/readrops/api/services/Credentials.kt @@ -12,7 +12,7 @@ abstract class Credentials(val authorization: String?, val url: String) { companion object { @JvmStatic fun toCredentials(account: Account): Credentials { - val endPoint = getEndPoint(account.accountType) + val endPoint = getEndPoint(account.accountType!!) return when (account.accountType) { AccountType.NEXTCLOUD_NEWS -> NextNewsCredentials(account.login, account.password, account.url + endPoint) diff --git a/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt b/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt index b957e24b..5975c6cf 100644 --- a/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt +++ b/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt @@ -51,7 +51,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map 1 && itemCount > 1) { notifContent.title = account.accountName notifContent.content = context.getString(R.string.new_items, itemCount.toString()) - notifContent.largeIcon = Utils.getBitmapFromDrawable(ContextCompat.getDrawable(context, account.accountType.iconRes)) + notifContent.largeIcon = Utils.getBitmapFromDrawable(ContextCompat.getDrawable(context, account.accountType!!.iconRes)) } else if (feedsIdsForNewItems.size == 1) // new items from only one feed from one account oneFeedCase(feedsIdsForNewItems.first(), syncResult.items) else if (itemCount == 1) diff --git a/db/src/main/java/com/readrops/db/entities/account/Account.java b/db/src/main/java/com/readrops/db/entities/account/Account.java deleted file mode 100644 index 1e37ecc8..00000000 --- a/db/src/main/java/com/readrops/db/entities/account/Account.java +++ /dev/null @@ -1,230 +0,0 @@ -package com.readrops.db.entities.account; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.Nullable; -import androidx.room.ColumnInfo; -import androidx.room.Entity; -import androidx.room.Ignore; -import androidx.room.PrimaryKey; - -@Entity -public class Account implements Parcelable { - - @PrimaryKey(autoGenerate = true) - private int id; - - private String url; - - @ColumnInfo(name = "account_name") - private String accountName; - - @ColumnInfo(name = "displayed_name") - private String displayedName; - - @ColumnInfo(name = "account_type") - private AccountType accountType; - - @ColumnInfo(name = "last_modified") - private long lastModified; - - @ColumnInfo(name = "current_account") - private boolean currentAccount; - - private String token; - private String writeToken; // TODO : see if there is a better solution to store specific service account fields - - @ColumnInfo(name = "notifications_enabled") - private boolean notificationsEnabled; - - @Ignore - private String login; - - @Ignore - private String password; - - public Account() { - } - - @Ignore - public Account(String url, String accountName, AccountType accountType) { - this.url = url; - this.accountName = accountName; - this.accountType = accountType; - } - - protected Account(Parcel in) { - id = in.readInt(); - url = in.readString(); - accountName = in.readString(); - accountType = AccountType.values()[in.readInt()]; - displayedName = in.readString(); - lastModified = in.readLong(); - currentAccount = in.readByte() != 0; - login = in.readString(); - password = in.readString(); - token = in.readString(); - writeToken = in.readString(); - notificationsEnabled = in.readByte() != 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public Account createFromParcel(Parcel in) { - return new Account(in); - } - - @Override - public Account[] newArray(int size) { - return new Account[size]; - } - }; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getAccountName() { - return accountName; - } - - public void setAccountName(String accountName) { - this.accountName = accountName; - } - - public String getDisplayedName() { - return displayedName; - } - - public void setDisplayedName(String displayedName) { - this.displayedName = displayedName; - } - - public AccountType getAccountType() { - return accountType; - } - - public void setAccountType(AccountType accountType) { - this.accountType = accountType; - } - - public long getLastModified() { - return lastModified; - } - - public void setLastModified(long lastModified) { - this.lastModified = lastModified; - } - - public boolean isCurrentAccount() { - return currentAccount; - } - - public void setCurrentAccount(boolean currentAccount) { - this.currentAccount = currentAccount; - } - - public String getLogin() { - return login; - } - - public void setLogin(String login) { - this.login = login; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getLoginKey() { - return accountType.name() + "_login_" + id; - } - - public String getPasswordKey() { - return accountType.name() + "_password_" + id; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public String getWriteToken() { - return writeToken; - } - - public void setWriteToken(String writeToken) { - this.writeToken = writeToken; - } - - public boolean isNotificationsEnabled() { - return notificationsEnabled; - } - - public void setNotificationsEnabled(boolean notificationsEnabled) { - this.notificationsEnabled = notificationsEnabled; - } - - public AccountConfig getConfig() { - return accountType.getAccountConfig(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(id); - dest.writeString(url); - dest.writeString(accountName); - dest.writeInt(accountType.ordinal()); - dest.writeString(displayedName); - dest.writeLong(lastModified); - dest.writeByte((byte) (currentAccount ? 1 : 0)); - dest.writeString(login); - dest.writeString(password); - dest.writeString(token); - dest.writeString(writeToken); - dest.writeByte((byte) (notificationsEnabled ? 1 : 0)); - } - - public boolean isLocal() { - return accountType == AccountType.LOCAL; - } - - public boolean is(AccountType accountType) { - return this.accountType == accountType; - } - - @Override - public boolean equals(@Nullable Object obj) { - if (obj == null) - return false; - else if (!(obj instanceof Account)) - return false; - else - return this.id == ((Account) obj).getId(); - } -} diff --git a/db/src/main/java/com/readrops/db/entities/account/Account.kt b/db/src/main/java/com/readrops/db/entities/account/Account.kt new file mode 100644 index 00000000..c6fc2f10 --- /dev/null +++ b/db/src/main/java/com/readrops/db/entities/account/Account.kt @@ -0,0 +1,43 @@ +package com.readrops.db.entities.account + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.Ignore +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity +data class Account( + @PrimaryKey(autoGenerate = true) var id: Int = 0, + var url: String? = null, + @ColumnInfo(name = "account_name") var accountName: String? = null, + @ColumnInfo(name = "displayed_name") var displayedName: String? = null, + @ColumnInfo(name = "account_type") var accountType: AccountType? = null, + @ColumnInfo(name = "last_modified") var lastModified: Long = 0, + @ColumnInfo(name = "current_account") var isCurrentAccount: Boolean = false, + var token: String? = null, + var writeToken: String? = null, // TODO : see if there is a better solution to store specific service account fields + @ColumnInfo(name = "notifications_enabled") var isNotificationsEnabled: Boolean = false, + @Ignore var login: String? = null, + @Ignore var password: String? = null, +) : Parcelable { + + constructor(accountUrl: String?, accountName: String, accountType: AccountType): + this(url = accountUrl, accountName = accountName, accountType = accountType) + + val config: AccountConfig + get() = accountType!!.accountConfig + + val isLocal + get() = accountType == AccountType.LOCAL + + fun `is`(accountType: AccountType) = this.accountType == accountType + + val loginKey + get() = accountType!!.name + "_login_" + id + + val passwordKey + get() = accountType!!.name + "_password_" + id +} \ No newline at end of file