Search in sources :

Example 6 with FeedItem

use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.

the class FeedAdapter method insert.

public void insert(FeedItem item) {
    String key = createKeyFor(item.getPost());
    FeedItem existing = mUniqueMapping.put(key, item);
    if (existing == null) {
        mList.add(item);
    } else {
        int pos = mList.indexOf(existing);
        mList.updateItemAt(pos, item);
    }
}
Also used : FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem)

Example 7 with FeedItem

use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.

the class FeedAdapter method onCreateViewHolder.

@Override
public FeedItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final FeedItemBinding binding = DataBindingUtil.inflate(mLayoutInflater, R.layout.feed_item, parent, false);
    FeedItemViewHolder holder = new FeedItemViewHolder(binding);
    holder.binding.userName.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mCallback == null) {
                return;
            }
            FeedItem model = binding.getModel();
            mCallback.onUserClick(model.getUser());
        }
    });
    // we don't need grid layout error messages
    holder.binding.grid.setPrinter(null);
    return holder;
}
Also used : FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem) FeedItemBinding(com.android.example.devsummit.archdemo.databinding.FeedItemBinding) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 8 with FeedItem

use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.

the class FeedModelTest method loadFeed.

@Test
public void loadFeed() {
    NewPostResponse response = new NewPostResponse();
    Post post = TestUtil.createDummyPost();
    User user = TestUtil.createDummyUser();
    post.setUserId(user.getId());
    response.setUser(user);
    response.setPost(post);
    mPostModel.save(post);
    mUserModel.save(user);
    assertThat(mUserModel.load(user.getId()), notNullValue());
    assertThat(mPostModel.load(post.getId()), notNullValue());
    List<FeedItem> feed = mFeedModel.loadFeed(0, user.getId());
    assertThat(feed, notNullValue());
    assertThat(feed.size(), is(1));
    FeedItem loaded = feed.get(0);
    assertThat(loaded.getUser().getId(), is(user.getId()));
    assertThat(loaded.getPost().getId(), is(post.getId()));
}
Also used : NewPostResponse(com.android.example.devsummit.archdemo.api.NewPostResponse) User(com.android.example.devsummit.archdemo.vo.User) FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem) Post(com.android.example.devsummit.archdemo.vo.Post) Test(org.junit.Test) BaseTest(com.android.example.devsummit.archdemo.BaseTest)

Example 9 with FeedItem

use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.

the class FeedActivityTest method refreshFeedWithNewItems.

@Test
public void refreshFeedWithNewItems() 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(1L);
    post2.setCreated(2L);
    //noinspection unchecked
    when(mockFeedModel.loadFeed(0L, null)).thenReturn(items);
    when(mockFeedModel.loadFeed(post1.getCreated(), 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(post2.getText())))).check(matches(withChild(withText(feedItem2.getUser().getName()))));
    onItemAt(1).check(matches(withChild(withText(post1.getText())))).check(matches(withChild(withText(feedItem1.getUser().getName()))));
}
Also used : FeedModel(com.android.example.devsummit.archdemo.model.FeedModel) FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem) Post(com.android.example.devsummit.archdemo.vo.Post) FetchedFeedEvent(com.android.example.devsummit.archdemo.event.feed.FetchedFeedEvent) Test(org.junit.Test)

Example 10 with FeedItem

use of com.android.example.devsummit.archdemo.vo.FeedItem in project dev-summit-architecture-demo by yigit.

the class FeedActivityTest method loadFeed.

@Test
public void loadFeed() {
    FeedModel mockFeedModel = mock(FeedModel.class);
    when(mComponent.feedModel()).thenReturn(mockFeedModel);
    List<FeedItem> items = Collections.singletonList(TestUtil.createDummyFeedItem());
    when(mockFeedModel.loadFeed(0L, null)).thenReturn(items);
    getActivity();
    onView(withId(R.id.user_name)).check(matches(withText(items.get(0).getUser().getName())));
    onView(withId(R.id.post_text)).check(matches(withText(items.get(0).getPost().getText())));
}
Also used : FeedModel(com.android.example.devsummit.archdemo.model.FeedModel) FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem) Test(org.junit.Test)

Aggregations

FeedItem (com.android.example.devsummit.archdemo.vo.FeedItem)10 Post (com.android.example.devsummit.archdemo.vo.Post)5 Test (org.junit.Test)4 FeedModel (com.android.example.devsummit.archdemo.model.FeedModel)3 User (com.android.example.devsummit.archdemo.vo.User)3 FetchedFeedEvent (com.android.example.devsummit.archdemo.event.feed.FetchedFeedEvent)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BaseTest (com.android.example.devsummit.archdemo.BaseTest)1 NewPostResponse (com.android.example.devsummit.archdemo.api.NewPostResponse)1 FeedItemBinding (com.android.example.devsummit.archdemo.databinding.FeedItemBinding)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1