148 lines
4.8 KiB
Java
148 lines
4.8 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.newpdlive.sy.R;
|
|
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.ShareBuilder;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class SharePopDialog extends AbsDialogPopupWindow {
|
|
private ShareAppAdapter adapter;
|
|
private RecyclerView list;
|
|
private RoundedImageView avatar;
|
|
private TextView info;
|
|
private TextView link;
|
|
private List<ShareBuilder> data;
|
|
|
|
private String uid;
|
|
private String anchorId;
|
|
private String anchorName;
|
|
private String anchorAvatar;
|
|
private String shareLink;
|
|
|
|
public SharePopDialog(@NonNull Context context) {
|
|
super(context);
|
|
}
|
|
|
|
public SharePopDialog setUid(String uid) {
|
|
this.uid = uid;
|
|
return this;
|
|
}
|
|
|
|
public SharePopDialog setAnchorId(String anchorId) {
|
|
this.anchorId = anchorId;
|
|
return this;
|
|
}
|
|
|
|
public SharePopDialog setAnchorName(String anchorName) {
|
|
this.anchorName = anchorName;
|
|
return this;
|
|
}
|
|
|
|
public SharePopDialog setAnchorAvatar(String anchorAvatar) {
|
|
this.anchorAvatar = anchorAvatar;
|
|
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());
|
|
list.setLayoutManager(new GridLayoutManager(getContext(), 3));
|
|
list.setAdapter(adapter);
|
|
initData();
|
|
}
|
|
|
|
private void initData() {
|
|
data = new ArrayList<>();
|
|
data.add(builder(ShareBuilder.APP_FACEBOOK));
|
|
data.add(builder(ShareBuilder.APP_LINE));
|
|
data.add(builder(ShareBuilder.APP_TWITTER));
|
|
data.add(builder(ShareBuilder.APP_WHATSAPP));
|
|
data.add(builder(ShareBuilder.APP_MESSENGER));
|
|
//data.add(builder(ShareBuilder.APP_INSTAGRAM));
|
|
adapter.setList(data);
|
|
String url;
|
|
if (shareLink == null) {
|
|
url = ShareBuilder.createLiveShareLink(uid, anchorId, anchorName, anchorAvatar).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(anchorName) ? "" : anchorName));
|
|
ImgLoader.display(getContext(), anchorAvatar, avatar);
|
|
}
|
|
|
|
private ShareBuilder builder(int type) {
|
|
ShareBuilder builder = ShareBuilder.builder(type);
|
|
builder.setText(String.format(getContext().getString(R.string.dialog_share_info), StringUtil.isEmpty(anchorName) ? "" : anchorName));
|
|
builder.setUid(uid);
|
|
builder.setAnchorId(anchorId);
|
|
builder.setAnchorName(anchorName);
|
|
builder.setAnchorAvatar(anchorAvatar);
|
|
if (shareLink != null) {
|
|
builder.setLink(shareLink);
|
|
}
|
|
return builder;
|
|
}
|
|
|
|
private void copyLink() {
|
|
String url;
|
|
if (shareLink != null) {
|
|
url = shareLink;
|
|
} else {
|
|
url = ShareBuilder.createLiveShareLink(uid, anchorId, anchorName, anchorAvatar);
|
|
}
|
|
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));
|
|
}
|
|
}
|