Adding feed icon and item description (without any html !) to the item layout

This commit is contained in:
Shinokuni 2019-02-01 22:11:27 +00:00
parent c5b068be17
commit be1c7ff01f
10 changed files with 104 additions and 25 deletions

Binary file not shown.

View File

@ -28,6 +28,10 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:palette-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
@ -45,15 +49,13 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:converter-simplexml:2.4.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
implementation "joda-time:joda-time:2.9.9"
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:palette-v7:28.0.0'

View File

@ -26,6 +26,8 @@ import com.readrops.readropslibrary.localfeed.json.JSONItem;
import com.readrops.readropslibrary.localfeed.rss.RSSFeed;
import com.readrops.readropslibrary.localfeed.rss.RSSItem;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@ -122,7 +124,10 @@ 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()));
String favUrl = HtmlParser.getFaviconLink(dbFeed.getSiteUrl());
dbFeed.setIconUrl(favUrl);
dbFeed.setColor(getFaviconColor(favUrl));
dbFeed.setId((int)(database.feedDao().insert(dbFeed)));
}
@ -141,7 +146,10 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
Feed dbFeed = database.feedDao().getFeedByUrl(feed.getLink());
if (dbFeed == null) {
dbFeed = Feed.feedFromATOM(feed);
dbFeed.setColor(getFaviconColor(dbFeed.getSiteUrl()));
String favUrl = HtmlParser.getFaviconLink(dbFeed.getSiteUrl());
dbFeed.setIconUrl(favUrl);
dbFeed.setColor(getFaviconColor(favUrl));
dbFeed.setId((int)(database.feedDao().insert(dbFeed)));
}
@ -161,7 +169,10 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
Feed dbFeed = database.feedDao().getFeedByUrl(feed.getFeedUrl());
if (dbFeed == null) {
dbFeed = Feed.feedFromJSON(feed);
dbFeed.setColor(getFaviconColor(dbFeed.getSiteUrl()));
String favUrl = HtmlParser.getFaviconLink(dbFeed.getSiteUrl());
dbFeed.setIconUrl(favUrl);
dbFeed.setColor(getFaviconColor(favUrl));
dbFeed.setId((int)(database.feedDao().insert(dbFeed)));
}
@ -178,6 +189,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
for (Item dbItem : items) {
if (!Boolean.valueOf(database.itemDao().guidExist(dbItem.getGuid()))) {
dbItem.setImageLink(HtmlParser.getDescImageLink(dbItem.getDescription()));
dbItem.setDescription(Jsoup.parse(dbItem.getDescription()).text());
database.itemDao().insert(dbItem);
Log.d(TAG, "adding " + dbItem.getTitle());
@ -185,8 +197,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
}
}
private @ColorInt int getFaviconColor(String url) throws IOException {
String favUrl = HtmlParser.getFaviconLink(url);
private @ColorInt int getFaviconColor(String favUrl) throws IOException {
Bitmap favicon = getFaviconFromUrl(favUrl);
Palette palette = Palette.from(favicon).generate();

View File

@ -12,7 +12,6 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.ListPreloader;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
@ -57,7 +56,7 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
}
};
private static final DrawableCrossFadeFactory fadeFactory = new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build();
private static final DrawableCrossFadeFactory FADE_FACTORY = new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build();
@NonNull
@Override
@ -79,11 +78,18 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
RequestOptions requestOptions = new RequestOptions();
requestOptions = requestOptions.transforms(new CenterCrop(), new RoundedCorners(16));
if (itemWithFeed.getItem().getImageLink() != null)
if (itemWithFeed.getItem().getImageLink() != null) {
manager.load(itemWithFeed.getItem().getImageLink())
.apply(requestOptions)
.transition(DrawableTransitionOptions.withCrossFade(fadeFactory))
.transition(DrawableTransitionOptions.withCrossFade(FADE_FACTORY))
.into(viewHolder.itemImage);
}
if (itemWithFeed.getFeedIconUrl() != null) {
manager.load(itemWithFeed.getFeedIconUrl())
.into(viewHolder.feedIcon);
}
}
@NonNull
@ -114,6 +120,8 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
private ImageView itemImage;
private TextView date;
private TextView feedName;
private TextView itemDescription;
private ImageView feedIcon;
ViewHolder(@NonNull View itemView) {
super(itemView);
@ -129,6 +137,8 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
itemImage = itemView.findViewById(R.id.item_image);
date = itemView.findViewById(R.id.item_date);
feedName = itemView.findViewById(R.id.item_feed_title);
itemDescription = itemView.findViewById(R.id.item_description);
feedIcon = itemView.findViewById(R.id.item_feed_icon);
}
private void bind(ItemWithFeed itemWithFeed) {
@ -137,6 +147,7 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
itemTitle.setText(item.getTitle());
date.setText(DateUtils.formatedDateByLocal(item.getPubDate()));
feedName.setText(itemWithFeed.getFeedName());
itemDescription.setText(item.getDescription());
if (itemWithFeed.getColor() != 0)
feedName.setTextColor(itemWithFeed.getColor());

View File

@ -15,6 +15,9 @@ public class ItemWithFeed {
private int color;
@ColumnInfo(name = "icon_url")
private String feedIconUrl;
public Item getItem() {
return item;
}
@ -38,4 +41,12 @@ public class ItemWithFeed {
public void setColor(int color) {
this.color = color;
}
public String getFeedIconUrl() {
return feedIconUrl;
}
public void setFeedIconUrl(String feedIconUrl) {
this.feedIconUrl = feedIconUrl;
}
}

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 from Item Inner Join Feed on Item.feed_id = Feed.id Order By pub_date DESC, Item.id")
@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 pub_date DESC, Item.id")
LiveData<List<ItemWithFeed>> getAllItemWithFeeds();
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")

View File

@ -26,6 +26,9 @@ public class Feed {
private @ColorInt int color;
@ColumnInfo(name = "icon_url")
private String iconUrl;
public Feed() {
}
@ -93,6 +96,14 @@ public class Feed {
this.color = color;
}
public String getIconUrl() {
return iconUrl;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
public static Feed feedFromRSS(RSSChannel channel) {
Feed feed = new Feed();

View File

@ -8,6 +8,7 @@ import com.readrops.readropslibrary.localfeed.json.JSONItem;
import com.readrops.readropslibrary.localfeed.rss.RSSItem;
import org.joda.time.LocalDateTime;
import org.jsoup.Jsoup;
import java.text.ParseException;
import java.util.ArrayList;

View File

@ -1,32 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="?android:attr/selectableItemBackground">
<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test title for this textview which is 3 maximum lines"
tools:text="test title for this textview which is 2 maximum lines"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:minLines="1"
android:maxLines="3"
android:maxLines="2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@id/item_image"
android:layout_toStartOf="@id/item_image"
android:ellipsize="end" />
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
<TextView
android:id="@+id/item_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/item_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@id/item_image"
android:layout_toStartOf="@id/item_image"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:minLines="1"
android:maxLines="3"
android:ellipsize="end"
style="@style/TextAppearance.AppCompat.Small"/>
<ImageView
android:id="@+id/item_image"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_height="90dp"
android:layout_marginTop="8dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
@ -34,28 +52,42 @@
android:layout_marginBottom="12dp"
/>
<ImageView
android:id="@+id/item_feed_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_below="@id/item_description"
android:src="@drawable/ic_rss_feed"
/>
<TextView
android:id="@+id/item_feed_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@id/item_image"
android:layout_below="@id/item_description"
android:layout_toRightOf="@id/item_feed_icon"
android:layout_marginLeft="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:text="Numerama"/>
tools:text="Numerama"/>
<TextView
android:id="@+id/item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 janvier 2019"
android:layout_below="@id/item_image"
android:layout_alignParentEnd="true"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
tools:text="January 10 2019"
/>
</RelativeLayout>

View File

@ -5,5 +5,5 @@
<color name="colorAccent">#0072bc</color>
<color name="colorControlNormal">#d7d7d7</color>
<color name="colorBackground">#fafafa</color>
<color name="textColorPrimary">#060aa3</color>
<color name="textColorPrimary">#000000</color>
</resources>