Skip to content

Instantly share code, notes, and snippets.

@voghDev
Last active November 22, 2016 12:21
Show Gist options
  • Select an option

  • Save voghDev/3599fdb00ba6847071b1065bcd5db05c to your computer and use it in GitHub Desktop.

Select an option

Save voghDev/3599fdb00ba6847071b1065bcd5db05c to your computer and use it in GitHub Desktop.
ListEntityRendererBuilder
import android.content.Context;
import com.pedrogomez.renderers.Renderer;
import com.pedrogomez.renderers.RendererBuilder;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class ListEntityRendererBuilder extends RendererBuilder<ListEntity> {
Map<String, Class> renderers = new HashMap<>();
public ListEntityRendererBuilder(Context context, ListEntityRenderer.OnRowClicked onClickListener) {
Collection<Renderer<ListEntity>> prototypes = getPrototypes(context, onClickListener);
setPrototypes(prototypes);
}
@Override
protected Class getPrototypeClass(ListEntity content) {
Class rendererClass = renderers.get(content.getClass().getName());
return rendererClass != null ?
rendererClass : NotificationRenderer.class;
}
private List<Renderer<ListEntity>> getPrototypes(Context context, ListEntityRenderer.OnRowClicked onRowClicked) {
List<Renderer<ListEntity>> prototypes = new LinkedList<Renderer<ListEntity>>();
ListEntityRenderer edr = new NotificationRenderer(context, onRowClicked);
prototypes.add(edr);
registerRenderer(NotificationListEntity.class.getName(), NotificationRenderer.class);
return prototypes;
}
protected void registerRenderer(String renderableClassName, Class rendererClass){
renderers.put(renderableClassName, rendererClass);
}
public static class EmptyListener implements ListEntityRenderer.OnRowClicked {
public void onRowBackgroundClicked(ListEntity i) {}
public void onRowBackgroundLongClicked(ListEntity i) {}
public void onThumbnailClicked(ListEntity i) {}
public void onWidget2Clicked(ListEntity i) {}
public void onWidget3Clicked(ListEntity i) {}
public void onWidget4Clicked(ListEntity i) {}
public void onWidget5Clicked(ListEntity i) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment