diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/LocationsProvider.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/LocationsProvider.kt new file mode 100644 index 0000000..6b192ef --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/LocationsProvider.kt @@ -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 { + 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> = locationStateFlow.asStateFlow() + + override fun provideSearchableItems(searchTerm: String): List { + return locationStateFlow + .value + .filter { it.isSearchApplicable(searchTerm) } + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/SearchAutoCompletionItemProvider.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/SearchAutoCompletionItemProvider.kt new file mode 100644 index 0000000..521e6e2 --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/SearchAutoCompletionItemProvider.kt @@ -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 { + fun provideSearchableItems(searchTerm: String): List +} \ No newline at end of file