aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/main/java/org/wordpress/android/ui/notifications/adapters/NoteBlockAdapter.java
diff options
context:
space:
mode:
Diffstat (limited to 'WordPress/src/main/java/org/wordpress/android/ui/notifications/adapters/NoteBlockAdapter.java')
-rw-r--r--WordPress/src/main/java/org/wordpress/android/ui/notifications/adapters/NoteBlockAdapter.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/adapters/NoteBlockAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/adapters/NoteBlockAdapter.java
new file mode 100644
index 000000000..0d19c796b
--- /dev/null
+++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/adapters/NoteBlockAdapter.java
@@ -0,0 +1,63 @@
+package org.wordpress.android.ui.notifications.adapters;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+
+import org.wordpress.android.R;
+import org.wordpress.android.ui.notifications.blocks.NoteBlock;
+
+import java.util.List;
+
+public class NoteBlockAdapter extends ArrayAdapter<NoteBlock> {
+
+ private final LayoutInflater mLayoutInflater;
+ private final int mBackgroundColor;
+
+ private List<NoteBlock> mNoteBlockList;
+
+ public NoteBlockAdapter(Context context, List<NoteBlock> noteBlocks, int backgroundColor) {
+ super(context, 0, noteBlocks);
+
+ mNoteBlockList = noteBlocks;
+ mLayoutInflater = LayoutInflater.from(context);
+ mBackgroundColor = backgroundColor;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return true;
+ }
+
+ @Override
+ public int getCount() {
+ return mNoteBlockList == null ? 0 : mNoteBlockList.size();
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ NoteBlock noteBlock = mNoteBlockList.get(position);
+
+ // Check the tag for this recycled view, if it matches we can reuse it
+ if (convertView == null || noteBlock.getBlockType() != convertView.getTag(R.id.note_block_tag_id)) {
+ convertView = mLayoutInflater.inflate(noteBlock.getLayoutResourceId(), parent, false);
+ convertView.setTag(noteBlock.getViewHolder(convertView));
+ }
+
+ // Update the block type for this view
+ convertView.setTag(R.id.note_block_tag_id, noteBlock.getBlockType());
+
+ noteBlock.setBackgroundColor(mBackgroundColor);
+
+ return noteBlock.configureView(convertView);
+ }
+
+ public void setNoteList(List<NoteBlock> noteList) {
+ if (noteList == null) return;
+
+ mNoteBlockList = noteList;
+ notifyDataSetChanged();
+ }
+}