Search in sources :

Example 16 with SignInterceptor

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

the class ImageListFragment method getStatusWithImage.

/**
 * 获取带图片的消息
 *
 * @param param
 */
private void getStatusWithImage(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) {
            LogHelper.d("请求响应code", String.valueOf(response.code()));
            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.notifyItemRangeInserted(lastVisibleItemPosition + 1, statusList.size());
                } else {
                    if (data.size() > 0) {
                        ToastUtil.showToast(getContext(), "没有更多了");
                    } else {
                        // 暂时还没有数据
                        ToastUtil.showToast(getContext(), "还没有相关数据");
                    }
                }
            } else if (response.code() == 403) {
                ToastUtil.showToast(getContext(), "对方设置了隐私,需先请求关注");
            }
        }

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

Example 17 with SignInterceptor

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

the class StatusListFragment method loadMoreHomeLineStatus.

private void loadMoreHomeLineStatus(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) {
                    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 18 with SignInterceptor

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

the class UserHomeActivity method getUserInfo.

private void getUserInfo() {
    UserApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(UserApi.class);
    Call<UserInfo> call = api.getUsersShow(getIntent().getStringExtra(USER_ID));
    call.enqueue(new Callback<UserInfo>() {

        @Override
        public void onResponse(Call<UserInfo> call, Response<UserInfo> response) {
            if (response.code() == 200) {
                UserInfo userInfo = response.body();
                if (userInfo != null) {
                    if (!TextUtils.isEmpty(userInfo.getDescription())) {
                        description.setText(userInfo.getDescription());
                    } else {
                        description.setText(getString(R.string.user_description));
                    }
                    location.setText(userInfo.getLocation());
                    reg_time.setText(DateUtil.toYear(userInfo.getCreatedAt()));
                    friendsCount.setText(formatCount(userInfo.getFriendsCount()));
                    followersCount.setText(formatCount(userInfo.getFollowersCount()));
                    statusesCount.setText(formatCount(userInfo.getStatusesCount()));
                    Glide.with(UserHomeActivity.this).load(userInfo.getProfileImageUrlLarge()).into(profileImage);
                    Glide.with(UserHomeActivity.this).load(userInfo.getProfileBackgroundImageUrl()).into(profileBackgroundImage);
                    mCollapsingToolbarLayout.setTitle(userInfo.getScreenName());
                    if (userInfo.isFollowing()) {
                        attention.setImageResource(R.drawable.ic_action_attention_original);
                    }
                } else {
                    ToastUtil.showToast(UserHomeActivity.this, "没有查询到");
                }
            } else {
                try {
                    LogHelper.e(response.code() + "测试" + response.message() + "哈哈" + response.errorBody().string());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onFailure(Call<UserInfo> call, Throwable t) {
            t.printStackTrace();
            ToastUtil.showToast(UserHomeActivity.this, "数据请求失败");
            LogHelper.e("请求失败", t.getMessage());
        }
    });
}
Also used : SignInterceptor(com.funstill.kelefun.http.SignInterceptor) UserInfo(com.funstill.kelefun.data.model.UserInfo) UserApi(com.funstill.kelefun.data.api.UserApi)

Example 19 with SignInterceptor

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

the class ExploreFragmentChild method getPublicTimeLineStatus.

/**
 * 请求public_timeline数据(随便看看)
 */
private void getPublicTimeLineStatus(Map<String, String> param) {
    StatusApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(StatusApi.class);
    Call<List<Status>> call = api.getPublicTimeLine(param);
    call.enqueue(new Callback<List<Status>>() {

        @Override
        public void onResponse(Call<List<Status>> call, Response<List<Status>> response) {
            LogHelper.d("请求响应code", String.valueOf(response.code()));
            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);
                        ToastUtil.showToast(_mActivity, "Fun+ " + statusList.size());
                    } else {
                        data.addAll(statusList);
                    }
                    mAdapter.notifyDataSetChanged();
                } else {
                    ToastUtil.showToast(_mActivity, "没有更多了");
                }
            }
            mRefreshLayout.setRefreshing(false);
        }

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

Example 20 with SignInterceptor

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

the class ExploreFragmentChild method loadMore.

private void loadMore(Map<String, String> param) {
    StatusApi api = BaseRetrofit.retrofit(new SignInterceptor()).create(StatusApi.class);
    Call<List<Status>> call = api.getPublicTimeLine(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);
                        for (Status status : statusList) {
                            // 是否重复
                            boolean exist = false;
                            for (Status temp : tempList) {
                                if (temp.getId().equals(status.getId())) {
                                    exist = true;
                                }
                            }
                            if (!exist) {
                                data.add(status);
                            }
                        }
                    } else {
                        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 : Status(com.funstill.kelefun.data.model.Status) 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