Get feed id as room insert result

This commit is contained in:
Shinokuni 2019-02-01 19:20:21 +00:00
parent 6cd29826c1
commit adbbf2f2bd
3 changed files with 6 additions and 11 deletions

View File

@ -122,11 +122,9 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
Feed dbFeed = database.feedDao().getFeedByUrl(rssFeed.getChannel().getFeedUrl());
if (dbFeed == null) {
dbFeed = Feed.feedFromRSS(rssFeed.getChannel());
dbFeed.setColor(getFaviconColor(dbFeed.getSiteUrl()));
database.feedDao().insert(dbFeed);
dbFeed.setId(database.feedDao().getFeedIdByUrl(rssFeed.getChannel().getFeedUrl()));
dbFeed.setId((int)(database.feedDao().insert(dbFeed)));
}
List<Item> dbItems = Item.itemsFromRSS(rssFeed.getChannel().getItems(), dbFeed);
@ -143,11 +141,9 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
Feed dbFeed = database.feedDao().getFeedByUrl(feed.getLink());
if (dbFeed == null) {
dbFeed = Feed.feedFromATOM(feed);
database.feedDao().insert(dbFeed);
dbFeed.setColor(getFaviconColor(dbFeed.getSiteUrl()));
dbFeed.setId(database.feedDao().getFeedIdByUrl(feed.getLink()));
dbFeed.setId((int)(database.feedDao().insert(dbFeed)));
}
List<Item> dbItems = Item.itemsFromATOM(feed.getEntries(), dbFeed);
@ -165,11 +161,9 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
Feed dbFeed = database.feedDao().getFeedByUrl(feed.getFeedUrl());
if (dbFeed == null) {
dbFeed = Feed.feedFromJSON(feed);
database.feedDao().insert(dbFeed);
dbFeed.setColor(getFaviconColor(dbFeed.getSiteUrl()));
dbFeed.setId(database.feedDao().getFeedIdByUrl(feed.getFeedUrl()));
dbFeed.setId((int)(database.feedDao().insert(dbFeed)));
}
List<Item> dbItems = Item.itemsFromJSON(feed.getItems(), dbFeed);
@ -205,6 +199,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
Response response = okHttpClient.newCall(request).execute();
InputStream inputStream = response.body().byteStream();
return BitmapFactory.decodeStream(inputStream);
}

View File

@ -16,7 +16,7 @@ public interface FeedDao {
List<Feed> getAllFeeds();
@Insert
void insert(Feed feed);
long insert(Feed feed);
@Query("Select count(*) from Feed")
int getFeedCount();

View File

@ -27,7 +27,7 @@ public interface ItemDao {
String guidExist(String guid);
@Insert
void insert(Item item);
long insert(Item item);
@Insert
void insertAll(List<Item> items);