Search in sources :

Example 1 with SectionCharacters

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

the class GoogleStyleFragment method onLoadMore.

@Override
public void onLoadMore() {
    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() {
                    if (mPageNum < 3) {
                        mPageNum++;
                        mAdapter.append(characters.getSections().subList(mPageNum, mPageNum + 1));
                    } else {
                        Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();
                    }
                    swipeToLoadLayout.setLoadingMore(false);
                }
            }, 2000);
        }
    }, 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 2 with SectionCharacters

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

the class TwitterGridViewFragment 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().get(mPageNum).getCharacters());
            } 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");
}
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 3 with SectionCharacters

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

the class TwitterScrollViewFragment 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 sectionCharacters) {
            List<Character> characters = sectionCharacters.getCharacters();
            for (int i = 0; i < characters.size(); i++) {
                String img = characters.get(i).getAvatar();
                if (i < ivArray.length) {
                    Picasso.with(getActivity()).load(img).into(ivArray[i]);
                }
            }
            swipeToLoadLayout.setRefreshing(false);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            swipeToLoadLayout.setRefreshing(false);
            volleyError.printStackTrace();
        }
    });
    App.getRequestQueue().add(request).setTag(TAG);
}
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) List(java.util.List)

Example 4 with SectionCharacters

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

the class TwitterGridViewFragment 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) {
            mAdapter.setList(characters.getSections().get(0).getCharacters());
            swipeToLoadLayout.setRefreshing(false);
            mPageNum = 0;
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            swipeToLoadLayout.setRefreshing(false);
            volleyError.printStackTrace();
        }
    });
    App.getRequestQueue().add(request).setTag(TAG + "refresh");
}
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 5 with SectionCharacters

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

the class TwitterListViewFragment 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) {
            mAdapter.setList(characters.getSections());
            if (viewPager.getAdapter() == null) {
                mPagerAdapter = new LoopViewPagerAdapter(viewPager, indicators);
                viewPager.setAdapter(mPagerAdapter);
                viewPager.addOnPageChangeListener(mPagerAdapter);
                mPagerAdapter.setList(characters.getCharacters());
                viewPager.setBackgroundDrawable(getResources().getDrawable(R.mipmap.bg_viewpager));
            } else {
                mPagerAdapter = (LoopViewPagerAdapter) viewPager.getAdapter();
                mPagerAdapter.setList(characters.getCharacters());
            }
            swipeToLoadLayout.setRefreshing(false);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            swipeToLoadLayout.setRefreshing(false);
            volleyError.printStackTrace();
        }
    });
    App.getRequestQueue().add(request).setTag(TAG);
}
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) LoopViewPagerAdapter(com.aspsine.swipetoloadlayout.demo.adapter.LoopViewPagerAdapter)

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