mirror of https://github.com/readrops/Readrops.git
Add support for mime-type application/xml and retrieving absolute favicon url
This commit is contained in:
parent
4c2a5c682a
commit
c8680af7ca
|
@ -132,7 +132,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Item> dbItems = Item.itemsFromRSS(rssFeed.getChannel().getItems(), dbFeed);
|
List<Item> dbItems = Item.itemsFromRSS(rssFeed.getChannel().getItems(), dbFeed);
|
||||||
insertItems(dbItems);
|
insertItems(dbItems, dbFeed);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failureCallBackInMainThread(e);
|
failureCallBackInMainThread(e);
|
||||||
|
@ -151,7 +151,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Item> dbItems = Item.itemsFromATOM(feed.getEntries(), dbFeed);
|
List<Item> dbItems = Item.itemsFromATOM(feed.getEntries(), dbFeed);
|
||||||
insertItems(dbItems);
|
insertItems(dbItems, dbFeed);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failureCallBackInMainThread(e);
|
failureCallBackInMainThread(e);
|
||||||
|
@ -171,19 +171,19 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Item> dbItems = Item.itemsFromJSON(feed.getItems(), dbFeed);
|
List<Item> dbItems = Item.itemsFromJSON(feed.getItems(), dbFeed);
|
||||||
insertItems(dbItems);
|
insertItems(dbItems, dbFeed);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failureCallBackInMainThread(e);
|
failureCallBackInMainThread(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertItems(List<Item> items) {
|
private void insertItems(List<Item> items, Feed feed) {
|
||||||
for (Item dbItem : items) {
|
for (Item dbItem : items) {
|
||||||
if (!Boolean.valueOf(database.itemDao().guidExist(dbItem.getGuid()))) {
|
if (!Boolean.valueOf(database.itemDao().guidExist(dbItem.getGuid()))) {
|
||||||
if (dbItem.getDescription() != null) {
|
if (dbItem.getDescription() != null) {
|
||||||
if (dbItem.getImageLink() == 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());
|
dbItem.setDescription(Jsoup.parse(dbItem.getDescription()).text());
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
|
||||||
|
|
||||||
glideRequests
|
glideRequests
|
||||||
.load(itemWithFeed.getItem().getImageLink())
|
.load(itemWithFeed.getItem().getImageLink())
|
||||||
|
.centerCrop()
|
||||||
.apply(requestOptions)
|
.apply(requestOptions)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||||
.transition(DrawableTransitionOptions.withCrossFade(FADE_FACTORY))
|
.transition(DrawableTransitionOptions.withCrossFade(FADE_FACTORY))
|
||||||
|
|
|
@ -20,7 +20,7 @@ public interface ItemDao {
|
||||||
@Query("Select * from Item Order By pub_date DESC")
|
@Query("Select * from Item Order By pub_date DESC")
|
||||||
LiveData<List<Item>> getAll();
|
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();
|
LiveData<List<ItemWithFeed>> getAllItemWithFeeds();
|
||||||
|
|
||||||
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")
|
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.readrops.readropslibrary;
|
package com.readrops.readropslibrary;
|
||||||
|
|
||||||
import android.text.LoginFilter;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.readrops.readropslibrary.Utils.Utils;
|
import com.readrops.readropslibrary.Utils.Utils;
|
||||||
|
@ -46,10 +45,11 @@ public final class HtmlParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isTypeRssFeed(String type) {
|
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.ATOM_CONTENT_TYPE) ||
|
||||||
type.equals(Utils.JSON_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;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDescImageLink(String description) {
|
public static String getDescImageLink(String description, String url) {
|
||||||
Document document = Jsoup.parse(description);
|
Document document = Jsoup.parse(description, url);
|
||||||
Elements elements = document.select("img");
|
Elements elements = document.select("img");
|
||||||
|
|
||||||
if (!elements.isEmpty())
|
if (!elements.isEmpty())
|
||||||
return elements.first().attr("src");
|
return elements.first().absUrl("src");
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,9 @@ import java.util.Scanner;
|
||||||
|
|
||||||
public final class Utils {
|
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_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 ATOM_CONTENT_TYPE = "application/atom+xml";
|
||||||
public static final String JSON_CONTENT_TYPE = "application/json";
|
public static final String JSON_CONTENT_TYPE = "application/json";
|
||||||
|
|
||||||
|
|
|
@ -100,10 +100,12 @@ public class RSSNetwork {
|
||||||
*/
|
*/
|
||||||
private RSSType getRSSType(String contentType) {
|
private RSSType getRSSType(String contentType) {
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case Utils.RSS_CONTENT_TYPE:
|
case Utils.RSS_DEFAULT_CONTENT_TYPE:
|
||||||
return RSSType.RSS_2;
|
return RSSType.RSS_2;
|
||||||
case Utils.RSS_TEXT_CONTENT_TYPE:
|
case Utils.RSS_TEXT_CONTENT_TYPE:
|
||||||
return RSSType.RSS_2;
|
return RSSType.RSS_2;
|
||||||
|
case Utils.RSS_APPLICATION_CONTENT_TYPE:
|
||||||
|
return RSSType.RSS_2;
|
||||||
case Utils.ATOM_CONTENT_TYPE:
|
case Utils.ATOM_CONTENT_TYPE:
|
||||||
return RSSType.RSS_ATOM;
|
return RSSType.RSS_ATOM;
|
||||||
case Utils.JSON_CONTENT_TYPE:
|
case Utils.JSON_CONTENT_TYPE:
|
||||||
|
|
Loading…
Reference in New Issue