Add LocationProvider service with mock data

This commit is contained in:
Nebojsa Vuksic 2025-07-23 14:54:19 +02:00
parent 6b1deab598
commit 5dffd6f91d
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package org.jetbrains.plugins.template.weatherApp.services
import com.intellij.openapi.components.Service
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import org.jetbrains.plugins.template.weatherApp.model.Location
@Service
internal class LocationsProvider : SearchAutoCompletionItemProvider<Location> {
private val locationStateFlow = MutableStateFlow(
listOf(
Location("Munich", "Germany"),
Location("Belgrade", "Serbia"),
Location("Berlin", "Germany"),
Location("Rome", "Italy"),
Location("Paris", "France"),
Location("Sydney", "Australia"),
Location("Moscow", "Russia"),
Location("Tokyo", "Japan"),
Location("New York", "USA"),
)
)
fun provideLocations(): StateFlow<List<Location>> = locationStateFlow.asStateFlow()
override fun provideSearchableItems(searchTerm: String): List<Location> {
return locationStateFlow
.value
.filter { it.isSearchApplicable(searchTerm) }
}
}

View File

@ -0,0 +1,16 @@
package org.jetbrains.plugins.template.weatherApp.services
import org.jetbrains.plugins.template.weatherApp.model.Searchable
/**
* Defines a provider interface for auto-completion items based on a search query.
*
* Implementations of this interface are responsible for supplying a filtered list of
* items that match the given search term. These items must conform to the [Searchable] interface,
* which ensures that they can be evaluated against the query.
*
* @param T The type of items provided by this interface, which must extend [Searchable].
*/
internal interface SearchAutoCompletionItemProvider<T : Searchable> {
fun provideSearchableItems(searchTerm: String): List<T>
}