Search in sources :

Example 1 with StatusApi

use of com.funstill.kelefun.data.api.StatusApi 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 StatusApi

use of com.funstill.kelefun.data.api.StatusApi 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 StatusApi

use of com.funstill.kelefun.data.api.StatusApi 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 StatusApi

use of com.funstill.kelefun.data.api.StatusApi 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)

Example 5 with StatusApi

use of com.funstill.kelefun.data.api.StatusApi in project keleFanfou by kelefun.

the class SendStatusFragmentChild method postStatus.

/**
 * 发送
 */
private void postStatus() {
    ToastUtil.showToast(_mActivity, "正在发布中...");
    // backToHome();
    StatusApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(StatusApi.class);
    if (imageUrl != null) {
        // 带图片
        RequestBody status = RequestBody.create(MediaType.parse("text/plain"), editText.getText().toString());
        // TODO 如果不是gif则压缩图片
        Luban.with(_mActivity).load(imageUrl).ignoreBy(// 2MB
        1024 * 2).putGear(4).setCompressListener(new OnCompressListener() {

            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(File file) {
                RequestBody photo = RequestBody.create(MediaType.parse("multipart/form-data"), file);
                MultipartBody.Part body = MultipartBody.Part.createFormData("photo", file.getName(), photo);
                Call<Status> call = api.uploadPhoto(status, body);
                enqueue(call);
            }

            @Override
            public void onError(Throwable e) {
            }
        }).launch();
    } else {
        // 只有文字
        if ("".equals(editText.getText().toString())) {
            ToastUtil.showToast(_mActivity, "输入不能为空");
            return;
        }
        String status = editText.getText().toString();
        Map<String, String> partMap = new ArrayMap<>();
        partMap.put("status", status);
        Call<Status> call = api.postStatus(partMap);
        enqueue(call);
    }
}
Also used : Status(com.funstill.kelefun.data.model.Status) StatusApi(com.funstill.kelefun.data.api.StatusApi) SignInterceptor(com.funstill.kelefun.http.SignInterceptor) OnCompressListener(top.zibin.luban.OnCompressListener) ArrayMap(android.support.v4.util.ArrayMap) MultipartBody(okhttp3.MultipartBody) File(java.io.File) RequestBody(okhttp3.RequestBody)

Aggregations

StatusApi (com.funstill.kelefun.data.api.StatusApi)19 SignInterceptor (com.funstill.kelefun.http.SignInterceptor)19 ArrayList (java.util.ArrayList)18 List (java.util.List)18 Status (com.funstill.kelefun.data.model.Status)2 ArrayMap (android.support.v4.util.ArrayMap)1 File (java.io.File)1 MultipartBody (okhttp3.MultipartBody)1 RequestBody (okhttp3.RequestBody)1 OnCompressListener (top.zibin.luban.OnCompressListener)1