From ef757a8adc78cff8a0271d3a96436be3228bc068 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 31 Mar 2023 15:09:18 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=88=86=E4=BA=AB=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E5=88=86=E4=BA=AB=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../share/adapters/ShareAppAdapter.java | 4 -- .../com/yunbao/share/ui/SharePopDialog.java | 39 ++++++++++++++++--- Share/src/main/res/values/strings.xml | 2 +- .../utils/JavascriptInterfaceUtils.java | 9 +++++ .../views/MainHomeCommunityViewHolder.java | 18 ++++++--- 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java b/Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java index db5772505..5c106481f 100644 --- a/Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java +++ b/Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java @@ -90,10 +90,6 @@ public class ShareAppAdapter extends RecyclerView.Adapter { switch (bean.getType()) { case ShareBuilder.APP_FACEBOOK: diff --git a/Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java b/Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java index 85a1735f9..1b38891a6 100644 --- a/Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java +++ b/Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java @@ -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)); } diff --git a/Share/src/main/res/values/strings.xml b/Share/src/main/res/values/strings.xml index 6fb1fdfb3..7a9acba8a 100644 --- a/Share/src/main/res/values/strings.xml +++ b/Share/src/main/res/values/strings.xml @@ -3,7 +3,7 @@ aq0eV4R1pqMK_AAeKRWnjPr7ErGMGgTPGgZJdm73WeRY-Kluws 分享 - 快來 PDLIVE觀看主播名稱直播,認識更多有趣的朋友吧! + 快來 PDLIVE觀看%s直播,認識更多有趣的朋友吧! Facebook Line Twitter diff --git a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java index cc1d35230..4cefb1f0f 100644 --- a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java @@ -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())); + } } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeCommunityViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeCommunityViewHolder.java index 8d3703f9e..1bb04c52b 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeCommunityViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeCommunityViewHolder.java @@ -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(); } } }