Skip to content

Commit

Permalink
Merge pull request #28 from UmairKhalid786/develop
Browse files Browse the repository at this point in the history
Profile and About me added
  • Loading branch information
UmairKhalid786 authored Apr 12, 2023
2 parents 03325b7 + 84c491f commit 2257bba
Show file tree
Hide file tree
Showing 20 changed files with 468 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.tv.material3.Text
import androidx.compose.runtime.*
Expand All @@ -19,8 +20,12 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.contentColorFor
import com.techlads.composetv.theme.AppTheme


@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
fun CarouselItem(parent: Int, child: Int, onItemFocus: (item: Int) -> Unit) {

Expand All @@ -47,13 +52,17 @@ fun CarouselItem(parent: Int, child: Int, onItemFocus: (item: Int) -> Unit) {
border = BorderStroke(
1.dp,
if (isFocused)
Color.LightGray
contentColorFor(backgroundColor = AppTheme.surface)
else
Color.Transparent
), shape = MaterialTheme.shapes.medium
)
.clickable { }
.focusable()
.focusable(),
colors = CardDefaults.cardColors(
containerColor = AppTheme.surface,
contentColor = contentColorFor(backgroundColor = AppTheme.surface)
)
) {
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
Text(text = "Item $parent x $child", textAlign = TextAlign.Center)
Expand All @@ -62,6 +71,7 @@ fun CarouselItem(parent: Int, child: Int, onItemFocus: (item: Int) -> Unit) {
}


@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
fun VerticalCarouselItem(parent: Int, child: Int) {

Expand All @@ -86,24 +96,31 @@ fun VerticalCarouselItem(parent: Int, child: Int) {
border = BorderStroke(
1.dp,
if (isFocused)
Color.LightGray
contentColorFor(backgroundColor = AppTheme.surface)
else
Color.Transparent
), shape = MaterialTheme.shapes.medium
)
.clickable { }
.focusable()
.focusable(),
colors = CardDefaults.cardColors(
containerColor = AppTheme.surface,
contentColor = contentColorFor(backgroundColor = AppTheme.surface)
)
) {
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
Text(text = "Item $parent x $child", textAlign = TextAlign.Center)
Text(
text = "Item $parent x $child",
textAlign = TextAlign.Center,
)
}
}
}

@Preview
@Composable
fun CarouselItemPrev() {
CarouselItem(1, 1){}
CarouselItem(1, 1) {}
}


Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/techlads/composetv/leftmenu/LeftMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.techlads.composetv.home.navigation.NestedScreens
import com.techlads.composetv.leftmenu.model.MenuItem
import com.techlads.composetv.theme.AppTheme
import compose.icons.LineAwesomeIcons
import compose.icons.lineawesomeicons.CogSolid
import compose.icons.lineawesomeicons.Comment
Expand Down Expand Up @@ -43,7 +43,7 @@ fun LeftMenu(

Box(
modifier = modifier
.background(Color.DarkGray.copy(alpha = 0.2f))
.background(AppTheme.surface.copy(alpha = 0.5f))
.wrapContentWidth()
) {
Column(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.techlads.composetv.leftmenu

import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.keyframes
Expand All @@ -9,16 +8,16 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.ShapeDefaults
import androidx.tv.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text
import com.techlads.composetv.leftmenu.model.MenuItem

@Composable
Expand All @@ -45,12 +44,11 @@ fun LeftMenuItem(
.focusRequester(requester)
.onFocusChanged {
isFocused = it.isFocused
Log.e("isFocused", it.isFocused.toString())
onMenuFocused?.invoke(menuItem, it.isFocused)
}
.focusable()
.background(
color = if (isFocused) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.surface,
color = if (isFocused) colorScheme.surface else colorScheme.onSurface,
shape = ShapeDefaults.Small
)
.clickable {
Expand All @@ -64,18 +62,18 @@ fun LeftMenuItem(
modifier = Modifier.size(20.dp),
imageVector = it,
contentDescription = menuItem.text,
tint = if (!isFocused)
MaterialTheme.colorScheme.onSurface
tint = if (isFocused)
colorScheme.onSurface
else
MaterialTheme.colorScheme.surface
colorScheme.surface
)
Spacer(modifier = Modifier.padding(horizontal = padding.value))
}

AnimatedVisibility(visible = expanded, modifier = Modifier.height(20.dp)) {
Text(
text = menuItem.text,
color = if (!isFocused) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.surface,
color = if (isFocused) colorScheme.onSurface else colorScheme.surface,
maxLines = 1
)
}
Expand Down
23 changes: 0 additions & 23 deletions app/src/main/java/com/techlads/composetv/settings/SearchScreen.kt

This file was deleted.

33 changes: 33 additions & 0 deletions app/src/main/java/com/techlads/composetv/settings/SettingsMenu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.techlads.composetv.settings

import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.list.TvLazyColumn
import com.techlads.composetv.settings.data.SettingsMenuModel

@Composable
fun SettingsMenu(modifier: Modifier = Modifier, onMenuSelected: (SettingsMenuModel) -> Unit) {
val settingsMenu = remember {
SettingsMenuData.menu
}
TvLazyColumn(modifier = modifier.width(200.dp)) {
items(settingsMenu.size) {
val item = settingsMenu[it]
SettingsMenuItem(item) {
onMenuSelected(item)
}
}
}
}

@Preview
@Composable
fun SettingsMenuPrev() {
SettingsMenu {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.techlads.composetv.settings

import com.techlads.composetv.settings.data.SettingsMenuModel
import com.techlads.composetv.settings.navigation.SettingsScreens


object SettingsMenuData {
val menu by lazy {
listOf(
SettingsMenuModel("Profile", SettingsScreens.Profile.title),
SettingsMenuModel("About Me", SettingsScreens.AboutMe.title)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.techlads.composetv.settings

import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text
import com.techlads.composetv.settings.data.SettingsMenuModel
import com.techlads.composetv.widgets.FocusableItem

@Composable
fun SettingsMenuItem(item: SettingsMenuModel, onMenuSelected: (SettingsMenuModel) -> Unit) {
FocusableItem(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
onClick = { onMenuSelected(item) }) {
Text(
text = item.text,
modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp)
)
}
}

@Preview
@Composable
fun SettingsMenuItemPrev() {
SettingsMenuItem(SettingsMenuModel("Menu", "")){

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.techlads.composetv.settings

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import com.techlads.composetv.settings.navigation.NestedSettingsScreenNavigation
import com.techlads.composetv.theme.AppTheme

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun SettingsScreen() {
val navController = rememberAnimatedNavController()

Row(
Modifier
.fillMaxSize()) {
SettingsMenu(
Modifier
.fillMaxHeight()
.background(AppTheme.surface.copy(alpha = 0.2f))
.padding(vertical = 32.dp, horizontal = 16.dp)
) {
navController.navigate(it.navigation)
}
SettingsNavigation(navController)
}
}

@Composable
fun SettingsNavigation(navController: NavHostController) {
NestedSettingsScreenNavigation(navController = navController)
}


@Preview
@Composable
fun SettingsScreenPrev() {
SettingsScreen()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.techlads.composetv.settings.data

data class SettingsMenuModel(val text: String, val navigation: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.techlads.composetv.settings.navigation

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import com.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable
import com.techlads.composetv.navigation.tabEnterTransition
import com.techlads.composetv.navigation.tabExitTransition
import com.techlads.composetv.settings.screens.about.AboutScreen
import com.techlads.composetv.settings.screens.profile.ProfileScreen

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun NestedSettingsScreenNavigation(navController: NavHostController) {
AnimatedNavHost(navController = navController, startDestination = SettingsScreens.Profile.title) {
// e.g will add auth routes here if when we will extend project
composable(
SettingsScreens.Profile.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
ProfileScreen()
}
composable(
SettingsScreens.AboutMe.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
AboutScreen()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.techlads.composetv.settings.navigation

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavHostController
import com.google.accompanist.navigation.animation.rememberAnimatedNavController

@Composable
fun NestedHomeNavigation(navController: NavHostController) {
NestedSettingsScreenNavigation(navController)
}

@OptIn(ExperimentalAnimationApi::class)
@Preview
@Composable
fun NestedHomeNavigationPrev() {
NestedHomeNavigation(rememberAnimatedNavController())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.techlads.composetv.settings.navigation

sealed class SettingsScreens(val title: String) {
object Profile : SettingsScreens("profile")
object AboutMe : SettingsScreens("about_me")
}
Loading

0 comments on commit 2257bba

Please sign in to comment.