158 lines
5.3 KiB
Java
158 lines
5.3 KiB
Java
package com.yunbao.share.ui;
|
|
|
|
import static android.content.Context.CLIPBOARD_SERVICE;
|
|
|
|
import android.content.ClipData;
|
|
import android.content.ClipboardManager;
|
|
import android.content.Context;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.lxj.xpopup.XPopup;
|
|
import com.makeramen.roundedimageview.RoundedImageView;
|
|
import com.pdlive.shayu.R;
|
|
import com.yunbao.common.dialog.AbsDialogCenterPopupWindow;
|
|
import com.yunbao.common.dialog.AbsDialogPopupWindow;
|
|
import com.yunbao.common.glide.ImgLoader;
|
|
import com.yunbao.common.utils.StringUtil;
|
|
import com.yunbao.common.utils.ToastUtil;
|
|
import com.yunbao.common.utils.WordUtil;
|
|
import com.yunbao.share.adapters.ShareAppAdapter;
|
|
import com.yunbao.share.bean.ShareBean;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class SharePopDialog extends AbsDialogPopupWindow {
|
|
public static final int TYPE_LIVE = 1;
|
|
public static final int TYPE_DYNAMIC = 0;
|
|
public static final int TYPE_VIDEO = 2;
|
|
private ShareAppAdapter adapter;
|
|
private RecyclerView list;
|
|
private RoundedImageView avatar;
|
|
private TextView info;
|
|
private TextView link;
|
|
private List<ShareBean> data;
|
|
|
|
private String shareLink;
|
|
private int type;
|
|
private ShareBean bean;
|
|
public onShareListener onShareListener;
|
|
|
|
public void setOnShareListener(SharePopDialog.onShareListener onShareListener) {
|
|
this.onShareListener = onShareListener;
|
|
}
|
|
|
|
public SharePopDialog(@NonNull Context context) {
|
|
super(context);
|
|
}
|
|
|
|
public SharePopDialog setShareType(int type) {
|
|
this.type = type;
|
|
return this;
|
|
}
|
|
|
|
public SharePopDialog setShareData(ShareBean build) {
|
|
this.bean = build;
|
|
return this;
|
|
}
|
|
|
|
public SharePopDialog setShareLink(String link) {
|
|
this.shareLink = link + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0);
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public void buildDialog(XPopup.Builder builder) {
|
|
}
|
|
|
|
@Override
|
|
public int bindLayoutId() {
|
|
return R.layout.dialog_share;
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void onCreate() {
|
|
super.onCreate();
|
|
findViewById(R.id.close).setOnClickListener(v -> dismiss());
|
|
findViewById(R.id.share_copy).setOnClickListener(v -> copyLink());
|
|
list = findViewById(R.id.share_apps_list);
|
|
avatar = findViewById(R.id.share_avatar);
|
|
info = findViewById(R.id.share_info);
|
|
link = findViewById(R.id.share_link);
|
|
adapter = new ShareAppAdapter(getContext());
|
|
adapter.setOnShareStatusListener(new ShareAppAdapter.ShareCallback() {
|
|
@Override
|
|
public void onSuccess() {
|
|
super.onSuccess();
|
|
dismiss();
|
|
}
|
|
});
|
|
adapter.setOnShareListener(new ShareAppAdapter.onShareListener() {
|
|
@Override
|
|
public void onAddShareCount() {
|
|
if (onShareListener != null) {
|
|
onShareListener.onShareAddCount();
|
|
}
|
|
}
|
|
});
|
|
list.setLayoutManager(new GridLayoutManager(getContext(), 3));
|
|
list.setAdapter(adapter);
|
|
initData();
|
|
}
|
|
|
|
private void initData() {
|
|
data = new ArrayList<>();
|
|
data.add(builder(ShareBean.APP_FACEBOOK));
|
|
data.add(builder(ShareBean.APP_LINE));
|
|
data.add(builder(ShareBean.APP_TWITTER));
|
|
data.add(builder(ShareBean.APP_WHATSAPP));
|
|
data.add(builder(ShareBean.APP_MESSENGER));
|
|
data.add(builder(ShareBean.APP_INTERNAL));
|
|
adapter.setList(data);
|
|
String url;
|
|
if (shareLink == null) {
|
|
url = ShareBean.createLiveShareLink(bean.getUid(), bean.getAnchorId(), bean.getAnchorName(), bean.getAnchorAvatar()).substring(0, 40) + "...";
|
|
} else {
|
|
if (shareLink.length() > 40) {
|
|
url = shareLink.substring(0, 40) + "...";
|
|
} else {
|
|
url = shareLink;
|
|
}
|
|
}
|
|
url = url + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0);
|
|
link.setText(url);
|
|
info.setText(String.format(getContext().getString(R.string.dialog_share_info), StringUtil.isEmpty(bean.getAnchorName()) ? "" : bean.getAnchorName()));
|
|
ImgLoader.display(getContext(), bean.getAnchorAvatar(), avatar);
|
|
}
|
|
|
|
private ShareBean builder(int type) {
|
|
ShareBean builder = bean.clone();
|
|
builder.setType(type);
|
|
builder.setText(String.format(getContext().getString(R.string.dialog_share_info), StringUtil.isEmpty(bean.getAnchorName()) ? "" : bean.getAnchorName()));
|
|
return builder;
|
|
}
|
|
|
|
private void copyLink() {
|
|
String url;
|
|
if (shareLink != null) {
|
|
url = shareLink;
|
|
} else {
|
|
url = ShareBean.createLiveShareLink(bean.getUid(), bean.getAnchorId(), bean.getAnchorName(), bean.getAnchorAvatar());
|
|
}
|
|
ClipboardManager cm = (ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE);
|
|
ClipData clipData = ClipData.newPlainText("text", info.getText().toString() + "\n" + url + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0));
|
|
cm.setPrimaryClip(clipData);
|
|
ToastUtil.show(getContext().getString(com.yunbao.common.R.string.copy_success));
|
|
}
|
|
|
|
public interface onShareListener {
|
|
void onShareAddCount();
|
|
}
|
|
|
|
}
|