mirror of
https://github.com/JetBrains/intellij-platform-plugin-template.git
synced 2025-12-05 14:21:55 +00:00
Add LocationProvider service with mock data
This commit is contained in:
parent
6b1deab598
commit
5dffd6f91d
@ -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) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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>
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user