darkmoon_uk
12/05/2022, 1:42 AMvar
to be replaced with a Flow
... all handled with only one mistake. When I pointed out the mistake, ChatGPT admitted to the bug and corrected it! I feel like this is the AI inflection point we've been hearing about... no it won't create you a complete software product, but it's already a highly valuable tool for bouncing ideas off and accelerating code production.Youssef Shoaib [MOD]
12/05/2022, 2:00 AMYoussef Shoaib [MOD]
12/05/2022, 2:02 AMYoussef Shoaib [MOD]
12/05/2022, 2:41 AMrequest
variable only, which I'm assuming is because the variable has its type determined directly by the type parameter.eygraber
12/05/2022, 4:08 AMYes, here is an updated version of the Android activity that uses Jetpack Compose to show the text "Hello, World!" on the screen, wrapped in awith aScaffold
that says "ChatGPT App", and uses a custom blue color palette for the Material Design themeTopAppBar
import androidx.compose.Composable
import androidx.ui.core.Text
import androidx.ui.core.setContent
import androidx.ui.graphics.Color
import androidx.ui.material.MaterialTheme
import androidx.ui.material.Scaffold
import androidx.ui.material.Surface
import androidx.ui.material.TopAppBar
import androidx.ui.tooling.preview.Preview
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BlueTheme {
MainScreen()
}
}
}
}
@Composable
fun BlueTheme(children: @Composable() () -> Unit) {
val blue = Color(0xFF0066FF)
MaterialTheme(colors = bluePalette(blue)) {
children()
}
}
fun bluePalette(blue: Color) = lightColors(
primary = blue,
primaryVariant = blue.copy(alpha = 0.7f),
secondary = blue,
secondaryVariant = blue.copy(alpha = 0.7f),
error = Color.Red
)
@Composable
fun MainScreen() {
Scaffold(topAppBar = {
TopAppBar(
title = { Text(text = "ChatGPT App") }
)
}) {
Surface(color = Color.Yellow) {
Text(text = "Hello, World!")
}
}
}
@Preview
@Composable
fun DefaultPreview() {
BlueTheme {
MainScreen()
}
}
Anything more complicated then that kind of broke it, but pretty cool πeygraber
12/05/2022, 4:09 AMimport androidx.compose.Composable
import androidx.ui.core.Text
import androidx.ui.core.setContent
import androidx.ui.graphics.Color
import androidx.ui.material.MaterialTheme
import androidx.ui.material.Scaffold
import androidx.ui.material.Surface
import androidx.ui.material.TopAppBar
import androidx.ui.tooling.preview.Preview
sealed class MainState {
data class Initial(val text: String) : MainState()
data class Updated(val text: String) : MainState()
}
sealed class MainIntent {
data class UpdateText(val text: String) : MainIntent()
}
fun mainReducer(state: MainState, intent: MainIntent) = when (state) {
is MainState.Initial -> when (intent) {
is MainIntent.UpdateText -> MainState.Updated(text = intent.text)
}
is MainState.Updated -> when (intent) {
is MainIntent.UpdateText -> MainState.Updated(text = intent.text)
}
}
@Composable
fun MainScreen(state: MainState, updateText: (String) -> Unit) {
Scaffold(topAppBar = {
TopAppBar(
title = { Text(text = "ChatGPT App") }
)
}) {
Surface(color = Color.Yellow) {
Text(text = state.text)
}
}
}
class MainActivity : AppCompatActivity() {
private val initialState = MainState.Initial(text = "Hello, World!")
private val reducer = ::mainReducer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BlueTheme {
MainScreen(state = initialState) { text ->
val intent = MainIntent.UpdateText(text = text)
val newState = reducer(state = initialState, intent = intent)
// Update the state with the new state
}
}
}
}
}
@Composable
fun BlueTheme(children: @Composable() () -> Unit) {
val blue = Color(0xFF0066FF)
val complementary = Color(0
orangy