Skip to content

Commit

Permalink
Hide chat screen UI if in split screen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed May 19, 2024
1 parent 10c841c commit dd378e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.livetl.android.ui.screen.player.PlayerViewModel
import com.livetl.android.util.collectAsStateWithLifecycle
import com.livetl.android.util.findActivity
import com.livetl.android.util.rememberIsInPipMode
import com.livetl.android.util.rememberIsInSplitScreenMode
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.launch

Expand All @@ -64,11 +65,12 @@ fun PlayerTabs(
viewModel: PlayerViewModel = viewModel(),
) {
val isInPipMode = rememberIsInPipMode()
val isInSplitScreenMode = rememberIsInSplitScreenMode()

val tlScale by viewModel.prefs.tlScale().collectAsStateWithLifecycle()
val filteredMessages by viewModel.filteredMessages.collectAsStateWithLifecycle()

if (isInPipMode) {
if (isInPipMode || isInSplitScreenMode) {
ChatTab(
filteredMessages = filteredMessages,
fontScale = tlScale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.livetl.android.ui.common.LoadingIndicator
import com.livetl.android.ui.screen.player.ChatState
import com.livetl.android.ui.screen.player.PlayerViewModel
import com.livetl.android.util.rememberIsInPipMode
import com.livetl.android.util.rememberIsInSplitScreenMode
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.launch
Expand All @@ -38,6 +39,7 @@ fun Chat(
) {
val scope = rememberCoroutineScope()
val isInPipMode = rememberIsInPipMode()
val isInSplitScreenMode = rememberIsInSplitScreenMode()

val scrollState = rememberLazyListState()
var isScrolledToBottom by remember { mutableStateOf(true) }
Expand Down Expand Up @@ -65,7 +67,7 @@ fun Chat(
checkIfAtBottom()
_messages = messages

scrollToBottom(force = isInPipMode)
scrollToBottom(force = isInPipMode || isInSplitScreenMode)
}

when (state) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/livetl/android/util/ContextExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.core.app.MultiWindowModeChangedInfo
import androidx.core.app.PictureInPictureModeChangedInfo
import androidx.core.util.Consumer
import com.livetl.android.R
Expand Down Expand Up @@ -91,3 +92,19 @@ fun rememberIsInPipMode(): Boolean = if (Build.VERSION.SDK_INT < Build.VERSION_C
}
pipMode
}

@Composable
fun rememberIsInSplitScreenMode(): Boolean {
val activity = LocalContext.current.findActivity()
var splitScreenMode by remember { mutableStateOf(activity.isInMultiWindowMode) }
DisposableEffect(activity) {
val observer = Consumer<MultiWindowModeChangedInfo> { info ->
splitScreenMode = info.isInMultiWindowMode
}
activity.addOnMultiWindowModeChangedListener(
observer,
)
onDispose { activity.removeOnMultiWindowModeChangedListener(observer) }
}
return splitScreenMode
}

0 comments on commit dd378e7

Please sign in to comment.