From 17597571761ee0d115dc8388547a487009a7656c Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 9 Jan 2024 16:37:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=A2=E6=9C=8D=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E8=BF=94=E5=9B=9E=E9=94=AE=E4=BA=A4=E7=BB=99h5?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=88=E5=90=AB=E7=B3=BB=E7=BB=9F=E6=8C=89?= =?UTF-8?q?=E9=94=AE/=E6=89=8B=E5=8A=BF=EF=BC=89=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=AE=A2=E6=9C=8D=E9=A1=B5=E9=9D=A2=E4=B8=BA=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AAWebView=20=E8=B0=83=E6=95=B4=E7=9F=AD=E5=89=A7?= =?UTF-8?q?=E4=B8=8E=E7=A4=BE=E5=8C=BA=E4=BD=BF=E7=94=A8=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E5=88=86=E5=BC=80=E5=8A=A0=E8=BD=BD=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E9=80=81=E7=A4=BC-=E5=8C=85=E8=A3=B9=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=B8=BA=E6=96=B0=E6=8E=A5=E5=8F=A3=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E7=B2=89=E4=B8=9D=E5=9B=A2=E7=A4=BC=E7=89=A9=E9=80=81=E7=A4=BC?= =?UTF-8?q?=E4=B8=BA=E6=96=B0=E6=8E=A5=E5=8F=A3=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=88=98=E4=BB=A4-=E5=85=91=E6=8D=A2-=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=9C=A8=E5=90=8D=E5=AD=97=E8=BF=87=E9=95=BF?= =?UTF-8?q?=E6=99=B4=E7=A9=BA=E4=B8=8B=E9=AB=98=E5=BA=A6=E4=B8=8D=E7=BB=9F?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/bean/LiveClassBean.java | 8 + .../com/yunbao/common/bean/LiveGiftBean.java | 20 + .../com/yunbao/common/http/LiveHttpUtil.java | 44 +- .../com/yunbao/common/utils/GoogleUtils.java | 5 +- .../utils/JavascriptInterfaceUtils.java | 6 +- .../live/adapter/LiveParcelItemAdapter.java | 1 + .../dialog/LiveFansGroupSendGiftDialog.java | 2 +- .../com/yunbao/live/dialog/LiveGiftPopup.java | 79 +-- .../CustomerServiceWebViewActivity.java | 20 +- .../yunbao/main/activity/EntryActivity.java | 3 +- .../fragment/MainHomeCommunityFragment.java | 443 +++++++++++++++++ .../MainHomeCommunityVideoFragment.java | 200 ++++++++ .../views/MainHomeCommunityViewHolder.java | 451 ++++++------------ .../res/layout/item_battlepass_exchange.xml | 7 +- .../main/res/layout/view_main_community.xml | 29 ++ .../res/layout/view_main_community_video.xml | 16 + .../main/res/layout/view_main_encourage.xml | 3 +- 17 files changed, 978 insertions(+), 359 deletions(-) create mode 100644 main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java create mode 100644 main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityVideoFragment.java create mode 100644 main/src/main/res/layout/view_main_community.xml create mode 100644 main/src/main/res/layout/view_main_community_video.xml diff --git a/common/src/main/java/com/yunbao/common/bean/LiveClassBean.java b/common/src/main/java/com/yunbao/common/bean/LiveClassBean.java index 3ff79aa6f..b83db90a2 100644 --- a/common/src/main/java/com/yunbao/common/bean/LiveClassBean.java +++ b/common/src/main/java/com/yunbao/common/bean/LiveClassBean.java @@ -20,6 +20,14 @@ public class LiveClassBean { @SerializedName("channel_show") private int channel_show; + public LiveClassBean() { + } + + public LiveClassBean(String chinese, String english) { + this.chinese = chinese; + this.english = english; + } + public String getChinese() { return chinese; } diff --git a/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java b/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java index 31c65e757..ee8b51204 100644 --- a/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java +++ b/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java @@ -3,6 +3,7 @@ package com.yunbao.common.bean; import android.view.View; import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; /** * Created by cxf on 2018/10/12. @@ -18,6 +19,8 @@ public class LiveGiftBean { // public static final int MARK_LUCK = 3; private int id; + @SerializedName("gift_id") + private int gift_id;//包裹礼物id private int type;//0 普通礼物 1是贵族 2守护 3粉丝团 5盲盒礼物 private int mark;// 0 普通 1热门 2守护 3幸运 private String name; @@ -34,6 +37,7 @@ public class LiveGiftBean { private String isweek; private String end_time; private String tag; + private boolean isPageGift; @JSONField(name = "blind_box_type") private int blind_box_type = 0; //礼物角标 @@ -71,6 +75,14 @@ public class LiveGiftBean { @JSONField(name = "blind_box_ticket_id") private int blindBoxTicketId; + public boolean isPageGift() { + return isPageGift; + } + + public void setPageGift(boolean pageGift) { + isPageGift = pageGift; + } + public int getBlindBoxTicketId() { return blindBoxTicketId; } @@ -80,6 +92,14 @@ public class LiveGiftBean { return this; } + public int getGift_id() { + return gift_id; + } + + public void setGift_id(int gift_id) { + this.gift_id = gift_id; + } + public int getBlindBoxTicket() { return blindBoxTicket; } diff --git a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java index b05f8f9e2..616a2d0f7 100644 --- a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java +++ b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java @@ -11,6 +11,7 @@ import com.yunbao.common.utils.L; import com.yunbao.common.utils.MD5Util; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.VersionUtil; +import com.yunbao.common.utils.WordUtil; import java.io.File; @@ -644,7 +645,40 @@ public class LiveHttpUtil { .params("appVersion", CommonAppConfig.getInstance().getVersion()) .execute(callback); } - + /** + * 观众给主播送礼物 - 包裹 + * + * @param isContactGift 是否为联系方式礼物 + */ + public static void sendGiftForPage(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, boolean isFansGroupGift, HttpCallback callback) { + HttpClient.getInstance().get("Live.sendPackGift", LiveHttpConsts.SEND_GIFT) + .params("liveuid", liveUid) + .params("stream", stream) + .params("giftid", giftId) + .params("isContactGift", isContactGift) + .params("giftcount", giftCount) + .params("isprank", by) + .params("fans_exclusive_pack", isFansGroupGift ? "1" : "0") + .params("appVersion", CommonAppConfig.getInstance().getVersion()) + .execute(callback); + } + /** + * 观众给主播送礼物 - 粉丝团 + * + * @param isContactGift 是否为联系方式礼物 + */ + public static void sendGiftForFansGroup(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, boolean isFansGroupGift, HttpCallback callback) { + HttpClient.getInstance().get("Live.fansExclusivePack", LiveHttpConsts.SEND_GIFT) + .params("liveuid", liveUid) + .params("stream", stream) + .params("giftid", giftId) + .params("isContactGift", isContactGift) + .params("giftcount", giftCount) + .params("isprank", by) + .params("fans_exclusive_pack", isFansGroupGift ? "1" : "0") + .params("appVersion", CommonAppConfig.getInstance().getVersion()) + .execute(callback); + } public static void sendBlindBoxTicket(String by, String liveUid, String stream, int giftId, HttpCallback callback) { HttpClient.getInstance().get("Live.sendBlindBoxTicket", LiveHttpConsts.SEND_GIFT) .params("liveuid", liveUid) @@ -1003,5 +1037,13 @@ public class LiveHttpUtil { .execute(callback); } + /** + * 获取短剧Url + */ + public static void getCoolydrama(HttpCallback callback){ + HttpClient.getInstance().get("cool.register", "Home.getFollow") + .params("lang", WordUtil.isNewZh()?"zh_CN":"en") + .execute(callback); + } } diff --git a/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java b/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java index 079fcecda..371d37027 100644 --- a/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java @@ -44,13 +44,14 @@ public class GoogleUtils { public boolean getGoogleService() { - boolean flag; + boolean flag =false; try { Class clz = mActivity.getClassLoader().loadClass("com.shayu.lib_google.utils.GoogleBillingManage"); googlePay = clz.getConstructor(Activity.class).newInstance(mActivity); flag = (boolean) googlePay.getClass().getMethod("getGoogleService").invoke(googlePay); } catch (Exception e) { - throw new RuntimeException(e); + e.printStackTrace(); + // throw new RuntimeException(e); } return flag; } 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 8918e70e0..8f013b898 100644 --- a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java @@ -607,7 +607,7 @@ public class JavascriptInterfaceUtils { public void androidClickToTaskPage() { ARouter.getInstance().build(PATH_REWARD).withString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=task&a=index" + "&uid=" + CommonAppConfig.getInstance().getUid() - + "&token=" + CommonAppConfig.getInstance().getToken() + "&tabIndex=1"+ "&isZh=" + (WordUtil.isNewZh() ? "1" : "0")).navigation(); + + "&token=" + CommonAppConfig.getInstance().getToken() + "&tabIndex=1" + "&isZh=" + (WordUtil.isNewZh() ? "1" : "0")).navigation(); } @JavascriptInterface @@ -678,4 +678,8 @@ public class JavascriptInterfaceUtils { }); } + @JavascriptInterface + public void androidGotoCustomerService(String url) { + RouteUtil.forwardCustomerService(url); + } } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveParcelItemAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveParcelItemAdapter.java index 8c1403d38..dad11e84a 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveParcelItemAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveParcelItemAdapter.java @@ -42,6 +42,7 @@ public class LiveParcelItemAdapter extends RecyclerView.Adapter { frameGiftViewHolder.giftSelect(giftJson.get(position), position, mStream, mLiveUid, new LiveParcelItemViewHolder.FrameGiftClickListener() { @Override public void onCallBack(int position, LiveGiftBean model) { + model.setPageGift(true); Bus.get().post(new LiveGiftItemEvent().setLiveGiftModel(model)); giftSelect(model); } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveFansGroupSendGiftDialog.java b/live/src/main/java/com/yunbao/live/dialog/LiveFansGroupSendGiftDialog.java index 3d830a4f3..ce4f1143e 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveFansGroupSendGiftDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveFansGroupSendGiftDialog.java @@ -55,7 +55,7 @@ public class LiveFansGroupSendGiftDialog extends AbsDialogCenterPopupWindow { recyclerView = findViewById(R.id.giftList); adapter = new LiveFansGroupSendGiftAdapter(mContext); adapter.setOnItemClickListener((bean, position) -> { - LiveHttpUtil.sendGift("0", + LiveHttpUtil.sendGiftForFansGroup("0", liveUid, mStream, bean.getId(), diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java index 644d2ef71..f4f4e0ff1 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java @@ -129,7 +129,7 @@ public class LiveGiftPopup extends AbsDialogFragment { private MarqueeTextView giftDescription, namingName; private boolean isPk; - private FragmentTransaction transaction=null; + private FragmentTransaction transaction = null; private FragmentManager fragmentManager; private Fragment contentFragment; @@ -137,8 +137,8 @@ public class LiveGiftPopup extends AbsDialogFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - if(transaction==null){ - transaction=getChildFragmentManager().beginTransaction(); + if (transaction == null) { + transaction = getChildFragmentManager().beginTransaction(); } Bus.getOn(this); initView(); @@ -243,8 +243,8 @@ public class LiveGiftPopup extends AbsDialogFragment { giftTitleAdapter.uncheck(); liveWrap.setAlpha(1.0f); liveWrap.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); - transaction=getTransaction(); - contentFragment=LiveParcelFragment.newInstance(mStream, mLiveUid); + transaction = getTransaction(); + contentFragment = LiveParcelFragment.newInstance(mStream, mLiveUid); transaction.replace(R.id.context_layout_gift, contentFragment); transaction.commitAllowingStateLoss(); isWrap = true; @@ -328,13 +328,13 @@ public class LiveGiftPopup extends AbsDialogFragment { .append(userInfo.getToken()) .append("&no_back=1") .append("&type=") - .append(blindBoxType-1) + .append(blindBoxType - 1) .append("&isZh=") .append(WordUtil.isNewZh() ? "1" : 0); Bundle bundle = new Bundle(); bundle.putString("url", htmlUrl.toString()); - // System.out.println("盲盒页面 = "+htmlUrl.toString()); + // System.out.println("盲盒页面 = "+htmlUrl.toString()); LiveHDDialogFragment fragment = new LiveHDDialogFragment(); fragment.setArguments(bundle); fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); @@ -399,7 +399,7 @@ public class LiveGiftPopup extends AbsDialogFragment { .append(userInfo.getId()) .append("&token=") .append(userInfo.getToken()) - .append("&for") .append("&isZh=") + .append("&for").append("&isZh=") .append(WordUtil.isNewZh() ? "1" : 0); Bundle bundle = new Bundle(); bundle.putString("url", htmlUrl.toString()); @@ -480,8 +480,8 @@ public class LiveGiftPopup extends AbsDialogFragment { List liveGiftBeans = JSONArray.parseArray(giftJson, LiveGiftBean.class); for (LiveGiftBean model : liveGiftBeans) { if (TextUtils.equals(model.getId() + "", mWishGiftId)) { - transaction=getTransaction(); - contentFragment=LiveGiftFragment.newInstance(giftJson, + transaction = getTransaction(); + contentFragment = LiveGiftFragment.newInstance(giftJson, liveGiftList.getJSONObject(i).getString("name"), mStream, mLiveUid, mWishGiftId); transaction.replace(R.id.context_layout_gift, contentFragment); @@ -495,11 +495,11 @@ public class LiveGiftPopup extends AbsDialogFragment { JSONObject obj2 = liveGiftList.getJSONObject(0); String giftJson = obj2.getString("giftlist"); - transaction=getTransaction(); - contentFragment= LiveGiftFragment.newInstance(giftJson, + transaction = getTransaction(); + contentFragment = LiveGiftFragment.newInstance(giftJson, liveGiftList.getJSONObject(0).getString("name"), mStream, mLiveUid, mWishGiftId); - transaction.replace(R.id.context_layout_gift,contentFragment); + transaction.replace(R.id.context_layout_gift, contentFragment); transaction.commitAllowingStateLoss(); } @@ -620,7 +620,11 @@ public class LiveGiftPopup extends AbsDialogFragment { if (isWrap && liveGiftModel.getType() == 7) { sendBlindBoxTicket(); } else { - sendGift(); + if (liveGiftModel.isPageGift()) { + sendGiftForPage(); + } else { + sendGift(); + } } } @@ -636,7 +640,7 @@ public class LiveGiftPopup extends AbsDialogFragment { LiveHttpUtil.sendBlindBoxTicket((by != null ? "1" : "0"), mLiveUid, mStream, - isWrap ? liveGiftModel.getId() : liveGiftModel.getBlindBoxTicketId(), new HttpCallback() { + isWrap ? liveGiftModel.getGift_id() : liveGiftModel.getBlindBoxTicketId(), new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { if (code == 0) { @@ -755,6 +759,16 @@ public class LiveGiftPopup extends AbsDialogFragment { } } + private void sendGiftForPage() { + if (liveGiftModel == null) return; + SendGiftCallback callback = new SendGiftCallback(liveGiftModel); + if (by != null) { + LiveHttpUtil.sendGiftForPage("1", mLiveUid, mStream, liveGiftModel.getGift_id(), mCount, 0, false, callback); + } else { + LiveHttpUtil.sendGiftForPage("0", mLiveUid, mStream, liveGiftModel.getGift_id(), mCount, 0, false, callback); + } + } + /** * 跳转到我的钻石 */ @@ -888,8 +902,8 @@ public class LiveGiftPopup extends AbsDialogFragment { giftNumberLayout.setVisibility(View.INVISIBLE); JSONObject obj2 = liveGiftList.getJSONObject(event.getmPosition()); String giftJson = obj2.getString("giftlist"); - transaction=getTransaction(); - contentFragment=LiveGiftFragment.newInstance(giftJson, event.getGiftTitle(), mStream, mLiveUid, mWishGiftId); + transaction = getTransaction(); + contentFragment = LiveGiftFragment.newInstance(giftJson, event.getGiftTitle(), mStream, mLiveUid, mWishGiftId); transaction.replace(R.id.context_layout_gift, contentFragment); transaction.commitAllowingStateLoss(); isWrap = false; @@ -1115,12 +1129,12 @@ public class LiveGiftPopup extends AbsDialogFragment { } if (!TextUtils.isEmpty(event.getDressName()) && !TextUtils.isEmpty(event.getDressMsg())) { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); - String boxBlindMsg = String.format(mContext.getString(R.string.random_availability2), WordUtil.isNewZh()?event.getGiftname():event.getGiftname_en(),WordUtil.isNewZh()? event.getDressName():event.getDress_nameen()); + String boxBlindMsg = String.format(mContext.getString(R.string.random_availability2), WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en(), WordUtil.isNewZh() ? event.getDressName() : event.getDress_nameen()); stringBuilder.append(boxBlindMsg); - int dressNameIndex = boxBlindMsg.indexOf(WordUtil.isNewZh()? event.getDressName():event.getDress_nameen()); - int dressNameSize =(WordUtil.isNewZh()? event.getDressName():event.getDress_nameen()).length(); - int giftNameIndex = boxBlindMsg.indexOf(WordUtil.isNewZh()?event.getGiftname():event.getGiftname_en()); - int giftNameSize = (WordUtil.isNewZh()?event.getGiftname():event.getGiftname_en()).length(); + int dressNameIndex = boxBlindMsg.indexOf(WordUtil.isNewZh() ? event.getDressName() : event.getDress_nameen()); + int dressNameSize = (WordUtil.isNewZh() ? event.getDressName() : event.getDress_nameen()).length(); + int giftNameIndex = boxBlindMsg.indexOf(WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en()); + int giftNameSize = (WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en()).length(); stringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(event.getDressColour())), dressNameIndex, dressNameIndex + dressNameSize, @@ -1132,11 +1146,11 @@ public class LiveGiftPopup extends AbsDialogFragment { stringBuilders.add(stringBuilder); } else { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); - String boxBlindMsg = String.format(mContext.getString(R.string.random_availability3), WordUtil.isNewZh()?event.getGiftname():event.getGiftname_en()); + String boxBlindMsg = String.format(mContext.getString(R.string.random_availability3), WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en()); stringBuilder.append(boxBlindMsg); - if (!TextUtils.isEmpty(event.getGiftname_en())){ - int giftNameIndex = boxBlindMsg.indexOf(WordUtil.isNewZh()?event.getGiftname():event.getGiftname_en()); - int giftNameSize = (WordUtil.isNewZh()?event.getGiftname():event.getGiftname_en()).length(); + if (!TextUtils.isEmpty(event.getGiftname_en())) { + int giftNameIndex = boxBlindMsg.indexOf(WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en()); + int giftNameSize = (WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en()).length(); stringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(event.getGiftColour())), giftNameIndex, giftNameIndex + giftNameSize, @@ -1446,15 +1460,16 @@ public class LiveGiftPopup extends AbsDialogFragment { } } } - private FragmentTransaction getTransaction(){ - if(contentFragment!=null && transaction!=null){ + + private FragmentTransaction getTransaction() { + if (contentFragment != null && transaction != null) { transaction.remove(contentFragment); - contentFragment=null; + contentFragment = null; } - if(fragmentManager==null){ - fragmentManager=getChildFragmentManager(); + if (fragmentManager == null) { + fragmentManager = getChildFragmentManager(); } - transaction=fragmentManager.beginTransaction(); + transaction = fragmentManager.beginTransaction(); return transaction; } diff --git a/main/src/main/java/com/yunbao/main/activity/CustomerServiceWebViewActivity.java b/main/src/main/java/com/yunbao/main/activity/CustomerServiceWebViewActivity.java index 972fe0736..8da89a678 100644 --- a/main/src/main/java/com/yunbao/main/activity/CustomerServiceWebViewActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/CustomerServiceWebViewActivity.java @@ -8,6 +8,7 @@ import android.os.Build; import android.provider.MediaStore; import android.text.TextUtils; import android.util.Log; +import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.webkit.ValueCallback; @@ -234,12 +235,25 @@ public class CustomerServiceWebViewActivity extends AbsActivity { } protected boolean canGoBack() { - return mWebView != null && mWebView.canGoBack(); + // return mWebView != null && mWebView.canGoBack(); + ToastUtil.showDebug("2调用js userBackShowPraise"); + mWebView.loadUrl("javascript:userBackShowPraise()"); + return false; + } + @Override + public void onBackPressed() { + // finish(); + ToastUtil.showDebug("调用js userBackShowPraise"); + mWebView.loadUrl("javascript:userBackShowPraise()"); } @Override - public void onBackPressed() { - finish(); + public boolean onKeyDown(int keyCode, KeyEvent event) { + if(keyCode==KeyEvent.KEYCODE_ESCAPE || keyCode==KeyEvent.KEYCODE_BACK){ + onBackPressed(); + return false; + } + return super.onKeyDown(keyCode, event); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java index 50b86d0b1..9d4bf9001 100644 --- a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java @@ -388,7 +388,8 @@ public class EntryActivity extends AppCompatActivity { public void onClick(View v) { if (!"".equals(kefuUrl)) { Constants.LoginKefu = true; - WebViewActivity.forward(EntryActivity.this, kefuUrl, false); + // WebViewActivity.forward(EntryActivity.this, kefuUrl, false); + RouteUtil.forwardCustomerService(kefuUrl); } } }); diff --git a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java new file mode 100644 index 000000000..96ed6cfd6 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java @@ -0,0 +1,443 @@ +package com.yunbao.main.fragment; + +import static android.content.Context.CLIPBOARD_SERVICE; + +import android.app.Activity; +import android.app.Dialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.provider.MediaStore; +import android.text.TextUtils; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.CookieManager; +import android.webkit.ValueCallback; +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; + +import androidx.annotation.RequiresApi; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.lxj.xpopup.XPopup; +import com.momo.mcamera.util.JsonUtil; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.HtmlConfig; +import com.yunbao.common.bean.CoolConfig; +import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.NativeCallbackModel; +import com.yunbao.common.dialog.CinemaTicketPopupWindow; +import com.yunbao.common.event.JavascriptInterfaceEvent; +import com.yunbao.common.fragment.BaseFragment; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DeviceUtils; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.JavascriptInterfacePlayLetUtils; +import com.yunbao.common.utils.JavascriptInterfaceUtils; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.LiveRoomCheckLivePresenter; +import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.live.views.LoadingView; +import com.yunbao.main.R; +import com.yunbao.main.activity.MainActivity; +import com.yunbao.main.activity.MyWalletActivity; +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; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.Arrays; +import java.util.Locale; + +public class MainHomeCommunityFragment extends BaseFragment { + private ProgressBar mProgressBar; + private WebView mWebView; + public final int CHOOSE = 100;//Android 5.0以下的 + public final int CHOOSE_ANDROID_5 = 200;//Android 5.0以上的 + public ValueCallback mValueCallback; + public ValueCallback mValueCallback2; + private MainActivity nowMainActivity; + Context mContext; + + public MainHomeCommunityFragment(MainActivity nowMainActivity) { + super(); + this.nowMainActivity=nowMainActivity; + } + + @Override + public View createView(LayoutInflater inflater, ViewGroup container) { + return inflater.inflate(R.layout.view_main_encourage, container, false); + } + + @Override + protected void initVariables(Bundle bundle) { + + } + + @Override + protected void initViews(Bundle savedInstanceState, View contentView) { + //Bus.getOn(MainHomeCommunityFragment.this); + mContext = contentView.getContext(); + nowMainActivity= (MainActivity) mContext; + String url = HtmlConfig.ENCOURAGE + "?t=" + Math.random() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"); +// String url = "https://api.coolydrama.com/?agentCode=186279"; + final LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView); + mProgressBar = (ProgressBar) findViewById(R.id.progressbar); + mWebView = new WebView(mContext); + int aa = BottomBarUtil.getNavigationBarHeightIfRoom(mContext); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + params.topMargin = DpUtil.dp2px(1); + mWebView.setLayoutParams(params); + mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); + + LoadingView loadingView = new LoadingView(mContext); + loadingView.show(); + + rootView.addView(loadingView); + + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setDomStorageEnabled(true); + CookieManager cookieManager = CookieManager.getInstance(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + cookieManager.setAcceptThirdPartyCookies(mWebView, true); + } else { + cookieManager.setAcceptCookie(true); + } + String appCachePath = mContext.getCacheDir().getAbsolutePath(); +// mWebView.getSettings().setAppCachePath(appCachePath); + mWebView.getSettings().setAllowFileAccess(true); + mWebView.getSettings().setUseWideViewPort(true); // 关键点 + mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件 + mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// 不加载缓存内容 + + mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口 + mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(nowMainActivity, mWebView), "androidObject"); + //短剧 + // mWebView.addJavascriptInterface(JavascriptInterfacePlayLetUtils.getInstance().setmContext(nowMainActivity, mWebView), "jsBridge"); + mWebView.getSettings().setSupportMultipleWindows(true); + rootView.addView(mWebView); + + mWebView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + L.e("H5-------->" + url); + if (url.startsWith(Constants.COPY_PREFIX)) { + String content = url.substring(Constants.COPY_PREFIX.length()); + if (!TextUtils.isEmpty(content)) { + copy(content); + } + } else { + view.loadUrl(url); + } + return true; + } + + @Override + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + setTitle(view.getTitle()); + if (url.contains("for")) { + mWebView.loadUrl("javascript:goAnchorTab()"); + } + + String userAgent = "shixinzhang"; + String js = "window.localStorage.setItem('userAgent','" + userAgent + "');"; + String jsUrl = "javascript:(function({ var localStorage = window.localStorage; localStorage.setItem('userAgent','" + userAgent + "') })()"; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + view.evaluateJavascript(js, null); + } else { + view.loadUrl(jsUrl); + view.reload(); + } + } + }); + mWebView.setWebChromeClient(new WebChromeClient() { + @Override + public void onProgressChanged(WebView view, int newProgress) { + if (newProgress == 100) { + loadingView.hide(); + mProgressBar.setVisibility(View.GONE); + } else { + loadingView.show(); + mProgressBar.setProgress(newProgress); + } + } + + //以下是在各个Android版本中 WebView调用文件选择器的方法 + // For Android < 3.0 + public void openFileChooser(ValueCallback valueCallback) { + openImageChooserActivity(valueCallback); + } + + // For Android >= 3.0 + public void openFileChooser(ValueCallback valueCallback, String acceptType) { + openImageChooserActivity(valueCallback); + } + + //For Android >= 4.1 + public void openFileChooser(ValueCallback valueCallback, + String acceptType, String capture) { + openImageChooserActivity(valueCallback); + } + + // For Android >= 5.0 + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + @Override + public boolean onShowFileChooser(WebView webView, + ValueCallback filePathCallback, + FileChooserParams fileChooserParams) { + mValueCallback2 = filePathCallback; + WebChromeClient.FileChooserParams mFileChooserParams; + mFileChooserParams = fileChooserParams; + String at = Arrays.toString(mFileChooserParams.getAcceptTypes()); + String type; + if (at.contains("image/")) {//图片 + type = "image/*"; + } else if (at.contains("video/")) { + type = "video/*"; + } else { + type = "*/*"; + } + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType(type); + nowMainActivity.startActivityMain2(intent, CHOOSE_ANDROID_5); + return true; + } + + }); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + } + mWebView.loadUrl(url); + findViewById(R.id.native_callback).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + } + }); + } + + protected void setTitle(String title) { + TextView titleView = (TextView) findViewById(R.id.titleView); + if (titleView != null) { + titleView.setText(title); + } + } + + private void gotoLive(final String live_id) { + LiveHttpUtil.getLiveInfo(live_id + "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); + + 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)); + } + + @Override + public void onCheckError(String contextError) { + + } + }); + } else { + + RouteUtil.forwardUserHome(mContext, String.valueOf(live_id), 0); + } + } + + }); + } + + private void openImageChooserActivity(ValueCallback valueCallback) { + mValueCallback = valueCallback; + Intent intent = new Intent(); + if (Build.VERSION.SDK_INT < 19) { + intent.setAction(Intent.ACTION_GET_CONTENT); + } else { + intent.setAction(Intent.ACTION_PICK); + intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + } + intent.setType("image/*"); + nowMainActivity.startActivityMain(Intent.createChooser(intent, mContext.getString(R.string.choose_flie)), CHOOSE); +// startActivityForResult(Intent.createChooser(intent,mContext.getString(R.string.choose_flie)), CHOOSE); + } + + + @Override + public void onDestroy() { + // Bus.getOff(MainHomeCommunityFragment.this); + if (mWebView != null) { + ViewGroup parent = (ViewGroup) mWebView.getParent(); + if (parent != null) { + parent.removeView(mWebView); + } + mWebView.reload(); + mWebView.destroy(); + } + super.onDestroy(); + } + + /** + * 复制到剪贴板 + */ + private void copy(String content) { + ClipboardManager cm = (ClipboardManager) mContext.getSystemService(CLIPBOARD_SERVICE); + ClipData clipData = ClipData.newPlainText("text", content); + cm.setPrimaryClip(clipData); + ToastUtil.show(mContext.getString(R.string.copy_success)); + } + + public void closeFinger() { + if (Build.VERSION.SDK_INT >= 21) { + mWebView.post(new Runnable() { + @Override + public void run() { + String method = "Left()";//拼接参数,就可以把数据传递给js + mWebView.evaluateJavascript(method, new ValueCallback() { + @Override + public void onReceiveValue(String value) { + Log.i("Log", "Left()js返回" + value); + } + }); + } + }); + } else { + mWebView.post(new Runnable() { + @Override + public void run() { + mWebView.setWebViewClient(new WebViewClient() { + @Override + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + mWebView.loadUrl("javascript:Left()"); + } + }); + } + }); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onJavascriptInterfaceEvent2(JavascriptInterfaceEvent event) { + if (!TextUtils.isEmpty(event.getMethod())) { + if (TextUtils.equals(event.getMethod(), "androidCommunityGift")) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + EncourageDialog fragment = new EncourageDialog(); + fragment.setId(event.getPostsId()); + if (mContext instanceof MainActivity) { + fragment.show(((MainActivity) mContext).getSupportFragmentManager(), "EncourageDialog"); + } + } + }); + } else if (TextUtils.equals(event.getMethod(), "androidPlayVideo")) { + VideoStorge.getInstance().put(Constants.VIDEO_COMMUNITY, event.getVideoBeanList()); + VideoPlayActivity.forward(mContext, event.getPosition(), Constants.VIDEO_COMMUNITY, 1); + } else if (TextUtils.equals(event.getMethod(), "androidMethodLookToLive")) { + //看直播 + gotoLive(event.getLiveId()); + } 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(); + } else if (TextUtils.equals(event.getMethod(), "postWeakBalance")) { + LiveNetManager.get(mContext). + getCoolConfig(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(CoolConfig data) { + new XPopup.Builder(mContext) + .enableDrag(false) + .autoOpenSoftInput(false) + .maxWidth(DeviceUtils.getScreenHeight((Activity) mContext) - DpUtil.dp2px(34)) + .asCustom(new CinemaTicketPopupWindow(mContext, data.setTicketCount(event.getCoolConfig().getTicketCount()), new CinemaTicketPopupWindow.CinemaTicketPopupWindowCallBack() { + @Override + public void onCallBack(String data) { + if (TextUtils.equals(data, "2")) { + DialogUitl.showSimpleDialog(mContext, mContext.getString(com.yunbao.live.R.string.live_coin_not_enough), false, + new DialogUitl.SimpleCallback2() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + mContext.startActivity(new Intent(mContext, MyWalletActivity.class).putExtra("p", 1)); + } + + @Override + public void onCancelClick() { + + } + }); + } else if (TextUtils.equals(data, "1")) { + ToastUtil.show(WordUtil.isNewZh() ? "兑换成功" : "Successful exchange"); + mWebView.post(new Runnable() { + @Override + public void run() { + + NativeCallbackModel model = new NativeCallbackModel(); + model.setUid(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + String nativeJson = new JsonUtil().toJson(model); + mWebView.evaluateJavascript("javascript:nativeCallback('" + nativeJson + "')", new ValueCallback() { + @Override + public void onReceiveValue(String value) { + } + }); + + } + }); + } + + } + })).show(); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } + } + } + + @Override + protected void loadData() { + + } + +} diff --git a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityVideoFragment.java b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityVideoFragment.java new file mode 100644 index 000000000..2730f6146 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityVideoFragment.java @@ -0,0 +1,200 @@ +package com.yunbao.main.fragment; + +import static android.content.Context.CLIPBOARD_SERVICE; + +import android.app.Activity; +import android.app.Dialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.CookieManager; +import android.webkit.ValueCallback; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import com.alibaba.fastjson.JSONObject; +import com.lxj.xpopup.XPopup; +import com.momo.mcamera.util.JsonUtil; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.CoolConfig; +import com.yunbao.common.bean.NativeCallbackModel; +import com.yunbao.common.dialog.CinemaTicketPopupWindow; +import com.yunbao.common.event.JavascriptInterfaceEvent; +import com.yunbao.common.fragment.BaseFragment; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.DeviceUtils; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.JavascriptInterfacePlayLetUtils; +import com.yunbao.common.utils.JavascriptInterfaceUtils; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.main.R; +import com.yunbao.main.activity.MyWalletActivity; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.Arrays; + +public class MainHomeCommunityVideoFragment extends BaseFragment { + WebView mWebView; + private Context mContext; + + @Override + public View createView(LayoutInflater inflater, ViewGroup container) { + return inflater.inflate(R.layout.view_main_community_video, container, false); + } + + @Override + protected void initVariables(Bundle bundle) { + + } + + @Override + protected void initViews(Bundle savedInstanceState, View contentView) { + mContext = getActivity(); + mWebView = findViewById(R.id.webView); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setDomStorageEnabled(true); + CookieManager cookieManager = CookieManager.getInstance(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + cookieManager.setAcceptThirdPartyCookies(mWebView, true); + } else { + cookieManager.setAcceptCookie(true); + } + mWebView.getSettings().setAllowFileAccess(true); + mWebView.getSettings().setUseWideViewPort(true); // 关键点 + mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件 + mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// 不加载缓存内容 + + mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口 + //短剧 + mWebView.addJavascriptInterface(JavascriptInterfacePlayLetUtils.getInstance().setmContext(getActivity(), mWebView), "jsBridge"); + mWebView.getSettings().setSupportMultipleWindows(true); + + mWebView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + L.e("H5-------->" + url); + if (url.startsWith(Constants.COPY_PREFIX)) { + String content = url.substring(Constants.COPY_PREFIX.length()); + if (!TextUtils.isEmpty(content)) { + copy(content); + } + } else { + view.loadUrl(url); + } + return true; + } + + @Override + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + if (url.contains("for")) { + mWebView.loadUrl("javascript:goAnchorTab()"); + } + + String userAgent = "shixinzhang"; + String js = "window.localStorage.setItem('userAgent','" + userAgent + "');"; + String jsUrl = "javascript:(function({ var localStorage = window.localStorage; localStorage.setItem('userAgent','" + userAgent + "') })()"; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + view.evaluateJavascript(js, null); + } else { + view.loadUrl(jsUrl); + view.reload(); + } + } + }); + } + + private void copy(String content) { + ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); + ClipData clipData = ClipData.newPlainText("text", content); + cm.setPrimaryClip(clipData); + ToastUtil.show(getActivity().getString(R.string.copy_success)); + } + + @Override + protected void loadData() { + LiveHttpUtil.getCoolydrama(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.toString(info)); + if (code == 0) { + mWebView.loadUrl(JSONObject.parseObject(info[0]).getString("url")); + } + } + }); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onJavascriptInterfaceEvent2(JavascriptInterfaceEvent event) { + if (TextUtils.equals(event.getMethod(), "postWeakBalance")) { + LiveNetManager.get(mContext). + getCoolConfig(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(CoolConfig data) { + new XPopup.Builder(mContext) + .enableDrag(false) + .autoOpenSoftInput(false) + .maxWidth(DeviceUtils.getScreenHeight((Activity) mContext) - DpUtil.dp2px(34)) + .asCustom(new CinemaTicketPopupWindow(mContext, data.setTicketCount(event.getCoolConfig().getTicketCount()), new CinemaTicketPopupWindow.CinemaTicketPopupWindowCallBack() { + @Override + public void onCallBack(String data) { + if (TextUtils.equals(data, "2")) { + DialogUitl.showSimpleDialog(mContext, mContext.getString(com.yunbao.live.R.string.live_coin_not_enough), false, + new DialogUitl.SimpleCallback2() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + mContext.startActivity(new Intent(mContext, MyWalletActivity.class).putExtra("p", 1)); + } + + @Override + public void onCancelClick() { + + } + }); + } else if (TextUtils.equals(data, "1")) { + ToastUtil.show(WordUtil.isNewZh() ? "兑换成功" : "Successful exchange"); + mWebView.post(new Runnable() { + @Override + public void run() { + + NativeCallbackModel model = new NativeCallbackModel(); + model.setUid(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + String nativeJson = new JsonUtil().toJson(model); + mWebView.evaluateJavascript("javascript:nativeCallback('" + nativeJson + "')", new ValueCallback() { + @Override + public void onReceiveValue(String value) { + } + }); + + } + }); + } + + } + })).show(); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } + } +} 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 423ab57ad..369a2edd9 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeCommunityViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeCommunityViewHolder.java @@ -8,6 +8,7 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; +import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Handler; @@ -27,7 +28,15 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager.widget.ViewPager; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -38,10 +47,12 @@ import com.yunbao.common.Constants; import com.yunbao.common.HtmlConfig; import com.yunbao.common.bean.CoolConfig; import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.LiveClassBean; import com.yunbao.common.bean.NativeCallbackModel; import com.yunbao.common.dialog.CinemaTicketPopupWindow; import com.yunbao.common.dialog.WarOrderExchangeDetailsPopupWindow; import com.yunbao.common.event.JavascriptInterfaceEvent; +import com.yunbao.common.fragment.BaseFragment; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.live.LiveNetManager; @@ -62,16 +73,33 @@ import com.yunbao.live.views.LoadingView; import com.yunbao.main.R; import com.yunbao.main.activity.MainActivity; import com.yunbao.main.activity.MyWalletActivity; +import com.yunbao.main.adapter.MainHomeLivesClassAdapter; import com.yunbao.main.dialog.EncourageDialog; +import com.yunbao.main.fragment.BattlePassRewardFragment; +import com.yunbao.main.fragment.MainHomeCommunityFragment; +import com.yunbao.main.fragment.MainHomeCommunityVideoFragment; +import com.yunbao.main.fragment.SearchResultsFragment; import com.yunbao.main.utils.BottomBarUtil; import com.yunbao.share.ui.SharePopDialog; import com.yunbao.video.activity.VideoPlayActivity; import com.yunbao.video.utils.VideoStorge; +import net.lucode.hackware.magicindicator.MagicIndicator; +import net.lucode.hackware.magicindicator.ViewPagerHelper; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Locale; /** @@ -88,359 +116,156 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl public ValueCallback mValueCallback; public ValueCallback mValueCallback2; private MainActivity nowMainActivity; + List fragments; + ViewPager2 viewPager; + private MagicIndicator mIndicator; + public MainHomeCommunityViewHolder(Context context, ViewGroup parentView, MainActivity mainActivity) { super(context, parentView); + mContext = context; nowMainActivity = mainActivity; } @Override protected int getLayoutId() { - return R.layout.view_main_encourage; + return R.layout.view_main_community; + } + + @Override + public void onCreate() { + super.onCreate(); } @Override public void init() { - Bus.getOn(this); - String url = HtmlConfig.ENCOURAGE + "?t=" + Math.random() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() - + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"); -// String url = "https://api.coolydrama.com/?agentCode=186279"; - final LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView); - mProgressBar = (ProgressBar) findViewById(R.id.progressbar); - mWebView = new WebView(mContext); - int aa = BottomBarUtil.getNavigationBarHeightIfRoom(mContext); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - params.topMargin = DpUtil.dp2px(1); - mWebView.setLayoutParams(params); - mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); - - LoadingView loadingView = new LoadingView(mContext); - loadingView.show(); - - rootView.addView(loadingView); - - mWebView.getSettings().setJavaScriptEnabled(true); - mWebView.getSettings().setDomStorageEnabled(true); - CookieManager cookieManager = CookieManager.getInstance(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - cookieManager.setAcceptThirdPartyCookies(mWebView, true); - } else { - cookieManager.setAcceptCookie(true); - } - String appCachePath = mContext.getCacheDir().getAbsolutePath(); -// mWebView.getSettings().setAppCachePath(appCachePath); - mWebView.getSettings().setAllowFileAccess(true); - mWebView.getSettings().setUseWideViewPort(true); // 关键点 - mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件 - mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// 不加载缓存内容 - - mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口 - mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(nowMainActivity, mWebView), "androidObject"); - //短剧 - mWebView.addJavascriptInterface(JavascriptInterfacePlayLetUtils.getInstance().setmContext(nowMainActivity, mWebView), "jsBridge"); - mWebView.getSettings().setSupportMultipleWindows(true); - rootView.addView(mWebView); - - mWebView.setWebViewClient(new WebViewClient() { + mIndicator = (MagicIndicator) findViewById(R.id.indicator); + viewPager = (ViewPager2) findViewById(R.id.community_viewpager); + fragments = new ArrayList<>(); + fragments.add(new MainHomeCommunityFragment(nowMainActivity)); + fragments.add(new MainHomeCommunityVideoFragment()); + viewPager.setAdapter(new FragmentStateAdapter(((AppCompatActivity) mContext)) { + @NonNull @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - L.e("H5-------->" + url); - if (url.startsWith(Constants.COPY_PREFIX)) { - String content = url.substring(Constants.COPY_PREFIX.length()); - if (!TextUtils.isEmpty(content)) { - copy(content); + public Fragment createFragment(int position) { + return fragments.get(position); + } + + @Override + public int getItemCount() { + return fragments.size(); + } + + @Override + public long getItemId(int position) { + return super.getItemId(position); + } + }); + viewPager.setUserInputEnabled(false); + initTab(); + } + + @Override + public void onStart() { + super.onStart(); + + } + + String[] titles; + + private void initTab() { + titles = new String[]{"社區", "短劇"}; + if (!WordUtil.isNewZh()) { + titles = new String[]{"Community", "Theater"}; + } + CommonNavigator commonNavigator = new CommonNavigator(mContext); + commonNavigator.setAdjustMode(true); + commonNavigator.setAdapter(new CommonNavigatorAdapter() { + @Override + public int getCount() { + return titles.length; + } + + @Override + public IPagerTitleView getTitleView(Context context, int index) { + SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context); + simplePagerTitleView.setNormalColor(Color.parseColor("#B1B1B1")); + simplePagerTitleView.setSelectedColor(Color.parseColor("#FFC621")); + simplePagerTitleView.setText(titles[index]); + simplePagerTitleView.setTextSize(18); + simplePagerTitleView.getPaint().setFakeBoldText(true); + simplePagerTitleView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (viewPager != null) { + viewPager.setCurrentItem(index); + } } - } else { - view.loadUrl(url); - } - return true; + }); + return simplePagerTitleView; } @Override - public void onPageFinished(WebView view, String url) { - super.onPageFinished(view, url); - setTitle(view.getTitle()); - if (url.contains("for")) { - mWebView.loadUrl("javascript:goAnchorTab()"); - } - - String userAgent = "shixinzhang"; - String js = "window.localStorage.setItem('userAgent','" + userAgent + "');"; - String jsUrl = "javascript:(function({ var localStorage = window.localStorage; localStorage.setItem('userAgent','" + userAgent + "') })()"; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - view.evaluateJavascript(js, null); - } else { - view.loadUrl(jsUrl); - view.reload(); - } + public IPagerIndicator getIndicator(Context context) { + LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context); + linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT); + linePagerIndicator.setXOffset(DpUtil.dp2px(5)); + linePagerIndicator.setRoundRadius(DpUtil.dp2px(2)); + linePagerIndicator.setColors(Color.parseColor("#FFC621")); + return linePagerIndicator; } }); - mWebView.setWebChromeClient(new WebChromeClient() { - @Override - public void onProgressChanged(WebView view, int newProgress) { - if (newProgress == 100) { - loadingView.hide(); - mProgressBar.setVisibility(View.GONE); - } else { - loadingView.show(); - mProgressBar.setProgress(newProgress); - } - } - - //以下是在各个Android版本中 WebView调用文件选择器的方法 - // For Android < 3.0 - public void openFileChooser(ValueCallback valueCallback) { - openImageChooserActivity(valueCallback); - } - - // For Android >= 3.0 - public void openFileChooser(ValueCallback valueCallback, String acceptType) { - openImageChooserActivity(valueCallback); - } - - //For Android >= 4.1 - public void openFileChooser(ValueCallback valueCallback, - String acceptType, String capture) { - openImageChooserActivity(valueCallback); - } - - // For Android >= 5.0 - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - @Override - public boolean onShowFileChooser(WebView webView, - ValueCallback filePathCallback, - FileChooserParams fileChooserParams) { - mValueCallback2 = filePathCallback; - WebChromeClient.FileChooserParams mFileChooserParams; - mFileChooserParams = fileChooserParams; - String at = Arrays.toString(mFileChooserParams.getAcceptTypes()); - String type; - if (at.contains("image/")) {//图片 - type = "image/*"; - } else if (at.contains("video/")) { - type = "video/*"; - } else { - type = "*/*"; - } - Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType(type); - nowMainActivity.startActivityMain2(intent, CHOOSE_ANDROID_5); - return true; - } - - }); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); - } - mWebView.loadUrl(url); - findViewById(R.id.native_callback).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - - } - }); - }//战令等级 + mIndicator.setNavigator(commonNavigator); + bind(mIndicator, viewPager); + mIndicator.onPageSelected(0); + viewPager.setCurrentItem(0); + } public void loadNewUrl() { } - protected void setTitle(String title) { - TextView titleView = (TextView) findViewById(R.id.titleView); - if (titleView != null) { - titleView.setText(title); - } - } - @Override public void onItemClick(LiveBean bean, int position) { } - - private void gotoLive(final String live_id) { - LiveHttpUtil.getLiveInfo(live_id + "", new HttpCallback() { + public static void bind(final MagicIndicator magicIndicator, ViewPager2 viewPager) { + viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); - - 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)); - } - - @Override - public void onCheckError(String contextError) { - - } - }); - } else { - - RouteUtil.forwardUserHome(mContext, String.valueOf(live_id), 0); - } + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + magicIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels); } + @Override + public void onPageSelected(int position) { + super.onPageSelected(position); + magicIndicator.onPageSelected(position); + } + + @Override + public void onPageScrollStateChanged(int state) { + super.onPageScrollStateChanged(state); + magicIndicator.onPageScrollStateChanged(state); + } }); - - } - - - private void openImageChooserActivity(ValueCallback valueCallback) { - mValueCallback = valueCallback; - Intent intent = new Intent(); - if (Build.VERSION.SDK_INT < 19) { - intent.setAction(Intent.ACTION_GET_CONTENT); - } else { - intent.setAction(Intent.ACTION_PICK); - intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); - } - intent.setType("image/*"); - nowMainActivity.startActivityMain(Intent.createChooser(intent, mContext.getString(R.string.choose_flie)), CHOOSE); -// startActivityForResult(Intent.createChooser(intent,mContext.getString(R.string.choose_flie)), CHOOSE); - } - - - @Override - public void onDestroy() { - Bus.getOff(this); - if (mWebView != null) { - ViewGroup parent = (ViewGroup) mWebView.getParent(); - if (parent != null) { - parent.removeView(mWebView); - } - mWebView.reload(); - mWebView.destroy(); - } - super.onDestroy(); - } - - /** - * 复制到剪贴板 - */ - private void copy(String content) { - ClipboardManager cm = (ClipboardManager) mContext.getSystemService(CLIPBOARD_SERVICE); - ClipData clipData = ClipData.newPlainText("text", content); - cm.setPrimaryClip(clipData); - ToastUtil.show(mContext.getString(R.string.copy_success)); } public void closeFinger() { - if (Build.VERSION.SDK_INT >= 21) { - mWebView.post(new Runnable() { - @Override - public void run() { - String method = "Left()";//拼接参数,就可以把数据传递给js - mWebView.evaluateJavascript(method, new ValueCallback() { - @Override - public void onReceiveValue(String value) { - Log.i("Log", "Left()js返回" + value); - } - }); - } - }); - } else { - mWebView.post(new Runnable() { - @Override - public void run() { - mWebView.setWebViewClient(new WebViewClient() { - @Override - public void onPageFinished(WebView view, String url) { - super.onPageFinished(view, url); - mWebView.loadUrl("javascript:Left()"); - } - }); - } - }); + BaseFragment fragment = fragments.get(viewPager.getCurrentItem()); + if (fragment instanceof MainHomeCommunityFragment) { + ((MainHomeCommunityFragment) fragment).closeFinger(); } } - @Subscribe(threadMode = ThreadMode.MAIN) - public void onJavascriptInterfaceEvent(JavascriptInterfaceEvent event) { - if (!TextUtils.isEmpty(event.getMethod())) { - if (TextUtils.equals(event.getMethod(), "androidCommunityGift")) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - EncourageDialog fragment = new EncourageDialog(); - fragment.setId(event.getPostsId()); - if (mContext instanceof MainActivity) { - fragment.show(((MainActivity) mContext).getSupportFragmentManager(), "EncourageDialog"); - } - } - }); - } else if (TextUtils.equals(event.getMethod(), "androidPlayVideo")) { - VideoStorge.getInstance().put(Constants.VIDEO_COMMUNITY, event.getVideoBeanList()); - VideoPlayActivity.forward(mContext, event.getPosition(), Constants.VIDEO_COMMUNITY, 1); - } else if (TextUtils.equals(event.getMethod(), "androidMethodLookToLive")) { - //看直播 - gotoLive(event.getLiveId()); - } 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(); - } else if (TextUtils.equals(event.getMethod(), "postWeakBalance")) { - LiveNetManager.get(mContext). - getCoolConfig(new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(CoolConfig data) { - new XPopup.Builder(mContext) - .enableDrag(false) - .autoOpenSoftInput(false) - .maxWidth(DeviceUtils.getScreenHeight((Activity) mContext) - DpUtil.dp2px(34)) - .asCustom(new CinemaTicketPopupWindow(mContext, data.setTicketCount(event.getCoolConfig().getTicketCount()), new CinemaTicketPopupWindow.CinemaTicketPopupWindowCallBack() { - @Override - public void onCallBack(String data) { - if (TextUtils.equals(data, "2")) { - DialogUitl.showSimpleDialog(mContext, mContext.getString(com.yunbao.live.R.string.live_coin_not_enough), false, - new DialogUitl.SimpleCallback2() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - mContext.startActivity(new Intent(mContext, MyWalletActivity.class).putExtra("p", 1)); - } - - @Override - public void onCancelClick() { - - } - }); - } else if (TextUtils.equals(data, "1")) { - ToastUtil.show(WordUtil.isNewZh() ? "兑换成功" : "Successful exchange"); - mWebView.post(new Runnable() { - @Override - public void run() { - - NativeCallbackModel model = new NativeCallbackModel(); - model.setUid(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - String nativeJson = new JsonUtil().toJson(model); - mWebView.evaluateJavascript("javascript:nativeCallback('" + nativeJson + "')", new ValueCallback() { - @Override - public void onReceiveValue(String value) { - } - }); - - } - }); - } - - } - })).show(); - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); + public void setValueCallback2(Uri[] results) { + BaseFragment fragment = fragments.get(viewPager.getCurrentItem()); + if (fragment instanceof MainHomeCommunityFragment) { + if (((MainHomeCommunityFragment) fragment).mValueCallback2 == null) { + return; } + ((MainHomeCommunityFragment) fragment).mValueCallback2.onReceiveValue(results); + ((MainHomeCommunityFragment) fragment).mValueCallback2 = null; } } diff --git a/main/src/main/res/layout/item_battlepass_exchange.xml b/main/src/main/res/layout/item_battlepass_exchange.xml index 4ec3897ce..86a44aed5 100644 --- a/main/src/main/res/layout/item_battlepass_exchange.xml +++ b/main/src/main/res/layout/item_battlepass_exchange.xml @@ -5,7 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="100dp" android:gravity="center" - android:layout_height="wrap_content" + android:layout_height="200dp" android:layout_marginBottom="10dp" android:layout_marginTop="10dp"> @@ -64,9 +64,10 @@ + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/view_main_community_video.xml b/main/src/main/res/layout/view_main_community_video.xml new file mode 100644 index 000000000..4c0f7fb70 --- /dev/null +++ b/main/src/main/res/layout/view_main_community_video.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/view_main_encourage.xml b/main/src/main/res/layout/view_main_encourage.xml index 554226137..8ba2a27ce 100644 --- a/main/src/main/res/layout/view_main_encourage.xml +++ b/main/src/main/res/layout/view_main_encourage.xml @@ -1,8 +1,7 @@ + android:layout_height="match_parent">