Last active
November 22, 2016 12:21
-
-
Save voghDev/3599fdb00ba6847071b1065bcd5db05c to your computer and use it in GitHub Desktop.
ListEntityRendererBuilder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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