Search in sources :

Example 1 with RefreshableItemPresentationModel

use of org.robobinding.itempresentationmodel.RefreshableItemPresentationModel in project RoboBinding by RoboBinding.

the class DataSetAdapter method updateItemPresentationModel.

private void updateItemPresentationModel(View view, int position) {
    ViewTag<RefreshableItemPresentationModel> viewTag = viewTags.tagFor(view);
    RefreshableItemPresentationModel itemPresentationModel = viewTag.get();
    itemPresentationModel.updateData(getItem(position), new ItemContext(view, position));
    refreshIfRequired(itemPresentationModel);
}
Also used : ItemContext(org.robobinding.itempresentationmodel.ItemContext) RefreshableItemPresentationModel(org.robobinding.itempresentationmodel.RefreshableItemPresentationModel)

Example 2 with RefreshableItemPresentationModel

use of org.robobinding.itempresentationmodel.RefreshableItemPresentationModel in project RoboBinding by RoboBinding.

the class DataSetAdapter method newView.

private View newView(int position, ViewGroup parent, DisplayType displayType) {
    BindableView bindableView;
    Object item = getItem(position);
    if (displayType == DisplayType.ITEM_LAYOUT) {
        int layoutId = itemLayoutSelector.selectLayout(getItemViewType(position));
        bindableView = itemLayoutBinder.inflate(parent, layoutId);
    } else {
        bindableView = dropdownLayoutBinder.inflate(parent, dropdownLayoutId);
    }
    View view = bindableView.getRootView();
    RefreshableItemPresentationModel itemPresentationModel = dataSetValueModel.newRefreshableItemPresentationModel(getItemViewType(position));
    itemPresentationModel.updateData(item, new ItemContext(view, position));
    bindableView.bindTo((AbstractPresentationModelObject) itemPresentationModel);
    ViewTag<RefreshableItemPresentationModel> viewTag = viewTags.tagFor(view);
    viewTag.set(itemPresentationModel);
    return view;
}
Also used : ItemContext(org.robobinding.itempresentationmodel.ItemContext) RefreshableItemPresentationModel(org.robobinding.itempresentationmodel.RefreshableItemPresentationModel) BindableView(org.robobinding.BindableView) AbstractPresentationModelObject(org.robobinding.presentationmodel.AbstractPresentationModelObject) BindableView(org.robobinding.BindableView) View(android.view.View)

Example 3 with RefreshableItemPresentationModel

use of org.robobinding.itempresentationmodel.RefreshableItemPresentationModel in project RoboBinding by RoboBinding.

the class DataSetAdapterTest method whenGenerateDropdownView_thenInflateTheCorrectViewWithItemPresentationModelAttached.

@Test
public void whenGenerateDropdownView_thenInflateTheCorrectViewWithItemPresentationModelAttached() {
    View view = mock(View.class);
    ItemLayoutBinder dropdownLayoutBinder = aItemLayoutBinder().inflateAndReturnRootView(view);
    ViewTag<RefreshableItemPresentationModel> viewTag = mockViewTag();
    ViewTags<RefreshableItemPresentationModel> viewTags = aViewTags().tagForViewAndReturn(view, viewTag);
    DataSetAdapter dataSetAdapter = aDataSetAdapter().withDropdownLayoutBinder(dropdownLayoutBinder).withViewTags(viewTags).build();
    View result = dataSetAdapter.getDropDownView(0, null, null);
    assertThat(result, sameInstance(view));
    verify(viewTag).set(notNull(RefreshableItemPresentationModel.class));
}
Also used : RefreshableItemPresentationModel(org.robobinding.itempresentationmodel.RefreshableItemPresentationModel) View(android.view.View) BindableView(org.robobinding.BindableView) Test(org.junit.Test)

Example 4 with RefreshableItemPresentationModel

use of org.robobinding.itempresentationmodel.RefreshableItemPresentationModel in project RoboBinding by RoboBinding.

the class DataSetAdapterBuilder method build.

public DataSetAdapter build() {
    ItemBinder itemBinder = bindingContext.createItemBinder();
    ItemLayoutBinder itemLayoutBinder = new ItemLayoutBinder(itemBinder, itemPredefinedMappings);
    ItemLayoutSelector itemLayoutSelector = buildItemLayoutSelector();
    DataSetAdapter dataSetAdapter = new DataSetAdapter(valueModelWithPreInitializeViews(), itemLayoutBinder, itemLayoutSelector, new ViewTags<RefreshableItemPresentationModel>(ITEM_PRESENTATION_MODEL_KEY), bindingContext.shouldPreInitializeViews());
    registerPropertyChangeListener(dataSetAdapter);
    return dataSetAdapter;
}
Also used : MultiItemLayoutSelector(org.robobinding.widget.adapterview.MultiItemLayoutSelector) ItemLayoutSelector(org.robobinding.widget.adapterview.ItemLayoutSelector) SingleItemLayoutSelector(org.robobinding.widget.adapterview.SingleItemLayoutSelector) ItemBinder(org.robobinding.ItemBinder) RefreshableItemPresentationModel(org.robobinding.itempresentationmodel.RefreshableItemPresentationModel) ItemLayoutBinder(org.robobinding.widget.adapterview.ItemLayoutBinder)

Example 5 with RefreshableItemPresentationModel

use of org.robobinding.itempresentationmodel.RefreshableItemPresentationModel in project RoboBinding by RoboBinding.

the class DataSetAdapter method onCreateViewHolder.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    BindableView bindableView;
    int layoutId = layoutSelector.selectLayout(viewType);
    bindableView = itemLayoutBinder.inflate(parent, layoutId);
    View view = bindableView.getRootView();
    RefreshableItemPresentationModel itemPresentationModel = dataSetValueModel.newRefreshableItemPresentationModel(viewType);
    ViewTag<RefreshableItemPresentationModel> viewTag = viewTags.tagFor(view);
    viewTag.set(itemPresentationModel);
    return new ViewHolder(view, bindableView, (AbstractPresentationModelObject) itemPresentationModel);
}
Also used : RefreshableItemPresentationModel(org.robobinding.itempresentationmodel.RefreshableItemPresentationModel) BindableView(org.robobinding.BindableView) RecyclerView(android.support.v7.widget.RecyclerView) BindableView(org.robobinding.BindableView) View(android.view.View)

Aggregations

RefreshableItemPresentationModel (org.robobinding.itempresentationmodel.RefreshableItemPresentationModel)8 View (android.view.View)5 BindableView (org.robobinding.BindableView)5 ItemContext (org.robobinding.itempresentationmodel.ItemContext)3 RecyclerView (android.support.v7.widget.RecyclerView)2 Test (org.junit.Test)2 ItemBinder (org.robobinding.ItemBinder)2 AbstractPresentationModelObject (org.robobinding.presentationmodel.AbstractPresentationModelObject)1 ItemLayoutBinder (org.robobinding.widget.adapterview.ItemLayoutBinder)1 ItemLayoutSelector (org.robobinding.widget.adapterview.ItemLayoutSelector)1 MultiItemLayoutSelector (org.robobinding.widget.adapterview.MultiItemLayoutSelector)1 SingleItemLayoutSelector (org.robobinding.widget.adapterview.SingleItemLayoutSelector)1