extends ThreeLayersPopup
{ + + public SimpleThreeLayersPopup(Context context) { + super(context); + } + + @Override + public void setPrimaryItemClickListener(final RecyclerAdapter.OnItemClickListener
onItemClickListener) { + RecyclerAdapter.OnItemClickListener
listener = new RecyclerAdapter.OnItemClickListener
() {
+ @Override
+ public void onItemClick(P data, int position) {
+ mSecondaryAdapter.updateData(mThreeLayersAdapter.setSecondaryData(data));
+ if (onItemClickListener != null)
+ onItemClickListener.onItemClick(data, position);
+ }
+ };
+ super.setPrimaryItemClickListener(listener);
+ }
+
+ @Override
+ public void setSecondaryItemClickListener(final RecyclerAdapter.OnItemClickListener onItemClickListener) {
+ RecyclerAdapter.OnItemClickListener listener = new RecyclerAdapter.OnItemClickListener() {
+ @Override
+ public void onItemClick(S data, int position) {
+ mTertiaryAdapter.updateData(mThreeLayersAdapter.setTertiaryData(data));
+ if (onItemClickListener != null)
+ onItemClickListener.onItemClick(data, position);
+ }
+ };
+ super.setSecondaryItemClickListener(listener);
+ }
+
+ @Override
+ public void setThreeLayersAdapter(ThreeLayersAdapter
threeLayersAdapter) { + super.setThreeLayersAdapter(threeLayersAdapter); + try{ + setPrimaryItemClickListener(null); + setSecondaryItemClickListener(null); + } catch (NullPointerException e){ + // + } + } + + public abstract static class SimpleThreeLayersAdapter
implements ThreeLayersAdapter
{ + @Override + public AbstractVH
createPrimaryVH(ViewGroup parent) {
+ return new PrimaryVH<>(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_simple_primary_layer, parent, false));
+ }
+
+ @Override
+ public AbstractVH extends AbstractVH {
+
+ private TextView mFirstText;
+
+ PrimaryVH(View itemView) {
+ super(itemView);
+ mFirstText = (TextView) itemView.findViewById(R.id.text_first_layer);
+ }
+
+ @Override
+ public void bind(P item) {
+ if (item != null) mFirstText.setText(item.toString());
+ }
+ }
+
+ private static class SecondaryVH extends TwoLayersPopup {
+
+ public SimpleTwoLayersPopup(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void setPrimaryItemClickListener(final RecyclerAdapter.OnItemClickListener onItemClickListener) {
+ RecyclerAdapter.OnItemClickListener listener = new RecyclerAdapter.OnItemClickListener () {
+ @Override
+ public void onItemClick(P data, int position) {
+ mSecondaryAdapter.updateData(mTwoLayersAdapter.setSecondaryData(data));
+ if (onItemClickListener != null)
+ onItemClickListener.onItemClick(data, position);
+ }
+ };
+ super.setPrimaryItemClickListener(listener);
+ }
+
+ @Override
+ public void setTwoLayersAdapter(TwoLayersAdapter twoLayersAdapter) {
+ super.setTwoLayersAdapter(twoLayersAdapter);
+ try{
+ setPrimaryItemClickListener(null);
+ } catch (NullPointerException e){
+ //
+ }
+ }
+
+ public abstract static class SimpleTwoLayersAdapter implements TwoLayersAdapter {
+ @Override
+ public AbstractVH createPrimaryVH(ViewGroup parent) {
+ return new PrimaryVH<>(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_simple_primary_layer, parent, false));
+ }
+
+ @Override
+ public AbstractVH extends AbstractVH {
+
+ private TextView mFirstText;
+
+ PrimaryVH(View itemView) {
+ super(itemView);
+ mFirstText = (TextView) itemView.findViewById(R.id.text_first_layer);
+ }
+
+ @Override
+ public void bind(P item) {
+ if (item != null) mFirstText.setText(item.toString());
+ }
+ }
+
+ private static class SecondaryVH extends TwoLayersAdapter {
+
+ List extends BasePopup {
+ protected RecyclerView mPrimaryLayer;
+ protected RecyclerView mSecondaryLayer;
+ protected RecyclerView mTertiaryLayer;
+
+ protected List mPrimaryData;
+ protected List mPrimaryAdapter;
+ protected RecyclerAdapter mThreeLayersAdapter;
+
+ public ThreeLayersPopup(Context context) {
+ super(context);
+ }
+
+ public void setLayerWeight(int primaryLayerWeight, int secondaryLayerWeight, int tertiaryAdapter) {
+ LinearLayout.LayoutParams lp1 = (LinearLayout.LayoutParams) mPrimaryLayer.getLayoutParams();
+ lp1.weight = primaryLayerWeight;
+ mPrimaryLayer.setLayoutParams(lp1);
+ mPrimaryLayer.requestLayout();
+
+ LinearLayout.LayoutParams lp2 = (LinearLayout.LayoutParams) mSecondaryLayer.getLayoutParams();
+ lp1.weight = secondaryLayerWeight;
+ mSecondaryLayer.setLayoutParams(lp2);
+ mSecondaryLayer.requestLayout();
+
+
+ LinearLayout.LayoutParams lp3 = (LinearLayout.LayoutParams) mTertiaryLayer.getLayoutParams();
+ lp1.weight = tertiaryAdapter;
+ mTertiaryLayer.setLayoutParams(lp3);
+ mTertiaryLayer.requestLayout();
+ }
+
+ public ThreeLayersAdapter getThreeLayersAdapter() {
+ return mThreeLayersAdapter;
+ }
+
+ public void setThreeLayersAdapter(ThreeLayersAdapter threeLayersAdapter) {
+ mThreeLayersAdapter = threeLayersAdapter;
+
+ mPrimaryData = mThreeLayersAdapter.setPrimaryData();
+ mSecondaryData = mThreeLayersAdapter.setSecondaryData(mPrimaryData.get(0));
+ mTertiaryData = mThreeLayersAdapter.setTertiaryData(mSecondaryData.get(0));
+
+ mPrimaryAdapter = new RecyclerAdapter (mPrimaryData) {
+ @Override
+ public AbstractVH createViewHolder(ViewGroup parent) {
+ return mThreeLayersAdapter.createPrimaryVH(parent);
+ }
+ };
+
+ mSecondaryAdapter = new RecyclerAdapter onItemClickListener) {
+ mPrimaryAdapter.setOnItemClickListener(onItemClickListener);
+ }
+
+ public void setSecondaryItemClickListener(RecyclerAdapter.OnItemClickListener {
+ List setPrimaryData();
+
+ List createPrimaryVH(ViewGroup parent);
+
+ AbstractVH extends BasePopup {
+ protected RecyclerView mPrimaryLayer;
+ protected RecyclerView mSecondaryLayer;
+
+ protected List mPrimaryData;
+ protected List mPrimaryAdapter;
+ protected RecyclerAdapter mTwoLayersAdapter;
+
+ public TwoLayersPopup(Context context) {
+ super(context);
+ }
+
+ public void setLayerWeight(int primaryLayerWeight, int secondaryLayerWeight) {
+ LinearLayout.LayoutParams lp1 = (LinearLayout.LayoutParams) mPrimaryLayer.getLayoutParams();
+ lp1.weight = primaryLayerWeight;
+ mPrimaryLayer.setLayoutParams(lp1);
+ mPrimaryLayer.requestLayout();
+
+ LinearLayout.LayoutParams lp2 = (LinearLayout.LayoutParams) mSecondaryLayer.getLayoutParams();
+ lp1.weight = secondaryLayerWeight;
+ mSecondaryLayer.setLayoutParams(lp2);
+ mSecondaryLayer.requestLayout();
+ }
+
+
+ public TwoLayersAdapter getTwoLayersAdapter() {
+ return mTwoLayersAdapter;
+ }
+
+ public void setTwoLayersAdapter(TwoLayersAdapter twoLayersAdapter) {
+ mTwoLayersAdapter = twoLayersAdapter;
+
+ mPrimaryData = mTwoLayersAdapter.setPrimaryData();
+ mSecondaryData = mTwoLayersAdapter.setSecondaryData(mPrimaryData.get(0));
+
+ mPrimaryAdapter = new RecyclerAdapter (mPrimaryData) {
+ @Override
+ public AbstractVH createViewHolder(ViewGroup parent) {
+ return mTwoLayersAdapter.createPrimaryVH(parent);
+ }
+ };
+
+ mSecondaryAdapter = new RecyclerAdapter onItemClickListener) {
+ mPrimaryAdapter.setOnItemClickListener(onItemClickListener);
+ }
+
+ public void setSecondaryItemClickListener(RecyclerAdapter.OnItemClickListener createSecondaryVH(ViewGroup parent) {
+ return new SecondaryVH<>(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_simple_secondary_layer, parent, false));
+ }
+
+ @Override
+ public AbstractVH extends AbstractVH {
+
+ private TextView mFirstText;
+
+ SecondaryVH(View itemView) {
+ super(itemView);
+ mFirstText = (TextView) itemView.findViewById(R.id.text_second_layer);
+ }
+
+ @Override
+ public void bind(S item) {
+ if (item != null) mFirstText.setText(item.toString());
+ }
+ }
+
+ private static class TertiaryVH createSecondaryVH(ViewGroup parent) {
+ return new SecondaryVH<>(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_simple_secondary_layer, parent, false));
+ }
+ }
+
+ private static class PrimaryVH extends AbstractVH {
+
+ private TextView mFirstText;
+
+ SecondaryVH(View itemView) {
+ super(itemView);
+ mFirstText = (TextView) itemView.findViewById(R.id.text_second_layer);
+ }
+
+ @Override
+ public void bind(S item) {
+ if (item != null) mFirstText.setText(item.toString());
+ }
+ }
+
+}
diff --git a/library/src/main/java/com/loopeer/android/popuputils/ThreeLayersAdapter.java b/library/src/main/java/com/loopeer/android/popuputils/ThreeLayersAdapter.java
new file mode 100644
index 0000000..cc05112
--- /dev/null
+++ b/library/src/main/java/com/loopeer/android/popuputils/ThreeLayersAdapter.java
@@ -0,0 +1,12 @@
+package com.loopeer.android.popuputils;
+
+import android.view.ViewGroup;
+
+import java.util.List;
+
+public interface ThreeLayersAdapter mSecondaryData;
+ protected List mSecondaryAdapter;
+ protected RecyclerAdapter(mSecondaryData) {
+ @Override
+ public AbstractVH createViewHolder(ViewGroup parent) {
+ return mThreeLayersAdapter.createSecondaryVH(parent);
+ }
+ };
+
+ mTertiaryAdapter = new RecyclerAdapter onItemClickListener) {
+ mSecondaryAdapter.setOnItemClickListener(onItemClickListener);
+ }
+
+ public void setTertiaryItemClickListener(RecyclerAdapter.OnItemClickListener setSecondaryData(P p);
+
+ AbstractVH createSecondaryVH(ViewGroup parent);
+}
diff --git a/library/src/main/java/com/loopeer/android/popuputils/TwoLayersPopup.java b/library/src/main/java/com/loopeer/android/popuputils/TwoLayersPopup.java
new file mode 100644
index 0000000..d47eb55
--- /dev/null
+++ b/library/src/main/java/com/loopeer/android/popuputils/TwoLayersPopup.java
@@ -0,0 +1,101 @@
+package com.loopeer.android.popuputils;
+
+import android.content.Context;
+import android.graphics.drawable.ColorDrawable;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.PopupWindow;
+
+import java.util.List;
+
+public class TwoLayersPopup mSecondaryData;
+
+ protected RecyclerAdapter mSecondaryAdapter;
+ protected TwoLayersAdapter(mSecondaryData) {
+ @Override
+ public AbstractVH createViewHolder(ViewGroup parent) {
+ return mTwoLayersAdapter.createSecondaryVH(parent);
+ }
+ };
+
+ mPrimaryLayer.setAdapter(mPrimaryAdapter);
+ mSecondaryLayer.setAdapter(mSecondaryAdapter);
+ }
+
+
+ public void setPrimaryItemClickListener(RecyclerAdapter.OnItemClickListener onItemClickListener) {
+ mSecondaryAdapter.setOnItemClickListener(onItemClickListener);
+ }
+
+ public P getCurPrimaryItem() {
+ return mPrimaryAdapter.getCurItem();
+ }
+
+ public S getCurSecondaryItem() {
+ return mSecondaryAdapter.getCurItem();
+ }
+
+ @Override
+ public PopupWindow initPopup(Context context) {
+ View v = View.inflate(context, R.layout.view_two_layers, null);
+ mPrimaryLayer = (RecyclerView) v.findViewById(R.id.primary_layer);
+ mSecondaryLayer = (RecyclerView) v.findViewById(R.id.secondary_layer);
+ mPrimaryLayer.setLayoutManager(new LinearLayoutManager(context));
+ mSecondaryLayer.setLayoutManager(new LinearLayoutManager(context));
+
+ PopupWindow popupWindow = new PopupWindow(v, ViewGroup.LayoutParams.MATCH_PARENT, context.getResources().getDimensionPixelSize(R.dimen.layers_height), true);
+ popupWindow.setBackgroundDrawable(new ColorDrawable());
+ popupWindow.setOutsideTouchable(true);
+
+ return popupWindow;
+ }
+}
diff --git a/library/src/main/res/layout/divider_layer.xml b/library/src/main/res/layout/divider_layer.xml
new file mode 100644
index 0000000..84b1d85
--- /dev/null
+++ b/library/src/main/res/layout/divider_layer.xml
@@ -0,0 +1,6 @@
+
+