-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f638bb5
commit b1708fd
Showing
38 changed files
with
329 additions
and
1,184 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
24 changes: 0 additions & 24 deletions
24
...e_counter/Android/app/src/androidTest/java/com/example/counter/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
120 changes: 0 additions & 120 deletions
120
templates/simple_counter/Android/app/src/main/java/com/example/counter/MainActivity.kt
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
templates/simple_counter/Android/app/src/main/java/com/example/simple_counter/Core.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,34 @@ | ||
package com.example.{{workspace}} | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import com.example.{{workspace}}.{{core_name}}.processEvent | ||
import com.example.{{workspace}}.{{core_name}}.view | ||
import com.example.{{workspace}}.{{type_gen}}.Effect | ||
import com.example.{{workspace}}.{{type_gen}}.Event | ||
import com.example.{{workspace}}.{{type_gen}}.Request | ||
import com.example.{{workspace}}.{{type_gen}}.Requests | ||
import com.example.{{workspace}}.{{type_gen}}.ViewModel | ||
|
||
class Core : androidx.lifecycle.ViewModel() { | ||
var view: ViewModel by mutableStateOf(ViewModel.bincodeDeserialize(view())) | ||
private set | ||
|
||
fun update(event: Event) { | ||
val effects = processEvent(event.bincodeSerialize()) | ||
|
||
val requests = Requests.bincodeDeserialize(effects) | ||
for (request in requests) { | ||
processEffect(request) | ||
} | ||
} | ||
|
||
private fun processEffect(request: Request) { | ||
when (request.effect) { | ||
is Effect.Render -> { | ||
this.view = ViewModel.bincodeDeserialize(view()) | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...lates/simple_counter/Android/app/src/main/java/com/example/simple_counter/MainActivity.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,71 @@ | ||
@file:OptIn(ExperimentalUnsignedTypes::class) | ||
|
||
package com.example.{{workspace}} | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material3.* | ||
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.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.example.{{workspace}}.{{type_gen}}.Event | ||
import com.example.{{workspace}}.ui.theme.CounterTheme | ||
|
||
class MainActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
CounterTheme { | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background | ||
) { | ||
View() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun View(core: Core = viewModel()) { | ||
Column( | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(10.dp), | ||
) { | ||
Text(text = core.view.count.toString(), modifier = Modifier.padding(10.dp)) | ||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) { | ||
Button( | ||
onClick = { core.update(Event.Reset()) }, colors = ButtonDefaults.buttonColors( | ||
containerColor = MaterialTheme.colorScheme.error | ||
) | ||
) { Text(text = "Reset", color = Color.White) } | ||
Button( | ||
onClick = { core.update(Event.Increment()) }, colors = ButtonDefaults.buttonColors( | ||
containerColor = MaterialTheme.colorScheme.primary | ||
) | ||
) { Text(text = "Increment", color = Color.White) } | ||
Button( | ||
onClick = { core.update(Event.Decrement()) }, colors = ButtonDefaults.buttonColors( | ||
containerColor = MaterialTheme.colorScheme.secondary | ||
) | ||
) { Text(text = "Decrement", color = Color.White) } | ||
} | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun DefaultPreview() { | ||
CounterTheme { | ||
View() | ||
} | ||
} |
Oops, something went wrong.