feat:完善游戏断网重连刷新机制

feat:完善部分UI调整
This commit is contained in:
max
2024-06-03 10:10:29 +08:00
parent 2b0e52ac20
commit 5c262c93c9
30 changed files with 40 additions and 8 deletions

View File

@@ -135,7 +135,7 @@ abstract class BaseGameActivity<T : ViewBinding> : BaseViewBindingActivity<T>(),
is GameInfoUiState.Empty -> {
gameInfoDialogManager?.dismissDialog()
toast(R.string.empty_data)
toast(R.string.game_end_tips)
finish()
}
}

View File

@@ -21,8 +21,13 @@ class GameIMEngineAbility(private val listenerOwner: ListenerOwner<GameIMEngineA
val stateFlow = MutableStateFlow<StatusCode>(StatusCode.INVALID)
// 恢复连接(中断后恢复)
val reconnectedFlow = MutableSharedFlow<Boolean>()
private var chatRoomClient: ChatRoomClient? = null
private var netBrokenTag = false
private val stateAbility: GameStateAbility?
get() = roomContext?.findAbility<GameStateAbility>(
GameStateAbility::class.java.simpleName
@@ -48,10 +53,20 @@ class GameIMEngineAbility(private val listenerOwner: ListenerOwner<GameIMEngineA
}
private fun initClient(sessionId: String) {
netBrokenTag = false
chatRoomClient = ChatRoomClientManager.getClient(sessionId)
chatRoomClient?.let {
safeLaunch {
it.stateFlow.collect {
if (it == StatusCode.NET_BROKEN) {
netBrokenTag = true
}
if (it == StatusCode.LOGINED) {
if (netBrokenTag) {
reconnectedFlow.emit(true)
}
netBrokenTag = false
}
this@GameIMEngineAbility.stateFlow.value = it
}
}

View File

@@ -10,10 +10,13 @@ import com.chwl.core.im.custom.bean.GameForcedEndAttachment
import com.chwl.core.im.custom.bean.GameQueueChangedAttachment
import com.chwl.core.support.room.RoomAbility
import com.chwl.core.support.room.RoomContext
import com.netease.nimlib.sdk.StatusCode
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flatMapConcat
class GameStateAbility : RoomAbility(), GameIMEngineAbility.Listener {
@@ -68,6 +71,11 @@ class GameStateAbility : RoomAbility(), GameIMEngineAbility.Listener {
val imEngineAbility =
context.findAbility<GameIMEngineAbility>(GameIMEngineAbility::class.java.simpleName)
imEngineAbility?.addListener(this)
safeLaunch {
imEngineAbility?.reconnectedFlow?.collectLatest {
requestRoomInfo()
}
}
}
private fun requestRoomInfo() {
@@ -159,8 +167,8 @@ class GameStateAbility : RoomAbility(), GameIMEngineAbility.Listener {
(attachment as? GameForcedEndAttachment)?.msgData ?: return
val results = data.results
safeLaunch {
gameResultFlow.emit(results)
syncGameState(data.matchStatus)
gameResultFlow.emit(results)
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 718 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 729 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -53,17 +53,23 @@
android:layout_marginTop="@dimen/dp_13"
app:layout_constraintTop_toTopOf="@id/space_title_bar" />
<Space
android:id="@+id/space_award_tips_top"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/queue_widget" />
<TextView
android:id="@+id/tv_award_tips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_9"
android:textColor="@color/white"
android:textSize="@dimen/dp_14"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/queue_widget"
app:layout_constraintBottom_toBottomOf="@id/space_award_tips_top"
tools:text="@string/game_award_tips_format"
tools:visibility="visible" />
@@ -72,7 +78,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_21"
android:layout_marginTop="@dimen/dp_22"
android:layout_marginTop="@dimen/dp_5"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_award_tips"
@@ -108,8 +114,9 @@
<com.chwl.app.game.ui.game.widgets.message.GameMessageWidget
android:id="@+id/message_widget"
android:layout_width="0dp"
android:layout_height="@dimen/dp_100"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bottom_widget"
app:layout_constraintDimensionRatio="283:129"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.277"
app:layout_constraintStart_toStartOf="parent"

View File

@@ -22,14 +22,13 @@
android:id="@+id/iv_state"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="-4.5dp"
android:layout_marginEnd="-4.5dp"
android:scaleType="fitCenter"
android:src="@drawable/game_ic_link"
app:layout_constraintBottom_toBottomOf="@id/iv_queue1_border"
app:layout_constraintEnd_toStartOf="@id/iv_queue2_border"
app:layout_constraintStart_toEndOf="@id/iv_queue1_border"
app:layout_constraintTop_toTopOf="@id/iv_queue1_border"
app:layout_constraintWidth_percent="0.242"
tools:src="@drawable/game_ic_vs" />
<com.google.android.material.imageview.ShapeableImageView

View File

@@ -9,4 +9,5 @@
<string name="game_match_failed">匹配失敗,是否重新開始?</string>
<string name="game_rematch">重新匹配</string>
<string name="resume_game_tips">遊戲進行中,是否返回房間?</string>
<string name="game_end_tips">遊戲已結束~</string>
</resources>

View File

@@ -10,4 +10,5 @@
<string name="game_match_failed">匹配失敗,是否重新開始?</string>
<string name="game_rematch">重新匹配</string>
<string name="resume_game_tips">遊戲進行中,是否返回房間?</string>
<string name="game_end_tips">遊戲已結束~</string>
</resources>

View File

@@ -9,4 +9,5 @@
<string name="game_match_failed">匹配失敗,是否重新開始?</string>
<string name="game_rematch">重新匹配</string>
<string name="resume_game_tips">遊戲進行中,是否返回房間?</string>
<string name="game_end_tips">遊戲已結束~</string>
</resources>