private static boolean isFromEventTypeSpecifiedInAnnotation( MethodParamModel methodParamModel, TypeName eventFieldType) { FromEvent fromEvent = (FromEvent) MethodParamModelUtils.getAnnotation(methodParamModel, FromEvent.class); TypeName baseClassType; try { baseClassType = ClassName.get(fromEvent.baseClass()); } catch (MirroredTypeException mte) { baseClassType = ClassName.get(mte.getTypeMirror()); } return baseClassType.equals(eventFieldType); } }
/** * Called during DataDiffSection's diffing to determine if two objects represent the same item. * See {@link android.support.v7.util.DiffUtil.Callback#areItemsTheSame(int, int)} for more info. * * @return true if the two objects in the event represent the same item. */ @OnEvent(OnCheckIsSameItemEvent.class) static boolean isSameItem( ComponentContext c, @FromEvent DemoListActivity.DemoListDataModel previousItem, @FromEvent DemoListActivity.DemoListDataModel nextItem) { return previousItem == nextItem; }
/** * Called during DataDiffSection's diffing to determine if two objects contain the same data. This * is used to detect of contents of an item have changed. See {@link * android.support.v7.util.DiffUtil.Callback#areContentsTheSame(int, int)} for more info. * * @return true if the two objects contain the same data. */ @OnEvent(OnCheckIsSameContentEvent.class) static boolean isSameContent( ComponentContext c, @FromEvent DemoListActivity.DemoListDataModel previousItem, @FromEvent DemoListActivity.DemoListDataModel nextItem) { // We're only displaying the name so checking if that's equal here is enough for our use case. return previousItem == null ? nextItem == null : previousItem.name == null ? nextItem.name == null : nextItem.name.equals(previousItem.name); }
@OnEvent(OnCheckIsSameContentEvent.class) protected static boolean onCheckIsSameContent( SectionContext c, @FromEvent Object previousItem, @FromEvent Object nextItem, @Prop(optional = true) Comparator isSameContentComparator) { return isSameContentComparator.compare(previousItem, nextItem) == 0; } }
@OnEvent(RenderEvent.class) protected static RenderInfo onRenderEvent( SectionContext c, @FromEvent int index, @FromEvent Object model, @FromEvent Bundle loggingExtras, @Prop EventHandler<RenderWithHideItemHandlerEvent> renderWithHideItemHandler) { return HideableDataDiffSection.dispatchRenderWithHideItemHandlerEvent( renderWithHideItemHandler, index, model, HideableDataDiffSection.onHideItem(c), loggingExtras); }
@OnEvent(RenderEvent.class) static RenderInfo onRender(ComponentContext c, @FromEvent Message model) { return model.createComponent(c); } }
@OnEvent(RenderEvent.class) static RenderInfo onRender(ComponentContext c, @FromEvent Datum model) { return model.createComponent(c); } }
@OnEvent(ClickEvent.class) static void onClick( ComponentContext c, @FromEvent View view) { FavouriteButton.toggleFavouritedSync(c); } }
@OnEvent(ItemSelectedEvent.class) static void onScrollToPositionSelected( ComponentContext c, @FromEvent String newSelection, @Prop RecyclerCollectionEventsController eventsController) { eventsController.requestScrollToPositionWithSnap(Integer.parseInt(newSelection)); }
@OnEvent(ClickEvent.class) static void onClick( ComponentContext c, @FromEvent View view, @Prop final DemoListActivity.DemoListDataModel model, @Prop final int[] currentIndices) { final Intent intent = new Intent( c.getAndroidContext(), model.datamodels == null ? model.klass : DemoListActivity.class); intent.putExtra(DemoListActivity.INDICES, currentIndices); c.getAndroidContext().startActivity(intent); } }
@OnEvent(HideItemEvent.class) public static void onHideItem( SectionContext c, @FromEvent Object model, @Prop EventHandler<GetUniqueIdentifierEvent> getUniqueIdentifierHandler) { HideableDataDiffSection.onBlacklistUpdateSync(c, model, getUniqueIdentifierHandler); } }
@OnEvent(ItemSelectedEvent.class) static void onSnapModeSelected(ComponentContext c, @FromEvent String newSelection) { HorizontalScrollWithSnapComponent.updateSnapModeSync(c, getSnapModeInt(newSelection)); }
@OnEvent(ErrorEvent.class) static void __internalOnErrorHandler(ComponentContext c, @FromEvent Exception exception) {} }
@OnEvent(RenderEvent.class) static RenderInfo onRender( ComponentContext c, @Prop @Nullable int[] parentIndices, @FromEvent DemoListActivity.DemoListDataModel model, @FromEvent int index) { return ComponentRenderInfo.create() .component( DemoListItemComponent.create(c) .model(model) .currentIndices(getUpdatedIndices(parentIndices, index)) .build()) .build(); }
@OnEvent(RenderEvent.class) static RenderInfo onRender(ComponentContext c, @FromEvent ListRow model) { return ComponentRenderInfo.create().component(model.createComponent(c)).build(); } }
@OnEvent(RenderEvent.class) static RenderInfo onRender(ComponentContext c, @FromEvent String model) { return ComponentRenderInfo.create().component(createImageComponent(c, model).build()).build(); }
@OnEvent(RenderEvent.class) protected static RenderInfo onRender( SectionContext c, @FromEvent Object model, @Param ComponentContext context) { return ComponentRenderInfo.create() .customAttribute("model", model) .component(Text.create(context).text(model.toString()).build()) .build(); }
@OnEvent(RenderEvent.class) static RenderInfo onRender( ComponentContext c, @FromEvent Class<? extends Component> model) { try { Method createMethod = model.getMethod("create", ComponentContext.class); Component.Builder componentBuilder = (Component.Builder) createMethod.invoke(null, c); return ComponentRenderInfo.create().component(componentBuilder.build()).build(); } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { return ComponentRenderInfo.create() .component(Text.create(c).textSizeDip(32).text(ex.getLocalizedMessage()).build()) .build(); } } }