Add support for mime-type application/xml and retrieving absolute favicon url

This commit is contained in:
Shinokuni 2019-02-04 17:39:19 +00:00
parent 4c2a5c682a
commit c8680af7ca
6 changed files with 18 additions and 14 deletions

View File

@ -132,7 +132,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
}
List<Item> dbItems = Item.itemsFromRSS(rssFeed.getChannel().getItems(), dbFeed);
insertItems(dbItems);
insertItems(dbItems, dbFeed);
} catch (Exception e) {
failureCallBackInMainThread(e);
@ -151,7 +151,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
}
List<Item> dbItems = Item.itemsFromATOM(feed.getEntries(), dbFeed);
insertItems(dbItems);
insertItems(dbItems, dbFeed);
} catch (Exception e) {
failureCallBackInMainThread(e);
@ -171,19 +171,19 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
}
List<Item> dbItems = Item.itemsFromJSON(feed.getItems(), dbFeed);
insertItems(dbItems);
insertItems(dbItems, dbFeed);
} catch (Exception e) {
failureCallBackInMainThread(e);
}
}
private void insertItems(List<Item> items) {
private void insertItems(List<Item> items, Feed feed) {
for (Item dbItem : items) {
if (!Boolean.valueOf(database.itemDao().guidExist(dbItem.getGuid()))) {
if (dbItem.getDescription() != null) {
if (dbItem.getImageLink() == null)
dbItem.setImageLink(HtmlParser.getDescImageLink(dbItem.getDescription()));
dbItem.setImageLink(HtmlParser.getDescImageLink(dbItem.getDescription(), feed.getSiteUrl()));
dbItem.setDescription(Jsoup.parse(dbItem.getDescription()).text());
}

View File

@ -86,6 +86,7 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
glideRequests
.load(itemWithFeed.getItem().getImageLink())
.centerCrop()
.apply(requestOptions)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.transition(DrawableTransitionOptions.withCrossFade(FADE_FACTORY))

View File

@ -20,7 +20,7 @@ public interface ItemDao {
@Query("Select * from Item Order By pub_date DESC")
LiveData<List<Item>> getAll();
@Query("Select Item.id, title, Item.description, image_link, pub_date, name, color, icon_url from Item Inner Join Feed on Item.feed_id = Feed.id Order By Item.id ASC")
@Query("Select Item.id, title, Item.description, image_link, pub_date, name, color, icon_url from Item Inner Join Feed on Item.feed_id = Feed.id Order By Item.id DESC")
LiveData<List<ItemWithFeed>> getAllItemWithFeeds();
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")

View File

@ -1,6 +1,5 @@
package com.readrops.readropslibrary;
import android.text.LoginFilter;
import android.util.Log;
import com.readrops.readropslibrary.Utils.Utils;
@ -46,10 +45,11 @@ public final class HtmlParser {
}
private static boolean isTypeRssFeed(String type) {
return type.equals(Utils.RSS_CONTENT_TYPE) ||
return type.equals(Utils.RSS_DEFAULT_CONTENT_TYPE) ||
type.equals(Utils.ATOM_CONTENT_TYPE) ||
type.equals(Utils.JSON_CONTENT_TYPE) ||
type.equals(Utils.RSS_TEXT_CONTENT_TYPE);
type.equals(Utils.RSS_TEXT_CONTENT_TYPE) ||
type.equals(Utils.RSS_APPLICATION_CONTENT_TYPE);
}
/**
@ -102,12 +102,12 @@ public final class HtmlParser {
return head;
}
public static String getDescImageLink(String description) {
Document document = Jsoup.parse(description);
public static String getDescImageLink(String description, String url) {
Document document = Jsoup.parse(description, url);
Elements elements = document.select("img");
if (!elements.isEmpty())
return elements.first().attr("src");
return elements.first().absUrl("src");
else
return null;
}

View File

@ -5,8 +5,9 @@ import java.util.Scanner;
public final class Utils {
public static final String RSS_CONTENT_TYPE = "application/rss+xml";
public static final String RSS_DEFAULT_CONTENT_TYPE = "application/rss+xml";
public static final String RSS_TEXT_CONTENT_TYPE = "text/xml";
public static final String RSS_APPLICATION_CONTENT_TYPE = "application/xml";
public static final String ATOM_CONTENT_TYPE = "application/atom+xml";
public static final String JSON_CONTENT_TYPE = "application/json";

View File

@ -100,10 +100,12 @@ public class RSSNetwork {
*/
private RSSType getRSSType(String contentType) {
switch (contentType) {
case Utils.RSS_CONTENT_TYPE:
case Utils.RSS_DEFAULT_CONTENT_TYPE:
return RSSType.RSS_2;
case Utils.RSS_TEXT_CONTENT_TYPE:
return RSSType.RSS_2;
case Utils.RSS_APPLICATION_CONTENT_TYPE:
return RSSType.RSS_2;
case Utils.ATOM_CONTENT_TYPE:
return RSSType.RSS_ATOM;
case Utils.JSON_CONTENT_TYPE: