use of com.android.volley.toolbox.GsonRequest 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);
}
use of com.android.volley.toolbox.GsonRequest 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);
}
use of com.android.volley.toolbox.GsonRequest 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);
}
use of com.android.volley.toolbox.GsonRequest 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");
}
Aggregations