Search in sources :

Example 6 with SectionCharacters

use of com.aspsine.swipetoloadlayout.demo.model.SectionCharacters in project SwipeToLoadLayout by Aspsine.

the class TwitterRecyclerFragment method onRefresh.

@Override
public void onRefresh() {
    GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {

        @Override
        public void onResponse(SectionCharacters characters) {
            mPageNum = 0;
            mAdapter.setList(characters.getCharacters(), characters.getSections().subList(0, mPageNum + 1));
            swipeToLoadLayout.setRefreshing(false);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            swipeToLoadLayout.setRefreshing(false);
            volleyError.printStackTrace();
        }
    });
    App.getRequestQueue().add(request).setTag(TAG + "refresh" + mType);
}
Also used : Response(com.android.volley.Response) SectionCharacters(com.aspsine.swipetoloadlayout.demo.model.SectionCharacters) VolleyError(com.android.volley.VolleyError) GsonRequest(com.android.volley.toolbox.GsonRequest)

Example 7 with SectionCharacters

use of com.aspsine.swipetoloadlayout.demo.model.SectionCharacters in project SwipeToLoadLayout by Aspsine.

the class TwitterRecyclerFragment method onLoadMore.

@Override
public void onLoadMore() {
    GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {

        @Override
        public void onResponse(SectionCharacters characters) {
            if (mPageNum < 3) {
                mPageNum++;
                mAdapter.append(characters.getSections().subList(mPageNum, mPageNum + 1));
            } else {
                Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();
            }
            swipeToLoadLayout.setLoadingMore(false);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            swipeToLoadLayout.setLoadingMore(false);
            volleyError.printStackTrace();
        }
    });
    App.getRequestQueue().add(request).setTag(TAG + "loadmore" + mType);
}
Also used : Response(com.android.volley.Response) SectionCharacters(com.aspsine.swipetoloadlayout.demo.model.SectionCharacters) VolleyError(com.android.volley.VolleyError) GsonRequest(com.android.volley.toolbox.GsonRequest)

Example 8 with SectionCharacters

use of com.aspsine.swipetoloadlayout.demo.model.SectionCharacters in project SwipeToLoadLayout by Aspsine.

the class GoogleStyleFragment method onRefresh.

@Override
public void onRefresh() {
    GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {

        @Override
        public void onResponse(final SectionCharacters characters) {
            // here, I use post delay to show more animation, you don't have to.
            swipeToLoadLayout.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mPageNum = 0;
                    mAdapter.setList(characters.getCharacters(), characters.getSections().subList(0, mPageNum + 1));
                    swipeToLoadLayout.setRefreshing(false);
                }
            }, 3000);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            swipeToLoadLayout.setRefreshing(false);
            volleyError.printStackTrace();
        }
    });
    App.getRequestQueue().add(request).setTag(TAG + "refresh" + mType);
}
Also used : Response(com.android.volley.Response) SectionCharacters(com.aspsine.swipetoloadlayout.demo.model.SectionCharacters) VolleyError(com.android.volley.VolleyError) GsonRequest(com.android.volley.toolbox.GsonRequest)

Aggregations

Response (com.android.volley.Response)8 VolleyError (com.android.volley.VolleyError)8 GsonRequest (com.android.volley.toolbox.GsonRequest)8 SectionCharacters (com.aspsine.swipetoloadlayout.demo.model.SectionCharacters)8 LoopViewPagerAdapter (com.aspsine.swipetoloadlayout.demo.adapter.LoopViewPagerAdapter)1 List (java.util.List)1