759 lines
37 KiB
Java
759 lines
37 KiB
Java
/*
|
||
* Copyright (c) 2020 WildFireChat. All rights reserved.
|
||
*/
|
||
|
||
package com.xunpaisoft.social.im.main;
|
||
|
||
import android.content.Intent;
|
||
import android.graphics.drawable.Drawable;
|
||
import android.os.Bundle;
|
||
import android.text.TextUtils;
|
||
import android.view.LayoutInflater;
|
||
import android.view.View;
|
||
import android.view.ViewGroup;
|
||
import android.widget.EditText;
|
||
import android.widget.ImageView;
|
||
import android.widget.TextView;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.annotation.Nullable;
|
||
import androidx.core.content.ContextCompat;
|
||
import androidx.fragment.app.Fragment;
|
||
import androidx.lifecycle.ViewModelProviders;
|
||
import androidx.recyclerview.widget.GridLayoutManager;
|
||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||
import androidx.recyclerview.widget.RecyclerView;
|
||
|
||
import com.luck.picture.lib.utils.ToastUtils;
|
||
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
|
||
import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
||
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
|
||
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
||
import com.xunpaisoft.social.R;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.Collections;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
|
||
import cn.wildfire.chat.kit.WfcIntent;
|
||
import cn.wildfire.chat.kit.WfcUIKit;
|
||
import cn.wildfire.chat.kit.WfcWebViewActivity;
|
||
import cn.wildfire.chat.kit.channel.ChannelListActivity;
|
||
import cn.wildfire.chat.kit.chatroom.ChatRoomListActivity;
|
||
import cn.wildfire.chat.kit.conversation.ConversationActivity;
|
||
import cn.wildfire.chat.kit.dialog.BaseRcyAdapter;
|
||
import cn.wildfire.chat.kit.dialog.CommDialog;
|
||
import cn.wildfire.chat.kit.dialog.CommentDialog;
|
||
import cn.wildfire.chat.kit.dialog.DialogCallBack;
|
||
import cn.wildfire.chat.kit.mm.MMPreviewActivity;
|
||
import cn.wildfire.chat.kit.net.AppService;
|
||
import cn.wildfire.chat.kit.net.BooleanCallback;
|
||
import cn.wildfire.chat.kit.net.Constants;
|
||
import cn.wildfire.chat.kit.net.SimpleCallback;
|
||
import cn.wildfire.chat.kit.net.model.GetCommentInfoResult;
|
||
import cn.wildfire.chat.kit.net.model.GetPengyouquanResult;
|
||
import cn.wildfire.chat.kit.user.PengyouquanActivity;
|
||
import cn.wildfire.chat.kit.user.PengyouquanDetailActivity;
|
||
import cn.wildfire.chat.kit.user.PublishActivity;
|
||
import cn.wildfire.chat.kit.user.UserInfoActivity;
|
||
import cn.wildfire.chat.kit.user.UserViewModel;
|
||
import cn.wildfire.chat.kit.utils.DateUtils;
|
||
import cn.wildfire.chat.kit.utils.GlideUtils;
|
||
import cn.wildfire.chat.kit.utils.LogUtil;
|
||
import cn.wildfire.chat.kit.viewmodel.MessageViewModel;
|
||
import cn.wildfire.chat.kit.voip.conference.ConferencePortalActivity;
|
||
import cn.wildfire.chat.kit.widget.OptionItemView;
|
||
import cn.wildfirechat.avenginekit.AVEngineKit;
|
||
import cn.wildfirechat.message.Message;
|
||
import cn.wildfirechat.message.core.MessageStatus;
|
||
import cn.wildfirechat.model.Conversation;
|
||
import cn.wildfirechat.model.UserInfo;
|
||
import cn.wildfirechat.remote.ChatManager;
|
||
|
||
public class DiscoveryFragment extends Fragment {
|
||
OptionItemView momentOptionItemView;
|
||
OptionItemView conferenceOptionItemView;
|
||
|
||
private RecyclerView mRcyItem;
|
||
|
||
private TextView mTVPublish;
|
||
|
||
private BaseRcyAdapter mBaseRcyAdapter;
|
||
|
||
private TextView tvGuangchang;
|
||
|
||
private TextView tvGuanzhu;
|
||
|
||
/**
|
||
* 默认选择广场
|
||
*/
|
||
private boolean mIsClickGuangchang = true;
|
||
|
||
private int mPage = 1;
|
||
|
||
private SmartRefreshLayout swipeRefreshLayout;
|
||
|
||
@Nullable
|
||
@Override
|
||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||
View view = inflater.inflate(R.layout.main_fragment_discovery, container, false);
|
||
bindViews(view);
|
||
bindEvents(view);
|
||
initMoment();
|
||
if (!AVEngineKit.isSupportConference()) {
|
||
conferenceOptionItemView.setVisibility(View.GONE);
|
||
}
|
||
return view;
|
||
}
|
||
|
||
private void bindEvents(View view) {
|
||
view.findViewById(R.id.chatRoomOptionItemView).setOnClickListener(v -> chatRoom());
|
||
view.findViewById(R.id.robotOptionItemView).setOnClickListener(v -> robot());
|
||
view.findViewById(R.id.channelOptionItemView).setOnClickListener(v -> channel());
|
||
view.findViewById(R.id.cookbookOptionItemView).setOnClickListener(v -> cookbook());
|
||
view.findViewById(R.id.momentOptionItemView).setOnClickListener(v -> moment());
|
||
view.findViewById(R.id.conferenceOptionItemView).setOnClickListener(v -> conference());
|
||
view.findViewById(R.id.tv_publish).setOnClickListener(view1 -> publish());
|
||
|
||
view.findViewById(R.id.tv_guangchang).setOnClickListener(view1 -> clickGuangchang());
|
||
view.findViewById(R.id.tv_guanzhu).setOnClickListener(view1 -> clickGuanzhu());
|
||
|
||
refreshView();
|
||
initRcyItem();
|
||
|
||
getPublish();
|
||
swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
||
@Override
|
||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||
mPage = 1;
|
||
getPublish();
|
||
}
|
||
});
|
||
swipeRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
|
||
@Override
|
||
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
||
mPage ++ ;
|
||
getPublish();
|
||
}
|
||
});
|
||
}
|
||
|
||
private void clickGuanzhu() {
|
||
mIsClickGuangchang = false;
|
||
refreshView();
|
||
mPage = 1;
|
||
getPublish();
|
||
}
|
||
|
||
private void clickGuangchang() {
|
||
mIsClickGuangchang = true;
|
||
refreshView();
|
||
mPage = 1;
|
||
getPublish();
|
||
}
|
||
|
||
private void bindViews(View view) {
|
||
momentOptionItemView = view.findViewById(R.id.momentOptionItemView);
|
||
conferenceOptionItemView = view.findViewById(R.id.conferenceOptionItemView);
|
||
mRcyItem = view.findViewById(R.id.rcy_item);
|
||
tvGuangchang = view.findViewById(R.id.tv_guangchang);
|
||
tvGuanzhu = view.findViewById(R.id.tv_guanzhu);
|
||
swipeRefreshLayout = view.findViewById(R.id.swipeRefreshLayout);
|
||
}
|
||
|
||
|
||
private void refreshView(){
|
||
if (mIsClickGuangchang) {
|
||
Drawable drawable = ContextCompat.getDrawable(getActivity(), cn.wildfire.chat.kit.R.drawable.bottom_line_style);
|
||
tvGuangchang.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
|
||
tvGuanzhu.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||
} else {
|
||
Drawable drawable = ContextCompat.getDrawable(getActivity(), cn.wildfire.chat.kit.R.drawable.bottom_line_style);
|
||
tvGuanzhu.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
|
||
tvGuangchang.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||
}
|
||
}
|
||
|
||
private void publish() {
|
||
startActivity(new Intent(getActivity(), PublishActivity.class));
|
||
}
|
||
EditText edt_dia_content;
|
||
private void initRcyItem(){
|
||
mRcyItem.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||
mBaseRcyAdapter = new BaseRcyAdapter(null, cn.wildfire.chat.kit.R.layout.adapter_pengyouquan_item) {
|
||
@Override
|
||
public void bindView(@NonNull BaseViewHolder holder, int position) {
|
||
GetPengyouquanResult.ListBean listBean = (GetPengyouquanResult.ListBean) this.getmData().get(position);
|
||
holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_content,listBean.getContent());
|
||
// holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_commit,listBean.getComments());
|
||
holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_like,listBean.getLikes());
|
||
holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_time, DateUtils.transferOnlyLongToDatePyq(listBean.getCreatetime()+"000"));
|
||
holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_nikename,listBean.getNickname());
|
||
|
||
ImageView imgHead = (ImageView) holder.getView(cn.wildfire.chat.kit.R.id.img_ada_head);
|
||
GlideUtils.loadRoundedCornerImage(getActivity(),AppService.APP_FILE_ADDRESS+listBean.getAvatar(),imgHead);
|
||
holder.setOnClickListener(cn.wildfire.chat.kit.R.id.img_ada_head, new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
UserViewModel userViewModel = ViewModelProviders.of(getActivity()).get(UserViewModel.class);
|
||
UserInfo userInfo = userViewModel.getUserInfo(listBean.getUser_id(), true);
|
||
if (userInfo == null) {
|
||
return;
|
||
}
|
||
Intent intent = new Intent(getActivity(), UserInfoActivity.class);
|
||
intent.putExtra("userInfo", userInfo);
|
||
startActivity(intent);
|
||
}
|
||
});
|
||
holder.setOnClickListener(cn.wildfire.chat.kit.R.id.tv_ada_nikename, new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
UserViewModel userViewModel = ViewModelProviders.of(getActivity()).get(UserViewModel.class);
|
||
UserInfo userInfo = userViewModel.getUserInfo(listBean.getUser_id(), true);
|
||
if (userInfo == null) {
|
||
return;
|
||
}
|
||
Intent intent = new Intent(getActivity(), UserInfoActivity.class);
|
||
intent.putExtra("userInfo", userInfo);
|
||
startActivity(intent);
|
||
}
|
||
});
|
||
ImageView imgSex = (ImageView) holder.getView(cn.wildfire.chat.kit.R.id.img_ada_sex);
|
||
if ("0".equals(listBean.getGender())){
|
||
imgSex.setImageResource(cn.wildfire.chat.kit.R.mipmap.icon_sex_man);
|
||
} else {
|
||
imgSex.setImageResource(cn.wildfire.chat.kit.R.mipmap.icon_sex_woman);
|
||
}
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.tv_ada_detal,true);
|
||
holder.setOnClickListener(cn.wildfire.chat.kit.R.id.tv_ada_detal, new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
Intent intent = new Intent(getActivity(), PengyouquanDetailActivity.class);
|
||
intent.putExtra("detailInfo",listBean);
|
||
startActivity(intent);
|
||
}
|
||
});
|
||
|
||
// 删除
|
||
if (Constants.getUserId().equals(listBean.getUser_id())){
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.tv_ada_delete,true);
|
||
holder.setOnClickListener(cn.wildfire.chat.kit.R.id.tv_ada_delete, new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
CommDialog commDialog = CommDialog.newInstance();
|
||
commDialog.setCallBak(new DialogCallBack() {
|
||
@Override
|
||
public void initView(View viewRoot) {
|
||
TextView diaTitle = viewRoot.findViewById(cn.wildfire.chat.kit.R.id.tv_ada_title);
|
||
TextView diaContent = viewRoot.findViewById(cn.wildfire.chat.kit.R.id.tv_dia_text);
|
||
diaTitle.setText("确认删除");
|
||
diaContent.setVisibility(View.GONE);
|
||
// diaContent.setText("注销后该账号将从平台彻底删除且无法恢复,请谨慎操作。");
|
||
viewRoot.findViewById(cn.wildfire.chat.kit.R.id.tv_dia_cancel).setOnClickListener(view1 -> commDialog.dismiss());
|
||
viewRoot.findViewById(cn.wildfire.chat.kit.R.id.tv_dia_ok).setOnClickListener(view1 -> {
|
||
commDialog.dismiss();
|
||
deleteSelfPyq(listBean.getId(), new SimpleCallback() {
|
||
@Override
|
||
public void onUiSuccess(Object o) {
|
||
mPage = 1;
|
||
getPublish();
|
||
}
|
||
|
||
@Override
|
||
public void onUiFailure(int code, String msg) {
|
||
|
||
}
|
||
});
|
||
});
|
||
}
|
||
});
|
||
commDialog.show(getActivity());
|
||
}
|
||
});
|
||
} else {
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.tv_ada_delete,false);
|
||
}
|
||
|
||
|
||
RecyclerView rv = (RecyclerView) holder.getView(cn.wildfire.chat.kit.R.id.rcy_comment);
|
||
ArrayList<GetCommentInfoResult.ListBean> comments = listBean.getComments();
|
||
holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_commit,comments.size()+"");
|
||
if (comments != null && comments.size() > 3){
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.ln_comment,true);
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.tv_ada_detal,true);
|
||
} else {
|
||
if (comments == null || comments.isEmpty()) {
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.ln_comment,false);
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.tv_ada_detal,false);
|
||
} else {
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.ln_comment,true);
|
||
holder.setVisible(cn.wildfire.chat.kit.R.id.tv_ada_detal,false);
|
||
}
|
||
}
|
||
if (comments != null && comments.size() > 3) {
|
||
List<GetCommentInfoResult.ListBean> listBeans = comments.subList(0, 3);
|
||
ArrayList list = new ArrayList(listBeans);
|
||
initRcyCommentView(rv, list, listBean.getId());
|
||
} else {
|
||
initRcyCommentView(rv, comments, listBean.getId());
|
||
}
|
||
//评论
|
||
holder.setOnClickListener(cn.wildfire.chat.kit.R.id.tv_ada_commit, new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
CommentDialog commentDialog = CommentDialog.newInstance();
|
||
|
||
commentDialog.setCallBak(new DialogCallBack() {
|
||
@Override
|
||
public void initView(View viewRoot) {
|
||
edt_dia_content = viewRoot.findViewById(cn.wildfire.chat.kit.R.id.et_dia_content);
|
||
TextView tvSend = viewRoot.findViewById(cn.wildfire.chat.kit.R.id.tv_dia_send);
|
||
|
||
tvSend.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
String content = edt_dia_content.getText().toString().trim();
|
||
if (TextUtils.isEmpty(content)){
|
||
ToastUtils.showToast(getActivity(),"请输入评论内容!");
|
||
} else {
|
||
submitComment(listBean.getId(), content, new BooleanCallback() {
|
||
@Override
|
||
public void onSuccess(boolean result) {
|
||
commentDialog.dismiss();
|
||
// publishCommentList(listBean.getId(), new SimpleCallback<GetCommentInfoResult>() {
|
||
// @Override
|
||
// public void onUiSuccess(GetCommentInfoResult result) {
|
||
// GetCommentInfoResult data = result.getData();
|
||
// ArrayList<GetCommentInfoResult.ListBean> list = (ArrayList<GetCommentInfoResult.ListBean>) data.getList();
|
||
// holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_commit,data.getCount());
|
||
// initRcyCommentView(rv, list);
|
||
// }
|
||
//
|
||
// @Override
|
||
// public void onUiFailure(int code, String msg) {
|
||
//
|
||
// }
|
||
// });
|
||
}
|
||
|
||
@Override
|
||
public void onFail(int code, String msg) {
|
||
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
commentDialog.show(getActivity());
|
||
// new Handler().postDelayed(() -> {
|
||
// if (edt_dia_content != null) {
|
||
// edt_dia_content.requestFocus();
|
||
// InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||
//
|
||
// }
|
||
// }, 500);
|
||
}
|
||
});
|
||
|
||
TextView tvLike = (TextView) holder.getView(cn.wildfire.chat.kit.R.id.tv_ada_like);
|
||
if ("0".equals(listBean.getIs_like())){
|
||
Drawable drawable = ContextCompat.getDrawable(getActivity(), cn.wildfire.chat.kit.R.mipmap.icon_dianzan);
|
||
tvLike.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||
} else {
|
||
Drawable drawable = ContextCompat.getDrawable(getActivity(), cn.wildfire.chat.kit.R.mipmap.icon_dianzan_yi);
|
||
tvLike.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||
}
|
||
holder.setOnClickListener(cn.wildfire.chat.kit.R.id.tv_ada_like, new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
likeDeal(listBean.getId(), new BooleanCallback() {
|
||
@Override
|
||
public void onSuccess(boolean result) {
|
||
//点赞成功了
|
||
if ("0".equals(listBean.getIs_like())){
|
||
Drawable drawable = ContextCompat.getDrawable(getActivity(), cn.wildfire.chat.kit.R.mipmap.icon_dianzan_yi);
|
||
tvLike.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||
listBean.setIs_like("1");
|
||
if (!TextUtils.isEmpty(listBean.getLikes())) {
|
||
int i = Integer.parseInt(listBean.getLikes()) + 1;
|
||
tvLike.setText(i+"");
|
||
}
|
||
} else {
|
||
//取消了
|
||
Drawable drawable = ContextCompat.getDrawable(getActivity(), cn.wildfire.chat.kit.R.mipmap.icon_dianzan);
|
||
tvLike.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||
listBean.setIs_like("0");
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onFail(int code, String msg) {
|
||
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
RecyclerView rcyPic = (RecyclerView) holder.getView(cn.wildfire.chat.kit.R.id.rcy_item);
|
||
TextView tvLocation = (TextView) holder.getView(cn.wildfire.chat.kit.R.id.tv_ada_location);
|
||
|
||
// 显示位置信息(POI)
|
||
String poi = listBean.getPoi();
|
||
if (!TextUtils.isEmpty(poi)) {
|
||
tvLocation.setText(poi);
|
||
tvLocation.setVisibility(View.VISIBLE);
|
||
} else {
|
||
tvLocation.setVisibility(View.GONE);
|
||
}
|
||
|
||
// 处理图片显示
|
||
if (TextUtils.isEmpty(listBean.getImages())){
|
||
rcyPic.setVisibility(View.GONE);
|
||
// 如果没有图片但有位置信息,仍然显示图片容器(用于显示位置信息)
|
||
if (TextUtils.isEmpty(poi)) {
|
||
holder.getView(cn.wildfire.chat.kit.R.id.ln_ada_pic_root).setVisibility(View.GONE);
|
||
} else {
|
||
holder.getView(cn.wildfire.chat.kit.R.id.ln_ada_pic_root).setVisibility(View.VISIBLE);
|
||
}
|
||
} else {
|
||
holder.getView(cn.wildfire.chat.kit.R.id.ln_ada_pic_root).setVisibility(View.VISIBLE);
|
||
itemPicInfo(rcyPic,listBean.getImages());
|
||
}
|
||
}
|
||
};
|
||
mRcyItem.setAdapter(mBaseRcyAdapter);
|
||
}
|
||
private void initRcyCommentView(RecyclerView rcy,ArrayList<GetCommentInfoResult.ListBean> list, String postId){
|
||
rcy.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||
rcy.setAdapter(new BaseRcyAdapter(list, cn.wildfire.chat.kit.R.layout.adapter_user_comment_item) {
|
||
@Override
|
||
public void bindView(@NonNull BaseViewHolder holder, int position) {
|
||
GetCommentInfoResult.ListBean listBean = (GetCommentInfoResult.ListBean) this.getmData().get(position);
|
||
//打印listBean里的数据
|
||
LogUtil.e("AppService","listBean = " + listBean.toString());
|
||
LogUtil.e("AppService","listBean = " + listBean.getContent());
|
||
LogUtil.e("AppService","listBean = " + listBean.getReceiver());
|
||
LogUtil.e("AppService","listBean = " + listBean.getReceiver_id());
|
||
// 名称展示:nickname 或 nickname 回复 receiver
|
||
String nameText;
|
||
try {
|
||
String receiver = null;
|
||
try { receiver = (String) GetCommentInfoResult.ListBean.class.getMethod("getReceiver").invoke(listBean); } catch (Throwable ignore) {}
|
||
receiver = listBean.getReceiver();
|
||
// if (TextUtils.isEmpty(receiver)) {
|
||
// try { receiver = (String) GetCommentInfoResult.ListBean.class.getMethod("getReceiver_name").invoke(listBean); } catch (Throwable ignore) {}
|
||
// }
|
||
// if (TextUtils.isEmpty(receiver)) {
|
||
// try { receiver = (String) GetCommentInfoResult.ListBean.class.getMethod("getReceiverNickname").invoke(listBean); } catch (Throwable ignore) {}
|
||
// }
|
||
if (!TextUtils.isEmpty(receiver)) {
|
||
nameText = listBean.getNickname() + " 回复 " + receiver + ":";
|
||
} else {
|
||
// 如果拿不到被回复人姓名,则不显示“回复”
|
||
nameText = listBean.getNickname() + ":";
|
||
}
|
||
} catch (Throwable t) {
|
||
nameText = listBean.getNickname() + ":";
|
||
}
|
||
holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_name,nameText);
|
||
// holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_time, DateUtils.transferOnlyLongToDate(listBean.getCreatetime()+"000"));
|
||
holder.setText(cn.wildfire.chat.kit.R.id.tv_ada_content,listBean.getContent());
|
||
// ImageView imgHead = (ImageView) holder.getView(cn.wildfire.chat.kit.R.id.img_ada_head);
|
||
// GlideUtils.loadRoundedCornerImage(getActivity(),AppService.APP_FILE_ADDRESS+listBean.getAvatar(),imgHead);
|
||
|
||
// 点击评论进行回复
|
||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
CommentDialog commentDialog = CommentDialog.newInstance();
|
||
commentDialog.setCallBak(new DialogCallBack() {
|
||
@Override
|
||
public void initView(View viewRoot) {
|
||
EditText edt = viewRoot.findViewById(cn.wildfire.chat.kit.R.id.et_dia_content);
|
||
TextView tvSend = viewRoot.findViewById(cn.wildfire.chat.kit.R.id.tv_dia_send);
|
||
if (edt != null) {
|
||
edt.setHint("回复 " + listBean.getNickname());
|
||
}
|
||
tvSend.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
String content = edt.getText().toString().trim();
|
||
if (TextUtils.isEmpty(content)) {
|
||
ToastUtils.showToast(getActivity(),"请输入回复内容!");
|
||
return;
|
||
}
|
||
submitComment(postId, listBean.getId(), content, new BooleanCallback() {
|
||
@Override
|
||
public void onSuccess(boolean result) {
|
||
commentDialog.dismiss();
|
||
mPage = 1;
|
||
getPublish();
|
||
}
|
||
|
||
@Override
|
||
public void onFail(int code, String msg) {
|
||
ToastUtils.showToast(getActivity(), msg);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
});
|
||
commentDialog.show(getActivity());
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
private void itemPicInfo(RecyclerView rcyPic, String images){
|
||
if (TextUtils.isEmpty(images)){
|
||
rcyPic.setVisibility(View.GONE);
|
||
return;
|
||
}
|
||
String[] split = images.split(",");
|
||
if (split ==null || split.length == 0) {
|
||
rcyPic.setVisibility(View.GONE);
|
||
return;
|
||
}
|
||
rcyPic.setVisibility(View.VISIBLE);
|
||
LogUtil.e("AppService","几张图片。= " + split.length);
|
||
rcyPic.setLayoutManager(new GridLayoutManager(getActivity(),3));
|
||
ArrayList<String> strings = new ArrayList<>(Arrays.asList(split));
|
||
if (strings.size() == 1){
|
||
rcyPic.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||
} else if (strings.size() == 2) {
|
||
rcyPic.setLayoutManager(new GridLayoutManager(getActivity(),3,LinearLayoutManager.VERTICAL,false));
|
||
} else {
|
||
rcyPic.setLayoutManager(new GridLayoutManager(getActivity(),3,LinearLayoutManager.VERTICAL,false));
|
||
}
|
||
mRcyItem.setHasFixedSize(true);
|
||
rcyPic.setNestedScrollingEnabled(false);
|
||
int adapterImage = strings.size() == 1 ? cn.wildfire.chat.kit.R.layout.adapter_image : cn.wildfire.chat.kit.R.layout.adapter_pengyouquan_max_image;
|
||
rcyPic.setAdapter(new BaseRcyAdapter(strings, adapterImage) {
|
||
@Override
|
||
public void bindView(@NonNull BaseViewHolder holder, int position) {
|
||
ArrayList<String> imgDatas = this.getmData();
|
||
String url = (String) imgDatas.get(position);
|
||
ImageView imgPic = (ImageView) holder.getView(cn.wildfire.chat.kit.R.id.img_ada_pic);
|
||
GlideUtils.loadNoRoundedCornerImage(getActivity(),AppService.APP_FILE_ADDRESS+url,imgPic);
|
||
holder.setOnClickListener(cn.wildfire.chat.kit.R.id.img_ada_pic, new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
// Intent intent = new Intent(mContext, ShowPicActivity.class);
|
||
// intent.putExtra("imgUrl",AppService.APP_FILE_ADDRESS+url);
|
||
// startActivity(intent);
|
||
ArrayList<String> list = new ArrayList();
|
||
for (int i = 0; i < imgDatas.size(); i++) {
|
||
String bean = imgDatas.get(i);
|
||
list.add(AppService.APP_FILE_ADDRESS+bean);
|
||
}
|
||
MMPreviewActivity.previewImageArrayList(getContext(),list,position);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
private void submitComment(String id,String content,BooleanCallback callback){
|
||
submitComment(id, null, content, callback);
|
||
}
|
||
|
||
private void submitComment(String postId, String parentCommentId, String content, BooleanCallback callback){
|
||
HashMap<String,String> headParams = new HashMap<>();
|
||
headParams.put("post_id",postId);
|
||
headParams.put("content",content);
|
||
if (!TextUtils.isEmpty(parentCommentId)) {
|
||
headParams.put("comment_id", parentCommentId);
|
||
}
|
||
AppService.Instance().publishComment(headParams, new SimpleCallback() {
|
||
@Override
|
||
public void onUiSuccess(Object o) {
|
||
if (callback != null) {
|
||
callback.onSuccess(true);
|
||
}
|
||
mPage = 1;
|
||
getPublish();
|
||
}
|
||
|
||
@Override
|
||
public void onUiFailure(int code, String msg) {
|
||
ToastUtils.showToast(getActivity(),msg);
|
||
}
|
||
});
|
||
}
|
||
|
||
private void getPublish() {
|
||
HashMap<String, String> headParams = new HashMap<>();
|
||
headParams.put("type", mIsClickGuangchang ? "0":"1");
|
||
headParams.put("page", mPage+"");
|
||
headParams.put("limit", AppService.PAGE_MAX_NUMBER + "");
|
||
// headParams.put("user_id", "31");
|
||
AppService.Instance().publishList(headParams, new SimpleCallback<GetPengyouquanResult>() {
|
||
@Override
|
||
public void onUiSuccess(GetPengyouquanResult result) {
|
||
if (swipeRefreshLayout != null) {
|
||
swipeRefreshLayout.finishRefresh();
|
||
swipeRefreshLayout.finishLoadMore();
|
||
}
|
||
GetPengyouquanResult data = result.getData();
|
||
if (mPage == 1) {
|
||
if (data != null) {
|
||
ArrayList<GetPengyouquanResult.ListBean> list = (ArrayList<GetPengyouquanResult.ListBean>) data.getList();
|
||
mBaseRcyAdapter.setmData(list);
|
||
}
|
||
} else {
|
||
ArrayList<GetPengyouquanResult.ListBean> list = (ArrayList<GetPengyouquanResult.ListBean>) data.getList();
|
||
mBaseRcyAdapter.setLoadmData(list);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onUiFailure(int code, String msg) {
|
||
if (swipeRefreshLayout != null) {
|
||
swipeRefreshLayout.finishRefresh();
|
||
swipeRefreshLayout.finishLoadMore();
|
||
}
|
||
ToastUtils.showToast(getActivity(),msg);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private void updateMomentBadgeView() {
|
||
List<Message> messages = ChatManager.Instance().getMessagesEx2(Collections.singletonList(Conversation.ConversationType.Single), Collections.singletonList(1), Arrays.asList(MessageStatus.Unread), 0, true, 100, null);
|
||
int count = messages == null ? 0 : messages.size();
|
||
momentOptionItemView.setBadgeCount(count);
|
||
}
|
||
|
||
@Override
|
||
public void onResume() {
|
||
super.onResume();
|
||
// 确保广场页面显示时状态栏颜色为#D4E4FE
|
||
android.util.Log.d("DiscoveryFragment", "onResume: 准备设置状态栏颜色");
|
||
if (getActivity() instanceof MainActivity) {
|
||
MainActivity mainActivity = (MainActivity) getActivity();
|
||
int colorResId = com.xunpaisoft.social.R.color.discovery_status_bar_color;
|
||
android.util.Log.d("DiscoveryFragment", "onResume: 颜色资源ID=" + colorResId + ", 准备调用setStatusBarColorForFragment");
|
||
mainActivity.setStatusBarColorForFragment(colorResId, false);
|
||
android.util.Log.d("DiscoveryFragment", "onResume: setStatusBarColorForFragment调用完成");
|
||
} else {
|
||
android.util.Log.w("DiscoveryFragment", "onResume: Activity不是MainActivity实例");
|
||
}
|
||
if (WfcUIKit.getWfcUIKit().isSupportMoment()) {
|
||
updateMomentBadgeView();
|
||
}
|
||
}
|
||
|
||
void chatRoom() {
|
||
Intent intent = new Intent(getActivity(), ChatRoomListActivity.class);
|
||
startActivity(intent);
|
||
}
|
||
|
||
void robot() {
|
||
Intent intent = ConversationActivity.buildConversationIntent(getActivity(), Conversation.ConversationType.Single, "FireRobot", 0);
|
||
startActivity(intent);
|
||
}
|
||
|
||
void channel() {
|
||
Intent intent = new Intent(getActivity(), ChannelListActivity.class);
|
||
startActivity(intent);
|
||
}
|
||
|
||
void cookbook() {
|
||
WfcWebViewActivity.loadUrl(getContext(), "IM开发文档", "https://docs.wildfirechat.cn");
|
||
}
|
||
|
||
|
||
private void initMoment() {
|
||
if (!WfcUIKit.getWfcUIKit().isSupportMoment()) {
|
||
momentOptionItemView.setVisibility(View.GONE);
|
||
return;
|
||
}
|
||
MessageViewModel messageViewModel = ViewModelProviders.of(this).get(MessageViewModel.class);
|
||
messageViewModel.messageLiveData().observe(getViewLifecycleOwner(), uiMessage -> updateMomentBadgeView());
|
||
messageViewModel.clearMessageLiveData().observe(getViewLifecycleOwner(), o -> updateMomentBadgeView());
|
||
}
|
||
|
||
void moment() {
|
||
Intent intent = new Intent(WfcIntent.ACTION_MOMENT);
|
||
// 具体项目中,如果不能隐式启动,可改为下面这种显示启动朋友圈页面
|
||
// Intent intent = new Intent(getActivity(), FeedListActivity.class);
|
||
startActivity(intent);
|
||
}
|
||
|
||
void conference() {
|
||
Intent intent = new Intent(getActivity(), ConferencePortalActivity.class);
|
||
startActivity(intent);
|
||
}
|
||
|
||
private void likeDeal(String commentId, BooleanCallback callback){
|
||
HashMap<String,String> headParams = new HashMap<>();
|
||
headParams.put("post_id",commentId);
|
||
AppService.Instance().publishLike(headParams, new SimpleCallback() {
|
||
@Override
|
||
public void onUiSuccess(Object o) {
|
||
if(callback != null) {
|
||
callback.onSuccess(true);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onUiFailure(int code, String msg) {
|
||
ToastUtils.showToast(getActivity(),msg);
|
||
}
|
||
});
|
||
}
|
||
|
||
private void publishCommentList(String id, SimpleCallback callback){
|
||
HashMap<String,String> headParams = new HashMap<>();
|
||
headParams.put("post_id",id);
|
||
headParams.put("page","1");
|
||
headParams.put("limit","5");
|
||
AppService.Instance().publishCommentList(headParams, new SimpleCallback<GetCommentInfoResult>() {
|
||
@Override
|
||
public void onUiSuccess(GetCommentInfoResult result) {
|
||
if (callback != null) {
|
||
callback.onSuccess(result);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onUiFailure(int code, String msg) {
|
||
// showToast(msg);
|
||
}
|
||
});
|
||
}
|
||
|
||
public void refreshAllView(){
|
||
mPage = 1;
|
||
getPublish();
|
||
}
|
||
|
||
|
||
private void deleteSelfPyq(String id, SimpleCallback callback){
|
||
HashMap<String,String> headParams = new HashMap<>();
|
||
headParams.put("post_id",id);
|
||
AppService.Instance().postpyqDelete(headParams, new SimpleCallback() {
|
||
@Override
|
||
public void onUiSuccess(Object result) {
|
||
if (callback != null) {
|
||
callback.onSuccess(result);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onUiFailure(int code, String msg) {
|
||
ToastUtils.showToast(getActivity(),msg);
|
||
}
|
||
});
|
||
}
|
||
}
|