Search in sources :

Example 1 with ModelContactCity

use of com.vondear.tools.model.ModelContactCity in project RxTools by vondear.

the class ActivityContact method initView.

private void initView() {
    mRxTitle.setLeftFinish(mContext);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    final PinnedHeaderDecoration decoration = new PinnedHeaderDecoration();
    decoration.registerTypePinnedHeader(1, new PinnedHeaderDecoration.PinnedHeaderCreator() {

        @Override
        public boolean create(RecyclerView parent, int adapterPosition) {
            return true;
        }
    });
    mRecyclerView.addItemDecoration(decoration);
    new Thread(new Runnable() {

        @Override
        public void run() {
            Type listType = new TypeToken<ArrayList<ModelContactCity>>() {
            }.getType();
            Gson gson = new Gson();
            final List<ModelContactCity> list = gson.fromJson(ModelContactCity.DATA, listType);
            Collections.sort(list, new ComparatorLetter());
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    mAdapterContactCity = new AdapterContactCity(mContext, list);
                    mRecyclerView.setAdapter(mAdapterContactCity);
                }
            });
        }
    }).start();
    mSideBarView.setOnTouchLetterChangeListener(new WaveSideBarView.OnTouchLetterChangeListener() {

        @Override
        public void onLetterChange(String letter) {
            int pos = mAdapterContactCity.getLetterPosition(letter);
            if (pos != -1) {
                mRecyclerView.scrollToPosition(pos);
                LinearLayoutManager mLayoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
                mLayoutManager.scrollToPositionWithOffset(pos, 0);
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Type(java.lang.reflect.Type) ComparatorLetter(com.vondear.tools.tools.ComparatorLetter) WaveSideBarView(com.vondear.rxtools.view.sidebar.WaveSideBarView) ModelContactCity(com.vondear.tools.model.ModelContactCity) PinnedHeaderDecoration(com.vondear.rxtools.view.sidebar.PinnedHeaderDecoration) RecyclerView(android.support.v7.widget.RecyclerView) AdapterContactCity(com.vondear.tools.adapter.AdapterContactCity)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Gson (com.google.gson.Gson)1 PinnedHeaderDecoration (com.vondear.rxtools.view.sidebar.PinnedHeaderDecoration)1 WaveSideBarView (com.vondear.rxtools.view.sidebar.WaveSideBarView)1 AdapterContactCity (com.vondear.tools.adapter.AdapterContactCity)1 ModelContactCity (com.vondear.tools.model.ModelContactCity)1 ComparatorLetter (com.vondear.tools.tools.ComparatorLetter)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1