The list item displays now an image when available (found in its description)

This commit is contained in:
Shinokuni 2019-01-27 15:35:44 +00:00
parent 9704b2bb5c
commit fb9a1a706c
11 changed files with 32 additions and 21 deletions

View File

@ -46,7 +46,7 @@ dependencies {
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
implementation "joda-time:joda-time:2.3"
implementation "joda-time:joda-time:2.9.9"
implementation 'com.android.support:cardview-v7:28.0.0'
}

View File

@ -37,8 +37,6 @@ public abstract class ARepository {
protected void failureCallBackInMainThread(Exception ex) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(() -> {
callback.onFailure(ex);
});
handler.post(() -> callback.onFailure(ex));
}
}

View File

@ -9,6 +9,7 @@ import android.util.Log;
import com.readrops.app.database.Database;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.Item;
import com.readrops.readropslibrary.HtmlParser;
import com.readrops.readropslibrary.QueryCallback;
import com.readrops.readropslibrary.localfeed.AItem;
import com.readrops.readropslibrary.localfeed.RSSNetwork;
@ -117,6 +118,8 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
for (Item dbItem : dbItems) {
if (!Boolean.valueOf(database.itemDao().guidExist(dbItem.getGuid()))) {
dbItem.setImageLink(HtmlParser.getDescImageLink(dbItem.getDescription()));
database.itemDao().insert(dbItem);
Log.d(TAG, "adding " + dbItem.getTitle());
}

View File

@ -17,7 +17,10 @@ import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.readrops.app.database.entities.Item;
@ -114,7 +117,7 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
private void initRecyclerView() {
recyclerView = findViewById(R.id.items_recycler_view);
adapter = new MainItemListAdapter();
adapter = new MainItemListAdapter(Glide.with(this));
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
@ -162,8 +165,8 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
}
@Override
public void onFailure(Exception ex) {
public void onFailure(Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
@Override

View File

@ -10,13 +10,17 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.readrops.app.database.entities.Item;
public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.ViewHolder> {
private RequestManager manager;
public MainItemListAdapter() {
public MainItemListAdapter(RequestManager manager) {
super(DIFF_CALLBACK);
this.manager = manager;
}
private static final DiffUtil.ItemCallback<Item> DIFF_CALLBACK = new DiffUtil.ItemCallback<Item>() {
@ -46,11 +50,8 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
Item item = getItem(i);
viewHolder.bind(item);
/*Thread thread = new Thread(() -> {
String imageUrl = PageParser.getOGImageLink(item.getLink());
Glide.with(context).load(imageUrl).into(viewHolder.itemImage);
});*/
if (item.getImageLink() != null)
manager.load(item.getImageLink()).into(viewHolder.itemImage);
}
static class ViewHolder extends RecyclerView.ViewHolder {

View File

@ -4,5 +4,5 @@ public interface SimpleCallback {
void onSuccess();
void onFailure(Exception ex);
void onFailure(Exception e);
}

View File

@ -35,7 +35,7 @@ public abstract class Database extends RoomDatabase {
public void onCreate(@NonNull SupportSQLiteDatabase db) {
super.onCreate(db);
Feed feed1 = new Feed("XDA Developers", "desc", "https://www.xda-developers.com/feed/");
Feed feed1 = new Feed("Le Media", "this is a description", "https://lemediapresse.fr/feed/");
new Thread(() -> database.feedDao().insert(feed1)).start();
}

View File

@ -13,7 +13,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public final class PageParser {
public final class HtmlParser {
/**
* Parse the html page to get the first rss url
@ -44,7 +44,7 @@ public final class PageParser {
return null;
}
private static boolean isTypeRssFeed(String type) {
return type.equals("application/rss+xml") || type.equals("application/atom+xml") || type.equals("application/json");
}
@ -84,4 +84,10 @@ public final class PageParser {
return null;
}
public static String getDescImageLink(String description) {
Document document = Jsoup.parse(description);
return document.select("img").first().attr("src");
}
}

View File

@ -51,12 +51,12 @@ public class RSSNetwork {
* @throws Exception
*/
private void parseFeed(InputStream stream, RSSType type, QueryCallback callback, String url) throws Exception {
//String xml = Utils.inputStreamToString(stream);
String xml = Utils.inputStreamToString(stream);
Serializer serializer = new Persister();
switch (type) {
case RSS_2:
RSSFeed rssFeed = serializer.read(RSSFeed.class, stream);
RSSFeed rssFeed = serializer.read(RSSFeed.class, xml);
callback.onSyncSuccess(rssFeed.getChannel().getItems(), type, url);
break;
case RSS_ATOM:

View File

@ -12,7 +12,7 @@ public class RSSItem extends AItem {
@Element(name = "title", required = false)
private String title;
@Element(name = "description", required = false)
@Element(name = "description", required = false, data = true)
private String description;
@Element(name = "link", required = false)
@ -27,7 +27,7 @@ public class RSSItem extends AItem {
@Element(name = "pubDate", required = false)
private String pubDate;
@Element(name = "encoded",required = false)
@Element(name = "encoded",required = false, data = true)
@Namespace(prefix = "content")
private String content;