diff --git a/app/src/main/java/com/lzx/demo/adapter/ItemDragAdapter.java b/app/src/main/java/com/lzx/demo/adapter/ItemDragAdapter.java new file mode 100644 index 0000000..c717be9 --- /dev/null +++ b/app/src/main/java/com/lzx/demo/adapter/ItemDragAdapter.java @@ -0,0 +1,53 @@ +package com.lzx.demo.adapter; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.lzx.demo.R; +import com.lzx.demo.base.BaseItemDraggableAdapter; +import com.lzx.demo.bean.ItemModel; + +/** + * Created by luoxw on 2016/6/20. + */ +public class ItemDragAdapter extends BaseItemDraggableAdapter { + + private LayoutInflater mLayoutInflater; + + public ItemDragAdapter(Context context) { + mLayoutInflater = LayoutInflater.from(context); + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ViewHolder(mLayoutInflater.inflate(R.layout.sample_item_text, parent, false)); + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + + String item = "item"+position; + + ViewHolder viewHolder = (ViewHolder) holder; + viewHolder.textView.setText(item); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + private TextView textView; + + public ViewHolder(View itemView) { + super(itemView); + textView = (TextView) itemView.findViewById(R.id.info_text); + } + } +} diff --git a/app/src/main/java/com/lzx/demo/base/BaseItemDraggableAdapter.java b/app/src/main/java/com/lzx/demo/base/BaseItemDraggableAdapter.java new file mode 100644 index 0000000..fa180e1 --- /dev/null +++ b/app/src/main/java/com/lzx/demo/base/BaseItemDraggableAdapter.java @@ -0,0 +1,207 @@ +package com.lzx.demo.base; + +import android.graphics.Canvas; +import android.support.annotation.NonNull; +import android.support.v4.view.MotionEventCompat; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; +import android.view.MotionEvent; +import android.view.View; + +import com.lzx.demo.R; +import com.lzx.demo.interfaces.OnItemDragListener; +import com.lzx.demo.interfaces.OnItemSwipeListener; + +import java.util.Collections; + +public abstract class BaseItemDraggableAdapter extends ListBaseAdapter { + + private static final int NO_TOGGLE_VIEW = 0; + protected int mToggleViewId = NO_TOGGLE_VIEW; + protected ItemTouchHelper mItemTouchHelper; + protected boolean itemDragEnabled = false; + protected boolean itemSwipeEnabled = false; + protected OnItemDragListener mOnItemDragListener; + protected OnItemSwipeListener mOnItemSwipeListener; + protected boolean mDragOnLongPress = true; + + protected View.OnTouchListener mOnToggleViewTouchListener; + protected View.OnLongClickListener mOnToggleViewLongClickListener; + + private static final String ERROR_NOT_SAME_ITEMTOUCHHELPER = "Item drag and item swipe should pass the same ItemTouchHelper"; + + + + /** + * Set the toggle view's id which will trigger drag event. + * If the toggle view id is not set, drag event will be triggered when the item is long pressed. + * + * @param toggleViewId the toggle view's id + */ + public void setToggleViewId(int toggleViewId) { + mToggleViewId = toggleViewId; + } + + /** + * Set the drag event should be trigger on long press. + * Work when the toggleViewId has been set. + * + * @param longPress by default is true. + */ + public void setToggleDragOnLongPress(boolean longPress) { + mDragOnLongPress = longPress; + if (mDragOnLongPress) { + mOnToggleViewTouchListener = null; + mOnToggleViewLongClickListener = new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + if (mItemTouchHelper != null && itemDragEnabled) { + mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support)); + } + return true; + } + }; + } else { + mOnToggleViewTouchListener = new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN + && !mDragOnLongPress) { + if (mItemTouchHelper != null && itemDragEnabled) { + mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support)); + } + return true; + } else { + return false; + } + } + }; + mOnToggleViewLongClickListener = null; + } + } + + /** + * Enable drag items. + * Use itemView as the toggleView when long pressed. + * + * @param itemTouchHelper {@link ItemTouchHelper} + */ + public void enableDragItem(@NonNull ItemTouchHelper itemTouchHelper) { + enableDragItem(itemTouchHelper, NO_TOGGLE_VIEW, true); + } + + /** + * Enable drag items. Use the specified view as toggle. + * + * @param itemTouchHelper {@link ItemTouchHelper} + * @param toggleViewId The toggle view's id. + * @param dragOnLongPress If true the drag event will be trigger on long press, otherwise on touch down. + */ + public void enableDragItem(@NonNull ItemTouchHelper itemTouchHelper, int toggleViewId, boolean dragOnLongPress) { + itemDragEnabled = true; + mItemTouchHelper = itemTouchHelper; + setToggleViewId(toggleViewId); + setToggleDragOnLongPress(dragOnLongPress); + } + + /** + * Disable drag items. + */ + public void disableDragItem() { + itemDragEnabled = false; + mItemTouchHelper = null; + } + + public boolean isItemDraggable() { + return itemDragEnabled; + } + + public void enableSwipeItem() { + itemSwipeEnabled = true; + } + + public void disableSwipeItem() { + itemSwipeEnabled = false; + } + + public boolean isItemSwipeEnable() { + return itemSwipeEnabled; + } + + /** + * @param onItemDragListener Register a callback to be invoked when drag event happen. + */ + public void setOnItemDragListener(OnItemDragListener onItemDragListener) { + mOnItemDragListener = onItemDragListener; + } + + public int getViewHolderPosition(RecyclerView.ViewHolder viewHolder) { + return viewHolder.getAdapterPosition(); + } + + public void onItemDragStart(RecyclerView.ViewHolder viewHolder) { + if (mOnItemDragListener != null && itemDragEnabled) { + mOnItemDragListener.onItemDragStart(viewHolder, getViewHolderPosition(viewHolder)); + } + } + + public void onItemDragMoving(RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) { + int from = getViewHolderPosition(source); + int to = getViewHolderPosition(target); + + if (from < to) { + for (int i = from; i < to; i++) { + Collections.swap(mDataList, i, i + 1); + } + } else { + for (int i = from; i > to; i--) { + Collections.swap(mDataList, i, i - 1); + } + } + notifyItemMoved(source.getAdapterPosition(), target.getAdapterPosition()); + + if (mOnItemDragListener != null && itemDragEnabled) { + mOnItemDragListener.onItemDragMoving(source, from, target, to); + } + } + + public void onItemDragEnd(RecyclerView.ViewHolder viewHolder) { + if (mOnItemDragListener != null && itemDragEnabled) { + mOnItemDragListener.onItemDragEnd(viewHolder, getViewHolderPosition(viewHolder)); + } + } + + public void setOnItemSwipeListener(OnItemSwipeListener listener) { + mOnItemSwipeListener = listener; + } + + public void onItemSwipeStart(RecyclerView.ViewHolder viewHolder) { + if (mOnItemSwipeListener != null && itemSwipeEnabled) { + mOnItemSwipeListener.onItemSwipeStart(viewHolder, getViewHolderPosition(viewHolder)); + } + } + + public void onItemSwipeClear(RecyclerView.ViewHolder viewHolder) { + if (mOnItemSwipeListener != null && itemSwipeEnabled) { + mOnItemSwipeListener.clearView(viewHolder, getViewHolderPosition(viewHolder)); + } + } + + public void onItemSwiped(RecyclerView.ViewHolder viewHolder) { + if (mOnItemSwipeListener != null && itemSwipeEnabled) { + mOnItemSwipeListener.onItemSwiped(viewHolder, getViewHolderPosition(viewHolder)); + } + + int pos = getViewHolderPosition(viewHolder); + + mDataList.remove(pos); + notifyItemRemoved(viewHolder.getAdapterPosition()); + } + + public void onItemSwiping(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive) { + if (mOnItemSwipeListener != null && itemSwipeEnabled) { + mOnItemSwipeListener.onItemSwipeMoving(canvas, viewHolder, dX, dY, isCurrentlyActive); + } + } + +} diff --git a/app/src/main/java/com/lzx/demo/callback/ItemDragAndSwipeCallback.java b/app/src/main/java/com/lzx/demo/callback/ItemDragAndSwipeCallback.java new file mode 100644 index 0000000..6380a20 --- /dev/null +++ b/app/src/main/java/com/lzx/demo/callback/ItemDragAndSwipeCallback.java @@ -0,0 +1,174 @@ +package com.lzx.demo.callback; + +import android.graphics.Canvas; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; +import android.view.View; + +import com.lzx.demo.R; +import com.lzx.demo.base.BaseItemDraggableAdapter; + +public class ItemDragAndSwipeCallback extends ItemTouchHelper.Callback { + + + BaseItemDraggableAdapter mAdapter; + + float mMoveThreshold = 0.1f; + float mSwipeThreshold = 0.7f; + + int mDragMoveFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT; + int mSwipeMoveFlags = ItemTouchHelper.END; + + public ItemDragAndSwipeCallback(BaseItemDraggableAdapter adapter) { + mAdapter = adapter; + } + + @Override + public boolean isLongPressDragEnabled() { + return false; + } + + @Override + public boolean isItemViewSwipeEnabled() { + return true; + } + + @Override + public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { + if (actionState == ItemTouchHelper.ACTION_STATE_DRAG ) { + mAdapter.onItemDragStart(viewHolder); + viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true); + } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE ) { + mAdapter.onItemSwipeStart(viewHolder); + viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true); + } + super.onSelectedChanged(viewHolder, actionState); + } + + @Override + public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + super.clearView(recyclerView, viewHolder); + + + if (viewHolder.itemView.getTag(R.id.BaseQuickAdapter_dragging_support) != null + && (Boolean)viewHolder.itemView.getTag(R.id.BaseQuickAdapter_dragging_support)) { + mAdapter.onItemDragEnd(viewHolder); + viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, false); + } + if (viewHolder.itemView.getTag(R.id.BaseQuickAdapter_swiping_support) != null + && (Boolean)viewHolder.itemView.getTag(R.id.BaseQuickAdapter_swiping_support)) { + mAdapter.onItemSwipeClear(viewHolder); + viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, false); + } + + + } + + @Override + public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + return makeMovementFlags(mDragMoveFlags, mSwipeMoveFlags); + } + + @Override + public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) { + if (source.getItemViewType() != target.getItemViewType()) { + return false; + } else { + return true; + } + } + + @Override + public void onMoved(RecyclerView recyclerView, RecyclerView.ViewHolder source, int fromPos, RecyclerView.ViewHolder target, int toPos, int x, int y) { + super.onMoved(recyclerView, source, fromPos, target, toPos, x, y); + mAdapter.onItemDragMoving(source, target); + } + + @Override + public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { + mAdapter.onItemSwiped(viewHolder); + } + + @Override + public float getMoveThreshold(RecyclerView.ViewHolder viewHolder) { + return mMoveThreshold; + } + + @Override + public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) { + return mSwipeThreshold; + } + + /** + * Set the fraction that the user should move the View to be considered as swiped. + * The fraction is calculated with respect to RecyclerView's bounds. + *

+ * Default value is .5f, which means, to swipe a View, user must move the View at least + * half of RecyclerView's width or height, depending on the swipe direction. + * + * @param swipeThreshold A float value that denotes the fraction of the View size. Default value + * is .8f . + */ + public void setSwipeThreshold(float swipeThreshold) { + mSwipeThreshold = swipeThreshold; + } + + + /** + * Set the fraction that the user should move the View to be considered as it is + * dragged. After a view is moved this amount, ItemTouchHelper starts checking for Views + * below it for a possible drop. + * + * @param moveThreshold A float value that denotes the fraction of the View size. Default value is + * .1f . + */ + public void setMoveThreshold(float moveThreshold) { + mMoveThreshold = moveThreshold; + } + + /** + *

Set the drag movement direction.

+ *

The value should be ItemTouchHelper.UP, ItemTouchHelper.DOWN, ItemTouchHelper.LEFT, ItemTouchHelper.RIGHT or their combination.

+ * You can combine them like ItemTouchHelper.UP | ItemTouchHelper.DOWN, it means that the item could only move up and down when dragged. + * @param dragMoveFlags the drag movement direction. Default value is ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT. + */ + public void setDragMoveFlags(int dragMoveFlags) { + mDragMoveFlags = dragMoveFlags; + } + + /** + *

Set the swipe movement direction.

+ *

The value should be ItemTouchHelper.START, ItemTouchHelper.END or their combination.

+ * You can combine them like ItemTouchHelper.START | ItemTouchHelper.END, it means that the item could swipe to both left or right. + * @param swipeMoveFlags the swipe movement direction. Default value is ItemTouchHelper.END. + */ + public void setSwipeMoveFlags(int swipeMoveFlags) { + mSwipeMoveFlags = swipeMoveFlags; + } + + @Override + public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, + float dX, float dY, int actionState, boolean isCurrentlyActive) { + super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); + + if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE ) { + View itemView = viewHolder.itemView; + + c.save(); + if (dX > 0) { + c.clipRect(itemView.getLeft(), itemView.getTop(), + itemView.getLeft() + dX, itemView.getBottom()); + c.translate(itemView.getLeft(), itemView.getTop()); + } else { + c.clipRect(itemView.getRight() + dX, itemView.getTop(), + itemView.getRight(), itemView.getBottom()); + c.translate(itemView.getRight() + dX, itemView.getTop()); + } + + mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive); + c.restore(); + + } + } + +} diff --git a/app/src/main/java/com/lzx/demo/interfaces/OnItemDragListener.java b/app/src/main/java/com/lzx/demo/interfaces/OnItemDragListener.java new file mode 100644 index 0000000..90128a0 --- /dev/null +++ b/app/src/main/java/com/lzx/demo/interfaces/OnItemDragListener.java @@ -0,0 +1,10 @@ +package com.lzx.demo.interfaces; + +import android.support.v7.widget.RecyclerView; + +public interface OnItemDragListener { + void onItemDragStart(RecyclerView.ViewHolder viewHolder, int pos); + void onItemDragMoving(RecyclerView.ViewHolder source, int from, RecyclerView.ViewHolder target, int to); + void onItemDragEnd(RecyclerView.ViewHolder viewHolder, int pos); + +} diff --git a/app/src/main/java/com/lzx/demo/interfaces/OnItemSwipeListener.java b/app/src/main/java/com/lzx/demo/interfaces/OnItemSwipeListener.java new file mode 100644 index 0000000..303b735 --- /dev/null +++ b/app/src/main/java/com/lzx/demo/interfaces/OnItemSwipeListener.java @@ -0,0 +1,36 @@ +package com.lzx.demo.interfaces; + +import android.graphics.Canvas; +import android.support.v7.widget.RecyclerView; + +public interface OnItemSwipeListener { + + /** + * Called when the swipe action start. + */ + void onItemSwipeStart(RecyclerView.ViewHolder viewHolder, int pos); + + /** + * Called when the swipe action is over. + * If you change the view on the start, you should reset is here, no matter the item has swiped or not. + * @param pos If the view is swiped, pos will be negative. + */ + void clearView(RecyclerView.ViewHolder viewHolder, int pos); + /** + * Called when item is swiped, the view is going to be removed from the adapter. + */ + void onItemSwiped(RecyclerView.ViewHolder viewHolder, int pos); + + /** + * Draw on the empty edge when swipe moving + * @param canvas the empty edge's canvas + * @param viewHolder The ViewHolder which is being interacted by the User or it was + * interacted and simply animating to its original position + * @param dX The amount of horizontal displacement caused by user's action + * @param dY The amount of vertical displacement caused by user's action + * @param isCurrentlyActive True if this view is currently being controlled by the user or + * false it is simply animating back to its original state. + */ + void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive); + +} diff --git a/app/src/main/java/com/lzx/demo/ui/ListDragMenuActivity.java b/app/src/main/java/com/lzx/demo/ui/ListDragMenuActivity.java new file mode 100644 index 0000000..13d1a9f --- /dev/null +++ b/app/src/main/java/com/lzx/demo/ui/ListDragMenuActivity.java @@ -0,0 +1,199 @@ +package com.lzx.demo.ui; + +import android.content.Context; +import android.graphics.Canvas; +import android.os.Bundle; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.CardView; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.support.v7.widget.helper.ItemTouchHelper; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.github.jdsjlzx.recyclerview.LRecyclerView; +import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter; +import com.lzx.demo.R; +import com.lzx.demo.adapter.ItemDragAdapter; +import com.lzx.demo.base.ListBaseAdapter; +import com.lzx.demo.bean.ItemModel; +import com.lzx.demo.callback.ItemDragAndSwipeCallback; +import com.lzx.demo.interfaces.OnItemDragListener; +import com.lzx.demo.interfaces.OnItemSwipeListener; +import com.lzx.demo.util.TLog; +import com.lzx.demo.view.SampleFooter; + +import java.util.ArrayList; + +/** + * + * 功能开发中,请等待 + */ +public class ListDragMenuActivity extends AppCompatActivity { + + private LRecyclerView mRecyclerView = null; + + private DataAdapter mDataAdapter = null; + + private LRecyclerViewAdapter mLRecyclerViewAdapter = null; + + private ItemDragAdapter mAdapter; + private ItemTouchHelper mItemTouchHelper; + private ItemDragAndSwipeCallback mItemDragAndSwipeCallback; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.sample_ll_activity); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + mRecyclerView = (LRecyclerView) findViewById(R.id.list); + + //init data + ArrayList dataList = new ArrayList<>(); + for (int i = 0; i < 16; i++) { + ItemModel itemModel = new ItemModel(); + itemModel.title = "item" + i; + dataList.add(itemModel); + } + + + mAdapter = new ItemDragAdapter(this); + mItemDragAndSwipeCallback = new ItemDragAndSwipeCallback(mAdapter); + mItemTouchHelper = new ItemTouchHelper(mItemDragAndSwipeCallback); + mItemTouchHelper.attachToRecyclerView(mRecyclerView); + + mItemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START | ItemTouchHelper.END); + mAdapter.enableSwipeItem(); + mAdapter.setOnItemSwipeListener(onItemSwipeListener); + mAdapter.enableDragItem(mItemTouchHelper); + mAdapter.setOnItemDragListener(listener); + + + /*mDataAdapter = new DataAdapter(this); + mDataAdapter.setDataList(dataList);*/ + mAdapter.setDataList(dataList); + mLRecyclerViewAdapter = new LRecyclerViewAdapter(mAdapter); + mRecyclerView.setAdapter(mLRecyclerViewAdapter); + + mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); + //mRecyclerView.setLayoutManager(new GridLayoutManager(this,2)); + + SampleFooter sampleFooter = new SampleFooter(this); + sampleFooter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //TODO 加载更多 + ArrayList dataList = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + ItemModel itemModel = new ItemModel(); + itemModel.title = "item" + (i + mDataAdapter.getItemCount()); + dataList.add(itemModel); + } + mDataAdapter.addAll(dataList); + } + }); + + //禁用下拉刷新功能 + mRecyclerView.setPullRefreshEnabled(false); + + //禁用自动加载更多功能 + mRecyclerView.setLoadMoreEnabled(false); + + + } + + private OnItemDragListener listener = new OnItemDragListener() { + @Override + public void onItemDragStart(RecyclerView.ViewHolder viewHolder, int pos) { + TLog.error("drag start"); + ((CardView)viewHolder.itemView).setCardBackgroundColor(ContextCompat.getColor(ListDragMenuActivity.this, R.color.color_light_blue)); + } + + @Override + public void onItemDragMoving(RecyclerView.ViewHolder source, int from, RecyclerView.ViewHolder target, int to) { + TLog.error("move from: " + source.getAdapterPosition() + " to: " + target.getAdapterPosition()); + } + + @Override + public void onItemDragEnd(RecyclerView.ViewHolder viewHolder, int pos) { + TLog.error("drag end"); + } + }; + + private OnItemSwipeListener onItemSwipeListener = new OnItemSwipeListener() { + @Override + public void onItemSwipeStart(RecyclerView.ViewHolder viewHolder, int pos) { + TLog.error("view swiped start: " + pos); + } + + @Override + public void clearView(RecyclerView.ViewHolder viewHolder, int pos) { + TLog.error("View reset: " + pos); + } + + @Override + public void onItemSwiped(RecyclerView.ViewHolder viewHolder, int pos) { + TLog.error("View Swiped: " + pos); + } + + @Override + public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive) { + + } + }; + + private class DataAdapter extends ListBaseAdapter { + + private LayoutInflater mLayoutInflater; + + public DataAdapter(Context context) { + mLayoutInflater = LayoutInflater.from(context); + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ViewHolder(mLayoutInflater.inflate(R.layout.sample_item_text, parent, false)); + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + + String item = mDataList.get(position).title; + + ViewHolder viewHolder = (ViewHolder) holder; + viewHolder.textView.setText(item); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + private class ViewHolder extends RecyclerView.ViewHolder { + + private TextView textView; + + public ViewHolder(View itemView) { + super(itemView); + textView = (TextView) itemView.findViewById(R.id.info_text); + } + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + } + return true; + } + +} \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c225453..4e7c1fb 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -33,4 +33,5 @@ #2e2d2d #404346 #ff4a57 + #14acae diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml new file mode 100644 index 0000000..972baf3 --- /dev/null +++ b/app/src/main/res/values/ids.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file