Migrate Folder entity to kotlin

This commit is contained in:
Shinokuni 2021-09-01 19:01:32 +02:00
parent 61f8798be5
commit 40c3a52948
7 changed files with 28 additions and 128 deletions

View File

@ -71,7 +71,7 @@ object OPMLParser {
if ((outline.outlines != null && !outline.outlines?.isEmpty()!!) || outline.xmlUrl.isNullOrEmpty()) {
// if the outline doesn't have text or title value but contains sub outlines,
// those sub outlines will be considered as not belonging to any folder and join the others at the top level of the hierarchy
val folder = if (outline.name != null) Folder(outline.name) else null
val folder = if (outline.name != null) Folder(name = outline.name) else null
outline.outlines?.forEach {
val recursiveFeedsFolders = parseOutline(it)

View File

@ -12,7 +12,7 @@ import java.util.*
class FreshRSSFoldersAdapter {
@ToJson
fun toJson(folder: Folder): String = ""
fun toJson(folders: List<Folder>): String = ""
@SuppressLint("CheckResult")
@FromJson

View File

@ -11,7 +11,7 @@ import com.squareup.moshi.ToJson
class NextNewsFoldersAdapter {
@ToJson
fun toJson(folder: Folder): String = ""
fun toJson(folders: List<Folder>): String = ""
@SuppressLint("CheckResult")
@FromJson

View File

@ -90,7 +90,8 @@ public class ManageFeedsFoldersActivity extends AppCompatActivity {
.title(R.string.add_folder)
.positiveText(R.string.validate)
.input(R.string.folder, 0, (dialog, input) -> {
Folder folder = new Folder(input.toString());
Folder folder = new Folder();
folder.setName(input.toString());
folder.setAccountId(account.getId());
viewModel.addFolder(folder)

View File

@ -63,7 +63,7 @@ public abstract class FeedDao implements BaseDao<Feed> {
public abstract void updateColors(int feedId, int textColor, int bgColor);
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("Select Feed.name as feed_name, Feed.id as feed_id, Folder.name as folder_name, Folder.id as folder_id, Folder.remoteId as folder_remoteId," +
@Query("Select Feed.name as feed_name, Feed.id as feed_id, Folder.name as folder_name, Folder.id as folder_id, Folder.remoteId as folder_remoteId, Folder.account_id as folder_account_id," +
"Feed.description as feed_description, Feed.icon_url as feed_icon_url, Feed.url as feed_url, Feed.folder_id as feed_folder_id" +
", Feed.siteUrl as feed_siteUrl, Feed.remoteId as feed_remoteId from Feed Left Join Folder on Feed.folder_id = Folder.id Where Feed.account_id = :accountId Order by Feed.name")
public abstract LiveData<List<FeedWithFolder>> getAllFeedsWithFolder(int accountId);

View File

@ -1,123 +0,0 @@
package com.readrops.db.entities;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import com.readrops.db.entities.account.Account;
import java.util.Objects;
@Entity(foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "id",
childColumns = "account_id", onDelete = ForeignKey.CASCADE))
public class Folder implements Parcelable, Comparable<Folder> {
@PrimaryKey(autoGenerate = true)
private int id;
private String name;
private String remoteId;
@ColumnInfo(name = "account_id", index = true)
private int accountId;
public Folder() {
}
@Ignore
public Folder(String name) {
this.name = name;
}
protected Folder(Parcel in) {
id = in.readInt();
name = in.readString();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRemoteId() {
return remoteId;
}
public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}
public int getAccountId() {
return accountId;
}
public void setAccountId(int accountId) {
this.accountId = accountId;
}
public static final Creator<Folder> CREATOR = new Creator<Folder>() {
@Override
public Folder createFromParcel(Parcel in) {
return new Folder(in);
}
@Override
public Folder[] newArray(int size) {
return new Folder[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
} else if (!(o instanceof Folder)) {
return false;
} else {
Folder folder = (Folder) o;
return id == folder.id && Objects.equals(name, folder.name) &&
Objects.equals(remoteId, folder.remoteId) &&
accountId == folder.accountId;
}
}
@Override
public int hashCode() {
return Objects.hash(id, name, remoteId, accountId);
}
@Override
public int compareTo(Folder o) {
return this.getName().compareTo(o.getName());
}
}

View File

@ -0,0 +1,22 @@
package com.readrops.db.entities
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
import com.readrops.db.entities.account.Account
import kotlinx.parcelize.Parcelize
@Parcelize
@Entity(foreignKeys = [ForeignKey(entity = Account::class, parentColumns = ["id"],
childColumns = ["account_id"], onDelete = ForeignKey.CASCADE)])
data class Folder(
@PrimaryKey(autoGenerate = true) var id: Int = 0,
var name: String? = null,
var remoteId: String? = null,
@ColumnInfo(name = "account_id", index = true) var accountId: Int = 0,
) : Parcelable, Comparable<Folder> {
override fun compareTo(other: Folder): Int = this.name!!.compareTo(other.name!!)
}