Modifying item request to have feed name
This commit is contained in:
parent
bab22e99ee
commit
bf15c04c68
@ -6,6 +6,7 @@ import android.os.Handler;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.readrops.app.database.ItemWithFeed;
|
||||||
import com.readrops.app.database.entities.Feed;
|
import com.readrops.app.database.entities.Feed;
|
||||||
import com.readrops.app.database.entities.Item;
|
import com.readrops.app.database.entities.Item;
|
||||||
import com.readrops.readropslibrary.HtmlParser;
|
import com.readrops.readropslibrary.HtmlParser;
|
||||||
@ -28,18 +29,16 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
|
|||||||
|
|
||||||
private static final String TAG = LocalFeedRepository.class.getSimpleName();
|
private static final String TAG = LocalFeedRepository.class.getSimpleName();
|
||||||
|
|
||||||
private LiveData<List<Item>> items;
|
private LiveData<List<ItemWithFeed>> itemsWhithFeed;
|
||||||
private List<Feed> feeds;
|
|
||||||
|
|
||||||
public LocalFeedRepository(Application application) {
|
public LocalFeedRepository(Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
||||||
items = database.itemDao().getAll();
|
itemsWhithFeed = database.itemDao().getAllItemWithFeeds();
|
||||||
//feeds = database.feedDao().getAllFeeds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Item>> getItems() {
|
public LiveData<List<ItemWithFeed>> getItemsWhithFeed() {
|
||||||
return items;
|
return itemsWhithFeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,6 +23,7 @@ import android.widget.Toast;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
|
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
|
||||||
import com.bumptech.glide.util.ViewPreloadSizeProvider;
|
import com.bumptech.glide.util.ViewPreloadSizeProvider;
|
||||||
|
import com.readrops.app.database.ItemWithFeed;
|
||||||
import com.readrops.app.database.entities.Item;
|
import com.readrops.app.database.entities.Item;
|
||||||
import com.readrops.readropslibrary.ParsingResult;
|
import com.readrops.readropslibrary.ParsingResult;
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
|
|||||||
private NavigationView navigationView;
|
private NavigationView navigationView;
|
||||||
private DrawerLayout drawerLayout;
|
private DrawerLayout drawerLayout;
|
||||||
|
|
||||||
private List<Item> newItems;
|
private List<ItemWithFeed> newItems;
|
||||||
|
|
||||||
private TreeMap<LocalDateTime, Item> itemsMap;
|
private TreeMap<LocalDateTime, Item> itemsMap;
|
||||||
|
|
||||||
@ -84,15 +85,11 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
|
|||||||
itemsMap = new TreeMap<>(LocalDateTime::compareTo);
|
itemsMap = new TreeMap<>(LocalDateTime::compareTo);
|
||||||
newItems = new ArrayList<>();
|
newItems = new ArrayList<>();
|
||||||
|
|
||||||
viewModel.getItems().observe(this, (List<Item> items) -> {
|
viewModel.getItemsWithFeed().observe(this, (itemWithFeeds -> {
|
||||||
/*for (Item item : items) {
|
newItems = itemWithFeeds;
|
||||||
itemsMap.put(item.getFormatedDate(), item);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
newItems = items;
|
|
||||||
if (!refreshLayout.isRefreshing())
|
if (!refreshLayout.isRefreshing())
|
||||||
adapter.submitList(newItems);
|
adapter.submitList(newItems);
|
||||||
});
|
}));
|
||||||
|
|
||||||
refreshLayout = findViewById(R.id.swipe_refresh_layout);
|
refreshLayout = findViewById(R.id.swipe_refresh_layout);
|
||||||
refreshLayout.setOnRefreshListener(this);
|
refreshLayout.setOnRefreshListener(this);
|
||||||
|
@ -6,7 +6,6 @@ import android.support.annotation.Nullable;
|
|||||||
import android.support.v7.recyclerview.extensions.ListAdapter;
|
import android.support.v7.recyclerview.extensions.ListAdapter;
|
||||||
import android.support.v7.util.DiffUtil;
|
import android.support.v7.util.DiffUtil;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Patterns;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -22,13 +21,13 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
|
|||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;
|
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;
|
||||||
import com.bumptech.glide.util.ViewPreloadSizeProvider;
|
import com.bumptech.glide.util.ViewPreloadSizeProvider;
|
||||||
|
import com.readrops.app.database.ItemWithFeed;
|
||||||
import com.readrops.app.database.entities.Item;
|
import com.readrops.app.database.entities.Item;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.ViewHolder> implements ListPreloader.PreloadModelProvider<String> {
|
public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListAdapter.ViewHolder> implements ListPreloader.PreloadModelProvider<String> {
|
||||||
|
|
||||||
private RequestManager manager;
|
private RequestManager manager;
|
||||||
private OnItemClickListener listener;
|
private OnItemClickListener listener;
|
||||||
@ -41,16 +40,19 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
|||||||
this.preloadSizeProvider = preloadSizeProvider;
|
this.preloadSizeProvider = preloadSizeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final DiffUtil.ItemCallback<Item> DIFF_CALLBACK = new DiffUtil.ItemCallback<Item>() {
|
private static final DiffUtil.ItemCallback<ItemWithFeed> DIFF_CALLBACK = new DiffUtil.ItemCallback<ItemWithFeed>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean areItemsTheSame(@NonNull Item item, @NonNull Item t1) {
|
public boolean areItemsTheSame(@NonNull ItemWithFeed item, @NonNull ItemWithFeed t1) {
|
||||||
return item.getId() == t1.getId();
|
return item.getItem().getId() == t1.getItem().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areContentsTheSame(@NonNull Item item, @NonNull Item t1) {
|
public boolean areContentsTheSame(@NonNull ItemWithFeed itemWithFeed, @NonNull ItemWithFeed t1) {
|
||||||
return item.getTitle().equals(t1.getTitle()) &&
|
Item item = itemWithFeed.getItem();
|
||||||
item.getDescription().equals(t1.getDescription());
|
Item item1 = t1.getItem();
|
||||||
|
|
||||||
|
return item.getTitle().equals(item1.getTitle()) &&
|
||||||
|
item.getDescription().equals(item1.getDescription());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,8 +69,8 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
|
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
|
||||||
Item item = getItem(i);
|
ItemWithFeed itemWithFeed = getItem(i);
|
||||||
viewHolder.bind(item);
|
viewHolder.bind(itemWithFeed);
|
||||||
|
|
||||||
preloadSizeProvider.setView(viewHolder.itemImage);
|
preloadSizeProvider.setView(viewHolder.itemImage);
|
||||||
|
|
||||||
@ -76,8 +78,8 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
|||||||
RequestOptions requestOptions = new RequestOptions();
|
RequestOptions requestOptions = new RequestOptions();
|
||||||
requestOptions = requestOptions.transforms(new CenterCrop(), new RoundedCorners(16));
|
requestOptions = requestOptions.transforms(new CenterCrop(), new RoundedCorners(16));
|
||||||
|
|
||||||
if (item.getImageLink() != null)
|
if (itemWithFeed.getItem().getImageLink() != null)
|
||||||
manager.load(item.getImageLink())
|
manager.load(itemWithFeed.getItem().getImageLink())
|
||||||
.apply(requestOptions)
|
.apply(requestOptions)
|
||||||
.transition(DrawableTransitionOptions.withCrossFade(fadeFactory))
|
.transition(DrawableTransitionOptions.withCrossFade(fadeFactory))
|
||||||
.into(viewHolder.itemImage);
|
.into(viewHolder.itemImage);
|
||||||
@ -86,7 +88,7 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getPreloadItems(int position) {
|
public List<String> getPreloadItems(int position) {
|
||||||
String url = getItem(position).getImageLink();
|
String url = getItem(position).getItem().getImageLink();
|
||||||
|
|
||||||
return Collections.singletonList(url);
|
return Collections.singletonList(url);
|
||||||
}
|
}
|
||||||
@ -98,7 +100,7 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface OnItemClickListener {
|
public interface OnItemClickListener {
|
||||||
void onItemClick(Item item);
|
void onItemClick(ItemWithFeed itemWithFeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||||
@ -110,6 +112,7 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
|||||||
private TextView itemTitle;
|
private TextView itemTitle;
|
||||||
private ImageView itemImage;
|
private ImageView itemImage;
|
||||||
private TextView date;
|
private TextView date;
|
||||||
|
private TextView feedName;
|
||||||
|
|
||||||
ViewHolder(@NonNull View itemView) {
|
ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
@ -124,11 +127,14 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
|||||||
itemTitle = itemView.findViewById(R.id.item_title);
|
itemTitle = itemView.findViewById(R.id.item_title);
|
||||||
itemImage = itemView.findViewById(R.id.item_image);
|
itemImage = itemView.findViewById(R.id.item_image);
|
||||||
date = itemView.findViewById(R.id.item_date);
|
date = itemView.findViewById(R.id.item_date);
|
||||||
|
feedName = itemView.findViewById(R.id.item_feed_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bind(Item item) {
|
private void bind(ItemWithFeed itemWithFeed) {
|
||||||
|
Item item = itemWithFeed.getItem();
|
||||||
itemTitle.setText(item.getTitle());
|
itemTitle.setText(item.getTitle());
|
||||||
date.setText(DateUtils.formatedDateByLocal(item.getFormatedDate()));
|
date.setText(DateUtils.formatedDateByLocal(item.getPubDate()));
|
||||||
|
feedName.setText(itemWithFeed.getFeedName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import android.arch.lifecycle.LiveData;
|
|||||||
import android.arch.lifecycle.Observer;
|
import android.arch.lifecycle.Observer;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.readrops.app.database.ItemWithFeed;
|
||||||
import com.readrops.app.database.entities.Item;
|
import com.readrops.app.database.entities.Item;
|
||||||
import com.readrops.readropslibrary.ParsingResult;
|
import com.readrops.readropslibrary.ParsingResult;
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MainViewModel extends AndroidViewModel {
|
public class MainViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
private LiveData<List<Item>> items;
|
private LiveData<List<ItemWithFeed>> itemsWithFeed;
|
||||||
private LocalFeedRepository repository;
|
private LocalFeedRepository repository;
|
||||||
|
|
||||||
public MainViewModel(@NonNull Application application) {
|
public MainViewModel(@NonNull Application application) {
|
||||||
@ -22,11 +23,11 @@ public class MainViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
repository = new LocalFeedRepository(application);
|
repository = new LocalFeedRepository(application);
|
||||||
|
|
||||||
items = repository.getItems();
|
itemsWithFeed = repository.getItemsWhithFeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Item>> getItems() {
|
public LiveData<List<ItemWithFeed>> getItemsWithFeed() {
|
||||||
return items;
|
return itemsWithFeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSimpleCallback(SimpleCallback simpleCallback) {
|
public void setSimpleCallback(SimpleCallback simpleCallback) {
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.readrops.app.database;
|
||||||
|
|
||||||
|
import android.arch.persistence.room.ColumnInfo;
|
||||||
|
import android.arch.persistence.room.Embedded;
|
||||||
|
|
||||||
|
import com.readrops.app.database.entities.Item;
|
||||||
|
|
||||||
|
public class ItemWithFeed {
|
||||||
|
|
||||||
|
@Embedded
|
||||||
|
private Item item;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "name")
|
||||||
|
private String feedName;
|
||||||
|
|
||||||
|
public Item getItem() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItem(Item item) {
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFeedName() {
|
||||||
|
return feedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeedName(String feedName) {
|
||||||
|
this.feedName = feedName;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import android.arch.persistence.room.Dao;
|
|||||||
import android.arch.persistence.room.Insert;
|
import android.arch.persistence.room.Insert;
|
||||||
import android.arch.persistence.room.Query;
|
import android.arch.persistence.room.Query;
|
||||||
|
|
||||||
|
import com.readrops.app.database.ItemWithFeed;
|
||||||
import com.readrops.app.database.entities.Item;
|
import com.readrops.app.database.entities.Item;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -16,9 +17,12 @@ public interface ItemDao {
|
|||||||
@Query("Select * from Item Where feed_id = :feedId")
|
@Query("Select * from Item Where feed_id = :feedId")
|
||||||
LiveData<List<Item>> getAllByFeed(int feedId);
|
LiveData<List<Item>> getAllByFeed(int feedId);
|
||||||
|
|
||||||
@Query("Select * from Item Order By formatedDate 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 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")
|
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")
|
||||||
String guidExist(String guid);
|
String guidExist(String guid);
|
||||||
|
|
||||||
|
@ -5,14 +5,12 @@ import android.arch.persistence.room.*;
|
|||||||
import com.readrops.app.DateUtils;
|
import com.readrops.app.DateUtils;
|
||||||
import com.readrops.readropslibrary.localfeed.atom.ATOMEntry;
|
import com.readrops.readropslibrary.localfeed.atom.ATOMEntry;
|
||||||
import com.readrops.readropslibrary.localfeed.json.JSONItem;
|
import com.readrops.readropslibrary.localfeed.json.JSONItem;
|
||||||
import com.readrops.readropslibrary.localfeed.rss.RSSChannel;
|
|
||||||
import com.readrops.readropslibrary.localfeed.rss.RSSItem;
|
import com.readrops.readropslibrary.localfeed.rss.RSSItem;
|
||||||
|
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@ -36,9 +34,7 @@ public class Item {
|
|||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
@ColumnInfo(name = "pub_date")
|
@ColumnInfo(name = "pub_date")
|
||||||
private String pubDate;
|
private LocalDateTime pubDate;
|
||||||
|
|
||||||
private LocalDateTime formatedDate;
|
|
||||||
|
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
@ -96,22 +92,14 @@ public class Item {
|
|||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPubDate() {
|
public LocalDateTime getPubDate() {
|
||||||
return pubDate;
|
return pubDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPubDate(String pubDate) {
|
public void setPubDate(LocalDateTime pubDate) {
|
||||||
this.pubDate = pubDate;
|
this.pubDate = pubDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getFormatedDate() {
|
|
||||||
return formatedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFormatedDate(LocalDateTime formatedDate) {
|
|
||||||
this.formatedDate = formatedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
@ -149,8 +137,7 @@ public class Item {
|
|||||||
newItem.setTitle(item.getTitle());
|
newItem.setTitle(item.getTitle());
|
||||||
newItem.setImageLink(item.getImageLink());
|
newItem.setImageLink(item.getImageLink());
|
||||||
|
|
||||||
newItem.setPubDate(item.getPubDate());
|
newItem.setPubDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.RSS_DATE_FORMAT));
|
||||||
newItem.setFormatedDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.RSS_DATE_FORMAT));
|
|
||||||
|
|
||||||
newItem.setLink(item.getLink());
|
newItem.setLink(item.getLink());
|
||||||
newItem.setFeedId(feed.getId());
|
newItem.setFeedId(feed.getId());
|
||||||
@ -172,8 +159,7 @@ public class Item {
|
|||||||
dbItem.setGuid(item.getId());
|
dbItem.setGuid(item.getId());
|
||||||
dbItem.setTitle(item.getTitle());
|
dbItem.setTitle(item.getTitle());
|
||||||
|
|
||||||
dbItem.setPubDate(item.getUpdated());
|
dbItem.setPubDate(DateUtils.stringToDateTime(item.getUpdated(), DateUtils.ATOM_JSON_DATE_FORMAT));
|
||||||
dbItem.setFormatedDate(DateUtils.stringToDateTime(item.getUpdated(), DateUtils.ATOM_JSON_DATE_FORMAT));
|
|
||||||
|
|
||||||
dbItem.setLink(item.getLink().getHref());
|
dbItem.setLink(item.getLink().getHref());
|
||||||
|
|
||||||
@ -195,8 +181,7 @@ public class Item {
|
|||||||
dbItem.setGuid(item.getId());
|
dbItem.setGuid(item.getId());
|
||||||
dbItem.setTitle(item.getTitle());
|
dbItem.setTitle(item.getTitle());
|
||||||
|
|
||||||
dbItem.setPubDate(item.getPubDate());
|
dbItem.setPubDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.ATOM_JSON_DATE_FORMAT));
|
||||||
dbItem.setFormatedDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.ATOM_JSON_DATE_FORMAT));
|
|
||||||
|
|
||||||
dbItem.setLink(item.getUrl());
|
dbItem.setLink(item.getUrl());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user