From adbbf2f2bd9da5ab8efca2a873fceae782eec65a Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Fri, 1 Feb 2019 19:20:21 +0000 Subject: [PATCH] Get feed id as room insert result --- .../java/com/readrops/app/LocalFeedRepository.java | 13 ++++--------- .../java/com/readrops/app/database/dao/FeedDao.java | 2 +- .../java/com/readrops/app/database/dao/ItemDao.java | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/readrops/app/LocalFeedRepository.java b/app/src/main/java/com/readrops/app/LocalFeedRepository.java index e8794ba6..e3c517e4 100644 --- a/app/src/main/java/com/readrops/app/LocalFeedRepository.java +++ b/app/src/main/java/com/readrops/app/LocalFeedRepository.java @@ -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 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 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 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); } diff --git a/app/src/main/java/com/readrops/app/database/dao/FeedDao.java b/app/src/main/java/com/readrops/app/database/dao/FeedDao.java index 628bab1e..727b16e1 100644 --- a/app/src/main/java/com/readrops/app/database/dao/FeedDao.java +++ b/app/src/main/java/com/readrops/app/database/dao/FeedDao.java @@ -16,7 +16,7 @@ public interface FeedDao { List getAllFeeds(); @Insert - void insert(Feed feed); + long insert(Feed feed); @Query("Select count(*) from Feed") int getFeedCount(); diff --git a/app/src/main/java/com/readrops/app/database/dao/ItemDao.java b/app/src/main/java/com/readrops/app/database/dao/ItemDao.java index 3decac9d..0a049f9a 100644 --- a/app/src/main/java/com/readrops/app/database/dao/ItemDao.java +++ b/app/src/main/java/com/readrops/app/database/dao/ItemDao.java @@ -27,7 +27,7 @@ public interface ItemDao { String guidExist(String guid); @Insert - void insert(Item item); + long insert(Item item); @Insert void insertAll(List items);