新增趣玩游戏对话框

This commit is contained in:
zlzw 2022-10-27 10:05:32 +08:00
parent 9c629937da
commit 875fa33625
5 changed files with 481 additions and 1 deletions

View File

@ -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;
}
/**
* 获取跳转网页地址
*

View File

@ -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;
}
}

View File

@ -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<List<ActiveModel>>() {
@Override
public void onSuccess(List<ActiveModel> data) {
initTab(data);
selectTab(tabIndex);
}
@Override
public void onError(String error) {
Log.i("debug", "onError: " + error);
ToastUtil.show(error);
dismiss();
}
});
}
private void initTab(List<ActiveModel> 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();
}
}

View File

@ -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{
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;
}
}
}

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:cardCornerRadius="12dp"
app:cardElevation="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabMaxWidth="100dp"
app:tabMode="scrollable"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</com.google.android.material.tabs.TabLayout>
<WebView
android:id="@+id/rlWebview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabLayout" />
</LinearLayout>
</androidx.cardview.widget.CardView>