Search in sources :

Example 1 with SignInterceptor

use of com.funstill.kelefun.http.SignInterceptor in project keleFanfou by kelefun.

the class FavouriteStatusListFragment method loadMoreHomeLineStatus.

private void loadMoreHomeLineStatus(Map<String, String> param) {
    StatusApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(StatusApi.class);
    Call<List<Status>> call = api.getFavourites(param);
    call.enqueue(new Callback<List<Status>>() {

        @Override
        public void onResponse(Call<List<Status>> call, Response<List<Status>> response) {
            if (response.code() == 200) {
                List<Status> statusList = response.body();
                if (statusList.size() > 0) {
                    data.addAll(statusList);
                    mAdapter.notifyDataSetChanged();
                } else {
                    ToastUtil.showToast(getContext(), "没有更多了");
                }
            }
            isLoadingMore = false;
        }

        @Override
        public void onFailure(Call<List<Status>> call, Throwable t) {
            t.printStackTrace();
            LogHelper.e("请求失败", t.getMessage());
            isLoadingMore = false;
        }
    });
}
Also used : StatusApi(com.funstill.kelefun.data.api.StatusApi) SignInterceptor(com.funstill.kelefun.http.SignInterceptor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with SignInterceptor

use of com.funstill.kelefun.http.SignInterceptor in project keleFanfou by kelefun.

the class ImageListFragment method loadMoreMentions.

private void loadMoreMentions(Map<String, String> param) {
    param.put("id", tuserId);
    StatusApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(StatusApi.class);
    Call<List<Status>> call = api.getUserTimeLineWithPhoto(param);
    call.enqueue(new Callback<List<Status>>() {

        @Override
        public void onResponse(Call<List<Status>> call, Response<List<Status>> response) {
            if (response.code() == 200) {
                List<Status> statusList = response.body();
                if (statusList.size() > 0) {
                    data.addAll(statusList);
                    mAdapter.notifyItemRangeInserted(lastVisibleItemPosition + 1, statusList.size());
                } else {
                    ToastUtil.showToast(getContext(), "没有更多了");
                }
            } else if (response.code() == 403) {
                ToastUtil.showToast(getContext(), "对方设置了隐私,需先请求关注");
            }
            isLoadingMore = false;
        }

        @Override
        public void onFailure(Call<List<Status>> call, Throwable t) {
            t.printStackTrace();
            LogHelper.e("请求失败", t.getMessage());
            isLoadingMore = false;
        }
    });
}
Also used : StatusApi(com.funstill.kelefun.data.api.StatusApi) SignInterceptor(com.funstill.kelefun.http.SignInterceptor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with SignInterceptor

use of com.funstill.kelefun.http.SignInterceptor in project keleFanfou by kelefun.

the class StatusListFragment method getUserTimeLineStatus.

private void getUserTimeLineStatus(Map<String, String> param) {
    StatusApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(StatusApi.class);
    Call<List<Status>> call = api.getUserTimeLine(param);
    call.enqueue(new Callback<List<Status>>() {

        @Override
        public void onResponse(Call<List<Status>> call, Response<List<Status>> response) {
            if (response.code() == 200) {
                List<Status> statusList = response.body();
                if (statusList.size() > 0) {
                    if (data.size() > 0) {
                        // 让新增的数据在前面
                        List<Status> tempList = new ArrayList<>();
                        tempList.addAll(data);
                        data.clear();
                        data.addAll(statusList);
                        data.addAll(tempList);
                    } else {
                        data.addAll(statusList);
                    }
                    mAdapter.notifyDataSetChanged();
                } else {
                    ToastUtil.showToast(getContext(), "没有更多了");
                }
            } else if (response.code() == 403) {
                ToastUtil.showToast(getContext(), "对方设置了隐私,需先请求关注");
            }
        }

        @Override
        public void onFailure(Call<List<Status>> call, Throwable t) {
            t.printStackTrace();
        }
    });
}
Also used : StatusApi(com.funstill.kelefun.data.api.StatusApi) SignInterceptor(com.funstill.kelefun.http.SignInterceptor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with SignInterceptor

use of com.funstill.kelefun.http.SignInterceptor in project keleFanfou by kelefun.

the class AccountService method getUserInfo.

/**
 * @param auth 用户 Id
 */
public UserInfo getUserInfo(OAuthToken auth) {
    Retrofit retrofit = BaseRetrofit.retrofit(new SignInterceptor());
    AccountApi api = retrofit.create(AccountApi.class);
    Call<ResponseBody> call = api.verifyCred();
    try {
        Response<ResponseBody> response = call.execute();
    // LogHelper.d(response.body().string());
    } catch (Exception e) {
        // TODO handle errors
        e.printStackTrace();
        LogHelper.e(e.getMessage());
    }
    return null;
}
Also used : BaseRetrofit(com.funstill.kelefun.http.BaseRetrofit) Retrofit(retrofit2.Retrofit) AccountApi(com.funstill.kelefun.data.api.AccountApi) SignInterceptor(com.funstill.kelefun.http.SignInterceptor) ResponseBody(okhttp3.ResponseBody)

Example 5 with SignInterceptor

use of com.funstill.kelefun.http.SignInterceptor in project keleFanfou by kelefun.

the class MentionsPagerFragment method loadMoreMentions.

private void loadMoreMentions(Map<String, String> param) {
    StatusApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(StatusApi.class);
    Call<List<Status>> call = api.getMentions(param);
    call.enqueue(new Callback<List<Status>>() {

        @Override
        public void onResponse(Call<List<Status>> call, Response<List<Status>> response) {
            if (response.code() == 200) {
                List<Status> statusList = response.body();
                if (statusList.size() > 0) {
                    data.addAll(statusList);
                    mAdapter.notifyDataSetChanged();
                } else {
                    ToastUtil.showToast(_mActivity, "没有更多了");
                }
            }
            isLoadingMore = false;
        }

        @Override
        public void onFailure(Call<List<Status>> call, Throwable t) {
            t.printStackTrace();
            LogHelper.e("请求失败", t.getMessage());
            isLoadingMore = false;
        }
    });
}
Also used : StatusApi(com.funstill.kelefun.data.api.StatusApi) SignInterceptor(com.funstill.kelefun.http.SignInterceptor) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SignInterceptor (com.funstill.kelefun.http.SignInterceptor)30 ArrayList (java.util.ArrayList)21 List (java.util.List)21 StatusApi (com.funstill.kelefun.data.api.StatusApi)19 UserInfo (com.funstill.kelefun.data.model.UserInfo)6 IOException (java.io.IOException)5 MsgApi (com.funstill.kelefun.data.api.MsgApi)4 UserApi (com.funstill.kelefun.data.api.UserApi)3 AccountApi (com.funstill.kelefun.data.api.AccountApi)2 FriendShipApi (com.funstill.kelefun.data.api.FriendShipApi)2 Status (com.funstill.kelefun.data.model.Status)2 BaseRetrofit (com.funstill.kelefun.http.BaseRetrofit)2 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 Retrofit (retrofit2.Retrofit)2 ArrayMap (android.support.v4.util.ArrayMap)1 AccountStore (com.funstill.kelefun.config.AccountStore)1 DirectMessage (com.funstill.kelefun.data.model.DirectMessage)1 File (java.io.File)1 MultipartBody (okhttp3.MultipartBody)1