diff --git a/.editorconfig b/.editorconfig index a2921b9..e6437b0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,16 +1,80 @@ +# top-most .editorconfig file root = true +# Global Settings: Apply to all file types in the project ✨ [*] -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true -charset = utf-8 +end_of_line = lf # Use Unix-style line endings (LF) +insert_final_newline = true # Ensure a newline character at the end of every file +trim_trailing_whitespace = true # Remove trailing whitespace on lines +charset = utf-8 # Use UTF-8 encoding for all files +# Kotlin-Specific Settings: Tailored for .kt and .kts files 📏 [*.{kt,kts}] -indent_size = 4 -indent_style = space -max_line_length = 100 -ktlint_standard_max_line_length = 100 +indent_size = 4 # Standard Kotlin indentation is 4 spaces +indent_style = space # Use spaces for indentation + +# Max Line Length: Adhering to Android Kotlin Style Guide (often 100 or 120) ✍️ +max_line_length = 100 # The hard limit for line length +ktlint_standard_max_line_length = 100 # KtLint-specific rule for line length + +# Trailing Commas: Highly Recommended for Clean Diffs and Reordering! 👍 +# Set to 'true' to allow/encourage trailing commas in declarations and call sites. +# If you *really* want to remove them, set these to 'false'. ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true + +# Import Order: Keep your imports tidy and consistent 📦 +# Prioritizes Android/AndroidX, then common, then Java/Kotlin built-ins. +ij_kotlin_imports_layout=*,android.,androidx.,com.,org.,java.,kotlin.,^ + +# Blank Lines: For readability and consistent spacing 📖 +ij_kotlin_blank_lines_around_declarations_in_class_body = 1 # One blank line around class members +ij_kotlin_blank_lines_before_package = 0 # No blank lines before package declaration +ij_kotlin_blank_lines_after_package = 1 # One blank line after package declaration +ij_kotlin_blank_lines_before_imports = 1 # One blank line before imports block +ij_kotlin_blank_lines_after_imports = 1 # One blank line after imports block + +# KtLint Rules Configuration: Fine-tuning behavior for the linter ⚙️ +# These directly map to KtLint's standard rules. Consult KtLint docs for full list. + +# Allow wildcard imports (common in Android, e.g., 'import android.view.*') ktlint_standard_no-wildcard-imports = disabled + +# Ensure a final newline at the end of the file +ktlint_standard_final-newline = enabled + +# Enforce filename matches top-level class/object/interface name +ktlint_standard_filename = enabled + +# --- One-Line Preference Configuration! ⭐ --- +# This is where we tell KtLint to be less aggressive with line breaks and +# keep things on one line as much as possible, respecting 'max_line_length'. + +# 1. Disable multiline-expression-wrapping: +# This is key for short lambdas, if-expressions, when-branches to stay on one line. +# Example: `val result = if (condition) "A" else "B"` instead of breaking. +# Disabling this means it will only break if 'max_line_length' is exceeded. +ktlint_standard_multiline-expression-wrapping = disabled + +# 2. Disable string-template-indent (often related to multiline-expression-wrapping issues) +ktlint_standard_string-template-indent = disabled + +# 3. Consider disabling argument-list-wrapping if it's too eager to break: +# Default behavior for KtLint might put each argument on a new line if it exceeds a certain length. +# Disabling it means arguments will try to stay on one line until 'max_line_length' is hit. +# ktlint_standard_argument-list-wrapping = disabled # Uncomment to try this! + +# 4. Consider disabling chain-wrapping for chained calls: +# If you prefer `obj.doSomething().anotherThing()` to stay on one line until it's too long. +# ktlint_standard_chain-wrapping = disabled # Uncomment to try this! + +# Exclusions: Ignore specific files or directories from linting/formatting 🚫 +# Crucial for generated code, build files, or test files if their style differs. +[**/build/**/*.kt] # Exclude all Kotlin files within 'build' directories +ktlint = disabled + +[**/src/test/**/*.kt] # Exclude Kotlin files in 'src/test' (if your test style is different) +ktlint = disabled + +# [path/to/specific/generated/file.kt] # Example for a specific generated file +# ktlint = disabled \ No newline at end of file diff --git a/.gitignore b/.gitignore index aa724b7..5bd175f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ .externalNativeBuild .cxx local.properties +.idea diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 4bec4ea..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index a55e7a1..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index b86273d..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/copyright/nphau.xml b/.idea/copyright/nphau.xml deleted file mode 100644 index 637d415..0000000 --- a/.idea/copyright/nphau.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index ba4cd6b..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 0c0c338..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml deleted file mode 100644 index b268ef3..0000000 --- a/.idea/deploymentTargetSelector.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 3cf6c7d..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index e0da3ee..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index fe63bb6..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml deleted file mode 100644 index f8051a6..0000000 --- a/.idea/migrations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 088e11d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 16660f1..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/studiobot.xml b/.idea/studiobot.xml deleted file mode 100644 index 539e3b8..0000000 --- a/.idea/studiobot.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/EmbeddedServer.kt b/app/src/main/java/com/nphausg/app/embeddedserver/EmbeddedServer.kt index fba3317..8c6b35e 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/EmbeddedServer.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/EmbeddedServer.kt @@ -15,7 +15,6 @@ import io.ktor.http.ContentDisposition import io.ktor.http.ContentType import io.ktor.http.HttpHeaders import io.ktor.http.HttpStatusCode -import io.ktor.http.HttpStatusCode.Companion.PartialContent import io.ktor.serialization.kotlinx.json.json import io.ktor.server.application.ApplicationCall import io.ktor.server.application.call @@ -31,15 +30,14 @@ import io.ktor.server.response.respondFile import io.ktor.server.response.respondText import io.ktor.server.routing.get import io.ktor.server.routing.routing +import java.io.File import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import java.io.File object EmbeddedServer { - private const val PORT = 6868 private val ioScope = CoroutineScope(Dispatchers.IO) private const val FILE_NAME = "file.jpg" @@ -53,10 +51,12 @@ object EmbeddedServer { anyHost() } install(ContentNegotiation) { - json(Json { - prettyPrint = true - isLenient = true - }) + json( + Json { + prettyPrint = true + isLenient = true + }, + ) } routing { // staticResources @@ -67,9 +67,12 @@ object EmbeddedServer { okText(call, "Hello!! You are here in ${Build.MODEL}") } get("/fruits") { - okText(call, FileUtils.readText("data.json").also { - Database.FRUITS.addAll(FileUtils.decode(it).items) - }) + okText( + call, + FileUtils.readText("data.json").also { + Database.FRUITS.addAll(FileUtils.decode(it).items) + }, + ) } get("/fruits/{id}") { val id = call.parameters["id"] @@ -84,10 +87,11 @@ object EmbeddedServer { val file = File("files/$FILE_NAME") call.response.header( HttpHeaders.ContentDisposition, - ContentDisposition.Attachment.withParameter( - key = ContentDisposition.Parameters.FileName, - value = FILE_NAME - ).toString() + ContentDisposition.Attachment + .withParameter( + key = ContentDisposition.Parameters.FileName, + value = FILE_NAME, + ).toString(), ) call.response.status(HttpStatusCode.OK) call.respondFile(file) @@ -117,11 +121,14 @@ object EmbeddedServer { val host: String get() = String.format("%s:%d", NetworkUtils.getLocalIpAddress(), PORT) - private suspend fun okText(call: ApplicationCall, text: String) { + private suspend fun okText( + call: ApplicationCall, + text: String, + ) { call.respondText( text = text, status = HttpStatusCode.OK, - contentType = ContentType.Application.Json + contentType = ContentType.Application.Json, ) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/data/BaseResponse.kt b/app/src/main/java/com/nphausg/app/embeddedserver/data/BaseResponse.kt index 85e7c2c..39055fc 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/data/BaseResponse.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/data/BaseResponse.kt @@ -9,4 +9,7 @@ package com.nphausg.app.embeddedserver.data import kotlinx.serialization.Serializable @Serializable -data class BaseResponse(val data: T? = null, val error: String? = null) \ No newline at end of file +data class BaseResponse( + val data: T? = null, + val error: String? = null, +) diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/data/Database.kt b/app/src/main/java/com/nphausg/app/embeddedserver/data/Database.kt index 2a18fdc..6183480 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/data/Database.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/data/Database.kt @@ -7,10 +7,7 @@ package com.nphausg.app.embeddedserver.data import com.nphausg.app.embeddedserver.data.models.Fruit -import java.util.UUID object Database { - val FRUITS = mutableListOf() - -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Cart.kt b/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Cart.kt index 97daa8a..ea49bd2 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Cart.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Cart.kt @@ -7,18 +7,19 @@ package com.nphausg.app.embeddedserver.data.models import com.nphausg.app.embeddedserver.data.Database -import kotlinx.serialization.Serializable import java.util.UUID +import kotlinx.serialization.Serializable @Serializable -data class Cart(val id: String, val items: List) { - +data class Cart( + val id: String, + val items: List, +) { companion object { - fun sample(): Cart { - return Cart( + fun sample(): Cart = + Cart( id = UUID.randomUUID().toString(), - items = Database.FRUITS + items = Database.FRUITS, ) - } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Fruit.kt b/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Fruit.kt index 56dc017..943803e 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Fruit.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/data/models/Fruit.kt @@ -9,4 +9,7 @@ package com.nphausg.app.embeddedserver.data.models import kotlinx.serialization.Serializable @Serializable -data class Fruit(val id: String = "", val name: String = "") \ No newline at end of file +data class Fruit( + val id: String = "", + val name: String = "", +) diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/ui/AnimatedLogo.kt b/app/src/main/java/com/nphausg/app/embeddedserver/ui/AnimatedLogo.kt index a6b1efc..4755f3a 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/ui/AnimatedLogo.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/ui/AnimatedLogo.kt @@ -21,7 +21,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import com.masewsg.app.ui.components.ThemePreviews @@ -30,7 +29,6 @@ import kotlinx.coroutines.launch @Composable internal fun AnimatedLogo() { - val coroutineScope = rememberCoroutineScope() val offsetX = remember { Animatable(0f) } val offsetY = remember { Animatable(0f) } @@ -41,10 +39,9 @@ internal fun AnimatedLogo() { .offset { IntOffset( offsetX.value.toInt(), - offsetY.value.toInt() + offsetY.value.toInt(), ) - } - .pointerInput(Unit) { + }.pointerInput(Unit) { detectDragGestures( onDragEnd = { coroutineScope.launch { @@ -52,8 +49,8 @@ internal fun AnimatedLogo() { targetValue = 0f, animationSpec = tween( durationMillis = 1000, - delayMillis = 0 - ) + delayMillis = 0, + ), ) } coroutineScope.launch { @@ -61,8 +58,8 @@ internal fun AnimatedLogo() { targetValue = 0f, animationSpec = tween( durationMillis = 1000, - delayMillis = 0 - ) + delayMillis = 0, + ), ) } }, @@ -74,15 +71,15 @@ internal fun AnimatedLogo() { coroutineScope.launch { offsetX.snapTo(offsetX.value + dragAmount.x) } - } + }, ) }, - shape = CircleShape + shape = CircleShape, ) { Image( painterResource(R.drawable.logo), contentDescription = "", - contentScale = ContentScale.Inside + contentScale = ContentScale.Inside, ) } } @@ -91,4 +88,4 @@ internal fun AnimatedLogo() { @ThemePreviews private fun AnimatedLogoPreview() { AnimatedLogo() -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/ui/MainActivity.kt b/app/src/main/java/com/nphausg/app/embeddedserver/ui/MainActivity.kt index 3733f1c..e7d72d1 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/ui/MainActivity.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/ui/MainActivity.kt @@ -10,16 +10,13 @@ import android.os.Build import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.LinearEasing import androidx.compose.animation.core.RepeatMode import androidx.compose.animation.core.animateFloat import androidx.compose.animation.core.infiniteRepeatable import androidx.compose.animation.core.rememberInfiniteTransition import androidx.compose.animation.core.tween -import androidx.compose.foundation.Image import androidx.compose.foundation.background -import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -27,12 +24,8 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material3.Card import androidx.compose.material3.Icon import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme @@ -43,18 +36,13 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer -import androidx.compose.ui.input.pointer.pointerInput -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import com.masewsg.app.ui.ComposeApp @@ -64,17 +52,14 @@ import com.masewsg.app.ui.components.button.ComposeOutlinedButton import com.masewsg.app.ui.components.icon.ComposeIcons import com.masewsg.app.ui.components.theme.ComposeTheme import com.nphausg.app.embeddedserver.EmbeddedServer -import com.nphausg.app.embeddedserver.R -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import kotlin.time.Duration.Companion.seconds +import kotlinx.coroutines.delay private val getRunningServerInfo = { ticks: Int -> "The server is running on: ${Build.MODEL} at ${EmbeddedServer.host} -> (${ticks}s ....)" } class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { val splashScreen = installSplashScreen() super.onCreate(savedInstanceState) @@ -100,7 +85,6 @@ class MainActivity : AppCompatActivity() { @Composable private fun MainScreen(modifier: Modifier = Modifier) { - var ticks by remember { mutableIntStateOf(0) } LaunchedEffect(Unit) { @@ -119,10 +103,11 @@ private fun MainScreen(modifier: Modifier = Modifier) { animationSpec = infiniteRepeatable( animation = tween( durationMillis = 1000, - easing = LinearEasing + easing = LinearEasing, ), - repeatMode = RepeatMode.Reverse - ), label = "" + repeatMode = RepeatMode.Reverse, + ), + label = "", ) Column( @@ -134,10 +119,9 @@ private fun MainScreen(modifier: Modifier = Modifier) { horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy( space = 20.dp, - alignment = Alignment.CenterVertically - ) + alignment = Alignment.CenterVertically, + ), ) { - val reusedModifier = Modifier.weight(1f) Spacer(modifier = reusedModifier) @@ -146,8 +130,8 @@ private fun MainScreen(modifier: Modifier = Modifier) { Column( verticalArrangement = Arrangement.spacedBy( space = 20.dp, - alignment = Alignment.CenterVertically - ) + alignment = Alignment.CenterVertically, + ), ) { Row { Icon(imageVector = ComposeIcons.PlayArrow, contentDescription = null) @@ -187,13 +171,12 @@ private fun MainScreen(modifier: Modifier = Modifier) { style = MaterialTheme.typography.titleMedium, ) } - } Row( modifier = Modifier .fillMaxWidth() - .padding(Dp(36f)) + .padding(Dp(36f)), ) { ComposeButton( enabled = !hasStarted, @@ -202,7 +185,7 @@ private fun MainScreen(modifier: Modifier = Modifier) { hasStarted = true EmbeddedServer.start() }, - text = { Text("Start") } + text = { Text("Start") }, ) Spacer(modifier = Modifier.weight(0.1f)) ComposeOutlinedButton( @@ -213,7 +196,7 @@ private fun MainScreen(modifier: Modifier = Modifier) { hasStarted = false EmbeddedServer.stop() }, - text = { Text("Stop") } + text = { Text("Stop") }, ) } @@ -254,4 +237,4 @@ private fun MainScreenPreview() { MainScreen() } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/utils/FileUtils.kt b/app/src/main/java/com/nphausg/app/embeddedserver/utils/FileUtils.kt index 82f4ab5..46045c2 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/utils/FileUtils.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/utils/FileUtils.kt @@ -10,13 +10,12 @@ import kotlinx.serialization.json.Json object FileUtils { fun readText(path: String): String = - this::class.java.classLoader?.getResource(path)?.readText().orEmpty() + this::class.java.classLoader + ?.getResource(path) + ?.readText() + .orEmpty() - inline fun decode(json: String): T = - Json.decodeFromString(json) + inline fun decode(json: String): T = Json.decodeFromString(json) - inline fun readJson(path: String): T = - decode(readText(path)) + inline fun readJson(path: String): T = decode(readText(path)) } - - diff --git a/app/src/main/java/com/nphausg/app/embeddedserver/utils/NetworkUtils.kt b/app/src/main/java/com/nphausg/app/embeddedserver/utils/NetworkUtils.kt index 75f5f65..6b33609 100644 --- a/app/src/main/java/com/nphausg/app/embeddedserver/utils/NetworkUtils.kt +++ b/app/src/main/java/com/nphausg/app/embeddedserver/utils/NetworkUtils.kt @@ -10,29 +10,31 @@ import java.net.InetAddress import java.net.NetworkInterface object NetworkUtils { + fun getLocalIpAddress(): String? = + getInetAddresses() + .filter { it.isLocalAddress() } + .map { it.hostAddress } + .firstOrNull() - fun getLocalIpAddress(): String? = getInetAddresses() - .filter { it.isLocalAddress() } - .map { it.hostAddress } - .firstOrNull() - - private fun getInetAddresses() = NetworkInterface.getNetworkInterfaces() - .iterator() - .asSequence() - .flatMap { networkInterface -> - networkInterface.inetAddresses - .asSequence() - .filter { !it.isLoopbackAddress } - }.toList() + private fun getInetAddresses() = + NetworkInterface + .getNetworkInterfaces() + .iterator() + .asSequence() + .flatMap { networkInterface -> + networkInterface.inetAddresses + .asSequence() + .filter { !it.isLoopbackAddress } + }.toList() } fun InetAddress.isLocalAddress(): Boolean { try { - return isSiteLocalAddress - && !hostAddress!!.contains(":") - && hostAddress != "127.0.0.1" + return isSiteLocalAddress && + !hostAddress!!.contains(":") && + hostAddress != "127.0.0.1" } catch (e: Exception) { e.printStackTrace() } return false -} \ No newline at end of file +} diff --git a/foundation/ui/src/main/java/com/masewsg/app/ui/ComposeApp.kt b/foundation/ui/src/main/java/com/masewsg/app/ui/ComposeApp.kt index 64b8000..c23f503 100644 --- a/foundation/ui/src/main/java/com/masewsg/app/ui/ComposeApp.kt +++ b/foundation/ui/src/main/java/com/masewsg/app/ui/ComposeApp.kt @@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.windowInsetsPadding -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState @@ -37,7 +36,6 @@ import com.masewsg.app.ui.components.color.LocalGradientColors @OptIn(ExperimentalComposeUiApi::class) @Composable fun ComposeApp(content: @Composable () -> Unit) { - val shouldShowGradientBackground by rememberSaveable { mutableStateOf(false) } ComposeBackground { @@ -58,7 +56,6 @@ fun ComposeApp(content: @Composable () -> Unit) { contentWindowInsets = WindowInsets(0, 0, 0, 0), snackbarHost = { SnackbarHost(snackbarHostState) }, bottomBar = { - }, ) { padding -> Row( diff --git a/foundation/ui/src/main/java/com/masewsg/app/ui/components/Background.kt b/foundation/ui/src/main/java/com/masewsg/app/ui/components/Background.kt index b383453..302dd7a 100644 --- a/foundation/ui/src/main/java/com/masewsg/app/ui/components/Background.kt +++ b/foundation/ui/src/main/java/com/masewsg/app/ui/components/Background.kt @@ -45,7 +45,6 @@ data class BackgroundTheme( */ val LocalBackgroundTheme = staticCompositionLocalOf { BackgroundTheme() } - /** * The main background for the app. * Uses [LocalBackgroundTheme] to set the color and tonal elevation of a [Surface]. @@ -200,4 +199,3 @@ fun GradientBackgroundAndroid() { ComposeGradientBackground(Modifier.size(100.dp), content = {}) } } - diff --git a/foundation/ui/src/main/java/com/masewsg/app/ui/components/button/Button.kt b/foundation/ui/src/main/java/com/masewsg/app/ui/components/button/Button.kt index 8dd7acb..69188dd 100644 --- a/foundation/ui/src/main/java/com/masewsg/app/ui/components/button/Button.kt +++ b/foundation/ui/src/main/java/com/masewsg/app/ui/components/button/Button.kt @@ -263,7 +263,10 @@ private fun ComposeButtonContent( } @Composable -fun ComposeToggleButton(checked: @Composable () -> Unit, unchecked: @Composable () -> Unit) { +fun ComposeToggleButton( + checked: @Composable () -> Unit, + unchecked: @Composable () -> Unit, +) { var hasChecked by remember { mutableStateOf(false) } FilledIconToggleButton(checked = hasChecked, onCheckedChange = { hasChecked = it }) { if (hasChecked) { diff --git a/foundation/ui/src/main/java/com/masewsg/app/ui/components/typography/Typography.kt b/foundation/ui/src/main/java/com/masewsg/app/ui/components/typography/Typography.kt index d54c8fe..a2b2963 100644 --- a/foundation/ui/src/main/java/com/masewsg/app/ui/components/typography/Typography.kt +++ b/foundation/ui/src/main/java/com/masewsg/app/ui/components/typography/Typography.kt @@ -136,4 +136,4 @@ internal val Typography = Typography( trim = Trim.LastLineBottom, ), ), -) \ No newline at end of file +)