Migrate Item entity to kotlin

This commit is contained in:
Shinokuni 2021-09-01 19:17:38 +02:00
parent 40c3a52948
commit 6b2a279813
4 changed files with 45 additions and 218 deletions

View File

@ -218,7 +218,7 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
@NonNull
@Override
public List<String> getPreloadItems(int position) {
if (getItem(position).getItem().hasImage()) {
if (getItem(position).getItem().getHasImage()) {
String url = getItem(position).getItem().getImageLink();
return Collections.singletonList(url);
} else {
@ -296,13 +296,13 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
binding.itemDescription.setText(item.getCleanDescription());
} else {
binding.itemDescription.setVisibility(View.GONE);
if (itemWithFeed.getItem().hasImage())
if (itemWithFeed.getItem().getHasImage())
binding.itemTitle.setMaxLines(4);
}
}
private void setImages(ItemWithFeed itemWithFeed) {
if (itemWithFeed.getItem().hasImage()) {
if (itemWithFeed.getItem().getHasImage()) {
binding.itemImage.setVisibility(View.VISIBLE);
glideRequests

View File

@ -43,9 +43,9 @@ interface ItemStateChangeDao : BaseDao<ItemStateChange> {
fun upsertItemReadStateChange(item: Item, accountId: Int, useSeparateState: Boolean) = Completable.create {
if (itemStateChangeExists(item.id, accountId)) {
val oldItemReadState = if (useSeparateState)
getItemReadState(item.remoteId, accountId)
getItemReadState(item.remoteId!!, accountId)
else
getStandardItemReadState(item.remoteId, accountId)
getStandardItemReadState(item.remoteId!!, accountId)
val readChange = item.isRead != oldItemReadState
@ -69,9 +69,9 @@ interface ItemStateChangeDao : BaseDao<ItemStateChange> {
fun upsertItemStarStateChange(item: Item, accountId: Int, useSeparateState: Boolean) = Completable.create {
if (itemStateChangeExists(item.id, accountId)) {
val oldItemStarState = if (useSeparateState)
getItemStarState(item.remoteId, accountId)
getItemStarState(item.remoteId!!, accountId)
else
getStandardItemStarState(item.remoteId, accountId)
getStandardItemStarState(item.remoteId!!, accountId)
val starChange = item.isStarred != oldItemStarState

View File

@ -1,211 +0,0 @@
package com.readrops.db.entities;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import org.joda.time.LocalDateTime;
import static androidx.room.ForeignKey.CASCADE;
@Entity(foreignKeys = @ForeignKey(entity = Feed.class, parentColumns = "id", childColumns = "feed_id", onDelete = CASCADE))
public class Item implements Comparable<Item> {
@PrimaryKey(autoGenerate = true)
private int id;
private String title;
private String description;
@ColumnInfo(name = "clean_description")
private String cleanDescription;
private String link;
@ColumnInfo(name = "image_link")
private String imageLink;
private String author;
@ColumnInfo(name = "pub_date")
private LocalDateTime pubDate;
private String content;
@ColumnInfo(name = "feed_id", index = true)
private int feedId;
@ColumnInfo(index = true)
private String guid;
@ColumnInfo(name = "read_time")
private double readTime;
private boolean read;
private boolean starred;
@ColumnInfo(name = "read_it_later")
private boolean readItLater;
private String remoteId;
@Ignore
private String feedRemoteId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCleanDescription() {
return cleanDescription;
}
public void setCleanDescription(String cleanDescription) {
this.cleanDescription = cleanDescription;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getImageLink() {
return imageLink;
}
public void setImageLink(String imageLink) {
this.imageLink = imageLink;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public LocalDateTime getPubDate() {
return pubDate;
}
public void setPubDate(LocalDateTime pubDate) {
this.pubDate = pubDate;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getGuid() {
return guid;
}
public void setGuid(String guid) {
this.guid = guid;
}
public int getFeedId() {
return feedId;
}
public void setFeedId(int feedId) {
this.feedId = feedId;
}
public boolean hasImage() {
return getImageLink() != null;
}
public double getReadTime() {
return readTime;
}
public void setReadTime(double readTime) {
this.readTime = readTime;
}
public String getText() {
if (content != null)
return content;
else
return description;
}
public boolean isRead() {
return read;
}
public void setRead(boolean read) {
this.read = read;
}
public boolean isStarred() {
return starred;
}
public void setStarred(boolean starred) {
this.starred = starred;
}
public boolean isReadItLater() {
return readItLater;
}
public void setReadItLater(boolean readItLater) {
this.readItLater = readItLater;
}
public String getRemoteId() {
return remoteId;
}
public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}
public String getFeedRemoteId() {
return feedRemoteId;
}
public void setFeedRemoteId(String feedRemoteId) {
this.feedRemoteId = feedRemoteId;
}
@Override
public int compareTo(Item o) {
return this.pubDate.compareTo(o.getPubDate());
}
}

View File

@ -0,0 +1,38 @@
package com.readrops.db.entities
import android.os.Parcelable
import androidx.room.*
import kotlinx.parcelize.Parcelize
import org.joda.time.LocalDateTime
@Parcelize
@Entity(foreignKeys = [ForeignKey(entity = Feed::class, parentColumns = ["id"],
childColumns = ["feed_id"], onDelete = ForeignKey.CASCADE)])
data class Item(
@PrimaryKey(autoGenerate = true) var id: Int = 0,
var title: String? = null,
var description: String? = null,
@ColumnInfo(name = "clean_description") var cleanDescription: String? = null,
var link: String? = null,
@ColumnInfo(name = "image_link") var imageLink: String? = null,
var author: String? = null,
@ColumnInfo(name = "pub_date") var pubDate: LocalDateTime? = null,
var content: String? = null,
@ColumnInfo(name = "feed_id", index = true) var feedId: Int = 0,
@ColumnInfo(index = true) var guid: String? = null,
@ColumnInfo(name = "read_time") var readTime: Double = 0.0,
@ColumnInfo(name = "read") var isRead: Boolean = false,
@ColumnInfo(name = "starred") var isStarred: Boolean = false,
@ColumnInfo(name = "read_it_later") var isReadItLater: Boolean = false,
var remoteId: String? = null,
@Ignore var feedRemoteId: String? = null,
) : Parcelable, Comparable<Item> {
val text
get() = if (content != null) content else description
val hasImage
get() = imageLink != null
override fun compareTo(other: Item): Int = this.pubDate!!.compareTo(other.pubDate)
}