update 分享支持社区分享按钮

This commit is contained in:
zlzw 2023-03-31 15:09:18 +08:00
parent 26cb58463a
commit ef757a8adc
5 changed files with 56 additions and 16 deletions

View File

@ -90,10 +90,6 @@ public class ShareAppAdapter extends RecyclerView.Adapter<ShareAppAdapter.AppVie
public void setData(ShareBuilder bean, @DrawableRes int iconId, @StringRes int appName) {
icon.setImageResource(iconId);
title.setText(appName);
String filename = "/ztest/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
File media = new File(mediaPath);
bean.setFile(media);
itemView.setOnClickListener(v -> {
switch (bean.getType()) {
case ShareBuilder.APP_FACEBOOK:

View File

@ -16,6 +16,7 @@ import com.makeramen.roundedimageview.RoundedImageView;
import com.pdlive.shayu.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.bean.ShareBuilder;
@ -36,6 +37,7 @@ public class SharePopDialog extends AbsDialogPopupWindow {
private String anchorId;
private String anchorName;
private String anchorAvatar;
private String shareLink;
public SharePopDialog(@NonNull Context context) {
super(context);
@ -61,6 +63,11 @@ public class SharePopDialog extends AbsDialogPopupWindow {
return this;
}
public SharePopDialog setShareLink(String link) {
this.shareLink = link;
return this;
}
@Override
public void buildDialog(XPopup.Builder builder) {
@ -96,23 +103,43 @@ public class SharePopDialog extends AbsDialogPopupWindow {
data.add(builder(ShareBuilder.APP_MESSENGER));
//data.add(builder(ShareBuilder.APP_INSTAGRAM));
adapter.setList(data);
String url=ShareBuilder.createLiveShareLink(uid,anchorId,anchorName,anchorAvatar).substring(0,40)+"...";
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;
}
}
link.setText(url);
ImgLoader.display(getContext(),anchorAvatar,avatar);
info.setText(String.format(WordUtil.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(WordUtil.getString(R.string.dialog_share_info));
private ShareBuilder builder(int type) {
ShareBuilder builder = ShareBuilder.builder(type);
builder.setText(String.format(WordUtil.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", ShareBuilder.createLiveShareLink(uid,anchorId,anchorName,anchorAvatar));
ClipData clipData = ClipData.newPlainText("text", url);
cm.setPrimaryClip(clipData);
ToastUtil.show(WordUtil.getString(com.yunbao.common.R.string.copy_success));
}

View File

@ -3,7 +3,7 @@
<string name="com.twitter.sdk.android.CONSUMER_SECRET" translatable="false">aq0eV4R1pqMK_AAeKRWnjPr7ErGMGgTPGgZJdm73WeRY-Kluws</string>
<string name="dialog_share_title">分享</string>
<string name="dialog_share_info">快來 PDLIVE觀看主播名稱直播,認識更多有趣的朋友吧!</string>
<string name="dialog_share_info">快來 PDLIVE觀看%s直播,認識更多有趣的朋友吧!</string>
<string name="dialog_share_app_facebook" translatable="false">Facebook</string>
<string name="dialog_share_app_line" translatable="false">Line</string>
<string name="dialog_share_app_twitter" translatable="false">Twitter</string>

View File

@ -497,4 +497,13 @@ public class JavascriptInterfaceUtils {
mWebView.setVisibility(View.VISIBLE);
});
}
@JavascriptInterface
public void androidCommunityShare(String avatar,String link){
JSONObject json=new JSONObject();
json.put("avatar",avatar);
json.put("link",link);
Bus.get().post(new JavascriptInterfaceEvent()
.setMethod("androidCommunityShare")
.setData(json.toJSONString()));
}
}

View File

@ -28,6 +28,7 @@ import android.widget.TextView;
import androidx.annotation.RequiresApi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
import com.yunbao.common.HtmlConfig;
@ -50,6 +51,7 @@ import com.yunbao.main.R;
import com.yunbao.main.activity.MainActivity;
import com.yunbao.main.dialog.EncourageDialog;
import com.yunbao.main.utils.BottomBarUtil;
import com.yunbao.share.ui.SharePopDialog;
import com.yunbao.video.activity.VideoPlayActivity;
import com.yunbao.video.utils.VideoStorge;
@ -238,7 +240,7 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl
new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() {
@Override
public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) {
RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal));
RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal));
}
@Override
@ -248,9 +250,9 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl
});
} else {
RouteUtil.forwardUserHome(mContext, String.valueOf(live_id), 0);
}
RouteUtil.forwardUserHome(mContext, String.valueOf(live_id), 0);
}
}
});
@ -345,10 +347,16 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl
} else if (TextUtils.equals(event.getMethod(), "androidMethodLookToLive")) {
//看直播
gotoLive(event.getLiveId());
}else if (TextUtils.equals(event.getMethod(), "isCloseNavigation")){
if(nowMainActivity!=null) {
} else if (TextUtils.equals(event.getMethod(), "isCloseNavigation")) {
if (nowMainActivity != null) {
nowMainActivity.isClose(event.getIsClose());
}
} else if (TextUtils.equals(event.getMethod(), "androidCommunityShare")) {
JSONObject json = JSONObject.parseObject(event.getData());
new SharePopDialog(mContext)
.setShareLink(CommonAppConfig.HOST+json.getString("link"))
.setAnchorAvatar(json.getString("avatar"))
.showDialog();
}
}
}