Search in sources :

Example 1 with ThumbsUpUser

use of com.rideread.rideread.data.result.ThumbsUpUser in project ride-read-android by Ride-Read.

the class UserMomentsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder tHolder, int position) {
    if (TYPE_ITEM == tHolder.getItemViewType()) {
        Moment moment = mMomentList.get(position);
        MomentViewHolder holder = (MomentViewHolder) tHolder;
        holder.mClMomentLayout.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putInt(MomentDetailActivity.SELECTED_MOMENT_MID, moment.getMid());
            mActivity.gotoActivity(MomentDetailActivity.class, bundle);
        });
        String msg = moment.getMsg();
        if (!TextUtils.isEmpty(msg)) {
            holder.mTvMomentText.setText(msg);
            holder.mTvMomentText.setVisibility(View.VISIBLE);
        } else {
            holder.mTvMomentText.setVisibility(View.GONE);
        }
        List<String> pictures = moment.getPictures();
        if (!ListUtils.isEmpty(pictures)) {
            holder.mNineGridImgView.setAdapter(adapter);
            holder.mNineGridImgView.setImagesData(pictures);
            holder.mNineGridImgView.setVisibility(View.VISIBLE);
        } else {
            holder.mNineGridImgView.setVisibility(View.GONE);
        }
        holder.mTvTime.setText(getFriendlyTimeSpanByNow(moment.getCreatedAt()));
        List<ThumbsUpUser> thumbsUp = moment.getThumbsUp();
        int likeCount = ListUtils.isEmpty(thumbsUp) ? 0 : thumbsUp.size();
        holder.mTvLikeCount.setText(likeCount + "");
        List<Comment> comments = moment.getComment();
        int commentSize = ListUtils.isEmpty(comments) ? 0 : comments.size();
        holder.mTvCommentCount.setText(commentSize + "");
        // TODO
        holder.mTvLocInfo.setText(moment.getMomentLocation() + " 距离我" + moment.getDistanceString());
        holder.setIsRecyclable(false);
    } else if (TYPE_HEADER == tHolder.getItemViewType()) {
    } else {
    // 最后一个位置
    }
}
Also used : Comment(com.rideread.rideread.data.result.Comment) Moment(com.rideread.rideread.data.result.Moment) Bundle(android.os.Bundle) ThumbsUpUser(com.rideread.rideread.data.result.ThumbsUpUser) Utils.getString(com.rideread.rideread.common.util.Utils.getString)

Example 2 with ThumbsUpUser

use of com.rideread.rideread.data.result.ThumbsUpUser in project ride-read-android by Ride-Read.

the class MomentsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder tHolder, int position) {
    if (TYPE_ITEM == tHolder.getItemViewType()) {
        Moment moment = mMomentList.get(position);
        MomentUser user = moment.getUser();
        boolean isAttent = 0 == user.getIsFollowed();
        MomentViewHolder holder = (MomentViewHolder) tHolder;
        holder.mClMomentLayout.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putInt(MomentDetailActivity.SELECTED_MOMENT_MID, moment.getMid());
            bundle.putInt(MomentDetailActivity.USER_TYPE, isAttent ? MomentDetailActivity.USER_TYPE_ATTENTED : MomentDetailActivity.USER_TYPE_NEARBY);
            mActivity.gotoActivity(MomentDetailActivity.class, bundle);
        });
        ImgLoader.getInstance().displayImage(user.getFaceUrl(), holder.mImgAvatar);
        holder.mTvName.setText(user.getUsername());
        holder.mImgAvatar.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putInt(UserMomentsActivity.SELECTED_UID, user.getUid());
            bundle.putString(UserMomentsActivity.SELECTED_USERNAME, user.getUsername());
            mActivity.gotoActivity(UserMomentsActivity.class, bundle);
        });
        String msg = moment.getMsg();
        if (!TextUtils.isEmpty(msg)) {
            holder.mTvMomentText.setText(msg);
            holder.mTvMomentText.setVisibility(View.VISIBLE);
        } else {
            holder.mTvMomentText.setVisibility(View.GONE);
        }
        List<String> pictures = moment.getPictures();
        if (!ListUtils.isEmpty(pictures)) {
            holder.mNineGridImgView.setAdapter(adapter);
            holder.mNineGridImgView.setImagesData(pictures);
            holder.mNineGridImgView.setVisibility(View.VISIBLE);
        } else {
            holder.mNineGridImgView.setVisibility(View.GONE);
        }
        holder.mBtnAttention.setBackgroundResource(isAttent ? R.drawable.icon_attented : R.drawable.icon_attention);
        holder.mBtnAttention.setOnClickListener(v -> {
            if (isAttent) {
                ApiUtils.unfollow(user.getUid(), new BaseCallback<BaseModel<DefJsonResult>>() {

                    @Override
                    protected void onSuccess(BaseModel<DefJsonResult> model) throws Exception {
                        holder.mBtnAttention.setBackgroundResource(R.drawable.icon_attention);
                        user.setIsFollowed(-1);
                    }
                });
            } else {
                ApiUtils.follow(user.getUid(), new BaseCallback<BaseModel<DefJsonResult>>() {

                    @Override
                    protected void onSuccess(BaseModel<DefJsonResult> model) throws Exception {
                        holder.mBtnAttention.setBackgroundResource(R.drawable.icon_attented);
                        user.setIsFollowed(1);
                    }
                });
            }
        });
        List<ThumbsUpUser> thumbsUp = moment.getThumbsUp();
        int likeCount = ListUtils.isEmpty(thumbsUp) ? 0 : thumbsUp.size();
        holder.mBtnLike.setOnClickListener(v -> ApiUtils.updateThumbsUp(moment.getMid(), new BaseCallback<BaseModel<DefJsonResult>>() {

            @Override
            protected void onSuccess(BaseModel<DefJsonResult> model) throws Exception {
                ToastUtils.show("成功点赞");
                holder.mTvLikeCount.setText((likeCount + 1) + "");
            }
        }));
        holder.mTvTime.setText(getFriendlyTimeSpanByNow(moment.getCreatedAt()));
        holder.mTvLikeCount.setText(likeCount + "");
        List<Comment> comments = moment.getComment();
        int commentSize = ListUtils.isEmpty(comments) ? 0 : comments.size();
        holder.mTvCommentCount.setText(commentSize + "");
        // TODO
        holder.mTvLocInfo.setText(moment.getMomentLocation() + " 距离我" + moment.getDistanceString());
        holder.setIsRecyclable(false);
    } else if (TYPE_HEADER == tHolder.getItemViewType()) {
    } else {
    // 最后一个位置
    }
}
Also used : Comment(com.rideread.rideread.data.result.Comment) Bundle(android.os.Bundle) ThumbsUpUser(com.rideread.rideread.data.result.ThumbsUpUser) Utils.getString(com.rideread.rideread.common.util.Utils.getString) MomentUser(com.rideread.rideread.data.result.MomentUser) Moment(com.rideread.rideread.data.result.Moment) DefJsonResult(com.rideread.rideread.data.result.DefJsonResult) BaseModel(com.rideread.rideread.function.net.retrofit.BaseModel) BaseCallback(com.rideread.rideread.function.net.retrofit.BaseCallback)

Example 3 with ThumbsUpUser

use of com.rideread.rideread.data.result.ThumbsUpUser in project ride-read-android by Ride-Read.

the class ThumbsUpUserAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder tHolder, int position) {
    UserViewHolder holder = (UserViewHolder) tHolder;
    ThumbsUpUser user = mUserList.get(position);
    ImgLoader.getInstance().displayImage(user.getFaceUrl(), holder.mImgAvatar);
    holder.mTvName.setText(user.getUsername());
    holder.mTvSignature.setText(user.getSignature());
    holder.mBtnAttention.setVisibility(View.VISIBLE);
    holder.mTvTime.setVisibility(View.GONE);
    boolean isAttent = 0 == user.getIsFollowed();
    holder.mBtnAttention.setBackgroundResource(isAttent ? R.drawable.icon_attented : R.drawable.icon_attention);
    holder.mBtnAttention.setOnClickListener(v -> {
        if (isAttent) {
            ApiUtils.unfollow(user.getUid(), new BaseCallback<BaseModel<DefJsonResult>>() {

                @Override
                protected void onSuccess(BaseModel<DefJsonResult> model) throws Exception {
                // holder.mBtnAttention.setBackgroundResource(R.drawable.icon_attention);
                // user.setIsFollowed(-1);
                // notifyDataSetChanged();
                }
            });
        } else {
            ApiUtils.follow(user.getUid(), new BaseCallback<BaseModel<DefJsonResult>>() {

                @Override
                protected void onSuccess(BaseModel<DefJsonResult> model) throws Exception {
                    holder.mBtnAttention.setVisibility(View.GONE);
                // holder.mBtnAttention.setBackgroundResource(R.drawable.icon_attented);
                // user.setIsFollowed(1);
                // notifyDataSetChanged();
                }
            });
        }
    });
    holder.mImgAvatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ToastUtils.show("进入个人页面");
        }
    });
// holder.setIsRecyclable(false);
}
Also used : DefJsonResult(com.rideread.rideread.data.result.DefJsonResult) BaseModel(com.rideread.rideread.function.net.retrofit.BaseModel) ThumbsUpUser(com.rideread.rideread.data.result.ThumbsUpUser) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View)

Example 4 with ThumbsUpUser

use of com.rideread.rideread.data.result.ThumbsUpUser in project ride-read-android by Ride-Read.

the class MomentDetailActivity method refreshView.

private void refreshView() {
    View momentHeader = initMomentHeader();
    mCurMomentUser = mCurMoment.getUser();
    if (null != mCurMomentUser) {
        ImgLoader.getInstance().displayImage(mCurMoment.getUser().getFaceUrl(), mImgAvatar);
        mTvName.setText(mCurMomentUser.getUsername());
        mTvTime.setText(TimeUtils.getFriendlyTimeSpanByNow(mCurMoment.getCreatedAt()));
        int isFollowInt = mCurMomentUser.getIsFollowed();
        isAttention = isFollowInt == 0 || isFollowInt == 1;
        mBtnAttention.setBackgroundResource(isAttention ? R.drawable.icon_attented : R.drawable.icon_attention);
        mTvMomentText.setText(mCurMoment.getMsg());
        mTvCommentCount.setText("评论 " + mCurMoment.getComment().size());
        mThumbUpCount = mCurMoment.getThumbsUp().size();
        mTvThumbCount.setText(Integer.toString(mThumbUpCount));
        if (mCurMomentUser.getUid() == UserUtils.getUid())
            mBtnAttention.setVisibility(View.GONE);
        mImgAvatar.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putInt(UserMomentsActivity.SELECTED_UID, mCurMomentUser.getUid());
            bundle.putString(UserMomentsActivity.SELECTED_USERNAME, mCurMomentUser.getUsername());
            gotoActivity(UserMomentsActivity.class, bundle);
        });
        mBtnAttention.setOnClickListener(v -> {
            if (isAttention) {
                ApiUtils.unfollow(mCurMomentUser.getUid(), new BaseCallback<BaseModel<DefJsonResult>>() {

                    @Override
                    protected void onSuccess(BaseModel<DefJsonResult> model) throws Exception {
                        mBtnAttention.setBackgroundResource(R.drawable.icon_attention);
                        isAttention = !isAttention;
                    }
                });
            } else {
                ApiUtils.follow(mCurMomentUser.getUid(), new BaseCallback<BaseModel<DefJsonResult>>() {

                    @Override
                    protected void onSuccess(BaseModel<DefJsonResult> model) throws Exception {
                        mBtnAttention.setBackgroundResource(R.drawable.icon_attented);
                        isAttention = !isAttention;
                    }
                });
            }
        });
        List<String> pictures = mCurMoment.getPictures();
        if (!ListUtils.isEmpty(pictures)) {
            mNineGridImgView.setAdapter(nineGridAdapter);
            mNineGridImgView.setImagesData(pictures);
            mNineGridImgView.setVisibility(View.VISIBLE);
        } else {
            mNineGridImgView.setVisibility(View.GONE);
        }
    }
    List<ThumbsUpUser> thumbsUpUsers = mCurMoment.getThumbsUp();
    SimpleDraweeView thumbUpUserAvatar;
    RoundingParams roundingParams = RoundingParams.fromCornersRadius(4f);
    roundingParams.setRoundAsCircle(true);
    for (ThumbsUpUser thumbsUpUser : thumbsUpUsers) {
        thumbUpUserAvatar = new SimpleDraweeView(this);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams((int) ScreenUtils.dp2px(28f), (int) ScreenUtils.dp2px(28f));
        thumbUpUserAvatar.setLayoutParams(params);
        thumbUpUserAvatar.getHierarchy().setRoundingParams(roundingParams);
        ImgLoader.getInstance().displayImage(thumbsUpUser.getFaceUrl(), thumbUpUserAvatar);
        mHllThumpUps.addView(thumbUpUserAvatar);
        if (UserUtils.getUid() == thumbsUpUser.getUid()) {
            myAvatar = thumbUpUserAvatar;
        }
        if (!mHllThumpUps.canAddView()) {
            break;
        }
    }
    if (!ListUtils.isEmpty(thumbsUpUsers)) {
        mHllThumpUps.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putInt(ThumbsUpUserActivity.MOMENT_ID, mCurMoment.getMid());
            gotoActivity(ThumbsUpUserActivity.class, bundle);
        });
    }
    for (ThumbsUpUser thumbsUpUser : thumbsUpUsers) {
        if (thumbsUpUser.getUid() == UserUtils.getUid()) {
            isThumbsUp = true;
            break;
        }
    }
    mBtnThumbsUp.setBackgroundResource(isThumbsUp ? R.drawable.ic_thumb_up_on : R.drawable.ic_thumb_up_off);
    mLvComments.addHeaderView(momentHeader);
    mAdapter = new CommentsAdapter(this);
    mCommentList = mCurMoment.getComment();
    mAdapter.setItems(mCommentList);
    mLvComments.setAdapter(mAdapter);
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) Bundle(android.os.Bundle) ThumbsUpUser(com.rideread.rideread.data.result.ThumbsUpUser) ViewGroup(android.view.ViewGroup) CommentsAdapter(com.rideread.rideread.common.adapter.CommentsAdapter) BindView(butterknife.BindView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) NineGridImgView(com.rideread.rideread.common.widget.NineGridImgView.NineGridImgView) TextView(android.widget.TextView) ListView(android.widget.ListView) DefJsonResult(com.rideread.rideread.data.result.DefJsonResult) BaseModel(com.rideread.rideread.function.net.retrofit.BaseModel) RoundingParams(com.facebook.drawee.generic.RoundingParams)

Aggregations

ThumbsUpUser (com.rideread.rideread.data.result.ThumbsUpUser)4 Bundle (android.os.Bundle)3 DefJsonResult (com.rideread.rideread.data.result.DefJsonResult)3 BaseModel (com.rideread.rideread.function.net.retrofit.BaseModel)3 View (android.view.View)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)2 Utils.getString (com.rideread.rideread.common.util.Utils.getString)2 Comment (com.rideread.rideread.data.result.Comment)2 Moment (com.rideread.rideread.data.result.Moment)2 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewGroup (android.view.ViewGroup)1 ListView (android.widget.ListView)1 RoundingParams (com.facebook.drawee.generic.RoundingParams)1 CommentsAdapter (com.rideread.rideread.common.adapter.CommentsAdapter)1 NineGridImgView (com.rideread.rideread.common.widget.NineGridImgView.NineGridImgView)1 MomentUser (com.rideread.rideread.data.result.MomentUser)1 BaseCallback (com.rideread.rideread.function.net.retrofit.BaseCallback)1