use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.
the class TestUtil method createDummyFeedItem.
public static FeedItem createDummyFeedItem() {
User user = createDummyUser();
Post post = createDummyPost(user.getId());
return new FeedItem(post, user);
}
use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.
the class FeedActivityTest method refreshFeedWithOlderItems.
@Test
public void refreshFeedWithOlderItems() throws Throwable {
FeedModel mockFeedModel = mock(FeedModel.class);
when(mComponent.feedModel()).thenReturn(mockFeedModel);
FeedItem feedItem1 = TestUtil.createDummyFeedItem();
FeedItem feedItem2 = TestUtil.createDummyFeedItem();
List<FeedItem> items = Collections.singletonList(feedItem1);
List<FeedItem> items2 = Arrays.asList(feedItem1, feedItem2);
Post post1 = feedItem1.getPost();
final Post post2 = feedItem2.getPost();
post1.setCreated(10L);
post2.setCreated(2L);
//noinspection unchecked
when(mockFeedModel.loadFeed(0L, null)).thenReturn(items);
when(mockFeedModel.loadFeed(1L, null)).thenReturn(items2);
getActivity();
onView(atAdapterPosition(getActivity().mBinding.list, 0)).check(matches(withChild(withText(post1.getText())))).check(matches(withChild(withText(feedItem1.getUser().getName()))));
runTestOnUiThread(new Runnable() {
@Override
public void run() {
getActivity().onEventMainThread(new FetchedFeedEvent(true, null, post2));
}
});
onItemAt(0).check(matches(withChild(withText(post1.getText())))).check(matches(withChild(withText(feedItem1.getUser().getName()))));
onItemAt(1).check(matches(withChild(withText(post2.getText())))).check(matches(withChild(withText(feedItem2.getUser().getName()))));
}
use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.
the class FeedAdapter method updatePost.
public void updatePost(Post post) {
String key = createKeyFor(post);
FeedItem existing = mUniqueMapping.get(key);
if (existing == null) {
L.d("update post is received but it does not exist, ignoring... %s", key);
return;
}
int pos = mList.indexOf(existing);
FeedItem newItem = new FeedItem(post, existing.getUser());
mUniqueMapping.put(key, newItem);
mList.updateItemAt(pos, newItem);
}
use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.
the class FeedAdapter method swapList.
public void swapList(List<FeedItem> items) {
Set<String> newListKeys = new HashSet<>();
for (FeedItem item : items) {
newListKeys.add(createKeyFor(item.getPost()));
}
for (int i = mList.size() - 1; i >= 0; i--) {
FeedItem item = mList.get(i);
String key = createKeyFor(item.getPost());
if (!newListKeys.contains(key)) {
mUniqueMapping.remove(key);
mList.removeItemAt(i);
}
}
insertAll(items);
}
use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.
the class FeedModel method loadFeed.
public List<FeedItem> loadFeed(long since, @Nullable Long userId) {
final List<Post> posts;
if (userId == null) {
posts = mComponent.postModel().loadPostsSince(since);
} else {
posts = mComponent.postModel().loadPostsOfUser(userId, since);
}
List<Long> userIds = new ArrayList<>();
for (Post post : posts) {
userIds.add(post.getUserId());
}
Map<Long, User> users = mComponent.userModel().loadUsersAsMap(userIds);
List<FeedItem> result = new ArrayList<>();
for (Post post : posts) {
User user = users.get(post.getUserId());
if (user != null) {
result.add(new FeedItem(post, user));
}
}
return result;
}
Aggregations