Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.openflocon.flocondesktop.features.network.list.model

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.remember

@Immutable
data class NetworkItemViewState(
Expand Down Expand Up @@ -84,6 +85,22 @@ fun previewNetworkItemViewState(): NetworkItemViewState = NetworkItemViewState(
isFromOldAppInstance = false,
)

fun previewNetworkItemViewStateError(): NetworkItemViewState = NetworkItemViewState(
uuid = "0",
dateFormatted = "00:00:00.0000",
requestSize = "10.kb",
responseSize = "0.B",
timeFormatted = "333ms",
domain = "google.com",
method = NetworkMethodUi.Http.GET,
status = NetworkStatusUi("500", NetworkStatusUi.Status.ERROR),
type = NetworkItemViewState.NetworkTypeUi.Url(
query = "/search?q=test",
),
isMocked = false,
isFromOldAppInstance = false,
)

fun previewGraphQlItemViewState(): NetworkItemViewState = NetworkItemViewState(
uuid = "0",
dateFormatted = "00:00:00.0000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ import io.github.openflocon.flocondesktop.common.ui.ContextualView
import io.github.openflocon.flocondesktop.features.network.list.model.NetworkAction
import io.github.openflocon.flocondesktop.features.network.list.model.NetworkItemColumnWidths
import io.github.openflocon.flocondesktop.features.network.list.model.NetworkItemViewState
import io.github.openflocon.flocondesktop.features.network.list.model.NetworkStatusUi
import io.github.openflocon.flocondesktop.features.network.list.model.header.OnFilterAction
import io.github.openflocon.flocondesktop.features.network.list.model.header.TextFilterAction
import io.github.openflocon.flocondesktop.features.network.list.model.previewNetworkItemViewState
import io.github.openflocon.flocondesktop.features.network.list.model.previewNetworkItemViewStateError
import io.github.openflocon.flocondesktop.features.network.list.view.components.MethodView
import io.github.openflocon.flocondesktop.features.network.list.view.components.StatusView
import io.github.openflocon.flocondesktop.features.network.list.view.components.errorTagText
import io.github.openflocon.flocondesktop.features.network.list.view.components.exceptionTagText
import io.github.openflocon.library.designsystem.FloconTheme
import io.github.openflocon.library.designsystem.common.FloconContextMenuItem
import io.github.openflocon.library.designsystem.common.buildMenu
import io.github.openflocon.library.designsystem.components.FloconSurface
import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable
Expand All @@ -56,6 +61,14 @@ fun NetworkItemView(
) {
val bodySmall = FloconTheme.typography.bodySmall.copy(fontSize = 11.sp)

val errorColor = remember(state) {
when(state.status.status) {
NetworkStatusUi.Status.ERROR -> errorTagText
NetworkStatusUi.Status.EXCEPTION -> exceptionTagText
else -> null
}
}

ContextualView(
items = contextualActions(
onAction = onAction,
Expand Down Expand Up @@ -100,7 +113,7 @@ fun NetworkItemView(
Text(
state.dateFormatted,
style = bodySmall,
color = FloconTheme.colorPalette.onPrimary
color = errorColor ?: FloconTheme.colorPalette.onPrimary
)
}

Expand All @@ -120,7 +133,7 @@ fun NetworkItemView(
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style = bodySmall,
color = FloconTheme.colorPalette.onPrimary,
color = errorColor ?: FloconTheme.colorPalette.onPrimary,
modifier = Modifier
.weight(columnWidths.domainWeight)
.padding(horizontal = 4.dp),
Expand Down Expand Up @@ -295,7 +308,7 @@ fun NetworkItemViewState.NetworkTypeUi.imageColor(): Color = when (this) {
@Composable
@Preview
private fun ItemViewPreview() {
MaterialTheme {
FloconTheme {
NetworkItemView(
modifier = Modifier.fillMaxWidth(),
selected = false,
Expand All @@ -304,3 +317,18 @@ private fun ItemViewPreview() {
)
}
}

@Composable
@Preview
private fun ItemViewPreview_error() {
FloconTheme {
FloconSurface {
NetworkItemView(
modifier = Modifier.fillMaxWidth(),
selected = false,
state = previewNetworkItemViewStateError(),
onAction = {},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import org.koin.dsl.bind
import org.koin.dsl.module

internal val messagesModule = module {
single<Server> { getServer() }
single<Server> { getServer(
json = get()
) }
singleOf(::MessageRemoteDataSourceImpl) bind MessageRemoteDataSource::class
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.flocon.data.remote.models.FloconOutgoingMessageDataModel
import io.github.openflocon.domain.Constant
import io.github.openflocon.domain.messages.models.FloconReceivedFileDomainModel
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.json.Json
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid

Expand All @@ -30,4 +31,4 @@ interface Server {
@OptIn(ExperimentalUuidApi::class)
fun newRequestId(): String = Uuid.random().toString()

expect fun getServer(): Server
expect fun getServer(json: Json): Server
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.flocon.data.remote.server

actual fun getServer(): Server = ServerJvm()
import kotlinx.serialization.json.Json

actual fun getServer(json: Json): Server = ServerJvm(json)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import java.util.concurrent.atomic.AtomicBoolean
import kotlin.io.path.absolutePathString
import kotlin.time.Duration.Companion.seconds

class ServerJvm : Server {
class ServerJvm(
private val json: Json,
) : Server {
private val _receivedMessages = Channel<FloconIncomingMessageDataModel>()
override val receivedMessages = _receivedMessages.receiveAsFlow()

Expand Down Expand Up @@ -85,7 +87,7 @@ class ServerJvm : Server {
Logger.w("<---- Received raw message: $receivedText")
try {
val floconIncomingMessageDataModel =
Json.decodeFromString<FloconIncomingMessageDataModel>(
json.decodeFromString<FloconIncomingMessageDataModel>(
receivedText,
)
val device = FloconDeviceIdAndPackageNameDataModel(
Expand Down