From 875fa33625b8832599df2eb2c8d0042de62b6eba Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 27 Oct 2022 10:05:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B6=A3=E7=8E=A9=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E5=AF=B9=E8=AF=9D=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/bean/ActiveModel.java | 20 + .../com/yunbao/common/utils/StringUtil.java | 4 + .../live/dialog/LiveGameDialogFragment.java | 408 ++++++++++++++++++ .../yunbao/live/views/LiveRoomViewHolder.java | 10 +- live/src/main/res/layout/dialog_live_game.xml | 40 ++ 5 files changed, 481 insertions(+), 1 deletion(-) create mode 100644 live/src/main/java/com/yunbao/live/dialog/LiveGameDialogFragment.java create mode 100644 live/src/main/res/layout/dialog_live_game.xml diff --git a/common/src/main/java/com/yunbao/common/bean/ActiveModel.java b/common/src/main/java/com/yunbao/common/bean/ActiveModel.java index 6dc80c326..88a8c3559 100644 --- a/common/src/main/java/com/yunbao/common/bean/ActiveModel.java +++ b/common/src/main/java/com/yunbao/common/bean/ActiveModel.java @@ -28,6 +28,10 @@ public class ActiveModel extends BaseModel { private String activeSrc = ""; @SerializedName("show_type") private String showType = ""; + @SerializedName("textColor") + private String textColor; + @SerializedName("bgColor") + private String bgColor; public String getActiveId() { return activeId; @@ -74,6 +78,22 @@ public class ActiveModel extends BaseModel { return this; } + public String getTextColor() { + return textColor; + } + + public void setTextColor(String textColor) { + this.textColor = textColor; + } + + public String getBgColor() { + return bgColor; + } + + public void setBgColor(String bgColor) { + this.bgColor = bgColor; + } + /** * 获取跳转网页地址 * diff --git a/common/src/main/java/com/yunbao/common/utils/StringUtil.java b/common/src/main/java/com/yunbao/common/utils/StringUtil.java index 6074021e4..b8ac11e99 100644 --- a/common/src/main/java/com/yunbao/common/utils/StringUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/StringUtil.java @@ -146,4 +146,8 @@ public class StringUtil { } return sStringBuilder.toString(); } + + public static boolean isEmpty(String bgColor) { + return bgColor == null || "".equals(bgColor.trim()) || bgColor.trim().length() == 0; + } } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGameDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveGameDialogFragment.java new file mode 100644 index 000000000..d48199f20 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGameDialogFragment.java @@ -0,0 +1,408 @@ +package com.yunbao.live.dialog; + +import static com.yunbao.common.CommonAppContext.logger; +import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics; +import static com.yunbao.common.utils.RouteUtil.PATH_COIN; + +import android.content.Intent; +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.text.TextUtils; +import android.util.Log; +import android.view.Display; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowInsets; +import android.view.WindowManager; +import android.webkit.JavascriptInterface; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.LinearLayout; + +import com.adjust.sdk.Adjust; +import com.adjust.sdk.AdjustEvent; +import com.alibaba.android.arouter.launcher.ARouter; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.google.android.material.tabs.TabLayout; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.ActiveModel; +import com.yunbao.common.bean.JsWishBean; +import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.ZhuangBanActivity; +import com.yunbao.live.event.LiveRoomChangeEvent; +import com.yunbao.live.http.LiveHttpUtil; +import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; + +import org.greenrobot.eventbus.EventBus; + +import java.util.List; + +/** + * 趣味游戏对话框 + */ +public class LiveGameDialogFragment extends AbsDialogFragment { + + private WebView mWebView; + private String roomId; + private TabLayout tabLayout; + private int tabIndex = 0; + + public LiveGameDialogFragment() { + + } + + /** + * 设置打开第几个tab + */ + public void selectIndex(int index) { + this.tabIndex = index; + } + + @Override + protected int getLayoutId() { + return R.layout.dialog_live_game; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + + window.setWindowAnimations(R.style.bottomToTopAnim); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = DpUtil.dp2px(540); + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + mWebView = (WebView) findViewById(R.id.rlWebview); + tabLayout = (TabLayout) findViewById(R.id.tabLayout); + mWebView.addJavascriptInterface(new JsInteration(), "androidObject"); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setDomStorageEnabled(true); + String appCachePath = mContext.getCacheDir().getAbsolutePath(); + mWebView.getSettings().setAppCachePath(appCachePath); + mWebView.getSettings().setAllowFileAccess(true); + mWebView.getSettings().setAppCacheEnabled(true); + + mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口 + mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DpUtil.dp2px(500)); + mWebView.setLayoutParams(params); + mWebView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + L.e("H5-------->" + url); + view.loadUrl(url); + + return true; + } + + @Override + public void onPageFinished(WebView view, String url) { + // view.loadUrl("javascript:window.androidObject.setHeight(document.body.clientHeight,document.body.clientWidth)"); + } + }); + initData(); + } + + private void initData() { + LiveNetManager.get(mContext) + .getActiveList(new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + initTab(data); + selectTab(tabIndex); + } + + @Override + public void onError(String error) { + Log.i("debug", "onError: " + error); + ToastUtil.show(error); + dismiss(); + } + }); + } + + private void initTab(List list) { + for (ActiveModel model : list) { + TabLayout.Tab tab = tabLayout.newTab(); + tab.setText(model.getActiveName()); + tab.setTag(model); + tabLayout.addTab(tab); + } + tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { + @Override + public void onTabSelected(TabLayout.Tab tab) { + selectTab(tab.getPosition()); + } + + @Override + public void onTabUnselected(TabLayout.Tab tab) { + + } + + @Override + public void onTabReselected(TabLayout.Tab tab) { + + } + }); + } + + private void selectTab(int position) { + TabLayout.Tab tab = tabLayout.getTabAt(position); + if (tab != null) { + tab.select(); + ActiveModel model = (ActiveModel) tab.getTag(); + if (model != null) { + if (!StringUtil.isEmpty(model.getBgColor()) && !"#".equals(model.getBgColor())) { + tabLayout.setBackgroundColor(Color.parseColor(model.getBgColor())); + } + if (!StringUtil.isEmpty(model.getTextColor()) && !"#".equals(model.getTextColor())) { + tabLayout.setTabTextColors(Color.parseColor("#B3FFFFFF"), Color.parseColor(model.getTextColor())); + } + String url = model.getActiveSrc(); + if (!url.startsWith("http")) { + url = CommonAppConfig.HOST + "/" + url; + } + if (url.contains("?")) { + url += "&"; + } else { + url += "?"; + } + url += "uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + + CommonAppConfig.getInstance().getToken(); + Log.i("debug", "selectTab: " + url); + mWebView.loadUrl(url); + } else { + dismiss(); + } + } else { + dismiss(); + } + } + + public void setRoomId(String roomId) { + this.roomId = roomId; + } + + //js调用原生 + public class JsInteration { + @JavascriptInterface + public void androidGoTopUp() { + + ARouter.getInstance().build(PATH_COIN).withInt("p", 0).withString("tag", "&first_page=1").navigation(); + + dismiss(); + } + + @JavascriptInterface + public String androidMethod(String data) { + if (data != null && !data.isEmpty()) { + onTrickerySendGiftInto(new JsWishBean(data)); + } + return ""; + } + + @JavascriptInterface + public void AndroidAdjustPrank() { + AdjustEvent adjustEvent1 = new AdjustEvent("v1nekv"); + Adjust.trackEvent(adjustEvent1); + mFirebaseAnalytics.logEvent("FS_prank_interaction", null); + logger.logEvent("FB_prank_interaction", null); + } + + @JavascriptInterface + public String androidMethodClickUser(String userId, String liveId) { + if (mContext instanceof LiveRyAnchorActivity) { + return ""; + } + //点击用户头像 + if (!TextUtils.isEmpty(userId) && !TextUtils.isEmpty(liveId)) { + showUserDialog(userId, liveId); + } + return ""; + } + + @JavascriptInterface + public void onTrickerySendGift(String id) { + if (id != null) { + onTrickerySendGiftInto(new JsWishBean(id)); + } + } + + @JavascriptInterface + public void openWrap() { + dismiss(); + ((LiveAudienceActivity) mContext).openGiftWindow(); + } + + @JavascriptInterface + public void androidGoBack() { + dismiss(); + } + + + @JavascriptInterface + public void androidMethodLookToLive(String liveId) { + if (mContext instanceof LiveRyAnchorActivity) { + return; + } + mWebView.post(new Runnable() { + @Override + public void run() { + if (TextUtils.equals(roomId, liveId)) { + ToastUtil.show(R.string.current_live_room); + dismiss(); + } else { + //看直播 + gotoLive(liveId); + } + + } + }); + + } + + @JavascriptInterface + public void androidClickToNewH5PageView(String url) { + url = CommonAppConfig.HOST + url; + url += "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + + CommonAppConfig.getInstance().getToken(); + Log.i("tag", url); + Intent intent = new Intent(mContext, ZhuangBanActivity.class); + intent.putExtra("url", url); + intent.putExtra("isFull", false); + mContext.startActivity(intent); + + } + + @JavascriptInterface + public void androidSignGift(String json) { + JSONObject data = JSONObject.parseObject(json); + if (data != null) { + // 恭喜您第一天簽到成功! + ((LiveAudienceActivity) mContext).openSignWindow(data.getString("icon"), + data.getString("name"), + "恭喜您" + data.getString("desc") + "簽到成功!" + ); + } + + //((LiveAudienceActivity) mContext).openSignWindow(icon, name, desc); + } + + @JavascriptInterface + public void setHeight(String height, String width) { + if ("0".equals(height)) { + return; + } + Handler handler = new Handler(Looper.getMainLooper()); + handler.post(() -> { + ViewGroup.LayoutParams params = mWebView.getLayoutParams(); + params.height = DpUtil.dp2px(Integer.parseInt(height)) - DpUtil.dp2px(30); + mWebView.setLayoutParams(params); + mWebView.setVisibility(View.VISIBLE); + }); + } + } + + private LiveRoomCheckLivePresenter mCheckLivePresenter; + + private void gotoLive(final String live_id) { + if (!TextUtils.equals(roomId, 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); + if (mCheckLivePresenter == null) { + mCheckLivePresenter = new LiveRoomCheckLivePresenter(mContext, new LiveRoomCheckLivePresenter.ActionListener() { + @Override + public void onLiveRoomChanged(LiveBean liveBean, int liveType, int liveTypeVal, int liveSdk) { + if (liveBean == null) { + return; + } + dismiss(); + EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, liveTypeVal)); + + } + }); + } + mCheckLivePresenter.checkLive(liveBean); + } else { + RouteUtil.forwardUserHome(mContext, live_id, 0); + } + } + }); + } + + } + + /** + * 显示个人资料弹窗 + */ + private void showUserDialog(String toUid, String liveId) { + if (!TextUtils.isEmpty(liveId) && !TextUtils.isEmpty(toUid)) { + LiveUserDialogFragment fragment = new LiveUserDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, liveId); + bundle.putString(Constants.STREAM, ""); + bundle.putString(Constants.TO_UID, toUid); + fragment.setArguments(bundle); + fragment.show(((LiveActivity) mContext).getSupportFragmentManager(), "LiveUserDialogFragment"); + } + } + + public void onTrickerySendGiftInto(JsWishBean id) { + Log.i("tvs", "來了" + id); + if (id != null) { + dismiss(); + Log.i("tvs", "來了111" + id); + if (mContext instanceof LiveAudienceActivity) { + Log.i("tvs", "來了333" + id); + ((LiveAudienceActivity) mContext).openGiftWindow(id.getGiftId(), "1"); + } + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + //结束webview的加载 + mWebView.destroy(); + } + +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 535f6c89d..172ad67e3 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -123,6 +123,7 @@ import com.yunbao.live.custom.RightGradual; import com.yunbao.live.custom.TopGradual; import com.yunbao.live.dialog.LiveFaceUnityDialogFragment; import com.yunbao.live.dialog.LiveFansMedalDialogFragment; +import com.yunbao.live.dialog.LiveGameDialogFragment; import com.yunbao.live.dialog.LiveHDDialogFragment; import com.yunbao.live.dialog.LiveUserDialogFragment; import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; @@ -3004,7 +3005,14 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } else if ("新人特惠".equals(bean.getName())) { showNewPeopleInfo(); }else{ - loadingDialog.dismiss(); + LiveGameDialogFragment fragment=new LiveGameDialogFragment(); + fragment.selectIndex(0); + fragment.setRoomId(mLiveUid); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGameDialogFragment"); + if (loadingDialog != null && loadingDialog.isShowing()) { + loadingDialog.dismiss(); + loadingDialog = null; + } } } diff --git a/live/src/main/res/layout/dialog_live_game.xml b/live/src/main/res/layout/dialog_live_game.xml new file mode 100644 index 000000000..3bf39c4de --- /dev/null +++ b/live/src/main/res/layout/dialog_live_game.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + \ No newline at end of file