summaryrefslogtreecommitdiffstats
path: root/android/app/src/main/java/eu/jopek/dingdongmail/MainActivity.kt
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2024-07-19 23:49:36 +0200
committerMaksymilian Jopek <maks@jopek.eu>2024-07-19 23:49:36 +0200
commit2b7c14f2b68a26cba893855cd1a142328888bb13 (patch)
tree6db090a2e4aa238ccda589a5fe899f459fbafea4 /android/app/src/main/java/eu/jopek/dingdongmail/MainActivity.kt
downloadding-dong-mail-2b7c14f2b68a26cba893855cd1a142328888bb13.tar.gz
ding-dong-mail-2b7c14f2b68a26cba893855cd1a142328888bb13.tar.zst
ding-dong-mail-2b7c14f2b68a26cba893855cd1a142328888bb13.zip
Initial commit
Android app works, but Android says it uses much more battery than ntfy.sh, which should never happen goimapnotify works Logo is awesome <3 There are problems with constant working, presumably after restarts.
Diffstat (limited to 'android/app/src/main/java/eu/jopek/dingdongmail/MainActivity.kt')
-rw-r--r--android/app/src/main/java/eu/jopek/dingdongmail/MainActivity.kt74
1 files changed, 74 insertions, 0 deletions
diff --git a/android/app/src/main/java/eu/jopek/dingdongmail/MainActivity.kt b/android/app/src/main/java/eu/jopek/dingdongmail/MainActivity.kt
new file mode 100644
index 0000000..a13b0d2
--- /dev/null
+++ b/android/app/src/main/java/eu/jopek/dingdongmail/MainActivity.kt
@@ -0,0 +1,74 @@
+package eu.jopek.dingdongmail
+
+import android.content.Intent
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.activity.enableEdgeToEdge
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Button
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.tooling.preview.Preview
+import eu.jopek.dingdongmail.ui.theme.DingDongMailTheme
+
+class MainActivity : ComponentActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ enableEdgeToEdge()
+ setContent {
+ DingDongMailTheme {
+ Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
+ Greeting(
+ modifier = Modifier.padding(innerPadding)
+ ) {
+ actionOnService(it)
+ }
+ }
+ }
+ }
+
+ log("Starting the service from MainActivity.onCreate")
+ Intent(this, MainWorkerService::class.java).also {
+ it.action = Actions.START.name
+ startForegroundService(it)
+ }
+ }
+
+ private fun actionOnService(action: Actions) {
+ log("Starting the service from button")
+ Intent(this, MainWorkerService::class.java).also {
+ it.action = action.name
+ if (action == Actions.STOP) stopService(it)
+ else startForegroundService(it)
+ }
+ }
+}
+
+@Composable
+fun Greeting(modifier: Modifier = Modifier, onClick: (Actions) -> Unit) {
+ Column {
+ Text(
+ text = "Ding-Dong Mail!",
+ modifier = modifier
+ )
+ Button(onClick = { onClick(Actions.START) }) {
+ Text(text = "Start")
+ }
+ Button(onClick = { onClick(Actions.STOP) }) {
+ Text(text = "Stop")
+ }
+ }
+}
+
+@Preview(showBackground = true)
+@Composable
+fun GreetingPreview() {
+ DingDongMailTheme {
+ Greeting() {}
+ }
+} \ No newline at end of file