mirror of https://github.com/readrops/Readrops.git
Migrate Folder entity to kotlin
This commit is contained in:
parent
61f8798be5
commit
40c3a52948
|
@ -71,7 +71,7 @@ object OPMLParser {
|
||||||
if ((outline.outlines != null && !outline.outlines?.isEmpty()!!) || outline.xmlUrl.isNullOrEmpty()) {
|
if ((outline.outlines != null && !outline.outlines?.isEmpty()!!) || outline.xmlUrl.isNullOrEmpty()) {
|
||||||
// if the outline doesn't have text or title value but contains sub outlines,
|
// 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
|
// 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 {
|
outline.outlines?.forEach {
|
||||||
val recursiveFeedsFolders = parseOutline(it)
|
val recursiveFeedsFolders = parseOutline(it)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.*
|
||||||
class FreshRSSFoldersAdapter {
|
class FreshRSSFoldersAdapter {
|
||||||
|
|
||||||
@ToJson
|
@ToJson
|
||||||
fun toJson(folder: Folder): String = ""
|
fun toJson(folders: List<Folder>): String = ""
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
@FromJson
|
@FromJson
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.squareup.moshi.ToJson
|
||||||
class NextNewsFoldersAdapter {
|
class NextNewsFoldersAdapter {
|
||||||
|
|
||||||
@ToJson
|
@ToJson
|
||||||
fun toJson(folder: Folder): String = ""
|
fun toJson(folders: List<Folder>): String = ""
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
@FromJson
|
@FromJson
|
||||||
|
|
|
@ -90,7 +90,8 @@ public class ManageFeedsFoldersActivity extends AppCompatActivity {
|
||||||
.title(R.string.add_folder)
|
.title(R.string.add_folder)
|
||||||
.positiveText(R.string.validate)
|
.positiveText(R.string.validate)
|
||||||
.input(R.string.folder, 0, (dialog, input) -> {
|
.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());
|
folder.setAccountId(account.getId());
|
||||||
|
|
||||||
viewModel.addFolder(folder)
|
viewModel.addFolder(folder)
|
||||||
|
|
|
@ -63,7 +63,7 @@ public abstract class FeedDao implements BaseDao<Feed> {
|
||||||
public abstract void updateColors(int feedId, int textColor, int bgColor);
|
public abstract void updateColors(int feedId, int textColor, int bgColor);
|
||||||
|
|
||||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
|
@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.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")
|
", 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);
|
public abstract LiveData<List<FeedWithFolder>> getAllFeedsWithFolder(int accountId);
|
||||||
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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!!)
|
||||||
|
}
|
Loading…
Reference in New Issue