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
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement.Center
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
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.material3.*
import androidx.compose.material3.ButtonDefaults.buttonColors
import androidx.compose.material3.ButtonDefaults.filledTonalButtonColors
import androidx.compose.material3.ButtonDefaults.shape
import androidx.compose.runtime.*
import androidx.compose.ui.*
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 ) {
val colors =
if ( scene . id == group . currentScene ?. id ) ButtonDefaults . buttonColors ()
else ButtonDefaults . filledTonalButtonColors ()
if ( scene . id == group . currentScene ?. id ) buttonColors ()
else filledTonalButtonColors ()
Button (
{ onSwitch (scene) } ,
Modifier . fillMaxWidth () ,
true ,
ButtonDefaults . shape ,
colors ,
) {
Button ( { onSwitch (scene) } , Modifier . fillMaxWidth () , true , shape , colors ) {
Text ( scene . name )
}
}

View file

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

View file

@ -1,14 +1,16 @@
package com.kernelmaft.zanbur
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.launch
import kotlinx.serialization.json.Json
import mqtt.MQTTVersion
import mqtt.Subscription
import mqtt.packets.Qos.AT_MOST_ONCE
import mqtt.packets.mqtt.MQTTPublish
import kotlinx.serialization.json.*
import mqtt.*
import mqtt.MQTTVersion.*
import mqtt.packets.Qos.*
import mqtt.packets.mqtt.*
@ -24,10 +26,10 @@ object MqttClient {
val json = Json { ignoreUnknownKeys = true }
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 )
}
client !! . subscribe ( listOf ( Subscription ( Config . MQTT_TOPIC + "/#" ) ) )
client !! . subscribe ( listOf ( Subscription ( MQTT_TOPIC + "/#" ) ) )
client !! . run ()
}

View file

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

View file

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

View file

@ -1,18 +1,17 @@
package com.kernelmaft.zanbur
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import com.kernelmaft.zanbur.Config.MQTT_TOPIC
import kotlinx.serialization.*
import kotlinx.serialization.json.*
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 ) )
. toByteArray ()
. asUByteArray ()
MqttClient.publish ( topic , packet )
MqttClient . publish ( topic , packet )
}
@Serializable private data class SceneRecallPacket (