Simplify imports

This commit is contained in:
Reinout Meliesie 2024-11-22 19:21:58 +01:00
parent aadac8551e
commit cb07139815
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
6 changed files with 49 additions and 68 deletions

View file

@ -1,20 +1,14 @@
package com.kernelmaft.zanbur package com.kernelmaft.zanbur
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement.Center import androidx.compose.foundation.layout.Arrangement.Center
import androidx.compose.foundation.layout.Column import androidx.compose.material3.*
import androidx.compose.foundation.layout.ColumnScope import androidx.compose.material3.ButtonDefaults.buttonColors
import androidx.compose.foundation.layout.Spacer import androidx.compose.material3.ButtonDefaults.filledTonalButtonColors
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.ButtonDefaults.shape
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.runtime.*
import androidx.compose.foundation.layout.height import androidx.compose.ui.*
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment.Companion.CenterHorizontally import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
@ -35,16 +29,10 @@ import androidx.compose.ui.Modifier
for ( scene in group . scenes ) { for ( scene in group . scenes ) {
val colors = val colors =
if ( scene . id == group . currentScene ?. id ) ButtonDefaults . buttonColors () if ( scene . id == group . currentScene ?. id ) buttonColors ()
else ButtonDefaults . filledTonalButtonColors () else filledTonalButtonColors ()
Button ( Button ( { onSwitch (scene) } , Modifier . fillMaxWidth () , true , shape , colors ) {
{ onSwitch (scene) } ,
Modifier . fillMaxWidth () ,
true ,
ButtonDefaults . shape ,
colors ,
) {
Text ( scene . name ) Text ( scene . name )
} }
} }

View file

@ -1,22 +1,17 @@
package com.kernelmaft.zanbur package com.kernelmaft.zanbur
import android.os.Bundle import android.os.*
import androidx.activity.ComponentActivity import androidx.activity.*
import androidx.activity.compose.setContent import androidx.activity.compose.*
import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column import androidx.compose.runtime.*
import androidx.compose.foundation.layout.width import androidx.compose.ui.*
import androidx.compose.runtime.getValue import androidx.compose.ui.unit.*
import androidx.compose.runtime.mutableStateOf import androidx.datastore.preferences.core.*
import androidx.compose.runtime.setValue import androidx.lifecycle.*
import androidx.compose.ui.Modifier import kotlinx.coroutines.*
import androidx.compose.ui.unit.dp
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
@ -30,7 +25,7 @@ class MainActivity : ComponentActivity () {
AppState . subscribe { groups = it } AppState . subscribe { groups = it }
lifecycleScope . launch (IO) { lifecycleScope . launch (IO) {
val prefs = applicationContext . dataStore . data . firstOrNull () val prefs = dataStore . data . firstOrNull ()
if ( prefs != null ) { if ( prefs != null ) {
val savedSceneName = prefs [ stringPreferencesKey ("scene") ] val savedSceneName = prefs [ stringPreferencesKey ("scene") ]
if ( savedSceneName != null ) { if ( savedSceneName != null ) {

View file

@ -1,14 +1,16 @@
package com.kernelmaft.zanbur package com.kernelmaft.zanbur
import MQTTClient import MQTTClient
import kotlinx.coroutines.CoroutineScope import com.kernelmaft.zanbur.Config.MQTT_SERVER_HOST
import com.kernelmaft.zanbur.Config.MQTT_SERVER_PORT
import com.kernelmaft.zanbur.Config.MQTT_TOPIC
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.serialization.json.*
import kotlinx.serialization.json.Json import mqtt.*
import mqtt.MQTTVersion import mqtt.MQTTVersion.*
import mqtt.Subscription import mqtt.packets.Qos.*
import mqtt.packets.Qos.AT_MOST_ONCE import mqtt.packets.mqtt.*
import mqtt.packets.mqtt.MQTTPublish
@ -24,10 +26,10 @@ object MqttClient {
val json = Json { ignoreUnknownKeys = true } val json = Json { ignoreUnknownKeys = true }
coroutineScope . launch (IO) { coroutineScope . launch (IO) {
client = MQTTClient ( MQTTVersion . MQTT5 , Config . MQTT_SERVER_HOST , Config . MQTT_SERVER_PORT , null ) { client = MQTTClient ( MQTT5 , MQTT_SERVER_HOST , MQTT_SERVER_PORT , null ) {
for ( handler in publishHandlers ) handler ( it , json ) for ( handler in publishHandlers ) handler ( it , json )
} }
client !! . subscribe ( listOf ( Subscription ( Config . MQTT_TOPIC + "/#" ) ) ) client !! . subscribe ( listOf ( Subscription ( MQTT_TOPIC + "/#" ) ) )
client !! . run () client !! . run ()
} }

View file

@ -1,9 +1,9 @@
package com.kernelmaft.zanbur package com.kernelmaft.zanbur
import android.content.Context import android.content.*
import androidx.datastore.core.DataStore import androidx.datastore.core.*
import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.*
import androidx.datastore.preferences.preferencesDataStore import androidx.datastore.preferences.core.*

View file

@ -1,14 +1,12 @@
package com.kernelmaft.zanbur package com.kernelmaft.zanbur
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.*
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.*
import androidx.compose.material3.MaterialTheme.shapes import androidx.compose.material3.MaterialTheme.shapes
import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.runtime.*
import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.ui.platform.*
import androidx.compose.runtime.Composable import androidx.compose.ui.unit.*
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
@ -16,11 +14,10 @@ val compactSpacing = 16 . dp
@Composable fun ZanburTheme ( content : @Composable () -> Unit ) { @Composable fun ZanburTheme ( content : @Composable () -> Unit ) {
val colorScheme = run { val colorScheme = run {
val context = LocalContext . current
if ( isSystemInDarkTheme () ) if ( isSystemInDarkTheme () )
dynamicDarkColorScheme (context) dynamicDarkColorScheme ( LocalContext . current )
else else
dynamicLightColorScheme (context) dynamicLightColorScheme ( LocalContext . current )
} }
MaterialTheme ( colorScheme, shapes , typography , content ) MaterialTheme ( colorScheme, shapes , typography , content )

View file

@ -1,18 +1,17 @@
package com.kernelmaft.zanbur package com.kernelmaft.zanbur
import kotlinx.serialization.SerialName import com.kernelmaft.zanbur.Config.MQTT_TOPIC
import kotlinx.serialization.Serializable import kotlinx.serialization.*
import kotlinx.serialization.encodeToString import kotlinx.serialization.json.*
import kotlinx.serialization.json.Json
fun publishSceneChange ( group : Group , newScene : Scene ) { fun publishSceneChange ( group : Group , newScene : Scene ) {
val topic = Config . MQTT_TOPIC + "/" + group . name + "/set" val topic = MQTT_TOPIC + "/" + group . name + "/set"
val packet = Json . encodeToString ( SceneRecallPacket ( newScene . id ) ) val packet = Json . encodeToString ( SceneRecallPacket ( newScene . id ) )
. toByteArray () . toByteArray ()
. asUByteArray () . asUByteArray ()
MqttClient.publish ( topic , packet ) MqttClient . publish ( topic , packet )
} }
@Serializable private data class SceneRecallPacket ( @Serializable private data class SceneRecallPacket (