feat:初步完成百顺游戏接入

This commit is contained in:
max
2024-04-30 19:45:48 +08:00
parent 5e634b1fda
commit 01f3418f43
29 changed files with 799 additions and 204 deletions

View File

@@ -668,7 +668,7 @@
android:theme="@style/dialog_web_view_activity"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".ui.webview.room_game.RoomGameWebDialogActivity"
android:name=".ui.webview.baishun.BaiShunGameWebActivity"
android:theme="@style/dialog_web_view_activity"
android:windowSoftInputMode="adjustPan" />
<activity

View File

@@ -47,4 +47,8 @@ public abstract class BottomViewListenerWrapper {
}
public void onRoomGameplayClick(){
}
}

View File

@@ -0,0 +1,17 @@
package com.chwl.app.avroom.adapter
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chwl.app.R
import com.chwl.app.ui.utils.load
import com.chwl.core.room.bean.RoomIcon
class RoomGameplayAdapter :
BaseQuickAdapter<RoomIcon, BaseViewHolder>(R.layout.room_gameplay_item2) {
override fun convert(helper: BaseViewHolder, item: RoomIcon?) {
helper.setText(R.id.tv_name, item?.name)
val iconView = helper.getView<ImageView>(R.id.iv_icon)
iconView.load(item?.icon)
}
}

View File

@@ -0,0 +1,192 @@
package com.chwl.app.avroom.dialog
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.chwl.app.R
import com.chwl.app.avroom.adapter.RoomGameplayAdapter
import com.chwl.app.databinding.RoomGameplayDialogBinding
import com.chwl.app.treasure_box.widget.GoldBoxHelper
import com.chwl.app.ui.webview.CommonWebViewActivity
import com.chwl.app.ui.webview.baishun.BaiShunGameWebActivity
import com.chwl.app.ui.webview.room_banner.RoomWebDialogActivity
import com.chwl.app.utils.CommonJumpHelper
import com.chwl.core.room.bean.RoomIcon
import com.chwl.core.room.core.RoomDataService
import com.chwl.core.room.game.bean.BaiShunGameConfig
import com.chwl.core.room.model.AvRoomModel
import com.chwl.core.support.room.RoomContext
import com.chwl.library.utils.SingleToastUtil
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.gson.Gson
import io.reactivex.disposables.CompositeDisposable
class RoomGameplayDialog :
BottomSheetDialogFragment() {
private var binding: RoomGameplayDialogBinding? = null
private var compositeDisposable: CompositeDisposable? = null
private val adapter = RoomGameplayAdapter()
override fun getTheme(): Int {
return R.style.ErbanBottomSheetDialogDimFalse
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = RoomGameplayDialogBinding.inflate(LayoutInflater.from(context))
return binding?.root
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
this.setCanceledOnTouchOutside(true)
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initView()
switchStatus(0)
requestData()
}
private fun initView() {
adapter.setOnItemClickListener { _, view, position ->
val item = adapter.getItem(position) as RoomIcon
jump(item)
}
binding?.recyclerView?.adapter = adapter
}
private fun requestData() {
val dataService =
RoomContext.get()?.findAbility<RoomDataService>(RoomDataService::class.java.simpleName)
val cacheKey = "gameplay_list#${parentFragment.hashCode()}"
val list = dataService?.getData(cacheKey) as? List<RoomIcon>
if (!list.isNullOrEmpty()) {
loadData(list)
return
}
val disposable = AvRoomModel.get().roomGamePlayList
.doOnError {
SingleToastUtil.showToast(it.message)
switchStatus(-2)
}
.subscribe { it: List<RoomIcon> ->
dataService?.putData(cacheKey, it)
loadData(it)
}
getCompositeDisposable().add(disposable)
}
private fun loadData(list: List<RoomIcon>?) {
if (list.isNullOrEmpty()) {
switchStatus(-1)
} else {
adapter.setNewData(list)
switchStatus(1)
}
}
private fun switchStatus(status: Int) {
when (status) {
// loading
0 -> {
binding?.recyclerView?.isVisible = false
binding?.layoutStatus?.isVisible = true
binding?.groupStatusLoading?.isVisible = true
binding?.groupStatusText?.isVisible = false
}
// 有数据
1 -> {
binding?.recyclerView?.isVisible = true
binding?.layoutStatus?.isVisible = false
}
// 空数据
-1 -> {
binding?.recyclerView?.isVisible = false
binding?.layoutStatus?.isVisible = true
binding?.groupStatusLoading?.isVisible = false
binding?.groupStatusText?.isVisible = true
binding?.tvStatus?.setText(R.string.avroom_presenter_roomnewbiehellowwordpresenter_01)
}
// 失败
else -> {
binding?.recyclerView?.isVisible = false
binding?.layoutStatus?.isVisible = true
binding?.groupStatusLoading?.isVisible = false
binding?.groupStatusText?.isVisible = true
binding?.tvStatus?.setText(R.string.request_failed_again_later)
}
}
}
private fun jump(data: RoomIcon) {
dismissAllowingStateLoss()
if (data.isFindLove()) {
GoldBoxHelper.handleBoxClick(context)
} else if (data.isBaiShunGame()) {
jumpBaiShunGame(data)
} else {
val url = data.skipContent
if (data.skipType == 3 && !url.isNullOrEmpty()) {
if (data.showType == 2) {
RoomWebDialogActivity.start(requireContext(), url, false)
} else {
CommonWebViewActivity.start(context, url)
}
} else {
CommonJumpHelper.bannerJump(context, data)
}
}
}
override fun onDestroy() {
super.onDestroy()
onUnbindContext()
}
private fun getCompositeDisposable(): CompositeDisposable {
var disposable = compositeDisposable
if (disposable == null) {
disposable = CompositeDisposable()
compositeDisposable = disposable
}
return disposable
}
private fun onUnbindContext() {
compositeDisposable?.dispose()
compositeDisposable = null
}
private fun jumpBaiShunGame(data: RoomIcon) {
try {
val url = data.skipContent
val ruleValue = Gson().fromJson<RoomIcon.RuleValueBean>(
data.ruleValue,
RoomIcon.RuleValueBean::class.java
)
val config = Gson().fromJson<BaiShunGameConfig>(
ruleValue.RESERVE,
BaiShunGameConfig::class.java
)
if (config != null && url != null) {
config.reloadDynamicParams()
BaiShunGameWebActivity.start(requireContext(), url, config)
} else {
SingleToastUtil.showToast(R.string.manager_trtc_trtcengineadapter_042)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}

View File

@@ -42,6 +42,7 @@ import com.chwl.app.avroom.adapter.OnMicroItemClickListener
import com.chwl.app.avroom.adapter.RoomMessageIndicatorAdapter
import com.chwl.app.avroom.dialog.AttentionHintDialog
import com.chwl.app.avroom.dialog.DatingVipRuleDialog
import com.chwl.app.avroom.dialog.RoomGameplayDialog
import com.chwl.app.avroom.dialog.RoomOperationDialog
import com.chwl.app.avroom.presenter.BaseRoomPresenter
import com.chwl.app.avroom.public_chat.PublicChatRoomMessageWidget
@@ -1418,6 +1419,10 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
override fun onRoomMessageClick() {
RoomMsgActivity.start(mContext)
}
override fun onRoomGameplayClick() {
RoomGameplayDialog().show(childFragmentManager, "ROOM_GAME_PLAY")
}
}
/**

View File

@@ -70,7 +70,6 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.lang.reflect.Field;
import java.util.Objects;
import io.reactivex.SingleObserver;
import io.reactivex.disposables.Disposable;
@@ -258,22 +257,23 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
GameInfo gameInfo = gameAdapter.getItem(position);
if (gameInfo != null) {
int type;
long mgId = 0;
if (Objects.equals(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_05), gameInfo.getName())) {
type = RoomInfo.ROOMTYPE_HOME_PARTY;
} else {
type = RoomInfo.ROOMTYPE_GAME;
mgId = JavaUtil.str2long(gameInfo.getMgId());
}
gameMainBinding.rvGame.setVisibility(View.GONE);
gameMainBinding.ivChangeGameArrow.setImageResource(R.drawable.ic_room_arrow_type_below);
OpenRoomHelper.updateRoomInfo(
getBaseActivity(),
AvRoomDataManager.get().mCurrentRoomInfo,
type,
mgId,
false);
if (gameInfo.isStandardRoom()) {
OpenRoomHelper.updateRoomInfo(
getBaseActivity(),
AvRoomDataManager.get().mCurrentRoomInfo,
RoomInfo.ROOMTYPE_HOME_PARTY,
0,
false);
} else {
OpenRoomHelper.updateRoomInfo(
getBaseActivity(),
AvRoomDataManager.get().mCurrentRoomInfo,
RoomInfo.ROOMTYPE_GAME,
JavaUtil.str2long(gameInfo.getMgId()),
false);
}
}
});
}
@@ -486,6 +486,7 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
}
}
GameInfo gameInfo = new GameInfo();
gameInfo.asStandardRoom();
gameInfo.setName(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_09));
gameInfos.add(gameInfo);
}

View File

@@ -133,8 +133,6 @@ public class HomePartyRoomFragment extends BaseRoomFragment<IHomePartyView, Home
@Override
public void initWidget() {
super.initWidget();
registerWidget(RoomGameplayListWidget.class.getSimpleName(), gameBinding.gameplayListWidget);
registerWidget(RoomGameplayWidget.class.getSimpleName(), gameBinding.gameplayWidget);
}
@SuppressLint("CheckResult")

View File

@@ -135,11 +135,6 @@ class SingleRoomFragment : BaseRoomFragment<ISingleRoomView?, SingleRoomPresente
override fun initWidget() {
super.initWidget()
registerWidget(
RoomGameplayListWidget::class.java.simpleName,
gameBinding.gameplayListWidget
)
registerWidget(RoomGameplayWidget::class.java.simpleName, gameBinding.gameplayWidget)
}
override fun onInitMusicPlayerView(view: MusicPlayerView) {

View File

@@ -12,7 +12,6 @@ import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
@@ -21,6 +20,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.chwl.app.avroom.dialog.RoomGameplayDialog;
import com.chwl.core.utils.extension.StringExtensionKt;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
@@ -38,9 +38,7 @@ import com.chwl.core.pay.event.FirstChargeEvent;
import com.chwl.core.room.bean.RoomInfo;
import com.chwl.core.room.bean.RoomModeType;
import com.chwl.core.super_admin.util.SuperAdminUtil;
import com.chwl.core.user.UserModel;
import com.chwl.core.utils.SharedPreferenceUtils;
import com.chwl.core.utils.net.RxHelper;
import com.chwl.library.utils.ListUtils;
import org.greenrobot.eventbus.EventBus;
@@ -54,7 +52,7 @@ import java.util.List;
* @date 2017/7/26
*/
public class BottomView extends FrameLayout implements View.OnClickListener {
public class BottomView extends LinearLayout implements View.OnClickListener {
/**
* 有新功能加1
@@ -112,6 +110,7 @@ public class BottomView extends FrameLayout implements View.OnClickListener {
iconRoomMsg = findViewById(R.id.iv_room_message);
iconVip = findViewById(R.id.icon_room_vip);
ImageView gameView = findViewById(R.id.icon_room_game);
openMic.setOnClickListener(this);
sendMsgInput.setOnClickListener(this);
sendFace.setOnClickListener(this);
@@ -121,6 +120,7 @@ public class BottomView extends FrameLayout implements View.OnClickListener {
iconMicQueue.setOnClickListener(this);
iconRoomMsg.setOnClickListener(this);
iconVip.setOnClickListener(this);
gameView.setOnClickListener(this);
setMicBtnEnable(false);
setMicBtnOpen(false);
@@ -323,6 +323,11 @@ public class BottomView extends FrameLayout implements View.OnClickListener {
case R.id.icon_room_vip:
VipMainActivity.start(getContext());
break;
case R.id.icon_room_game:
if (wrapper != null) {
wrapper.onRoomGameplayClick();
}
break;
default:
break;
}

View File

@@ -1,20 +1,25 @@
package com.chwl.app.ui.webview.room_game
package com.chwl.app.ui.webview.baishun
import android.webkit.JavascriptInterface
import androidx.annotation.Keep
import com.chwl.app.ui.pay.ChargeActivity
import com.example.lib_utils.log.ILog
import com.google.gson.Gson
import org.json.JSONObject
@Keep
class RoomGameJSBridge(val activity: RoomGameWebDialogActivity) : ILog {
class BaiShunGameJSBridge(val activity: BaiShunGameWebActivity) : ILog {
@JavascriptInterface
public fun getConfig(params: String) {
logD("getConfig()")
try {
val obj = JSONObject(params)
callJs("")
val jsFunName = obj.optString("jsCallback")
val config = activity.getGameConfig()
val str = (jsFunName + "(" + Gson().toJson(config) + ")")
callJs(str)
} catch (ex: Exception) {
ex.printStackTrace()
}
@@ -40,6 +45,9 @@ class RoomGameJSBridge(val activity: RoomGameWebDialogActivity) : ILog {
public fun gameLoaded(params: String) {
logD("游戏调⽤gameLoaded")
//游戏加载完毕
activity.runOnUiThread {
activity.dialogManager.dismissDialog()
}
}
private fun callJs(str: String) {

View File

@@ -0,0 +1,247 @@
package com.chwl.app.ui.webview.baishun
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.net.http.SslError
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.webkit.SslErrorHandler
import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import com.chwl.app.R
import com.chwl.app.base.BaseViewBindingActivity
import com.chwl.app.common.widget.dialog.DialogManager.OkCancelDialogListener
import com.chwl.app.databinding.RoomGameActivityBinding
import com.chwl.core.auth.AuthModel
import com.chwl.core.pay.event.GetWalletInfoEvent
import com.chwl.core.pay.event.UpdateWalletInfoEvent
import com.chwl.core.room.game.bean.BaiShunGameConfig
import com.chwl.library.utils.ResUtil
import com.google.gson.Gson
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
class BaiShunGameWebActivity : BaseViewBindingActivity<RoomGameActivityBinding>() {
private var gameConfig: BaiShunGameConfig? = null
private var gameUrl = ""
private var isLoadError = false
companion object {
fun start(context: Context, url: String, config: BaiShunGameConfig) {
val intent = Intent(context, BaiShunGameWebActivity::class.java)
intent.putExtra("url", url)
intent.putExtra("config", config)
context.startActivity(intent)
}
}
override fun init() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
window.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT
)
val url = intent.getStringExtra("url")
gameConfig = intent.getSerializableExtra("config") as? BaiShunGameConfig
if (url.isNullOrEmpty() || gameConfig == null) {
toast(R.string.utils_net_beanobserver_05)
finish()
return
}
gameUrl = url
initView()
binding.webView.isInvisible = true
binding.webView.loadUrl(url)
}
private fun initView() {
initWebView()
}
@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface")
private fun initWebView() {
//防⽌⽤浏览器打开⽹⻚
binding.webView.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
isLoadError = false
if (url == gameUrl) {
dialogManager.showProgressDialog(this@BaiShunGameWebActivity)
}
}
override fun onReceivedError(
view: WebView?,
errorCode: Int,
description: String?,
failingUrl: String?
) {
super.onReceivedError(view, errorCode, description, failingUrl)
isLoadError = true
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
onReceivedError(failingUrl, errorCode, description)
}
}
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
super.onReceivedError(view, request, error)
isLoadError = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
onReceivedError(request?.url?.toString(), error?.errorCode, error?.description)
}
}
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
if (!isLoadError) {
binding.webView.isVisible = true
}
}
override fun onReceivedSslError(
view: WebView,
handler: SslErrorHandler,
error: SslError?
) {
// super.onReceivedSslError(view, handler, error);
val builder = AlertDialog.Builder(view.context)
builder.setMessage(ResUtil.getString(R.string.ui_webview_commonwebviewactivity_07))
builder.setPositiveButton(
ResUtil.getString(R.string.ui_webview_commonwebviewactivity_08)
) { dialog, which ->
handler.proceed() // 接受https所有网站的证书
}
builder.setNegativeButton(
ResUtil.getString(R.string.ui_webview_commonwebviewactivity_09)
) { dialog, which -> handler.cancel() }
val dialog = builder.create()
dialog.show()
}
}
//设置webview背景透明,默认为⽩⾊
binding.webView.setBackgroundColor(0)
//设置view背景透明默认为⽩⾊ 可选(单独activity添加webView组件时需要添加)
binding.root.setBackgroundColor(0)
val settings = binding.webView.settings
//设置⽀持Javascript
settings.javaScriptEnabled = true
//设置默认⽂本编码
settings.defaultTextEncodingName = "UTF-8"
//设置可访问本地⽂件
settings.allowFileAccess = true
//设置允许通过file url加载的Javascript读取全部资源(包括⽂件,http,https)
settings.allowUniversalAccessFromFileURLs = true
//设置优先加载缓存
settings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK
//设置启⽤HTML5 DOM storage
settings.domStorageEnabled = true
//设置开启数据库缓存
settings.databaseEnabled = true
settings.databasePath = (applicationContext.filesDir.absolutePath)
//设置⽀持缩放
settings.setSupportZoom(true)
//设置⾃适应
settings.useWideViewPort = true
//设置⾃动播放媒体
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
settings.mediaPlaybackRequiresUserGesture = false
}
//设置5.0以上允许加载http和https混合的⻚⾯
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}
//游戏调⽤的类,必须定义为 NativeBridge
binding.webView.addJavascriptInterface(BaiShunGameJSBridge(this), "NativeBridge")
}
fun callJs(str: String) {
binding.webView.post {
binding.webView.loadUrl("javascript:$str")
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onWalletInfoUpdate(event: UpdateWalletInfoEvent?) {
updateGameWallet()
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onGetWalletInfoEvent(event: GetWalletInfoEvent?) {
updateGameWallet()
}
private fun updateGameWallet() {
try {
//数据只是参考值需要根据⾃⼰APP进⾏赋值
val map = HashMap<String, Any>()
map["userId"] = AuthModel.get().currentUid
val str = "walletUpdate" + "(" + Gson().toJson(map) + ")"
this.callJs(str)
} catch (e: Exception) {
e.printStackTrace()
}
}
fun getGameConfig() = gameConfig
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
EventBus.getDefault().register(this)
}
override fun onDestroy() {
super.onDestroy()
EventBus.getDefault().unregister(this)
}
private fun onReceivedError(url: String?, code: Int?, message: CharSequence?) {
if (url == gameUrl) {
binding.webView.isInvisible = true
dialogManager.dismissDialog()
showLoadErrorDialog(message?.toString() ?: "($code)")
}
}
private fun showLoadErrorDialog(message: String) {
dialogManager.showOkCancelDialog(
getString(R.string.load_failed),
message,
getString(R.string.retry),
getString(R.string.exit_text),
false, false, true, object : OkCancelDialogListener {
override fun onOk() {
binding.webView.reload()
}
override fun onCancel() {
super.onCancel()
finish()
}
}, null, false
)
}
}

View File

@@ -1,123 +0,0 @@
package com.chwl.app.ui.webview.room_game
import android.annotation.SuppressLint
import android.net.http.SslError
import android.os.Build
import android.view.View
import android.view.WindowManager
import android.webkit.SslErrorHandler
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AlertDialog
import com.chwl.app.R
import com.chwl.app.base.BaseViewBindingActivity
import com.chwl.app.databinding.RoomGameActivityBinding
import com.chwl.core.auth.AuthModel
import com.chwl.core.pay.event.UpdateWalletInfoEvent
import com.chwl.library.utils.ResUtil
import com.google.gson.Gson
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
class RoomGameWebDialogActivity : BaseViewBindingActivity<RoomGameActivityBinding>() {
override fun init() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
window.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT
)
initView()
}
private fun initView() {
initWebView()
binding.webView.loadUrl("https://baidu.com")
}
@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface")
private fun initWebView() {
//防⽌⽤浏览器打开⽹⻚
binding.webView.webViewClient = object : WebViewClient() {
override fun onReceivedSslError(
view: WebView,
handler: SslErrorHandler,
error: SslError?
) {
// super.onReceivedSslError(view, handler, error);
val builder = AlertDialog.Builder(view.context)
builder.setMessage(ResUtil.getString(R.string.ui_webview_commonwebviewactivity_07))
builder.setPositiveButton(
ResUtil.getString(R.string.ui_webview_commonwebviewactivity_08)
) { dialog, which ->
handler.proceed() // 接受https所有网站的证书
}
builder.setNegativeButton(
ResUtil.getString(R.string.ui_webview_commonwebviewactivity_09)
) { dialog, which -> handler.cancel() }
val dialog = builder.create()
dialog.show()
}
}
//设置webview背景透明,默认为⽩⾊
binding.webView.setBackgroundColor(0)
//设置view背景透明默认为⽩⾊ 可选(单独activity添加webView组件时需要添加)
binding.root.setBackgroundColor(0)
val settings = binding.webView.settings
//设置⽀持Javascript
settings.javaScriptEnabled = true
//设置默认⽂本编码
settings.defaultTextEncodingName = "UTF-8"
//设置可访问本地⽂件
settings.allowFileAccess = true
//设置允许通过file url加载的Javascript读取全部资源(包括⽂件,http,https)
settings.allowUniversalAccessFromFileURLs = true
//设置优先加载缓存
settings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK
//设置启⽤HTML5 DOM storage
settings.domStorageEnabled = true
//设置开启数据库缓存
settings.databaseEnabled = true
settings.databasePath = (applicationContext.filesDir.absolutePath)
//设置⽀持缩放
settings.setSupportZoom(true);
//设置⾃适应
settings.setUseWideViewPort(true);
//设置⾃动播放媒体
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
settings.mediaPlaybackRequiresUserGesture = false
}
//设置5.0以上允许加载http和https混合的⻚⾯
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}
//游戏调⽤的类,必须定义为 NativeBridge
binding.webView.addJavascriptInterface(RoomGameJSBridge(this), "NativeBridge")
}
fun callJs(str: String) {
binding.webView.post {
binding.webView.loadUrl("javascript:$str")
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onWalletInfoUpdate(event: UpdateWalletInfoEvent?) {
updateGameWallet()
}
private fun updateGameWallet() {
//数据只是参考值需要根据⾃⼰APP进⾏赋值
val map = HashMap<String, Any>()
map["userId"] = AuthModel.get().currentUid
val str = "walletUpdate" + "(" + Gson().toJson(map) + ")"
this.callJs(str)
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -158,10 +158,10 @@
android:id="@+id/iv_queuing_micro"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_above="@id/gameplay_widget"
android:layout_alignParentEnd="true"
android:layout_above="@id/bottom_view"
android:layout_marginEnd="6dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="true"
android:adjustViewBounds="true"
android:onClick="@{click}"
android:src="@drawable/ic_dating_queuing_micro"
@@ -169,26 +169,6 @@
tools:contentDescription="@string/layout_fragment_av_room_game_05"
tools:visibility="visible" />
<com.chwl.app.avroom.gameplay.RoomGameplayWidget
android:id="@+id/gameplay_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/bottom_view"
android:layout_alignParentEnd="true"
android:layout_marginEnd="6dp"
android:layout_marginBottom="10dp"
android:visibility="gone"
tools:visibility="visible" />
<com.chwl.app.avroom.gameplay.RoomGameplayListWidget
android:id="@+id/gameplay_list_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/gameplay_widget"
android:layout_alignBottom="@id/gameplay_widget"
android:visibility="gone"
tools:visibility="visible" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@@ -92,26 +92,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/message_indicator" />
<com.chwl.app.avroom.gameplay.RoomGameplayWidget
android:id="@+id/gameplay_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:layout_marginBottom="6dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/bottom_view"
app:layout_constraintEnd_toEndOf="parent"
tools:visibility="visible" />
<com.chwl.app.avroom.gameplay.RoomGameplayListWidget
android:id="@+id/gameplay_list_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/gameplay_widget"
app:layout_constraintEnd_toEndOf="@id/gameplay_widget"
tools:visibility="visible" />
<RelativeLayout
android:id="@+id/input_layout"
android:layout_width="0dp"

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -17,8 +18,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:maxWidth="@dimen/dp_150"
android:maxLines="1"
android:textColor="@color/white"
android:textSize="15sp"
android:textSize="15dp"
app:autoSizeMaxTextSize="15dp"
app:autoSizeMinTextSize="7dp"
app:autoSizeStepGranularity="1px"
app:autoSizeTextType="uniform"
tools:text="@string/layout_item_room_select_game_01" />
</LinearLayout>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="52dp"
@@ -8,12 +8,13 @@
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:scrollbars="none"
android:overScrollMode="never"
android:layout_gravity="center_vertical"
android:layout_marginEnd="65dp">
android:layout_marginEnd="@dimen/dp_10"
android:layout_weight="1"
android:overScrollMode="never"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
@@ -129,6 +130,15 @@
</HorizontalScrollView>
<ImageView
android:id="@+id/icon_room_game"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="@dimen/dp_10"
android:scaleType="fitXY"
android:src="@drawable/room_bottom_ic_game" />
<ImageView
android:id="@+id/icon_room_send_gift"
android:layout_width="38dp"
@@ -138,5 +148,5 @@
android:scaleType="fitXY"
android:src="@drawable/icon_room_send_gift" />
</FrameLayout>
</LinearLayout>

View File

@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/base_shape_2d1e4d_top_12dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_3"
android:layout_marginVertical="@dimen/dp_10"
android:orientation="vertical"
android:visibility="visible"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:spanCount="5"
tools:listitem="@layout/room_gameplay_item2"
tools:visibility="gone" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_status"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_260"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<ProgressBar
android:id="@+id/iv_loading"
style="@style/progressDialog"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:indeterminate="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_loading"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:text="@string/layout_dialog_loading_01"
android:textColor="@color/white"
android:textSize="@dimen/dp_14"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/iv_loading"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/group_status_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="iv_loading,tv_loading" />
<androidx.constraintlayout.widget.Group
android:id="@+id/group_status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="iv_status,tv_status" />
<ImageView
android:id="@+id/iv_status"
android:layout_width="101dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:src="@drawable/default_status_empty"
app:layout_constraintBottom_toTopOf="@id/tv_status"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/tv_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_14"
android:text="@string/avroom_presenter_roomnewbiehellowwordpresenter_01"
android:textColor="@color/white"
android:textSize="@dimen/dp_14"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_status" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_9"
android:layout_marginVertical="@dimen/dp_10">
<ImageView
android:id="@+id/iv_icon"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/default_cover" />
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:textColor="@color/white"
android:textSize="@dimen/dp_10"
app:autoSizeMaxTextSize="@dimen/dp_10"
app:autoSizeMinTextSize="@dimen/dp_6"
app:autoSizeStepGranularity="1px"
app:autoSizeTextType="uniform"
app:layout_constraintTop_toBottomOf="@id/iv_icon"
tools:text="Name" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -5265,4 +5265,6 @@
<string name="permission_mic_tips">يرجى السماح بإذن الميكروفون والمحاولة مرة أخرى</string>
<string name="game_failed_tips">فشل تهيئة دليل تطوير الألعاب:%s</string>
<string name="load_failed">فشل التحميل</string>
<string name="retry">أعد المحاولة</string>
</resources>

View File

@@ -5207,4 +5207,7 @@
<string name="game_failed_tips">初始化遊戲SDK失敗:%s</string>
<string name="load_failed">加載失敗</string>
<string name="retry">重試</string>
</resources>

View File

@@ -5246,6 +5246,8 @@
<string name="game_failed_tips">Failed to initialize game SDK:%s</string>
<string name="load_failed">Loading failed</string>
<string name="retry">Retry</string>
</resources>

View File

@@ -2,6 +2,7 @@ package com.chwl.core.room.bean
import androidx.annotation.Keep
import com.chwl.core.bean.IRouterData
import com.chwl.core.room.game.bean.BaiShunGameConfig
/**
* Created by Max on 2024/2/20 11:49
@@ -40,6 +41,7 @@ data class RoomIcon(
fun isSeizeTreasure(): Boolean = code == "SEIZE_TREASURE"
fun isFindLove(): Boolean = code == "FIND_LOVE"
fun isNauticalAdventure(): Boolean = code == "NAUTICAL_ADVENTURE"
fun isBaiShunGame() = code == "BAISHUN"
override fun getSkipUri(): String? {
return skipContent
@@ -56,4 +58,9 @@ data class RoomIcon(
override fun getRouterValue(): String? {
return null
}
@Keep
class RuleValueBean {
val RESERVE: String? = null
}
}

View File

@@ -1,10 +1,55 @@
package com.chwl.core.room.core
import com.chwl.core.support.room.RoomContext
import com.chwl.core.support.room.RoomService
import java.util.concurrent.ConcurrentHashMap
/**
* Created by Max on 2023/10/26 12:36
* Desc:房间数据服务
**/
class RoomDataService : RoomService() {
/**
* 数据存储器
*/
private val dataMap: ConcurrentHashMap<String, Any> = ConcurrentHashMap()
/**
* 获取数据
*/
fun getData(key: String): Any? {
return dataMap.get(key)
}
/**
* 获取数据
* @param key
*/
fun getData(key: String, factory: (() -> Any)): Any {
val data = dataMap.get(key)
return if (data != null) {
data
} else {
val newData = factory.invoke()
dataMap.put(key, newData)
newData
}
}
/**
* 设置数据
*/
fun putData(key: String, data: Any?) {
if (data == null) {
dataMap.remove(key)
} else {
dataMap.put(key, data)
}
}
override fun onStop(context: RoomContext) {
super.onStop(context)
dataMap.clear()
}
}

View File

@@ -0,0 +1,50 @@
package com.chwl.core.room.game.bean
import androidx.annotation.Keep
import com.chwl.core.auth.AuthModel
import com.chwl.core.manager.AvRoomDataManager
import com.chwl.core.user.UserModel
import com.chwl.library.language.LanguageHelper
import java.io.Serializable
@Keep
class BaiShunGameConfig : Serializable {
val appChannel: String? = null
val appId: Long? = null
var userId: String? = null
val code: String? = null
var roomId: String? = null
// 游戏场景 2:半屏(秀场) 3: 全屏(游戏场)
val gameMode: String? = null
var language: String? = null
val gameConfig: Config? = null
val gsp: Int? = null
@Keep
class Config : Serializable {
val sceneMode: Int? = null
//货币图标(外⽹可访问 URL60*60 ⼤⼩)
val currencyIcon: String? = null
}
fun reloadDynamicParams() {
roomId = AvRoomDataManager.get().roomId.toString()
userId = AuthModel.get().currentUid.toString()
language = when (LanguageHelper.getCurrentLanguageType()) {
LanguageHelper.AR -> {
"7"
}
LanguageHelper.ZH -> {
"1"
}
else -> {
"2"
}
}
}
}

View File

@@ -1,5 +1,7 @@
package com.chwl.core.room.game.bean
import java.io.Serializable
data class GameInfo(
val isShow: Boolean = false,
val mgId: String = "",
@@ -7,5 +9,13 @@ data class GameInfo(
val pic: String = "",
val remark: String = "",
val seq: Int = 0,
var isSelect: Boolean = false
)
var isSelect: Boolean = false,
// 本地自己维护的,为了区分普通房
private var isStandardRoom: Boolean? = null,
) : Serializable {
fun isStandardRoom() = isStandardRoom == true
fun asStandardRoom() {
isStandardRoom = true
}
}

View File

@@ -2,6 +2,7 @@ package com.chwl.core.support.room
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.chwl.core.room.core.RoomDataService
import com.example.lib_utils.log.ILog
import com.chwl.core.support.room.lifecycle.RoomLifecycle
import com.chwl.core.support.room.lifecycle.RoomLifecycleRegistry
@@ -77,6 +78,7 @@ abstract class RoomContext(val roomId: Long) : ILog {
* 装载能力组件
*/
open fun loadAbility(list: MutableMap<String, RoomAbility>) {
list.put(RoomDataService::class.java.simpleName, RoomDataService())
}
/**

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#2D1E4D" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>