Skip to content

Instantly share code, notes, and snippets.

View devDeejay's full-sized avatar
🏠
Working from home

Dhananjay Trivedi devDeejay

🏠
Working from home
View GitHub Profile
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// Calling our Refactored function
ChatScreen(SampleListData.conversationSample)
}
}
@Composable
private fun ChatScreen(messages: List<Message>) {
@Composable
private fun ChatCard(title: String, body: String) {
Surface(
shape = MaterialTheme.shapes.medium,
elevation = 8.dp,
modifier = Modifier.padding(all = 8.dp)
) {
Row(modifier = Modifier.padding(all = 8.dp)) {
Image(
painter = painterResource(
// Preview Annotation with name for Light Mode
@Preview(name = "Light Mode")
// Adding another Preview annotation for Dark Mode
@Preview(
uiMode = Configuration.UI_MODE_NIGHT_YES,
showBackground = true,
name = "Dark Mode"
)
/// Same Function as before
@Composable
@Composable
fun GreetUser(name: String) {
// Adding a modifier to our Row
Row(modifier = Modifier.padding(all = 8.dp)) {
Image(
painter = painterResource(
id = R.drawable.ic_launcher_background
), contentDescription = "Some cool image",
// Image Modifier
@Composable
fun GreetUser(name: String) {
Row {
Image(
painter = painterResource(
id = R.drawable.ic_launcher_background
), contentDescription = "Some cool image"
)
Column {
Text(text = "Hello!")
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// This is the block where we will call
// our Composable Functions
setContent {
Text("Hello world!") //<-- Composable Function
}
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// Calling our Refactored function
GreetUser("DEEJAY")
}
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// Calling our Refactored function
GreetUser("DEEJAY")
}
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// This is the block where we will call our
// Composable Functions
setContent {
GreetUser("DEEJAY")
}
}
// Hilt Module
// @InstallIn <-- We define the component (See Hilt Components for more)
// This helps Hilt knows how long these dependencies have to stay in the memory
// But We use the Application level component for this example
// So NetworkRepo() will stay as long as Application is running.
@InstallIn(ActivityComponent::class)
@Module
abstract class NetworkRepoModule {
@ActivityScoped
@Binds