Skip to content
Snippets Groups Projects
Commit 150b722c authored by Sebastian Kürten's avatar Sebastian Kürten
Browse files

Implement some parts of a recycler view tutorial

parent 8f885088
No related branches found
No related tags found
No related merge requests found
# Compose Playground
Forked from https://github.com/JetBrains/compose-jb
Forked from https://github.com/JetBrains/compose-jb (Apache 2.0)
Partially added:
https://www.waseefakhtar.com/android/recyclerview-in-jetpack-compose/ /
https://github.com/waseefakhtar/bark (Apache 2.0)
[![official project](http://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
[![Latest release](https://img.shields.io/github/v/release/JetBrains/compose-jb?color=brightgreen&label=latest%20release)](https://github.com/JetBrains/compose-jb/releases/latest)
......
package org.briarproject.briar.compose.barkhome
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.dp
@Composable
fun BarkHomeContent() {
val puppies = remember { DataProvider.puppyList }
LazyColumn(
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp)
) {
items(
items = puppies,
itemContent = {
PuppyListItem(puppy = it)
})
}
}
\ No newline at end of file
package org.briarproject.briar.compose.barkhome
object DataProvider {
val puppyList = listOf(
Puppy(
id = 1,
title = "Monty",
description = "Monty enjoys chicken treats and cuddling while watching Seinfeld.",
),
Puppy(
id = 2,
title = "Jubilee",
description = "Jubilee enjoys thoughtful discussions by the campfire.",
),
Puppy(
id = 3,
title = "Beezy",
description = "Beezy's favorite past-time is helping you choose your brand color.",
),
Puppy(
id = 4,
title = "Mochi",
description = "Mochi is the perfect \"rubbery ducky\" debugging pup, always listening.",
),
Puppy(
id = 5,
title = "Brewery",
description = "Brewery loves fetching you your favorite homebrew.",
),
Puppy(
id = 6,
title = "Lucy",
description = "Picture yourself in a boat on a river, Lucy is a pup with kaleidoscope eyes.",
),
Puppy(
id = 7,
title = "Astro",
description = "Is it a bird? A plane? No, it's Astro blasting off into your heart!",
),
Puppy(
id = 8,
title = "Boo",
description = "Boo is just a teddy bear in disguise. What he lacks in grace, he makes up in charm.",
),
Puppy(
id = 9,
title = "Pippa",
description = "Pippa likes to look out the window and write pup-poetry.",
),
Puppy(
id = 10,
title = "Coco",
description = "Coco enjoys getting pampered at the local puppy spa.",
),
Puppy(
id = 11,
title = "Brody",
description = "Brody is a good boy, waiting for your next command.",
),
Puppy(
id = 12,
title = "Stella",
description = "Stella! Calm and always up for a challenge, she's the perfect companion.",
),
)
}
\ No newline at end of file
package org.briarproject.briar.compose.barkhome
data class Puppy(
val id: Int,
val title: String,
val description: String,
val puppyImageId: Int = 0
)
package org.briarproject.briar.compose.barkhome
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.demo.widgets.theme.typography
@Composable
fun PuppyListItem(puppy: Puppy) {
Card(
modifier = Modifier.padding(horizontal = 8.dp, vertical = 8.dp).fillMaxWidth(),
elevation = 2.dp,
backgroundColor = Color.White,
shape = RoundedCornerShape(corner = CornerSize(16.dp))
) {
Row {
Column(
modifier = Modifier.padding(16.dp).fillMaxWidth().align(Alignment.CenterVertically)
) {
Text(text = puppy.title, style = typography.h6)
Text(text = "VIEW DETAIL", style = typography.caption)
}
}
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import org.briarproject.briar.compose.barkhome.BarkHomeContent
import org.jetbrains.compose.demo.widgets.ui.screens.*
@Composable
......@@ -13,6 +14,10 @@ fun WidgetsView(
widgetsTypeState: MutableState<WidgetsType>,
modifier: Modifier
) {
if (widgetsTypeState.value == WidgetsType.PUPPIES) {
Column { BarkHomeContent() }
return
}
Column(modifier = modifier.verticalScroll(state = rememberScrollState())) {
@Suppress("UNUSED_VARIABLE")
val exhaustive = when (widgetsTypeState.value) {
......@@ -25,6 +30,7 @@ fun WidgetsView(
WidgetsType.TEXT_INPUTS -> TextInputs()
WidgetsType.TOGGLES -> Toggles()
WidgetsType.UI_CARDS -> UICards()
WidgetsType.PUPPIES -> null
}
}
}
package org.jetbrains.compose.demo.widgets.ui
enum class WidgetsType(private val customTitle: String? = null) {
PUPPIES,
APP_BARS,
BUTTONS,
CHIPS,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment