-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from UmairKhalid786/develop
Develop
- Loading branch information
Showing
15 changed files
with
423 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
/.idea/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.techlads.composetv.hero | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.techlads.composetv.R | ||
|
||
@Composable | ||
fun HeroItem(modifier: Modifier = Modifier) { | ||
Card( | ||
modifier = modifier | ||
.padding(horizontal = 24.dp, vertical = 24.dp) | ||
.fillMaxWidth() | ||
.height(200.dp), | ||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp), | ||
) { | ||
Box { | ||
Image( | ||
modifier = Modifier.fillMaxSize(), | ||
painter = painterResource(id = R.drawable.hero_item), | ||
contentDescription = "Hero item background", | ||
contentScale = ContentScale.Crop | ||
) | ||
Column( | ||
Modifier | ||
.fillMaxSize() | ||
.background(Color.Black.copy(alpha = 0.7f)) | ||
.padding(32.dp) | ||
) { | ||
Spacer(modifier = Modifier.weight(1f)) | ||
Text(text = "Heading", style = MaterialTheme.typography.titleLarge) | ||
Text( | ||
text = "Description", | ||
style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.ExtraLight) | ||
) | ||
} | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun HeroItemPrev() { | ||
HeroItem() | ||
} |
28 changes: 21 additions & 7 deletions
28
app/src/main/java/com/techlads/composetv/home/HomeScreenContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/techlads/composetv/home/carousel/CarouselItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.techlads.composetv.home.carousel | ||
|
||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.focusable | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.onFocusChanged | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
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 | ||
|
||
|
||
@Composable | ||
fun CarouselItem(parent: Int, child: Int) { | ||
|
||
var isFocused by remember { mutableStateOf(false) } | ||
val scale = animateFloatAsState(if (isFocused) 1.2f else 1f) | ||
|
||
|
||
Card( | ||
modifier = Modifier | ||
.zIndex(if (isFocused) 20f else 1f) | ||
.graphicsLayer( | ||
scaleX = scale.value, | ||
scaleY = scale.value | ||
) | ||
.padding(horizontal = 8.dp) | ||
.fillMaxHeight() | ||
.aspectRatio(1.8f) | ||
.onFocusChanged { | ||
isFocused = it.isFocused | ||
} | ||
.border( | ||
border = BorderStroke( | ||
1.dp, | ||
if (isFocused) | ||
Color.LightGray | ||
else | ||
Color.Transparent | ||
), shape = MaterialTheme.shapes.medium | ||
) | ||
.clickable { } | ||
.focusable() | ||
) { | ||
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) { | ||
Text(text = "Item $parent x $child", textAlign = TextAlign.Center) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun CarouselItemPrev() { | ||
CarouselItem(1, 1) | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/techlads/composetv/home/carousel/HomeCarousel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.techlads.composetv.home.carousel | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
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.foundation.lazy.list.TvLazyColumn | ||
|
||
|
||
@Composable | ||
fun HomeCarousel(modifier: Modifier) { | ||
TvLazyColumn(modifier, contentPadding = PaddingValues(bottom = 100.dp)) { | ||
items(15) { | ||
HorizontalCarouselItem(it) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun HomeCarouselPrev() { | ||
HomeCarousel(Modifier) | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/techlads/composetv/home/carousel/HorizontalCarouselItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.techlads.composetv.home.carousel | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Text | ||
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.foundation.lazy.list.TvLazyRow | ||
|
||
@Composable | ||
fun HorizontalCarouselItem(index: Int) { | ||
Column(Modifier.height(150.dp)) { | ||
Text(text = "Row $index", modifier = Modifier.padding(horizontal = 24.dp)) | ||
TvLazyRow( | ||
contentPadding = PaddingValues( | ||
start = 16.dp, | ||
top = 8.dp, | ||
bottom = 8.dp, | ||
end = 100.dp | ||
) | ||
) { | ||
items(15) { | ||
CarouselItem(index, it) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun HorizontalCarouselItemPrev() { | ||
HorizontalCarouselItem(1) | ||
} |
17 changes: 16 additions & 1 deletion
17
app/src/main/java/com/techlads/composetv/home/navigation/NestedHomeNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
package com.techlads.composetv.home.navigation | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.techlads.composetv.hero.HeroItem | ||
import com.techlads.composetv.home.carousel.HomeCarousel | ||
|
||
@Composable | ||
fun NestedHomeNavigation(){ | ||
fun NestedHomeNavigation() { | ||
Column(Modifier.fillMaxSize()) { | ||
HeroItem() | ||
HomeCarousel(Modifier.weight(1f)) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun NestedHomeNavigationPrev() { | ||
NestedHomeNavigation() | ||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/techlads/composetv/leftmenu/CenteredMenu.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.techlads.composetv.leftmenu | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.tv.foundation.lazy.list.TvLazyColumn | ||
import com.techlads.composetv.leftmenu.model.MenuItem | ||
|
||
@Composable | ||
fun CenteredMenu( | ||
modifier: Modifier = Modifier, | ||
requester: FocusRequester = FocusRequester(), | ||
menuItems: List<MenuItem>, | ||
defaultFocus: Int, | ||
isExpanded: Boolean = false, | ||
onMenuFocused: ((menuItem: MenuItem, isFocused: Boolean) -> Unit)? = null, | ||
onMenuSelected: ((menuItem: MenuItem) -> Unit)? = null, | ||
) { | ||
val menus = remember { | ||
menuItems | ||
} | ||
|
||
TvLazyColumn( | ||
modifier | ||
) { | ||
items(menus.size) { | ||
val item = menus[it] | ||
if (it == defaultFocus) { | ||
LeftMenuItem( | ||
requester = requester, | ||
menuItem = item, | ||
modifier = Modifier.fillParentMaxWidth(), | ||
expanded = isExpanded, | ||
onMenuFocused = onMenuFocused, | ||
onMenuSelected = onMenuSelected | ||
) | ||
} else { | ||
LeftMenuItem( | ||
menuItem = item, | ||
modifier = Modifier.fillParentMaxWidth(), | ||
expanded = isExpanded, | ||
onMenuFocused = onMenuFocused, | ||
onMenuSelected = onMenuSelected | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.