mirror of
https://github.com/JetBrains/intellij-platform-plugin-template.git
synced 2025-12-05 06:11:52 +00:00
Add Location, WeatherForecastData, Searchable and PreviewableItem models
This commit is contained in:
parent
9a6945d9e1
commit
6b1deab598
@ -0,0 +1,34 @@
|
|||||||
|
package org.jetbrains.plugins.template.weatherApp.model
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Immutable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a location with a name and associated country.
|
||||||
|
*
|
||||||
|
* @property name The name of the location.
|
||||||
|
* @property country The associated country of the location.
|
||||||
|
* @property id A derived unique identifier for the location in the format `name, country`.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
internal data class Location(val name: String, val country: String) : PreviewableItem, Searchable {
|
||||||
|
val id: String = "$name, $country"
|
||||||
|
|
||||||
|
override fun isSearchApplicable(query: String): Boolean {
|
||||||
|
val applicableCandidates = listOf(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
country,
|
||||||
|
name.split(" ").map { it.first() }.joinToString(""),
|
||||||
|
"${name.first()}${country.first()}",
|
||||||
|
"${country.first()}${name.first()}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return applicableCandidates.any { it.contains(query, ignoreCase = true) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override val label: String
|
||||||
|
get() = id
|
||||||
|
}
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
internal data class SelectableLocation(val location: Location, val isSelected: Boolean)
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package org.jetbrains.plugins.template.weatherApp.model
|
||||||
|
|
||||||
|
interface PreviewableItem {
|
||||||
|
val label: String
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package org.jetbrains.plugins.template.weatherApp.model
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an entity that can be filtered by a search query.
|
||||||
|
*/
|
||||||
|
internal interface Searchable {
|
||||||
|
fun isSearchApplicable(query: String): Boolean
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
package org.jetbrains.plugins.template.weatherApp.model
|
||||||
|
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data class representing weather information to be displayed in the Weather Card.
|
||||||
|
*/
|
||||||
|
data class WeatherForecastData(
|
||||||
|
val cityName: String,
|
||||||
|
val temperature: Float,
|
||||||
|
val currentTime: LocalDateTime,
|
||||||
|
val windSpeed: Float,
|
||||||
|
val windDirection: WindDirection,
|
||||||
|
val humidity: Int, // Percentage
|
||||||
|
val weatherType: WeatherType
|
||||||
|
) {
|
||||||
|
companion object Companion {
|
||||||
|
val EMPTY: WeatherForecastData = WeatherForecastData(
|
||||||
|
"",
|
||||||
|
0f,
|
||||||
|
LocalDateTime.now(),
|
||||||
|
0f,
|
||||||
|
WindDirection.NORTH,
|
||||||
|
0,
|
||||||
|
WeatherType.SUNNY
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum representing different weather types.
|
||||||
|
*/
|
||||||
|
enum class WeatherType(val label: String) {
|
||||||
|
SUNNY("Sunny"),
|
||||||
|
CLOUDY("Cloudy"),
|
||||||
|
PARTLY_CLOUDY("Partly Cloudy"),
|
||||||
|
RAINY("Rainy"),
|
||||||
|
SNOWY("Snowy"),
|
||||||
|
STORMY("Stormy");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun random(): WeatherType = entries.toTypedArray().random()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum representing wind directions.
|
||||||
|
*/
|
||||||
|
enum class WindDirection(val label: String) {
|
||||||
|
NORTH("N"),
|
||||||
|
NORTH_EAST("NE"),
|
||||||
|
EAST("E"),
|
||||||
|
SOUTH_EAST("SE"),
|
||||||
|
SOUTH("S"),
|
||||||
|
SOUTH_WEST("SW"),
|
||||||
|
WEST("W"),
|
||||||
|
NORTH_WEST("NW");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun random(): WindDirection = entries.toTypedArray().random()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user