Skip to content

Commit 55385d0

Browse files
feature: Add refresh
1 parent 6d3baa5 commit 55385d0

File tree

5 files changed

+48
-30
lines changed

5 files changed

+48
-30
lines changed

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/app/ui/view/topbar/MainScreenTopBar.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import io.github.openflocon.flocondesktop.app.ui.view.topbar.actions.TopBarActio
2828
import io.github.openflocon.library.designsystem.FloconTheme
2929
import org.jetbrains.compose.resources.painterResource
3030

31+
val TopBarHeight = 48.dp
32+
3133
@Composable
3234
fun MainScreenTopBar(
3335
modifier: Modifier = Modifier,

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/app/ui/view/topbar/TopBarDeviceAndAppView.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package io.github.openflocon.flocondesktop.app.ui.view.topbar
66
import androidx.compose.animation.AnimatedVisibility
77
import androidx.compose.foundation.layout.Arrangement
88
import androidx.compose.foundation.layout.Row
9+
import androidx.compose.foundation.layout.height
910
import androidx.compose.material3.ExperimentalMaterial3Api
1011
import androidx.compose.runtime.Composable
1112
import androidx.compose.ui.Alignment
@@ -38,7 +39,8 @@ internal fun TopBarDeviceAndAppView(
3839
state = devicesState,
3940
onDeviceSelected = onDeviceSelected,
4041
deleteDevice = deleteDevice,
41-
onClickDetail = onClickDetail
42+
onClickDetail = onClickDetail,
43+
modifier = Modifier.height(TopBarHeight)
4244
)
4345

4446
AnimatedVisibility(devicesState is DevicesStateUiModel.WithDevices) {

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/app/ui/view/topbar/device/TopBarDeviceDropdown.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package io.github.openflocon.flocondesktop.app.ui.view.topbar.device
66
import androidx.compose.foundation.layout.padding
77
import androidx.compose.foundation.shape.RoundedCornerShape
88
import androidx.compose.material3.ExperimentalMaterial3Api
9+
import androidx.compose.material3.ExposedDropdownMenuAnchorType
910
import androidx.compose.material3.ExposedDropdownMenuBox
10-
import androidx.compose.material3.MenuAnchorType
1111
import androidx.compose.material3.Text
1212
import androidx.compose.runtime.Composable
1313
import androidx.compose.runtime.getValue
@@ -50,7 +50,9 @@ internal fun TopBarDeviceDropdown(
5050
) {
5151
TopBarDeviceView(
5252
device = state.deviceSelected,
53-
modifier = Modifier.menuAnchor(MenuAnchorType.PrimaryNotEditable),
53+
onClick = { expanded = true },
54+
onClickDetail = { onClickDetail(state.deviceSelected) },
55+
modifier = Modifier.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable),
5456
)
5557
}
5658
}

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/app/ui/view/topbar/device/TopBarDeviceView.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.material.icons.filled.PhoneIphone
2020
import androidx.compose.material.icons.filled.Smartphone
2121
import androidx.compose.material.icons.outlined.Close
2222
import androidx.compose.material.icons.outlined.Details
23+
import androidx.compose.material.icons.outlined.Info
2324
import androidx.compose.material.icons.outlined.MobileOff
2425
import androidx.compose.material3.Text
2526
import androidx.compose.runtime.Composable
@@ -37,6 +38,7 @@ import io.github.openflocon.library.designsystem.FloconTheme
3738
import io.github.openflocon.library.designsystem.components.FloconIcon
3839
import io.github.openflocon.library.designsystem.components.FloconIconButton
3940
import io.github.openflocon.library.designsystem.components.FloconSurface
41+
import io.github.openflocon.library.designsystem.components.FloconVerticalDivider
4042

4143
@Composable
4244
internal fun TopBarDeviceView(
@@ -55,7 +57,7 @@ internal fun TopBarDeviceView(
5557
else
5658
Modifier
5759
)
58-
.padding(horizontal = 8.dp, 4.dp),
60+
.padding(horizontal = 8.dp),
5961
verticalAlignment = Alignment.CenterVertically,
6062
horizontalArrangement = Arrangement.spacedBy(4.dp),
6163
) {
@@ -99,6 +101,7 @@ internal fun TopBarDeviceView(
99101
}
100102

101103
Row(
104+
horizontalArrangement = Arrangement.spacedBy(4.dp),
102105
verticalAlignment = Alignment.CenterVertically,
103106
) {
104107
Column(
@@ -114,21 +117,25 @@ internal fun TopBarDeviceView(
114117
Text(
115118
text = if (device.isActive.not()) {
116119
"Disconnected"
117-
} else "Connected",
120+
} else {
121+
"Connected"
122+
},
118123
color = FloconTheme.colorPalette.onPrimary,
119124
style = FloconTheme.typography.bodySmall.copy(
120125
fontSize = 10.sp,
121126
),
122127
)
123128
}
129+
FloconVerticalDivider(color = FloconTheme.colorPalette.secondary)
124130
FloconIconButton(
125131
onClick = { onClickDetail?.invoke() }
126132
) {
127133
FloconIcon(
128-
imageVector = Icons.Outlined.Details
134+
imageVector = Icons.Outlined.Info
129135
)
130136
}
131137
if (!selected && onDelete != null) {
138+
FloconVerticalDivider(color = FloconTheme.colorPalette.secondary)
132139
Spacer(modifier = Modifier.weight(1f))
133140
Box(
134141
Modifier

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/device/pages/memory/MemoryViewModel.kt

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import androidx.lifecycle.viewModelScope
44
import io.github.openflocon.domain.adb.usecase.SendCommandUseCase
55
import io.github.openflocon.flocondesktop.device.PageViewModel
66
import kotlinx.coroutines.Dispatchers
7+
import kotlinx.coroutines.delay
78
import kotlinx.coroutines.flow.MutableStateFlow
89
import kotlinx.coroutines.flow.asStateFlow
910
import kotlinx.coroutines.flow.update
1011
import kotlinx.coroutines.launch
12+
import kotlin.time.Duration.Companion.seconds
1113

1214
class MemoryViewModel(
1315
deviceSerial: String,
@@ -18,38 +20,41 @@ class MemoryViewModel(
1820
val uiState = _uiState.asStateFlow()
1921

2022
init {
21-
refreshMemory()
23+
viewModelScope.launch(Dispatchers.IO) {
24+
while (true) {
25+
refreshMemory()
26+
delay(10.seconds)
27+
}
28+
}
2229
}
2330

2431
fun onAction(action: MemoryAction) {
2532

2633
}
2734

28-
private fun refreshMemory() {
29-
viewModelScope.launch(Dispatchers.IO) {
30-
val output = sendCommand("shell", "dumpsys", "meminfo")
31-
val regex = MEM_REGEX.toRegex()
32-
val items = output.lineSequence()
33-
.map { it.trim() }
34-
.mapNotNull { regex.find(it) }
35-
.mapNotNull {
36-
try {
37-
MemoryItem(
38-
memoryUsage = formatMemoryUsage(
39-
memoryUsageKB = it.groupValues[1].replace(",", "").toDoubleOrNull()
40-
),
41-
processName = it.groupValues[2],
42-
pid = it.groupValues[3].toIntOrNull() ?: return@mapNotNull null
43-
)
44-
} catch (e: NumberFormatException) {
45-
// Handle parsing errors gracefully (e.g., log the error)
46-
null
47-
}
35+
private suspend fun refreshMemory() {
36+
val output = sendCommand("shell", "dumpsys", "meminfo")
37+
val regex = MEM_REGEX.toRegex()
38+
val items = output.lineSequence()
39+
.map { it.trim() }
40+
.mapNotNull { regex.find(it) }
41+
.mapNotNull {
42+
try {
43+
MemoryItem(
44+
memoryUsage = formatMemoryUsage(
45+
memoryUsageKB = it.groupValues[1].replace(",", "").toDoubleOrNull()
46+
),
47+
processName = it.groupValues[2],
48+
pid = it.groupValues[3].toIntOrNull() ?: return@mapNotNull null
49+
)
50+
} catch (e: NumberFormatException) {
51+
// Handle parsing errors gracefully (e.g., log the error)
52+
null
4853
}
49-
.toList()
54+
}
55+
.toList()
5056

51-
_uiState.update { it.copy(list = items) }
52-
}
57+
_uiState.update { it.copy(list = items) }
5358
}
5459

5560
private fun formatMemoryUsage(memoryUsageKB: Double?): String {

0 commit comments

Comments
 (0)