From da59c853b40e596efc955adadc92cc1546a212cb Mon Sep 17 00:00:00 2001 From: Umair Date: Fri, 15 Sep 2023 01:00:53 +0200 Subject: [PATCH] BackButton and Skip support added on login page --- .../withToken/DeviceTokenAuthentication.kt | 16 ++++++- .../DeviceTokenAuthenticationContent.kt | 47 +++++++++++++++---- .../player/{Mp3Player.kt => AudioPlayer.kt} | 10 ++-- ...PlayerContent.kt => AudioPlayerContent.kt} | 3 +- .../composetv/navigation/AppNavigation.kt | 10 ++-- 5 files changed, 68 insertions(+), 18 deletions(-) rename app/src/main/java/com/techlads/composetv/features/mp3/player/{Mp3Player.kt => AudioPlayer.kt} (57%) rename app/src/main/java/com/techlads/composetv/features/mp3/player/{Mp3PlayerContent.kt => AudioPlayerContent.kt} (99%) diff --git a/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthentication.kt b/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthentication.kt index b279c95..c913715 100644 --- a/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthentication.kt +++ b/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthentication.kt @@ -5,16 +5,30 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview import com.techlads.composetv.navigation.Screens +import com.techlads.composetv.theme.ComposeTvTheme @Composable fun DeviceTokenAuthenticationScreen( modifier: Modifier = Modifier, + onSkip: () -> Unit, goToScreen: (Screens) -> Unit, ) { Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - DeviceTokenAuthenticationContent(token = "OTF2", "www.google.com") { + DeviceTokenAuthenticationContent(token = "OTF2", "www.google.com", skip = onSkip) { goToScreen(Screens.Login) } } } + + +@Preview +@Composable +private fun DeviceTokenAuthenticationScreenPreview() { + ComposeTvTheme { + DeviceTokenAuthenticationScreen(Modifier.fillMaxSize(), onSkip = {}) { + + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthenticationContent.kt b/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthenticationContent.kt index 5c57ee8..639bccc 100644 --- a/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthenticationContent.kt +++ b/app/src/main/java/com/techlads/composetv/features/login/withToken/DeviceTokenAuthenticationContent.kt @@ -3,9 +3,7 @@ package com.techlads.composetv.features.login.withToken import androidx.compose.foundation.Image -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -15,7 +13,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.material3.Divider import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -27,16 +24,20 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.core.graphics.drawable.toBitmap +import androidx.tv.material3.ButtonDefaults import androidx.tv.material3.ExperimentalTvMaterial3Api +import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import com.github.alexzhirkevich.customqrgenerator.QrData import com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawable import com.github.alexzhirkevich.customqrgenerator.vector.QrVectorOptions import com.github.alexzhirkevich.customqrgenerator.vector.style.QrVectorColor import com.github.alexzhirkevich.customqrgenerator.vector.style.QrVectorColors +import com.techlads.composetv.theme.ComposeTvTheme import com.techlads.composetv.widgets.TvButton @OptIn(ExperimentalTvMaterial3Api::class) @@ -44,7 +45,7 @@ import com.techlads.composetv.widgets.TvButton fun DeviceTokenAuthenticationContent( token: String, url: String, - interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + skip: () -> Unit, onLoginClick: (token: String) -> Unit, ) { val context = LocalContext.current @@ -149,14 +150,14 @@ fun DeviceTokenAuthenticationContent( Spacer(modifier = Modifier.height(50.dp)) - Box( + Row( modifier = Modifier - .width(300.dp) .padding(40.dp, 0.dp, 40.dp, 0.dp), ) { TvButton( - modifier = Modifier.padding(start = 20.dp, end = 20.dp), - interactionSource = interactionSource, + modifier = Modifier + .weight(1f) + .padding(start = 20.dp, end = 20.dp), onClick = { onLoginClick(token) }, ) { Text( @@ -169,6 +170,36 @@ fun DeviceTokenAuthenticationContent( ), ) } + + TvButton( + modifier = Modifier + .weight(1f) + .padding(start = 20.dp, end = 20.dp), + colors = ButtonDefaults.colors( + containerColor = MaterialTheme.colorScheme.surface, + contentColor = MaterialTheme.colorScheme.onSurface, + ), + onClick = { skip() }, + ) { + Text( + modifier = Modifier.fillMaxWidth(), + text = "Skip", + style = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Light, + textAlign = TextAlign.Center, + ), + ) + } } } } + + +@Preview +@Composable +fun DeviceTokenAuthenticationContentPreview() { + ComposeTvTheme { + DeviceTokenAuthenticationContent(token = "OTF2", "www.google.com", skip = {}, onLoginClick = {}) + } +} diff --git a/app/src/main/java/com/techlads/composetv/features/mp3/player/Mp3Player.kt b/app/src/main/java/com/techlads/composetv/features/mp3/player/AudioPlayer.kt similarity index 57% rename from app/src/main/java/com/techlads/composetv/features/mp3/player/Mp3Player.kt rename to app/src/main/java/com/techlads/composetv/features/mp3/player/AudioPlayer.kt index 47a0405..69a753b 100644 --- a/app/src/main/java/com/techlads/composetv/features/mp3/player/Mp3Player.kt +++ b/app/src/main/java/com/techlads/composetv/features/mp3/player/AudioPlayer.kt @@ -1,5 +1,6 @@ package com.techlads.composetv.features.mp3.player +import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -8,12 +9,13 @@ import androidx.compose.ui.tooling.preview.Preview @Composable -fun Mp3PlayerScreen() { - Mp3PlayerScreenContent(modifier = Modifier.fillMaxSize()) +fun AudioPlayerScreen(onBackPressed: () -> Unit) { + BackHandler(onBack = onBackPressed) + AudioPlayerScreenContent(modifier = Modifier.fillMaxSize()) } @Preview(device = Devices.TV_1080p) @Composable -private fun Mp3PlayerScreenPrev() { - Mp3PlayerScreen() +private fun AudioPlayerScreenPrev() { + AudioPlayerScreen {} } \ No newline at end of file diff --git a/app/src/main/java/com/techlads/composetv/features/mp3/player/Mp3PlayerContent.kt b/app/src/main/java/com/techlads/composetv/features/mp3/player/AudioPlayerContent.kt similarity index 99% rename from app/src/main/java/com/techlads/composetv/features/mp3/player/Mp3PlayerContent.kt rename to app/src/main/java/com/techlads/composetv/features/mp3/player/AudioPlayerContent.kt index 0cdb7fd..2d5217c 100644 --- a/app/src/main/java/com/techlads/composetv/features/mp3/player/Mp3PlayerContent.kt +++ b/app/src/main/java/com/techlads/composetv/features/mp3/player/AudioPlayerContent.kt @@ -35,7 +35,7 @@ import com.techlads.composetv.features.player.controls.VideoPlayerControllerIndi import com.techlads.composetv.features.player.controls.rememberVideoPlayerState @Composable -fun Mp3PlayerScreenContent(modifier: Modifier){ +fun AudioPlayerScreenContent(modifier: Modifier){ Box(contentAlignment = Alignment.Center, modifier = modifier.fillMaxSize()) { Column(horizontalAlignment = Alignment.CenterHorizontally) { Poster() @@ -132,7 +132,6 @@ fun SongProgressBar( @Composable fun Details() { - Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.fillMaxWidth()) { Text(text = "Chris Brown - Babie ft. Tyga", style = MaterialTheme.typography.titleLarge) Spacer(modifier = Modifier.size(2.dp)) diff --git a/app/src/main/java/com/techlads/composetv/navigation/AppNavigation.kt b/app/src/main/java/com/techlads/composetv/navigation/AppNavigation.kt index 6704c26..fae47d7 100644 --- a/app/src/main/java/com/techlads/composetv/navigation/AppNavigation.kt +++ b/app/src/main/java/com/techlads/composetv/navigation/AppNavigation.kt @@ -14,7 +14,7 @@ import com.techlads.composetv.features.details.ProductDetailsScreen import com.techlads.composetv.features.home.HomeScreen import com.techlads.composetv.features.login.withEmailPassword.LoginScreen import com.techlads.composetv.features.login.withToken.DeviceTokenAuthenticationScreen -import com.techlads.composetv.features.mp3.player.Mp3PlayerScreen +import com.techlads.composetv.features.mp3.player.AudioPlayerScreen import com.techlads.composetv.features.player.PlayerScreen import com.techlads.composetv.features.wiw.WhoIsWatchingScreen @@ -38,7 +38,9 @@ fun AppNavigation(navController: NavHostController) { enterTransition = { tabEnterTransition() }, exitTransition = { tabExitTransition() }, ) { - DeviceTokenAuthenticationScreen { + DeviceTokenAuthenticationScreen(onSkip = { + navController.navigateSingleTopTo(Screens.Home.title) + }) { navController.navigateSingleTopTo(it.title) } } @@ -56,7 +58,9 @@ fun AppNavigation(navController: NavHostController) { Screens.Mp3Player.title, enterTransition = { tabEnterTransition() }, exitTransition = { tabExitTransition() }) { - Mp3PlayerScreen() + AudioPlayerScreen { + navController.navigateUp() + } } composable(