Filter容器--PopsTabView

#PopsTabView

PopsTabView是個filter容器,他可以自動,快速,構建不同篩選樣式,自由組合成一組tab.

目前版本v1.1

篩選樣式 篩選種類
單列 單選,多選
三行 單選,多選
雙列 單選,多選
複雜 單項單選,單項多選

後續篩選會不斷完善補充.

項目地址傳送門 https://github.com/ccj659/PopsTabView

#Show

單欄.gif

兩欄.gif

四欄.gif

更多.gif

#Introduction

用戶只需要,知道自己需要哪種filter,將數據轉化FilterTabBean,然後addFilterItem(),最後自己在onPopTabSet()回調,即可使用,簡單粗暴.

##優點:

  • 支持用for()循環全自動配置,自動記住位置,並在點擊時,返回位置以及選取值.
  • 支持快速,構建不同篩選樣式,自由組合成一組filter的tab.
  • 支持自定義filter的順序,選擇樣式.
  • 解決Android版本兼容(解決popwindow顯示位置偏差).
  • 用接口抽象出filter樣式配置器loader,與功能代碼解耦.
  • 支持自定義配置 篩選過程ResultLoader<T>
  • 可以自由擴展,其他類型的Filter類型.

##待完善:

  • 增加其他類型的篩選樣式
  • 回調參數,需待調整
  • view的樣式可配置爲可自定義
  • 代碼冗餘還需優化.

#TO USE

##1.設定,篩選器類型. 將PopTypeLoader暴露,用於用戶 篩選器類型.

需要自己按照該模式進行擴展.創建 具體 popwindow 實體對象. 創建對象和 功能代碼解耦和,細節在PopTabView.addItem()中.若有需要,需要自由擴展,配置.


public class PopTypeLoaderImp implements PopTypeLoader {
    @Override
    public PopupWindow getPopEntity(Context context, List data, OnMultipeFilterSetListener filterSetListener, int tag, int type) {
        PopupWindow popupWindow = null;
        switch (tag) {
            case FilterConfig.TYPE_POPWINDOW_LINKED:
                popupWindow = new LinkFilterPopupWindow(context, data, filterSetListener,type);
                break;
            case FilterConfig.TYPE_POPWINDOW_SORT:
                popupWindow = new SortPopupWindow(context, data, filterSetListener, tag,type);
                break;
            default:
                popupWindow = new MSingleFilterWindow(context, data, filterSetListener,type);
                break;
        }
        return popupWindow;
    }
}

##2.使用方式

###2.1 Builder模式,完成篩選器的創建.


        popTabView.setOnPopTabSetListener(this)
                .setPopEntityLoader(new PopTypeLoaderImp()) //配置 {篩選類型}  方式
                .addFilterItem("篩選1", singleFilterList1.getFilter_tab(), singleFilterList1.getTab_group_type(), FilterConfig.FILTER_TYPE_MUTIFY)
                .addFilterItem("篩選2", linkFilterList.getFilter_tab(), linkFilterList.getTab_group_type(), FilterConfig.FILTER_TYPE_MUTIFY)
                .addFilterItem("篩選3", singleFilterList2.getFilter_tab(), singleFilterList2.getTab_group_type(), FilterConfig.FILTER_TYPE_MUTIFY)
                .addFilterItem("篩選4", sortFilterList.getFilter_tab(), sortFilterList.getTab_group_type(), FilterConfig.FILTER_TYPE_MUTIFY);

###2.2 for()循環全自動配置模式,完成篩選器的創建.

  /**
             *
             * @param title 篩選標題
             * @param data 篩選數據
             * @param tag 篩選類別- 一級篩選,二級篩選,複雜篩選
             * @param type 篩選方式-單選or多選
             * @return
             */
            popTabView.addFilterItem("篩選" + i, singleFilterList1.getFilter_tab(), singleFilterList1.getTab_group_type(), FilterConfig.FILTER_TYPE_SINGLE);

##3.配置篩選後的返回值樣式ResultLoader<T>


public class ResultLoaderImp implements ResultLoader<String> {

    @Override
    public String getResultParamsIds(List<FilterTabBean> selectedList) {

        StringBuilder stringIds =new StringBuilder();

        for (int i = 0; i < selectedList.size(); i++) {
            stringIds.append(selectedList.get(i).getTab_id()+",");
        }

        return  builderToString(stringIds);
    }

    @Override
    public String getResultShowValues(List<FilterTabBean> selectedList) {

        StringBuilder stringValues =new StringBuilder();

        for (int i = 0; i < selectedList.size(); i++) {
            stringValues.append(selectedList.get(i).getTab_name()+",");
        }

        return builderToString(stringValues);
    }

##4.成功的回調,可配置爲藉口傳參.此處回調,可以自主修改,擴展.

 /**
     * @param index  操作的 filter的下標號 0.1.2.3
     * @param lable  操作的 filter的對應的標籤title
     * @param params 選中的 參數(需要傳參)
     * @param value  選中的 值
     */
    @Override
    public void onPopTabSet(int index, String lable, String params, String value) {

        Toast.makeText(this, "lable=" + index + "\n&value=" + value, Toast.LENGTH_SHORT).show();
        tv_content.setText("&篩選項=" + index + "\n&篩選傳參=" + params + "\n&篩選值=" + value);

    }

##樣式調整--待優化

1.可在各級Adapter.ViewHolder 中自己定義.

2.可在xml文件中自定義修改

3.O__O "….....好吧,還是我太懶了....以後會補充的~~

##About Me

CSDN:http://blog.csdn.net/ccj659/article/

簡書:http://www.jianshu.com/u/94423b4ef5cf

github: https//github.com/ccj659/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章