feat:恢复游戏房功能
This commit is contained in:
@@ -272,6 +272,8 @@ dependencies {
|
||||
if (!isolationMode && file("../modules/module_google/build.gradle").exists()) {
|
||||
implementation project(':modules:module_google')
|
||||
}
|
||||
|
||||
implementation 'tech.sud.mgp:SudMGP-static:1.3.3.1158'
|
||||
}
|
||||
|
||||
channel {
|
||||
|
@@ -667,6 +667,10 @@
|
||||
android:name=".ui.webview.DialogWebViewActivity"
|
||||
android:theme="@style/dialog_web_view_activity"
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
<activity
|
||||
android:name=".ui.webview.room_game.RoomGameWebDialogActivity"
|
||||
android:theme="@style/dialog_web_view_activity"
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
<activity
|
||||
android:name=".ui.webview.room_banner.RoomWebDialogActivity"
|
||||
android:theme="@style/room_dialog_web_view_activity"
|
||||
|
@@ -0,0 +1,181 @@
|
||||
package com.chwl.app.avroom.fragment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.avroom.adapter.GameMicroViewAdapter
|
||||
import com.chwl.app.avroom.adapter.GameMiniMicroViewAdapter
|
||||
import com.chwl.app.avroom.adapter.OnMicroItemClickListener
|
||||
import com.chwl.app.avroom.game.GameDelegate
|
||||
import com.chwl.app.avroom.game.OnGameStatusChangeListener
|
||||
import com.chwl.app.avroom.presenter.GameRoomPresenter
|
||||
import com.chwl.app.avroom.view.IGameRoomView
|
||||
import com.chwl.app.databinding.FragmentGameRoomBinding
|
||||
import com.chwl.app.ui.widget.GiftDialog.OnGiftDialogBtnClickListener
|
||||
import com.chwl.core.manager.AvRoomDataManager
|
||||
import com.chwl.core.music.model.PlayerModel
|
||||
import com.chwl.core.room.event.FinishAvRoomEvent
|
||||
import com.chwl.library.base.factory.CreatePresenter
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
/**
|
||||
* 轰趴房间
|
||||
*
|
||||
* @author chenran
|
||||
* @date 2017/7/26
|
||||
*/
|
||||
@CreatePresenter(GameRoomPresenter::class)
|
||||
class GameRoomFragment : BaseRoomFragment<IGameRoomView?, GameRoomPresenter?>(),
|
||||
View.OnClickListener, OnGiftDialogBtnClickListener, IGameRoomView, OnMicroItemClickListener,
|
||||
OnGameStatusChangeListener {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance(): GameRoomFragment {
|
||||
val roomFragment = GameRoomFragment()
|
||||
val bundle = Bundle()
|
||||
roomFragment.arguments = bundle
|
||||
return roomFragment
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var gameBinding: FragmentGameRoomBinding
|
||||
private lateinit var gameDelegate: GameDelegate
|
||||
private var isShowMiniMic = false
|
||||
|
||||
override fun getRootLayoutId(): Int {
|
||||
return R.layout.fragment_game_room
|
||||
}
|
||||
|
||||
override fun onFindViews() {
|
||||
super.onFindViews()
|
||||
gameBinding = DataBindingUtil.bind(mView)!!
|
||||
gameBinding.lifecycleOwner = this
|
||||
gameBinding.click = this
|
||||
gameBinding.ktvModel = false
|
||||
gameDelegate = GameDelegate(
|
||||
requireActivity(),
|
||||
gameBinding.flGameContainer,
|
||||
AvRoomDataManager.get().mCurrentRoomInfo?.mgId
|
||||
)
|
||||
gameDelegate.setOnGameStatusChangeListener(this)
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun initiate() {
|
||||
gameBinding.microView.bindAdapter(GameMicroViewAdapter(context))
|
||||
super.initiate()
|
||||
//游戏模式暂时不需要这个
|
||||
PlayerModel.get().stop()
|
||||
gameBinding.roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
|
||||
gameBinding.tvShowMiniMic.setOnClickListener { showMiniMic() }
|
||||
gameBinding.ivShowMic.setOnClickListener { showMic() }
|
||||
}
|
||||
|
||||
private fun showMiniMic() {
|
||||
if (isShowMiniMic) return
|
||||
isShowMiniMic = true
|
||||
gameBinding.microView.bindAdapter(GameMiniMicroViewAdapter(context).apply {
|
||||
setOnClick { showMic() }
|
||||
})
|
||||
gameBinding.tvShowMiniMic.isVisible = false
|
||||
gameBinding.microView.postDelayed({
|
||||
gameBinding.ivShowMic.isVisible = true
|
||||
gameBinding.llMicView.setBackgroundResource(R.drawable.bg_mini_mic_entrance)
|
||||
}, 100)
|
||||
}
|
||||
|
||||
private fun showMic() {
|
||||
if (!isShowMiniMic) return
|
||||
isShowMiniMic = false
|
||||
gameBinding.microView.bindAdapter(GameMicroViewAdapter(context))
|
||||
gameBinding.tvShowMiniMic.isVisible = true
|
||||
gameBinding.llMicView.background = null
|
||||
gameBinding.ivShowMic.isVisible = false
|
||||
}
|
||||
|
||||
override fun onSetListener() {
|
||||
super.onSetListener()
|
||||
bottomView.setBottomViewListener(BaseRoomBottomViewWrapper())
|
||||
}
|
||||
|
||||
override fun updateView() {
|
||||
super.updateView()
|
||||
gameDelegate.updateGame(AvRoomDataManager.get().mCurrentRoomInfo?.mgId)
|
||||
gameBinding.roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
|
||||
if (isSixMic()) {
|
||||
gameBinding.tvShowMiniMic.isVisible = !isShowMiniMic
|
||||
gameBinding.ivShowMic.isVisible = isShowMiniMic
|
||||
} else {
|
||||
showMic()
|
||||
gameBinding.tvShowMiniMic.isInvisible = true
|
||||
gameBinding.ivShowMic.isVisible = false
|
||||
}
|
||||
gameBinding.microView.adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onGameStart() {
|
||||
if (isSixMic()) {
|
||||
showMiniMic()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onGameEnd() {
|
||||
if (isSixMic()) {
|
||||
showMic()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSixMic(): Boolean {
|
||||
return AvRoomDataManager.get().mgMicNum == AvRoomDataManager.GAME_DEF_MIC_COUNT
|
||||
}
|
||||
|
||||
override fun onSendMsgSuccess(msg: String?) {
|
||||
super.onSendMsgSuccess(msg)
|
||||
msg?.let {
|
||||
if (AvRoomDataManager.get().isSelfGamePlaying) {
|
||||
gameDelegate.hitTheMark(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onFinishAvRoomEvent(event: FinishAvRoomEvent) {
|
||||
gameDelegate.exitGame()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
gameDelegate.onStart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
gameDelegate.onResume()
|
||||
}
|
||||
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
gameDelegate.onPause()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
gameDelegate.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
gameDelegate.onDestroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun initWidget() {
|
||||
super.initWidget()
|
||||
}
|
||||
}
|
@@ -16,9 +16,15 @@ import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.chwl.app.avroom.adapter.SelectGameAdapter;
|
||||
import com.chwl.app.home.helper.OpenRoomHelper;
|
||||
import com.chwl.app.ui.widget.GiftDialog;
|
||||
import com.chwl.app.ui.widget.UserInfoDialog;
|
||||
import com.chwl.core.room.bean.RoomModeType;
|
||||
import com.chwl.core.room.game.GameModel;
|
||||
import com.chwl.core.room.game.bean.GameInfo;
|
||||
import com.chwl.library.utils.JavaUtil;
|
||||
import com.example.lib_utils.UiUtils;
|
||||
import com.netease.nim.uikit.common.util.string.StringUtil;
|
||||
@@ -64,6 +70,7 @@ 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;
|
||||
@@ -98,6 +105,7 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
|
||||
|
||||
//收藏房间
|
||||
private String FOLLOW_ROOM_TYPE = "";
|
||||
private SelectGameAdapter gameAdapter;
|
||||
|
||||
public static HomePartyFragment newInstance() {
|
||||
HomePartyFragment homePartyFragment = new HomePartyFragment();
|
||||
@@ -216,6 +224,72 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
|
||||
}
|
||||
}
|
||||
|
||||
private void initRvGame() {
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo == null || gameAdapter != null) return;
|
||||
gameMainBinding.rvGame.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
gameMainBinding.rvGame.setAdapter(gameAdapter = new SelectGameAdapter());
|
||||
gameMainBinding.llSelectGame.setOnClickListener(v -> {
|
||||
if (gameMainBinding.rvGame.getVisibility() == View.VISIBLE) {
|
||||
gameMainBinding.rvGame.setVisibility(View.GONE);
|
||||
gameMainBinding.ivChangeGameArrow.setImageResource(R.drawable.ic_room_arrow_type_below);
|
||||
} else {
|
||||
if (!isShowChangeGame()) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_01));
|
||||
return;
|
||||
}
|
||||
if (AvRoomDataManager.get().isGamePlaying()) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_02));
|
||||
} else {
|
||||
gameMainBinding.rvGame.setVisibility(View.VISIBLE);
|
||||
gameMainBinding.ivChangeGameArrow.setImageResource(R.drawable.ic_room_arrow_type);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
gameAdapter.setOnItemClickListener((adapter, view, position) -> {
|
||||
if (AvRoomDataManager.get().isGamePlaying()) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_03));
|
||||
}
|
||||
if (!isShowChangeGame()) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_04));
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//这里的2和4是服务端定义的错误状态 关闭排麦模式和关闭PK模式!
|
||||
private boolean isShowChangeGame() {
|
||||
RoomInfo currentRoomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
return currentRoomInfo != null &&
|
||||
AvRoomDataManager.get().isRoomOwner() &&
|
||||
currentRoomInfo.getIsPermitRoom() != 1 &&
|
||||
currentRoomInfo.getType() != RoomInfo.ROOM_TYPE_SINGLE &&
|
||||
(currentRoomInfo.getRoomModeType() == RoomModeType.NORMAL_MODE ||
|
||||
currentRoomInfo.getRoomModeType() == 2 ||
|
||||
currentRoomInfo.getRoomModeType() == 4);
|
||||
}
|
||||
|
||||
public void setRoomBg(RoomInfo roomInfo) {
|
||||
if (svgaRoomBg == null) return;
|
||||
updateView(roomInfo);
|
||||
@@ -351,11 +425,11 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
|
||||
|
||||
Fragment tempFragment = roomFragment;
|
||||
switch (currentRoomInfo.getType()) {
|
||||
// case RoomInfo.ROOMTYPE_GAME:
|
||||
// if (!(tempFragment instanceof GameRoomFragment)) {
|
||||
// tempFragment = GameRoomFragment.newInstance();
|
||||
// }
|
||||
// break;
|
||||
case RoomInfo.ROOMTYPE_GAME:
|
||||
if (!(tempFragment instanceof GameRoomFragment)) {
|
||||
tempFragment = GameRoomFragment.newInstance();
|
||||
}
|
||||
break;
|
||||
case RoomInfo.ROOM_TYPE_SINGLE:
|
||||
if (!(tempFragment instanceof SingleRoomFragment)) {
|
||||
tempFragment = SingleRoomFragment.newInstance();
|
||||
@@ -391,6 +465,35 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
|
||||
ivFollowRoom.setImageResource(AvRoomDataManager.get().isRoomFans ? R.drawable.room_ic_collect_yes : R.drawable.room_ic_collect_no);
|
||||
|
||||
setIdOnlineData();
|
||||
|
||||
if (isShowChangeGame()) {
|
||||
initRvGame();
|
||||
gameMainBinding.llChangeGame.setVisibility(View.VISIBLE);
|
||||
if (AvRoomDataManager.get().isOpenGame()) {
|
||||
gameMainBinding.tvCurrGame.setText(currentRoomInfo.getMgName());
|
||||
} else {
|
||||
gameMainBinding.tvCurrGame.setText(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_08));
|
||||
}
|
||||
GameModel.INSTANCE.getGameList()
|
||||
.compose(bindToLifecycle())
|
||||
.subscribe(gameInfos -> {
|
||||
if (AvRoomDataManager.get().isOpenGame()) {
|
||||
for (int i = 0; i < gameInfos.size(); i++) {
|
||||
GameInfo gameInfo = gameInfos.get(i);
|
||||
if (JavaUtil.str2long(gameInfo.getMgId()) == currentRoomInfo.getMgId()) {
|
||||
gameInfos.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setName(ResUtil.getString(R.string.avroom_fragment_homepartyfragment_09));
|
||||
gameInfos.add(gameInfo);
|
||||
}
|
||||
gameAdapter.setNewData(gameInfos);
|
||||
});
|
||||
} else {
|
||||
gameMainBinding.llChangeGame.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
16
app/src/main/java/com/chwl/app/avroom/game/AppConfig.java
Normal file
16
app/src/main/java/com/chwl/app/avroom/game/AppConfig.java
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
Copyright © Sud.Tech
|
||||
https://sud.tech
|
||||
*/
|
||||
package com.chwl.app.avroom.game;
|
||||
|
||||
|
||||
import com.chwl.app.BuildConfig;
|
||||
|
||||
public class AppConfig {
|
||||
|
||||
protected static final String APP_ID = "1578948593831571457";
|
||||
protected static final String APP_KEY = "J9lHOXvFWkAZiTfl4SK7IGt0wDnW3fWd";
|
||||
protected static boolean isTestEnv = BuildConfig.DEBUG;
|
||||
|
||||
}
|
695
app/src/main/java/com/chwl/app/avroom/game/GameDelegate.kt
Normal file
695
app/src/main/java/com/chwl/app/avroom/game/GameDelegate.kt
Normal file
@@ -0,0 +1,695 @@
|
||||
package com.chwl.app.avroom.game
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener
|
||||
import android.widget.FrameLayout
|
||||
import com.google.gson.Gson
|
||||
import com.chwl.app.R
|
||||
import com.chwl.core.auth.AuthModel
|
||||
import com.chwl.core.manager.AvRoomDataManager
|
||||
import com.chwl.core.room.game.bean.GameCfg
|
||||
import com.chwl.core.room.game.GameModel
|
||||
import com.chwl.core.room.game.GameStatus
|
||||
import com.chwl.core.room.model.HomePartyModel
|
||||
import com.chwl.core.user.UserModel
|
||||
import com.chwl.core.utils.LogUtils
|
||||
import com.chwl.core.utils.net.RxHelper
|
||||
import com.chwl.library.language.LanguageHelper
|
||||
import com.chwl.library.net.rxnet.callback.CallBack
|
||||
import com.chwl.library.utils.SingleToastUtil
|
||||
import okhttp3.*
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import tech.sud.mgp.core.*
|
||||
import java.util.*
|
||||
|
||||
class GameDelegate(val activity: Activity, val container: FrameLayout, var mgId: Long?) {
|
||||
|
||||
private val TAG = "GameDelegate"
|
||||
private var APP_CODE = ""
|
||||
|
||||
private val mRoomID :String get() = AvRoomDataManager.get().roomUid.toString()
|
||||
private var mLanguage = "zh-TW" //語言
|
||||
|
||||
//調用遊戲SDK的接口,成功加載遊戲後可用:
|
||||
private var iSudFSTAPP: ISudFSTAPP? = null
|
||||
|
||||
private val gson = Gson()
|
||||
|
||||
//小遊戲ID
|
||||
private var mMGID = 0L
|
||||
|
||||
//通用狀態-遊戲,關鍵詞
|
||||
private var mKeyWord: String? = null
|
||||
private val mUid = AuthModel.get().currentUid.toString()
|
||||
|
||||
private val homePartyModel = HomePartyModel()
|
||||
|
||||
private var onGameStatusChangeListener: OnGameStatusChangeListener? = null
|
||||
|
||||
fun setOnGameStatusChangeListener(onGameStatusChangeListener: OnGameStatusChangeListener) {
|
||||
this.onGameStatusChangeListener = onGameStatusChangeListener
|
||||
}
|
||||
|
||||
private val loginCallback: AppLoginListener =
|
||||
object : AppLoginListener {
|
||||
override fun onLoginFailure(err: String?) {
|
||||
SingleToastUtil.showToast(err)
|
||||
}
|
||||
|
||||
override fun onLoginSuccess(new_code: String, expire_Date: Long) {
|
||||
APP_CODE = new_code
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
//初始化遊戲SDK
|
||||
initGameSDK(
|
||||
activity,
|
||||
AppConfig.APP_ID,
|
||||
AppConfig.APP_KEY,
|
||||
AppConfig.isTestEnv
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
init {
|
||||
mMGID = mgId ?: 0L
|
||||
mLanguage = getGameLanguage()
|
||||
login(loginCallback)
|
||||
}
|
||||
|
||||
fun updateGame(mgId: Long?) {
|
||||
if (mgId == null || mgId == 0L) return
|
||||
if (mgId == mMGID && iSudFSTAPP != null) {
|
||||
return
|
||||
}
|
||||
mMGID = mgId
|
||||
updateMyMicQueue(GameStatus.STATUS_NOT_JOIN)
|
||||
loadMG(activity, mUid, mRoomID, APP_CODE, mMGID, mLanguage)
|
||||
}
|
||||
|
||||
fun exitGame() {
|
||||
UserModel.get().cacheLoginUserInfo?.gameStatus = GameStatus.STATUS_NOT_JOIN
|
||||
notifySelfPlayingState(false)
|
||||
notifySelfInState(false)
|
||||
}
|
||||
|
||||
/**
|
||||
* 例如"你畫我猜"遊戲的文字命中
|
||||
*/
|
||||
fun hitTheMark(msg: String) {
|
||||
mKeyWord?.let {
|
||||
if (msg.contains(it)) {
|
||||
notifySelfTextHit(it, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "接入方客戶端"登陸接口, 從"接入方服務端"獲得Code
|
||||
* "接入方服務端"是通過"服務端接入SDK"獲得Code來返回給"接入方客戶端"的
|
||||
* @param listener
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private fun login(listener: AppLoginListener) {
|
||||
GameModel.getGameCode()
|
||||
.compose(RxHelper.bindContext(activity))
|
||||
.subscribe({
|
||||
listener.onLoginSuccess(it.code, it.expireDate)
|
||||
}, {
|
||||
listener.onLoginFailure(it.message)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 1,初始化遊戲SDK
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param appID appID
|
||||
* @param appKey appKey
|
||||
* @param isTestEnv 是否是測試環境,true:測試環境,false:正式環境
|
||||
*/
|
||||
private fun initGameSDK(context: Context, appID: String, appKey: String, isTestEnv: Boolean) {
|
||||
SudMGP.initSDK(context, appID, appKey, isTestEnv, object : ISudListenerInitSDK {
|
||||
override fun onSuccess() {
|
||||
loadMG(activity, mUid, mRoomID, APP_CODE, mMGID, mLanguage)
|
||||
}
|
||||
|
||||
override fun onFailure(code: Int, errInfo: String) {
|
||||
val msg = context.getString(R.string.game_failed_tips).format("$code-${errInfo}")
|
||||
showToast(msg)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 2,加載遊戲
|
||||
*
|
||||
* @param activity 上下文Activity
|
||||
* @param userID 用戶ID,業務系統保證每個用戶擁有唯一ID
|
||||
* @param roomID 房間ID,進入同一房間內的
|
||||
* @param code 令牌
|
||||
* @param mgID 小遊戲ID
|
||||
* @param language 遊戲語言 現支持,簡體:zh-CN 繁體:zh-TW 英語:en-US 馬來語:ms-MY
|
||||
*/
|
||||
private fun loadMG(
|
||||
activity: Activity,
|
||||
userID: String,
|
||||
roomID: String,
|
||||
code: String,
|
||||
mgID: Long,
|
||||
language: String
|
||||
) {
|
||||
iSudFSTAPP?.destroyMG()
|
||||
iSudFSTAPP = SudMGP.loadMG(activity, userID, roomID, code, mgID, language, mISudFSMMG)
|
||||
iSudFSTAPP?.apply {
|
||||
addGameView(gameView)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 3,將遊戲view添加到我們的布局當中
|
||||
*
|
||||
* @param gameView
|
||||
*/
|
||||
private fun addGameView(gameView: View) {
|
||||
container.removeAllViews()
|
||||
container.addView(gameView)
|
||||
}
|
||||
|
||||
private fun showToast(content: String?) {
|
||||
SingleToastUtil.showToast(content)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通知"文字命中狀態"到遊戲端
|
||||
*
|
||||
* @param iSudFSTAPP
|
||||
* @param keyWord
|
||||
*/
|
||||
private fun notifySelfTextHit(keyWord: String?, msg: String) {
|
||||
LogUtils.d("notifySelfTextHit")
|
||||
try {
|
||||
//狀態名稱
|
||||
val state: String = SudMGPAPPState.APP_COMMON_SELF_TEXT_HIT
|
||||
|
||||
//狀態數據
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("isHit", true) // true 命中,false 未命中
|
||||
jsonObject.put("keyWord", keyWord) // true 命中,false 未命中
|
||||
jsonObject.put("text", msg) // 聊天原始內容,這裏的值只是一個示例,意指內容當中包含關鍵詞則命中,具體按業務規則定。
|
||||
val dataJson = jsonObject.toString()
|
||||
//調用接口
|
||||
iSudFSTAPP?.notifyStateChange(state, dataJson, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 設置當前關鍵詞
|
||||
*
|
||||
* @param keyWord
|
||||
*/
|
||||
private fun setKeyWord(keyWord: String?) {
|
||||
mKeyWord = keyWord
|
||||
}
|
||||
|
||||
private fun getGameLanguage(): String {
|
||||
return when (LanguageHelper.getCurrentLanguageType()) {
|
||||
LanguageHelper.ZH -> {
|
||||
"zh-TW"
|
||||
}
|
||||
|
||||
LanguageHelper.AR -> {
|
||||
"ar-SA"
|
||||
}
|
||||
|
||||
else -> {
|
||||
"en-US"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 遊戲SDK調用app的接口
|
||||
*/
|
||||
private val mISudFSMMG: ISudFSMMG = object : ISudFSMMG {
|
||||
|
||||
override fun onGameLog(p0: String?) {
|
||||
LogUtils.d(p0)
|
||||
}
|
||||
|
||||
override fun onGameLoadingProgress(p0: Int, p1: Int, p2: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onGameStarted() {
|
||||
}
|
||||
|
||||
override fun onGameDestroyed() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 回調此方法,表示令牌過期,此時需要刷新令牌並使用ISudFSMStateHandle回調
|
||||
* @param handle
|
||||
* @param dataJson
|
||||
*/
|
||||
override fun onExpireCode(handle: ISudFSMStateHandle, dataJson: String) {
|
||||
login(object : AppLoginListener {
|
||||
override fun onLoginFailure(err: String?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onLoginSuccess(new_code: String, expire_Date: Long) {
|
||||
APP_CODE = new_code
|
||||
try {
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("ret_code", 0)
|
||||
jsonObject.put("ret_msg", "success")
|
||||
handle.success(jsonObject.toString())
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
iSudFSTAPP?.updateCode(APP_CODE, null)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 處理獲取遊戲視圖信息
|
||||
* @param handle
|
||||
* @param dataJson
|
||||
*/
|
||||
override fun onGetGameViewInfo(handle: ISudFSMStateHandle, dataJson: String) {
|
||||
//拿到遊戲View的寬高
|
||||
val gameViewWidth = container.measuredWidth
|
||||
val gameViewHeight = container.measuredHeight
|
||||
if (gameViewWidth > 0 && gameViewHeight > 0) {
|
||||
notifyGameViewInfo(handle, gameViewWidth, gameViewHeight)
|
||||
return
|
||||
}
|
||||
|
||||
//如果遊戲View未加載完成,則監聽加載完成時回調
|
||||
container.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
container.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
val width = container.measuredWidth
|
||||
val height = container.measuredHeight
|
||||
notifyGameViewInfo(handle, width, height)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onGetGameCfg(handle: ISudFSMStateHandle?, p1: String?) {
|
||||
handle?.success(gson.toJson(GameCfg()))
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知遊戲,遊戲視圖信息
|
||||
* @param handle
|
||||
* @param gameViewWidth
|
||||
* @param gameViewHeight
|
||||
*/
|
||||
private fun notifyGameViewInfo(
|
||||
handle: ISudFSMStateHandle,
|
||||
gameViewWidth: Int,
|
||||
gameViewHeight: Int
|
||||
) {
|
||||
try {
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("ret_code", 0)
|
||||
jsonObject.put("ret_msg", "success")
|
||||
|
||||
//遊戲View大小
|
||||
val viewSize = JSONObject()
|
||||
viewSize.put("width", gameViewWidth)
|
||||
viewSize.put("height", gameViewHeight)
|
||||
jsonObject.put("view_size", viewSize)
|
||||
|
||||
//遊戲安全操作區域
|
||||
val viewGameRect = JSONObject()
|
||||
viewGameRect.put("left", 0)
|
||||
viewGameRect.put("top", container.context.resources.getDimensionPixelOffset(R.dimen.dp_180))
|
||||
viewGameRect.put("right", 0)
|
||||
viewGameRect.put("bottom", container.context.resources.getDimensionPixelOffset(R.dimen.dp_150))
|
||||
jsonObject.put("view_game_rect", viewGameRect)
|
||||
|
||||
//通知遊戲
|
||||
val json = jsonObject.toString()
|
||||
Log.d(TAG, "notifyGameViewInfo:$json")
|
||||
handle.success(json)
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 遊戲狀態變化
|
||||
* @param handle
|
||||
* @param state 狀態名
|
||||
* @param dataJson 狀態數據,json字符串
|
||||
*/
|
||||
override fun onGameStateChange(
|
||||
handle: ISudFSMStateHandle,
|
||||
state: String,
|
||||
dataJson: String
|
||||
) {
|
||||
Log.d(TAG, "onGameStateChange state:$state--dataJson:$dataJson")
|
||||
when (state) {
|
||||
//SudMGPMGState.MG_COMMON_PUBLIC_MESSAGE -> showToast("遊戲:公屏消息")
|
||||
SudMGPMGState.MG_COMMON_KEY_WORD_TO_HIT -> {
|
||||
if (TextUtils.isEmpty(dataJson)) {
|
||||
setKeyWord(null)
|
||||
} else {
|
||||
try {
|
||||
val jsonObject = JSONObject(dataJson)
|
||||
if (jsonObject.isNull("word")) {
|
||||
setKeyWord(null)
|
||||
} else {
|
||||
val keyWord = jsonObject.getString("word")
|
||||
setKeyWord(keyWord)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
SudMGPMGState.APP_COMMON_SELF_CLICK_JOIN_BTN -> {
|
||||
|
||||
try {
|
||||
val jsonObject = JSONObject(dataJson)
|
||||
val seatIndex = jsonObject.optInt("seatIndex", -1)
|
||||
updateMyMicQueue(GameStatus.STATUS_NOT_READY, true, seatIndex)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
SudMGPMGState.APP_COMMON_SELF_CLICK_START_BTN -> {
|
||||
notifySelfPlayingState(true)
|
||||
}
|
||||
SudMGPMGState.MG_COMMON_GAME_STATE -> handleGameState(dataJson)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家狀態變化
|
||||
* @param handle
|
||||
* @param userId 玩家用戶ID
|
||||
* @param state 狀態名
|
||||
* @param dataJson 狀態數據,json字符串。參考文檔
|
||||
*/
|
||||
override fun onPlayerStateChange(
|
||||
handle: ISudFSMStateHandle,
|
||||
userId: String,
|
||||
state: String,
|
||||
dataJson: String
|
||||
) {
|
||||
Log.d(TAG, "onPlayerStateChange userId:$userId--state:$state--dataJson:$dataJson")
|
||||
when (state) {
|
||||
SudMGPMGState.MG_COMMON_PLAYER_IN -> handlePlayerIn(userId, dataJson)
|
||||
SudMGPMGState.MG_COMMON_PLAYER_READY -> handlePlayerReady(userId, dataJson)
|
||||
SudMGPMGState.MG_COMMON_PLAYER_CAPTAIN -> handlePlayerCaptain(dataJson)
|
||||
SudMGPMGState.MG_COMMON_PLAYER_PLAYING -> handlePlayerPlaying(userId, dataJson)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlePlayerIn(userId: String, dataJson: String) {
|
||||
if (userId != mUid) return
|
||||
try {
|
||||
val jsonObject = JSONObject(dataJson)
|
||||
val retCode = jsonObject.getInt("retCode")
|
||||
val isIn = jsonObject.getBoolean("isIn")
|
||||
if (retCode != 0) {
|
||||
return
|
||||
}
|
||||
if (isIn) { // 已加入
|
||||
if (AvRoomDataManager.get().isRoomOwner) {
|
||||
notifySelfCaptainState(mUid)
|
||||
}
|
||||
} else { // 未加入
|
||||
var reason = 0
|
||||
if (jsonObject.has("reason")) {
|
||||
reason = jsonObject.getInt("reason")
|
||||
}
|
||||
if (reason == 0) {
|
||||
updateMyMicQueue(GameStatus.STATUS_NOT_JOIN)
|
||||
} else if (reason == 1) {
|
||||
updateMyMicQueue(GameStatus.STATUS_NOT_JOIN)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateMyMicQueue(gameStatus: Int, isJoin: Boolean = false, seatIndex: Int = -1) {
|
||||
UserModel.get().cacheLoginUserInfo?.gameStatus = gameStatus
|
||||
val position = AvRoomDataManager.get().getMicPosition(mUid)
|
||||
if (position != AvRoomDataManager.POSITON_NOT_ON_MIC) {
|
||||
if (isJoin) notifySelfInState(true, seatIndex)
|
||||
homePartyModel.updateMyMicQueue(
|
||||
position,
|
||||
AvRoomDataManager.get().roomId.toString(),
|
||||
UserModel.get().cacheLoginUserInfo
|
||||
).subscribe()
|
||||
} else if (isJoin) {
|
||||
val upPosition = AvRoomDataManager.get().findGamePosition()
|
||||
if (upPosition == Int.MIN_VALUE) {
|
||||
showToast("當前遊戲人數已滿!")
|
||||
} else {
|
||||
UserModel.get().cacheLoginUserInfo?.gameStatus = 1
|
||||
homePartyModel.upMicroPhone(upPosition,
|
||||
mUid,
|
||||
AvRoomDataManager.get().roomId.toString(),
|
||||
false, object : CallBack<String> {
|
||||
override fun onSuccess(data: String?) {
|
||||
notifySelfInState(true, seatIndex)
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, error: String?) {
|
||||
showToast(error)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlePlayerReady(userId: String, dataJson: String) {
|
||||
if (userId != mUid) return
|
||||
try {
|
||||
val jsonObject = JSONObject(dataJson)
|
||||
val retCode = jsonObject.getInt("retCode")
|
||||
val isReady = jsonObject.getBoolean("isReady")
|
||||
if (retCode != 0) {
|
||||
return
|
||||
}
|
||||
updateMyMicQueue(if (isReady) GameStatus.STATUS_READY else GameStatus.STATUS_NOT_READY)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlePlayerCaptain(dataJson: String) {
|
||||
try {
|
||||
val jsonObject = JSONObject(dataJson)
|
||||
val retCode = jsonObject.getInt("retCode")
|
||||
if (retCode != 0) {
|
||||
return
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleGameState(dataJson: String) {
|
||||
try {
|
||||
val jsonObject = JSONObject(dataJson)
|
||||
val gameState = jsonObject.getInt("gameState")
|
||||
if (gameState == 0) {
|
||||
onGameStatusChangeListener?.onGameEnd()
|
||||
} else if (gameState == 2) {
|
||||
onGameStatusChangeListener?.onGameStart()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlePlayerPlaying(userId: String, dataJson: String) {
|
||||
if (userId != mUid) return
|
||||
try {
|
||||
val jsonObject = JSONObject(dataJson)
|
||||
val retCode = jsonObject.getInt("retCode")
|
||||
if (retCode != 0) {
|
||||
return
|
||||
}
|
||||
val isPlaying = jsonObject.getBoolean("isPlaying")
|
||||
if (isPlaying) {
|
||||
updateMyMicQueue(GameStatus.STATUS_PLAYING)
|
||||
} else {
|
||||
updateMyMicQueue(GameStatus.STATUS_NOT_READY)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifySelfInState(isIn: Boolean, seatIndex: Int = -1) {
|
||||
try {
|
||||
if (!isIn) {
|
||||
notifySelfReadyState(false)
|
||||
}
|
||||
//狀態名稱
|
||||
val state = SudMGPAPPState.APP_COMMON_SELF_IN
|
||||
//狀態數據
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("isIn", isIn) // true 加入遊戲,false 退出遊戲
|
||||
if (seatIndex != -1) {
|
||||
jsonObject.put("seatIndex", seatIndex)
|
||||
}
|
||||
jsonObject.put("teamId", 1) //哪一隊伍(2v2,4v4)
|
||||
val dataJson = jsonObject.toString()
|
||||
|
||||
//調用接口
|
||||
iSudFSTAPP?.notifyStateChange(state, dataJson, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifySelfReadyState(isReady: Boolean) {
|
||||
try {
|
||||
//狀態名稱
|
||||
val state = SudMGPAPPState.APP_COMMON_SELF_READY
|
||||
|
||||
//狀態數據
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("isReady", isReady) // true 準備,false 取消準備
|
||||
val dataJson = jsonObject.toString()
|
||||
|
||||
//調用接口
|
||||
iSudFSTAPP?.notifyStateChange(state, dataJson, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifySelfPlayingState(isPlaying: Boolean) {
|
||||
try {
|
||||
//狀態名稱
|
||||
val state = SudMGPAPPState.APP_COMMON_SELF_PLAYING
|
||||
|
||||
//狀態數據
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("isPlaying", isPlaying) // true 開始遊戲,false 結束遊戲
|
||||
val dataJson = jsonObject.toString()
|
||||
|
||||
//調用接口
|
||||
iSudFSTAPP?.notifyStateChange(state, dataJson, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifySelfCaptainState(uid: String) {
|
||||
try {
|
||||
//狀態名稱
|
||||
val state = SudMGPAPPState.APP_COMMON_SELF_CAPTAIN
|
||||
|
||||
//狀態數據
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("curCaptainUID", uid) // 必填,指定隊長uid
|
||||
val dataJson = jsonObject.toString()
|
||||
|
||||
//調用接口
|
||||
iSudFSTAPP?.notifyStateChange(state, dataJson, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifySelfKickState(uid: String) {
|
||||
try {
|
||||
//狀態名稱
|
||||
val state = SudMGPAPPState.APP_COMMON_SELF_KICK
|
||||
|
||||
//狀態數據
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("kickedUID", uid) // 被踢用戶uid
|
||||
val dataJson = jsonObject.toString()
|
||||
|
||||
//調用接口
|
||||
iSudFSTAPP?.notifyStateChange(state, dataJson, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifySelfEndState() {
|
||||
try {
|
||||
//狀態名稱
|
||||
val state = SudMGPAPPState.APP_COMMON_SELF_END
|
||||
|
||||
//狀態數據
|
||||
val jsonObject = JSONObject()
|
||||
val dataJson = jsonObject.toString()
|
||||
|
||||
//調用接口
|
||||
iSudFSTAPP?.notifyStateChange(state, dataJson, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun onStart() {
|
||||
iSudFSTAPP?.startMG() //啟動遊戲
|
||||
}
|
||||
|
||||
fun onResume() {
|
||||
iSudFSTAPP?.playMG() //開始遊戲
|
||||
}
|
||||
|
||||
fun onPause() {
|
||||
iSudFSTAPP?.pauseMG() //暫停遊戲
|
||||
}
|
||||
|
||||
fun onStop() {
|
||||
iSudFSTAPP?.stopMG() //停止遊戲
|
||||
}
|
||||
|
||||
fun onDestroy() {
|
||||
updateMyMicQueue(GameStatus.STATUS_NOT_JOIN)
|
||||
iSudFSTAPP?.destroyMG()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal interface AppLoginListener {
|
||||
/**
|
||||
* App Server 登陸失敗, App Server 不能返回CODE
|
||||
*/
|
||||
fun onLoginFailure(err: String?)
|
||||
|
||||
/**
|
||||
* App Server 登陸成功, App Server調用服務端接入SDK的API獲取Code 返回給 App
|
||||
* App 就要用CODE和自己生成的UserID去調用SDK的初始化函數,登陸小遊戲
|
||||
* 小遊戲登陸成功後,其UserID,就是App傳的UserID
|
||||
*/
|
||||
fun onLoginSuccess(new_code: String, expire_Date: Long)
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.chwl.app.avroom.game
|
||||
|
||||
interface OnGameStatusChangeListener {
|
||||
/**
|
||||
* 游戏开始
|
||||
*/
|
||||
fun onGameStart()
|
||||
|
||||
/**
|
||||
* 游戏结束
|
||||
*/
|
||||
fun onGameEnd()
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright © Sud.Tech
|
||||
https://sud.tech
|
||||
*/
|
||||
package com.chwl.app.avroom.game;
|
||||
|
||||
/**
|
||||
* Time:2021/10/19
|
||||
* Description: APP to MG 的状态定义
|
||||
*/
|
||||
public class SudMGPAPPState {
|
||||
|
||||
// region 通用状态
|
||||
|
||||
/**
|
||||
* 加入状态
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_IN = "app_common_self_in";
|
||||
|
||||
/**
|
||||
* 准备状态
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_READY = "app_common_self_ready";
|
||||
|
||||
/**
|
||||
* 游戏状态
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_PLAYING = "app_common_self_playing";
|
||||
|
||||
/**
|
||||
* 队长状态
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_CAPTAIN = "app_common_self_captain";
|
||||
|
||||
/**
|
||||
* 踢人
|
||||
* v1.1.30.xx
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_KICK = "app_common_self_kick";
|
||||
|
||||
/**
|
||||
* 结束游戏
|
||||
* v1.1.30.xx
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_END = "app_common_self_end";
|
||||
|
||||
/**
|
||||
* 麦克风状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_MICROPHONE = "app_common_self_microphone";
|
||||
|
||||
/**
|
||||
* 文字命中状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_TEXT_HIT = "app_common_self_text_hit";
|
||||
|
||||
}
|
125
app/src/main/java/com/chwl/app/avroom/game/SudMGPMGState.java
Normal file
125
app/src/main/java/com/chwl/app/avroom/game/SudMGPMGState.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
Copyright © Sud.Tech
|
||||
https://sud.tech
|
||||
*/
|
||||
package com.chwl.app.avroom.game;
|
||||
|
||||
/**
|
||||
* Time:2021/10/19
|
||||
* Description: MG to APP 的状态定义
|
||||
*/
|
||||
public class SudMGPMGState {
|
||||
|
||||
// region 通用状态-游戏
|
||||
|
||||
/**
|
||||
* 公屏消息 (已修改)
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String MG_COMMON_PUBLIC_MESSAGE = "mg_common_public_message";
|
||||
|
||||
/**
|
||||
* 关键词状态
|
||||
*/
|
||||
public static final String MG_COMMON_KEY_WORD_TO_HIT = "mg_common_key_word_to_hit";
|
||||
|
||||
// endregion 通用状态-游戏
|
||||
|
||||
|
||||
// region 通用状态-玩家
|
||||
|
||||
/**
|
||||
* 加入状态 (已修改)
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String MG_COMMON_PLAYER_IN = "mg_common_player_in";
|
||||
|
||||
/**
|
||||
* 准备状态 (已修改)
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String MG_COMMON_PLAYER_READY = "mg_common_player_ready";
|
||||
|
||||
/**
|
||||
* 队长状态 (已修改)
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String MG_COMMON_PLAYER_CAPTAIN = "mg_common_player_captain";
|
||||
|
||||
/**
|
||||
* 游戏状态 (已修改)
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String MG_COMMON_PLAYER_PLAYING = "mg_common_player_playing";
|
||||
|
||||
/**
|
||||
* 游戏状态(已修改)
|
||||
* 最低版本: v1.1.30.xx
|
||||
*/
|
||||
public static final String MG_COMMON_GAME_STATE = "mg_common_game_state";
|
||||
|
||||
// endregion 通用状态-玩家
|
||||
|
||||
|
||||
// region 碰碰我最强
|
||||
// endregion 碰碰我最强
|
||||
|
||||
// region 飞刀达人
|
||||
// endregion 飞刀达人
|
||||
|
||||
// region 你画我猜
|
||||
|
||||
/**
|
||||
* 选词中
|
||||
*/
|
||||
public static final String MG_DG_SELECTING = "mg_dg_selecting";
|
||||
|
||||
/**
|
||||
* 作画中
|
||||
*/
|
||||
public static final String MG_DG_PAINTING = "mg_dg_painting";
|
||||
|
||||
/**
|
||||
* 错误答案
|
||||
*/
|
||||
public static final String MG_DG_ERRORANSWER = "mg_dg_erroranswer";
|
||||
|
||||
/**
|
||||
* 总积分
|
||||
*/
|
||||
public static final String MG_DG_TOTALSCORE = "mg_dg_totalscore";
|
||||
|
||||
/**
|
||||
* 本次积分
|
||||
*/
|
||||
public static final String MG_DG_SCORE = "mg_dg_score";
|
||||
|
||||
// endregion 你画我猜
|
||||
|
||||
|
||||
/**
|
||||
* 加入游戏按钮点击状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_CLICK_JOIN_BTN = "mg_common_self_click_join_btn";
|
||||
/**
|
||||
* 取消加入游戏按钮点击状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_CLICK_CANCEL_JOIN_BTN = "mg_common_self_click_cancel_join_btn";
|
||||
/**
|
||||
* 准备按钮点击状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_CLICK_READY_BTN = "mg_common_self_click_ready_btn";
|
||||
/**
|
||||
* 取消准备按钮点击状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_CLICK_CANCEL_READY_BTN = "mg_common_self_click_cancel_ready_btn";
|
||||
/**
|
||||
* 开始游戏按钮点击状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_CLICK_START_BTN = "mg_common_self_click_start_btn";
|
||||
/**
|
||||
* 分享按钮点击状态
|
||||
*/
|
||||
public static final String APP_COMMON_SELF_CLICK_SHARE_BTN = "mg_common_self_click_share_btn";
|
||||
|
||||
}
|
@@ -19,13 +19,13 @@ class HomeViewModel : BaseViewModel() {
|
||||
//
|
||||
private val _bannerLiveData = MutableLiveData<List<BannerInfo>?>()
|
||||
val bannerLiveData: MutableLiveData<List<BannerInfo>?> = _bannerLiveData
|
||||
//
|
||||
// private val _currentResourceLiveData = MutableLiveData<List<CurrentResourceInfo>?>()
|
||||
// val currentResourceLiveData: MutableLiveData<List<CurrentResourceInfo>?> = _currentResourceLiveData
|
||||
//
|
||||
// private val _resourceJumpLiveData = MutableLiveData<HomeRoomInfo?>()
|
||||
// val resourceJumpLiveData: LiveData<HomeRoomInfo?> = _resourceJumpLiveData
|
||||
//
|
||||
|
||||
private val _currentResourceLiveData = MutableLiveData<List<CurrentResourceInfo>?>()
|
||||
val currentResourceLiveData: MutableLiveData<List<CurrentResourceInfo>?> = _currentResourceLiveData
|
||||
|
||||
private val _resourceJumpLiveData = MutableLiveData<HomeRoomInfo?>()
|
||||
val resourceJumpLiveData: LiveData<HomeRoomInfo?> = _resourceJumpLiveData
|
||||
|
||||
// private val _homeChatPickLiveData = MutableLiveData<String?>()
|
||||
// val homeChatPickLiveData: LiveData<String?> = _homeChatPickLiveData
|
||||
|
||||
@@ -73,31 +73,31 @@ class HomeViewModel : BaseViewModel() {
|
||||
// )
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 首页改版资源位
|
||||
// */
|
||||
// fun getCurrentResourceInfo() {
|
||||
// safeLaunch(
|
||||
// onError = {
|
||||
// _currentResourceLiveData.value = null
|
||||
// },
|
||||
// block = {
|
||||
// _currentResourceLiveData.value = HomeModel.getCurrentResource()
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
/**
|
||||
* 首页改版资源位
|
||||
*/
|
||||
fun getCurrentResourceInfo() {
|
||||
safeLaunch(
|
||||
onError = {
|
||||
_currentResourceLiveData.value = null
|
||||
},
|
||||
block = {
|
||||
_currentResourceLiveData.value = HomeModel.getCurrentResource()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// fun getResourceJumpInfo(id: Int) {
|
||||
// safeLaunch(
|
||||
// onError = {
|
||||
// _resourceJumpLiveData.value = null
|
||||
// it.message.toast()
|
||||
// },
|
||||
// block = {
|
||||
// _resourceJumpLiveData.value = HomeModel.getResourceJumpInfo(id)
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
fun getResourceJumpInfo(id: Int) {
|
||||
safeLaunch(
|
||||
onError = {
|
||||
_resourceJumpLiveData.value = null
|
||||
it.message.toast()
|
||||
},
|
||||
block = {
|
||||
_resourceJumpLiveData.value = HomeModel.getResourceJumpInfo(id)
|
||||
}
|
||||
)
|
||||
}
|
||||
//
|
||||
// fun getHomeChatPick() {
|
||||
// safeLaunch(
|
||||
|
@@ -1,15 +1,19 @@
|
||||
package com.chwl.app.home.fragment
|
||||
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.application.IReportConstants
|
||||
import com.chwl.app.application.ReportManager
|
||||
import com.chwl.app.avroom.activity.AVRoomActivity
|
||||
import com.chwl.app.base.BaseViewBindingFragment
|
||||
import com.chwl.app.databinding.FragmentHomeBinding
|
||||
import com.chwl.app.home.HomeViewModel
|
||||
import com.chwl.app.home.adapter.HomeBannerAdapter
|
||||
import com.chwl.app.home.dialog.RecommendRoomDialog
|
||||
import com.chwl.app.ui.search.SearchActivity
|
||||
import com.chwl.app.ui.utils.load
|
||||
import com.chwl.app.ui.webview.CommonWebViewActivity
|
||||
import com.chwl.app.ui.widget.magicindicator.buildins.UIUtil
|
||||
import com.chwl.app.utils.CommonJumpHelper
|
||||
@@ -32,6 +36,49 @@ class HomeFragment : BaseViewBindingFragment<FragmentHomeBinding>(), View.OnClic
|
||||
initBanner()
|
||||
childFragmentManager.beginTransaction()
|
||||
.replace(R.id.frameLayout, RecommendFragment(), "RECOMMEND").commitAllowingStateLoss()
|
||||
|
||||
homeViewModel.currentResourceLiveData.observe(this) {
|
||||
it?.let {
|
||||
val resourceViews = arrayOf(
|
||||
binding.ivResource0,
|
||||
binding.ivResource1
|
||||
)
|
||||
if (it.size != 2) {
|
||||
resourceViews.forEach {
|
||||
it.isVisible = false
|
||||
}
|
||||
return@observe
|
||||
}
|
||||
resourceViews.forEach {
|
||||
it.isVisible = true
|
||||
}
|
||||
for (i in resourceViews.indices) {
|
||||
resourceViews[i].load(it[i].icon)
|
||||
resourceViews[i].setOnClickListener { _ ->
|
||||
when {
|
||||
it[i].resourceType == 5 -> {
|
||||
CommonWebViewActivity.start(context, it[i].resourceContent)
|
||||
}
|
||||
else -> {
|
||||
dialogManager.showProgressDialog(mContext)
|
||||
homeViewModel.getResourceJumpInfo(it[i].id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
homeViewModel.resourceJumpLiveData.observe(this) {
|
||||
dialogManager.dismissDialog()
|
||||
it?.let {
|
||||
if (it.isPick) {
|
||||
AVRoomActivity.start(context, it.uid)
|
||||
} else {
|
||||
RecommendRoomDialog.newInstance(it).show(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
homeViewModel.getCurrentResourceInfo()
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
|
@@ -0,0 +1,48 @@
|
||||
package com.chwl.app.ui.webview.room_game
|
||||
|
||||
import android.webkit.JavascriptInterface
|
||||
import androidx.annotation.Keep
|
||||
import com.chwl.app.ui.pay.ChargeActivity
|
||||
import com.example.lib_utils.log.ILog
|
||||
import org.json.JSONObject
|
||||
|
||||
@Keep
|
||||
class RoomGameJSBridge(val activity: RoomGameWebDialogActivity) : ILog {
|
||||
|
||||
@JavascriptInterface
|
||||
public fun getConfig(params: String) {
|
||||
logD("getConfig()")
|
||||
try {
|
||||
val obj = JSONObject(params)
|
||||
callJs("")
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public fun destroy(params: String) {
|
||||
logD("游戏调⽤destroy")
|
||||
activity.runOnUiThread {
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public fun gameRecharge(params: String) {
|
||||
logD("游戏调⽤gameRecharge")
|
||||
activity.runOnUiThread {
|
||||
ChargeActivity.start(activity)
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public fun gameLoaded(params: String) {
|
||||
logD("游戏调⽤gameLoaded")
|
||||
//游戏加载完毕
|
||||
}
|
||||
|
||||
private fun callJs(str: String) {
|
||||
activity.callJs(str)
|
||||
}
|
||||
}
|
@@ -0,0 +1,123 @@
|
||||
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)
|
||||
}
|
||||
}
|
@@ -34,27 +34,40 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<LinearLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_40"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_44"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Space
|
||||
android:id="@+id/space_title_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_40"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_back"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/arrow_left_white" />
|
||||
android:src="@drawable/arrow_left_white"
|
||||
app:layout_constraintBottom_toBottomOf="@id/space_title_bar"
|
||||
app:layout_constraintStart_toStartOf="@id/space_title_bar"
|
||||
app:layout_constraintTop_toTopOf="@id/space_title_bar" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_room_info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_5"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="@id/space_title_bar"
|
||||
app:layout_constraintStart_toEndOf="@id/iv_back"
|
||||
app:layout_constraintTop_toTopOf="@id/space_title_bar">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_title"
|
||||
@@ -122,17 +135,74 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_change_game"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:background="@drawable/bg_room_select_game"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toStartOf="@id/barrier_title_bar_right_menu_start"
|
||||
app:layout_constraintTop_toTopOf="@id/space_title_bar"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_select_game"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_curr_game"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:includeFontPadding="true"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="15sp"
|
||||
tools:text="@string/layout_fragment_chatroom_game_main_04" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_change_game_arrow"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="10dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_room_arrow_type_below" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_game"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="4dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/barrier_title_bar_right_menu_start"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="start"
|
||||
app:constraint_referenced_ids="iv_follow_room,room_more" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_follow_room"
|
||||
android:layout_width="@dimen/dp_32"
|
||||
android:layout_height="@dimen/dp_32"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/room_ic_collect_no" />
|
||||
android:src="@drawable/room_ic_collect_no"
|
||||
app:layout_constraintBottom_toBottomOf="@id/space_title_bar"
|
||||
app:layout_constraintEnd_toStartOf="@id/room_more"
|
||||
app:layout_constraintTop_toTopOf="@id/space_title_bar" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/room_more"
|
||||
@@ -140,9 +210,12 @@
|
||||
android:layout_height="@dimen/dp_32"
|
||||
android:layout_marginEnd="@dimen/dp_10"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/room_ic_more" />
|
||||
android:src="@drawable/room_ic_more"
|
||||
app:layout_constraintBottom_toBottomOf="@id/space_title_bar"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/space_title_bar" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/vs_gift_view"
|
||||
|
144
app/src/main/res/layout/fragment_game_room.xml
Normal file
144
app/src/main/res/layout/fragment_game_room.xml
Normal file
@@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout 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"
|
||||
tools:context="com.yizhuan.erban.avroom.fragment.HomePartyRoomFragment">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="click"
|
||||
type="android.view.View.OnClickListener" />
|
||||
|
||||
<variable
|
||||
name="roomInfo"
|
||||
type="com.chwl.core.room.bean.RoomInfo" />
|
||||
|
||||
<variable
|
||||
name="ktvModel"
|
||||
type="Boolean" />
|
||||
|
||||
<import type="android.view.View" />
|
||||
</data>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fl_game_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="75dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_show_mini_mic"
|
||||
android:layout_width="26dp"
|
||||
android:layout_height="23dp"
|
||||
android:layout_gravity="end"
|
||||
android:background="@drawable/bg_mini_mic_entrance"
|
||||
android:drawableStart="@drawable/ic_room_mic_right"
|
||||
android:gravity="center"
|
||||
android:paddingEnd="3dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_mic_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:gravity="end|center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_show_mic"
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="22dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:rotation="180"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_room_mic_right"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.chwl.app.avroom.widget.MicroView
|
||||
android:id="@+id/micro_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<com.chwl.app.avroom.widget.BottomView
|
||||
android:id="@+id/bottom_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
tools:layout_height="@dimen/dp_52" />
|
||||
|
||||
<com.chwl.app.avroom.widget.MessageView
|
||||
android:id="@+id/message_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_above="@id/bottom_view"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="@dimen/dp_5"
|
||||
android:layout_marginEnd="90dp"
|
||||
android:layout_marginBottom="@dimen/dp_10" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:background="@android:color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/input_edit"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/white"
|
||||
android:hint="@string/layout_fragment_game_room_02"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:textColor="#888889"
|
||||
android:textColorHint="#c8c8c8"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/input_send"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@drawable/click_white_gray_selector"
|
||||
android:scaleType="center"
|
||||
android:src="@android:drawable/ic_menu_send" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.chwl.app.vip.VipBroadcastView
|
||||
android:id="@+id/vip_broadcast_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="75dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
||||
</layout>
|
@@ -95,12 +95,46 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
android:id="@+id/iv_resource0"
|
||||
android:layout_width="@dimen/dp_0"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="@dimen/dp_14"
|
||||
android:layout_marginTop="@dimen/dp_16"
|
||||
android:scaleType="centerCrop"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintDimensionRatio="170:82"
|
||||
app:layout_constraintEnd_toStartOf="@+id/iv_resource1"
|
||||
app:layout_constraintHorizontal_weight="1"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:riv_corner_radius="@dimen/dp_4"
|
||||
tools:src="@drawable/default_banner"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
android:id="@+id/iv_resource1"
|
||||
android:layout_width="@dimen/dp_0"
|
||||
android:layout_height="@dimen/dp_0"
|
||||
android:layout_marginStart="@dimen/dp_10"
|
||||
android:layout_marginEnd="@dimen/dp_14"
|
||||
android:scaleType="centerCrop"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintDimensionRatio="170:82"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_weight="1"
|
||||
app:layout_constraintStart_toEndOf="@+id/iv_resource0"
|
||||
app:layout_constraintTop_toTopOf="@id/iv_resource0"
|
||||
app:riv_corner_radius="@dimen/dp_4"
|
||||
tools:src="@drawable/default_banner"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.zhpan.bannerview.BannerViewPager
|
||||
android:id="@+id/banner_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginHorizontal="@dimen/dp_12"
|
||||
android:layout_marginTop="@dimen/dp_16"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:background="@drawable/base_shape_negative_5dp"
|
||||
android:visibility="gone"
|
||||
app:bvp_auto_play="true"
|
||||
@@ -111,7 +145,8 @@
|
||||
app:bvp_indicator_visibility="visible"
|
||||
app:bvp_page_style="multi_page_scale"
|
||||
app:layout_constraintDimensionRatio="351:80"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/iv_resource0"
|
||||
app:layout_goneMarginTop="@dimen/dp_16"
|
||||
tools:visibility="visible" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
10
app/src/main/res/layout/room_game_activity.xml
Normal file
10
app/src/main/res/layout/room_game_activity.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -5263,4 +5263,6 @@
|
||||
<string name="send_gift_vip_level_tips">أنت لم تصل إلى المستوى الـ VIP المطلوب لإرسال %1$s. المستوى الـ VIP المطلوب: %2$s</string>
|
||||
<string name="exception_try_again">حدثت بعض الاستثناءات، يرجى المحاولة مرة أخرى لاحقًا!</string>
|
||||
<string name="permission_mic_tips">يرجى السماح بإذن الميكروفون والمحاولة مرة أخرى</string>
|
||||
|
||||
<string name="game_failed_tips">فشل تهيئة دليل تطوير الألعاب:%s</string>
|
||||
</resources>
|
@@ -5204,4 +5204,7 @@
|
||||
<string name="gift_message_07">{0}運氣爆表!在{1}中開出了價值{2}金币的{3}</string>
|
||||
<string name="gift_message_08">{0}運氣爆表!在{1}中開出了價值{2}金币的{3}X{4}</string>
|
||||
<string name="exception_try_again">發生一些異常,請稍後重試!</string>
|
||||
|
||||
|
||||
<string name="game_failed_tips">初始化遊戲SDK失敗:%s</string>
|
||||
</resources>
|
@@ -5243,6 +5243,9 @@
|
||||
|
||||
<string name="exception_try_again">Some exceptions occurred, please try again later!</string>
|
||||
<string name="permission_mic_tips">Please allow microphone permission and try again</string>
|
||||
|
||||
|
||||
<string name="game_failed_tips">Failed to initialize game SDK:%s</string>
|
||||
</resources>
|
||||
|
||||
|
||||
|
@@ -158,6 +158,17 @@ object HomeModel : BaseModel() {
|
||||
api.getStarUserList(pageNum, pageSize)
|
||||
}
|
||||
|
||||
//首页改版资源位
|
||||
suspend fun getCurrentResource(): List<CurrentResourceInfo>? =
|
||||
launchRequest {
|
||||
api.getCurrentResource()
|
||||
}
|
||||
|
||||
suspend fun getResourceJumpInfo(id: Int): HomeRoomInfo? =
|
||||
launchRequest {
|
||||
api.getResourceJumpInfo(id)
|
||||
}
|
||||
|
||||
private interface Api {
|
||||
/**
|
||||
* 提交反馈
|
||||
@@ -322,6 +333,22 @@ object HomeModel : BaseModel() {
|
||||
@Query("pageNum") pageNum: Int,
|
||||
@Query("pageSize") pageSize: Int
|
||||
): ServiceResult<List<StarUser>>
|
||||
|
||||
/**
|
||||
* 首页改版资源位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET("/home/currentResource")
|
||||
suspend fun getCurrentResource(): ServiceResult<List<CurrentResourceInfo>>
|
||||
|
||||
/**
|
||||
* 首页资源位跳转
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET("/home/pickResource")
|
||||
suspend fun getResourceJumpInfo(@Query("id") id: Int): ServiceResult<HomeRoomInfo>
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user