Commit 45c34fb1 by Demid Merzlyakov

Fix showing of state for US locations in search.

parent f2156b33
......@@ -164,6 +164,7 @@
CE578FE525FB415F00E8B85D /* CityCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE225FB415F00E8B85D /* CityCell.swift */; };
CE578FE625FB415F00E8B85D /* LocationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE325FB415F00E8B85D /* LocationViewController.swift */; };
CE578FE725FB415F00E8B85D /* LocationsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */; };
CE6BE4942634170800626822 /* USStateCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6BE4932634170800626822 /* USStateCode.swift */; };
CE89628C26175D8D00CA274A /* regenerate_objects.sh in Resources */ = {isa = PBXBuildFile; fileRef = CE89628B26175D8D00CA274A /* regenerate_objects.sh */; };
CE8962A226175DF500CA274A /* _CoreAirQuality.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE89629126175DF400CA274A /* _CoreAirQuality.swift */; };
CE8962A426175DF500CA274A /* _CorePollutant.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE89629326175DF400CA274A /* _CorePollutant.swift */; };
......@@ -401,6 +402,7 @@
CE578FE225FB415F00E8B85D /* CityCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CityCell.swift; sourceTree = "<group>"; };
CE578FE325FB415F00E8B85D /* LocationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationViewController.swift; sourceTree = "<group>"; };
CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationsViewModel.swift; sourceTree = "<group>"; };
CE6BE4932634170800626822 /* USStateCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = USStateCode.swift; sourceTree = "<group>"; };
CE89628B26175D8D00CA274A /* regenerate_objects.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = regenerate_objects.sh; sourceTree = "<group>"; };
CE89629126175DF400CA274A /* _CoreAirQuality.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _CoreAirQuality.swift; sourceTree = "<group>"; };
CE89629326175DF400CA274A /* _CorePollutant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _CorePollutant.swift; sourceTree = "<group>"; };
......@@ -1155,6 +1157,7 @@
CEAFF0A225E0FF0800DF4EBF /* LocationManager.swift */,
CEF959A526035A2600975FAA /* DeviceLocationMonitor.swift */,
CD37D3EA260DD30F002669D6 /* Settings.swift */,
CE6BE4932634170800626822 /* USStateCode.swift */,
);
path = Model;
sourceTree = "<group>";
......@@ -1526,6 +1529,7 @@
CDD0F1EE25725BCF00CF5017 /* ThemeManager.swift in Sources */,
CD1237F4255D889F00C98139 /* GradientView.swift in Sources */,
CD37D3EF260DF4E6002669D6 /* SettingsViewController.swift in Sources */,
CE6BE4942634170800626822 /* USStateCode.swift in Sources */,
CD593BC926089FC100C93428 /* UITableView+HeaderSize.swift in Sources */,
CD37D3F3260DF4FB002669D6 /* SettingsCoordinator.swift in Sources */,
CD1237C3255D5C5900C98139 /* AppDelegate.swift in Sources */,
......
......@@ -147,7 +147,7 @@ extension GeoNamesPlace: PartialLocation {
}
var region: String? {
return stateCode
return stateCode ?? state
}
var cityName: String? {
......
//
// USStateCode.swift
// OneWeather
//
// Created by Demid Merzlyakov on 04.02.2021.
// Copyright © 2021 OneLouder, Inc. All rights reserved.
//
import Foundation
struct USStateCode {
@available(*, unavailable)
init() {}
public static let maxStateCodeLength = 2
public static func stateCode(for fullStateName: String?) -> String? {
// This mapping is based on Android's USStateCode, but I added an "armed forces": "AE" case
// and also made all the items lowercase, so that
guard let fullStateName = fullStateName else { return nil }
let mapping = [
"alabama": "AL",
"alaska": "AK",
"alberta": "AB",
"american samoa": "AS",
"arizona": "AZ",
"arkansas": "AR",
"armed forces": "AE",
"armed forces (ae)": "AE",
"armed forces americas": "AA",
"armed forces pacific": "AP",
"british columbia": "BC",
"california": "CA",
"colorado": "CO",
"connecticut": "CT",
"delaware": "DE",
"district of columbia": "DC",
"florida": "FL",
"georgia": "GA",
"guam": "GU",
"hawaii": "HI",
"idaho": "ID",
"illinois": "IL",
"indiana": "IN",
"iowa": "IA",
"kansas": "KS",
"kentucky": "KY",
"louisiana": "LA",
"maine": "ME",
"manitoba": "MB",
"maryland": "MD",
"massachusetts": "MA",
"michigan": "MI",
"minnesota": "MN",
"mississippi": "MS",
"missouri": "MO",
"montana": "MT",
"nebraska": "NE",
"nevada": "NV",
"new brunswick": "NB",
"new hampshire": "NH",
"new jersey": "NJ",
"new mexico": "NM",
"new york": "NY",
"newfoundland": "NF",
"north carolina": "NC",
"north dakota": "ND",
"northwest territories": "NT",
"nova scotia": "NS",
"nunavut": "NU",
"ohio": "OH",
"oklahoma": "OK",
"ontario": "ON",
"oregon": "OR",
"pennsylvania": "PA",
"prince edward island": "PE",
"puerto rico": "PR",
"quebec": "PQ",
"rhode island": "RI",
"saskatchewan": "SK",
"south carolina": "SC",
"south dakota": "SD",
"tennessee": "TN",
"texas": "TX",
"utah": "UT",
"vermont": "VT",
"virgin islands": "VI",
"virginia": "VA",
"washington": "WA",
"west virginia": "WV",
"wisconsin": "WI",
"wyoming": "WY",
"yukon territory": "YT",
]
return mapping[fullStateName.lowercased()]
}
}
......@@ -142,6 +142,7 @@ public class LocationsViewModel {
place.city = hit.object.localeNames?.first
place.state = hit.object.administrative?.first
place.stateCode = USStateCode.stateCode(for: place.state) // if it's not US, it will not work, but this attribute was not filled otherwise anyway, so it's our best guess
place.country = hit.object.country ?? "" // ?? "" part is from the Android code, may be not needed on iOS
place.countryCode = hit.object.countryCode?.rawValue.uppercased() ?? "" // ?? "" part is from the Android code, may be not needed on iOS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment