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
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.LocalOverscrollFactory
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
Expand Down Expand Up @@ -46,6 +47,7 @@ fun SearchScreen(
val list: List<Oui> by viewModel.list.collectAsState(listOf())
val lookupList: List<String> by viewModel.bulkLookupList.collectAsState(listOf())
val placeholder by viewModel.placeholder.collectAsState(UiSearchPlaceholder.Instructions)
val selectedOui by viewModel.selectedOui.collectAsState()

val clipboardPasteScope = rememberCoroutineScope()
LifecycleEventEffect(Lifecycle.Event.ON_RESUME, lifecycleOwner) {
Expand All @@ -62,7 +64,9 @@ fun SearchScreen(
onTextChange = { value -> viewModel.onTextChange(value) },
list = list,
lookupList = lookupList,
placeholder = placeholder
placeholder = placeholder,
selectedOui = selectedOui,
onOuiSelected = { oui -> viewModel.onOuiSelected(oui) }
)
}

Expand All @@ -73,7 +77,9 @@ fun SearchScreen(
onTextChange: (value: String) -> Unit,
list: List<Oui>,
lookupList: List<String>,
placeholder: UiSearchPlaceholder?
placeholder: UiSearchPlaceholder?,
selectedOui: Oui?,
onOuiSelected: (Oui?) -> Unit
) {
val scrollState = rememberLazyListState()
val bottomBarVisible by remember { derivedStateOf { scrollState.firstVisibleItemIndex == 0 } }
Expand Down Expand Up @@ -129,15 +135,29 @@ fun SearchScreen(
}
}
else
items(list) { device ->
items(list) { oui ->
ListItem(
headlineContent = { Text(device.orgName) },
supportingContent = { Text(device.oui) }
headlineContent = { Text(oui.orgName) },
supportingContent = { Text(oui.oui) },
modifier = Modifier.clickable { onOuiSelected(oui) }
)
}
}
}
}

selectedOui?.let { oui ->
AlertDialog(
onDismissRequest = { onOuiSelected(null) },
title = { Text(oui.orgName) },
text = { Text(oui.orgAddress) },
confirmButton = {
TextButton(onClick = { onOuiSelected(null) }) {
Text(stringResource(android.R.string.ok))
}
}
)
}
}

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -238,7 +258,9 @@ fun DefaultPreview() {
Oui("FF:FF:FF", "Google", "")
),
lookupList = listOf("BB:BB:BB"),
placeholder = null
placeholder = null,
selectedOui = null,
onOuiSelected = { }
)
}
}
Expand All @@ -253,7 +275,9 @@ fun EmptyPreview() {
onTextChange = { },
list = emptyList(),
lookupList = emptyList(),
placeholder = UiSearchPlaceholder.NoResults
placeholder = UiSearchPlaceholder.NoResults,
selectedOui = null,
onOuiSelected = { }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import org.alberto97.ouilookup.db.Oui
import org.alberto97.ouilookup.repository.IOuiRepository
import org.alberto97.ouilookup.tools.IUpdateManager
import org.alberto97.ouilookup.tools.StringInspector
Expand All @@ -26,6 +27,9 @@ class SearchViewModel @Inject constructor(
private val _bulkLookupList = MutableStateFlow(listOf<String>())
val bulkLookupList = _bulkLookupList.asStateFlow()

private val _selectedOui = MutableStateFlow<Oui?>(null)
val selectedOui = _selectedOui.asStateFlow()

val list = combine(_text, _bulkLookupList) { text, list ->
if (text.isNotEmpty())
repository.search(text)
Expand Down Expand Up @@ -71,6 +75,10 @@ class SearchViewModel @Inject constructor(
}
}

fun onOuiSelected(oui: Oui?) {
_selectedOui.value = oui
}

fun onTextChange(text: String) {
val list = StringInspector.splitForList(text)
if (StringInspector.countSearchable(list) > 1) {
Expand Down