Skip to content

Instantly share code, notes, and snippets.

@yrezgui
Last active November 20, 2023 23:53
Show Gist options
  • Save yrezgui/26a1060d67bf0ec2a73fa12695166436 to your computer and use it in GitHub Desktop.
Save yrezgui/26a1060d67bf0ec2a73fa12695166436 to your computer and use it in GitHub Desktop.
Compose tutorial sample data
package com.example.compose.tutorial
object SampleData {
// Sample conversation data
val conversationSample = listOf(
Message(
"Colleague",
"Test...Test...Test..."
),
Message(
"Colleague",
"List of Android versions:\n" +
"Android KitKat (API 19)\n" +
"Android Lollipop (API 21)\n" +
"Android Marshmallow (API 23)\n" +
"Android Nougat (API 24)\n" +
"Android Oreo (API 26)\n" +
"Android Pie (API 28)\n" +
"Android 10 (API 29)\n" +
"Android 11 (API 30)\n" +
"Android 12 (API 31)\n"
),
Message(
"Colleague",
"I think Kotlin is my favorite programming language.\n" +
"It's so much fun!"
),
Message(
"Colleague",
"Searching for alternatives to XML layouts..."
),
Message(
"Colleague",
"Hey, take a look at Jetpack Compose, it's great!\n" +
"It's the Android's modern toolkit for building native UI." +
"It simplifies and accelerates UI development on Android." +
"Less code, powerful tools, and intuitive Kotlin APIs :)"
),
Message(
"Colleague",
"It's available from API 21+ :)"
),
Message(
"Colleague",
"Writing Kotlin for UI seems so natural, Compose where have you been all my life?"
),
Message(
"Colleague",
"Android Studio next version's name is Arctic Fox"
),
Message(
"Colleague",
"Android Studio Arctic Fox tooling for Compose is top notch ^_^"
),
Message(
"Colleague",
"I didn't know you can now run the emulator directly from Android Studio"
),
Message(
"Colleague",
"Compose Previews are great to check quickly how a composable layout looks like"
),
Message(
"Colleague",
"Previews are also interactive after enabling the experimental setting"
),
Message(
"Colleague",
"Have you tried writing build.gradle with KTS?"
),
)
}
@sorianog
Copy link

I agree with @j-m-hoffmann's approach of using Kotlin's String Literals.
Less code and easier to read!

@Zfashion
Copy link

Zfashion commented Mar 3, 2022

interesting ✨✨✨

@wnduqrla
Copy link

wnduqrla commented May 5, 2022

I agree with your idea.
@j-m-hoffmann Thank you 👍

@rofrol
Copy link

rofrol commented Jun 29, 2022

To import it right click in Project tab, Android selected in dropdown.

Right-click on app > java > dev.yourname.composetutorial then New > Kotlin Class/File and just paste content from this gist.

image

image

@correabuscar
Copy link

correabuscar commented Jul 16, 2022

Does anyone know how to add 3 dots (...) at the end of the line when not expanded?

I imagine this is hard because you'd have to know the last 3 chars shown on the line and then replace them with ... and then ensure the line still displays them (didn't grow).

Or perhaps there's a better/idiomatic way to mark a message as incompletely-showing and thus in need of expansion?

Another,unrelated, thing:
EDIT: [SOLVED] by replacing remember with rememberSaveable yay!(thanks to this and this) // Does anyone know how to not lose the state of the expansion even though you scrolled away ? for example, expand the second entry then scroll to the bottom, then scroll back up, the second entry is no longer expanded! The state of isExpanded was lost and reset to false... This is rather unexpected (from the UI perspective)... (but of course code-wise it makes sense that the value false gets set when recomposition happens)

@nadim365
Copy link

To import it right click in Project tab, Android selected in dropdown.

Right-click on app > java > dev.yourname.composetutorial then New > Kotlin Class/File and just paste content from this gist.

image image

thank for the screenshot and help. Also how do you have the package name dev.username.[something] I only have com.example.composetutorial

@oriohac
Copy link

oriohac commented Nov 16, 2022

@rofrol and @nadim365 we're clearly not creating a class, but an object, so what you have to select when you click on Kotlin Class/File, should be an object.
Screenshot (13)

@moocstudent
Copy link

thanks very much.

@oriohac
Copy link

oriohac commented Aug 18, 2023

thanks very much.

You're welcome, glad that my response helped out.

@zenikigai
Copy link

To import it right click in Project tab, Android selected in dropdown.

Right-click on app > java > dev.yourname.composetutorial then New > Kotlin Class/File and just paste content from this gist.

image image

THIS!!!! thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment