Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store country code in Vessel Information page #336

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions o-fish-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
BCE480EEF0B2F0E6A189ECC6 /* ViolationPickerDataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48E834DC859834E1E01E4 /* ViolationPickerDataView.swift */; };
BCE4814543022D42A642CA4A /* KeyboardController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE486CABA40FF0D6D14E5F9 /* KeyboardController.swift */; };
BCE4815F88C024AD476B8DE2 /* DutyState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48D936613848423BBAF33 /* DutyState.swift */; };
BCE4817B0B89F5D95768925A /* CountryPickerView.swif.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE486BCBC428C8539A22A9D /* CountryPickerView.swif.swift */; };
BCE4817B0B89F5D95768925A /* CountryPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE486BCBC428C8539A22A9D /* CountryPickerView.swift */; };
BCE4820A7E5A15B8AA93DB4A /* TextPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48555D654177BE1259C7B /* TextPickerView.swift */; };
BCE4825F4A971D6F6F24D571 /* CatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48E5B87FCD1126A5C26C4 /* CatchView.swift */; };
BCE48275C134A902EF0293D4 /* GlassIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48B8D8932DF568200B811 /* GlassIconView.swift */; };
Expand Down Expand Up @@ -525,7 +525,7 @@
BCE4867F873ECC8BEEF0AF47 /* ViolationCrewMemberSelectView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViolationCrewMemberSelectView.swift; sourceTree = "<group>"; };
BCE4869550ED589453572C7E /* VesselInformationInputView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VesselInformationInputView.swift; sourceTree = "<group>"; };
BCE486BBFA7E770F010DA1AA /* AlertItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertItem.swift; sourceTree = "<group>"; };
BCE486BCBC428C8539A22A9D /* CountryPickerView.swif.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryPickerView.swif.swift; sourceTree = "<group>"; };
BCE486BCBC428C8539A22A9D /* CountryPickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryPickerView.swift; sourceTree = "<group>"; };
BCE486CABA40FF0D6D14E5F9 /* KeyboardController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardController.swift; sourceTree = "<group>"; };
BCE486E471A682C466E106D0 /* ModalView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalView.swift; sourceTree = "<group>"; };
BCE486EF5A22D91EE1260968 /* MainNavigationRootView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainNavigationRootView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1229,7 +1229,7 @@
BCE48B04A5E3CDA8E4879663 /* Country */ = {
isa = PBXGroup;
children = (
BCE486BCBC428C8539A22A9D /* CountryPickerView.swif.swift */,
BCE486BCBC428C8539A22A9D /* CountryPickerView.swift */,
BCE4824D90AA3E6903C93562 /* CountryPickerDataView.swift */,
);
path = Country;
Expand Down Expand Up @@ -1731,7 +1731,7 @@
BCE48B9CAD5B8F1EB27C60BD /* ChooseEMSView.swift in Sources */,
BCE48B02D6D3331545500562 /* ChooseSpeciesView.swift in Sources */,
BCE48D2FCD0F20F23AEC0EF4 /* ChooseNationalityView.swift in Sources */,
BCE4817B0B89F5D95768925A /* CountryPickerView.swif.swift in Sources */,
BCE4817B0B89F5D95768925A /* CountryPickerView.swift in Sources */,
3093805F24460A2A00E23350 /* VesselRecordItemView.swift in Sources */,
BCE48D4A017A5B4B64690CCE /* ViolationPickerView.swift in Sources */,
BCE4854AADAFBC1B0BD9ECFB /* ChooseViolationsView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct CountryPickerDataView: View {

var body: some View {
HStack(spacing: Dimensions.spacing) {
Text("\(flag(from: item.image).uppercased())")
Text("\(flag(for: item.code).uppercased())")
.font(.system(size: Dimensions.imageSize))
.foregroundColor(.white)
.clipShape(Circle())
Expand All @@ -34,10 +34,10 @@ struct CountryPickerDataView: View {
.padding(.bottom, Dimensions.bottomPadding)
}

private func flag(from country: String) -> String {
private func flag(for countryCode: String) -> String {
let base: UInt32 = 127397 // magic number for transforming country prefix into emoji
var emojiFlag = ""
for letter in country.uppercased().unicodeScalars {
for letter in countryCode.uppercased().unicodeScalars {
if let element = UnicodeScalar(base + letter.value) {
emojiFlag.unicodeScalars.append(element)
}
Expand All @@ -49,7 +49,7 @@ struct CountryPickerDataView: View {

struct CountryPickerDataView_Previews: PreviewProvider {
static var previews: some View {
CountryPickerDataView(item: CountryPickerData(image: "FR",
CountryPickerDataView(item: CountryPickerData(code: "FR",
title: "France"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import SwiftUI

struct CountryPickerData {
var image: String
var code: String
var title: String
}

extension CountryPickerData: SearchableDataProtocol {
static let notSelected = CountryPickerData(image: "", title: "")
static let notSelected = CountryPickerData(code: "", title: "")

var id: String {
title
Expand Down Expand Up @@ -43,11 +43,11 @@ struct CountryPickerView: View {

struct CountryPickerView_Previews: PreviewProvider {
static var previews: some View {
let items = [CountryPickerData(image: "FR", title: "France"),
CountryPickerData(image: "NL", title: "Netherlands"),
CountryPickerData(image: "PL", title: "Poland")]
let items = [CountryPickerData(code: "FR", title: "France"),
CountryPickerData(code: "NL", title: "Netherlands"),
CountryPickerData(code: "PL", title: "Poland")]

return CountryPickerView(selectedItem: .constant(CountryPickerData(image: "FR",
return CountryPickerView(selectedItem: .constant(CountryPickerData(code: "FR",
title: "France")),
items: items,
title: "Title" ,
Expand Down
6 changes: 5 additions & 1 deletion o-fish-ios/Views/ReportDetails/VesselSummaryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct VesselSummaryView: View {

HStack(alignment: .top, spacing: Dimensions.spacing) {
LabeledText(label: "Home Port", text: "\(vessel.homePort)")
LabeledText(label: "Flag State", text: "\(vessel.nationality)")
LabeledText(label: "Flag State", text: "\(getCountryName(from: vessel.nationality))")
}

if !vessel.attachments.notes.isEmpty || !vessel.attachments.photoIDs.isEmpty {
Expand All @@ -47,6 +47,10 @@ struct VesselSummaryView: View {
}
.padding(.bottom, Dimensions.bottomPading)
}

private func getCountryName(from countryCode: String) -> String {
return Locale.autoupdatingCurrent.localizedString(forRegionCode: countryCode) ?? ""
}
}

struct VesselSummaryView_Previews: PreviewProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private class CountryHelper {

private func pickerDataFromCountry(code: String) -> CountryPickerData? {
if let name = Locale.autoupdatingCurrent.localizedString(forRegionCode: code) {
return CountryPickerData(image: code, title: name)
return CountryPickerData(code: code, title: name)
}
return nil
}
Expand Down Expand Up @@ -70,7 +70,7 @@ struct ChooseNationalityView: View {

struct ChooseNationalityView_Previews: PreviewProvider {
static var previews: some View {
ChooseNationalityView(selectedItem: .constant(CountryPickerData(image: "FR",
ChooseNationalityView(selectedItem: .constant(CountryPickerData(code: "FR",
title: "France")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct VesselInformationInputView: View {
Binding<CountryPickerData>(
get: { self.displayedNationality },
set: {
self.vessel.nationality = $0.title
self.vessel.nationality = $0.code
self.checkAllInput()
}
))
Expand Down Expand Up @@ -116,17 +116,11 @@ struct VesselInformationInputView: View {
}

private var displayedNationality: CountryPickerData {
CountryPickerData(image: "\(transformCountryName(from: vessel.nationality))", title: vessel.nationality)
CountryPickerData(code: vessel.nationality, title: getCountryName(from: vessel.nationality))
}

private func transformCountryName(from country: String) -> String {
for code in Locale.isoRegionCodes as [String] {
if let name = Locale.autoupdatingCurrent.localizedString(forRegionCode: code),
name == country {
return code
}
}
return ""
private func getCountryName(from countryCode: String) -> String {
return Locale.autoupdatingCurrent.localizedString(forRegionCode: countryCode) ?? ""
}

private func checkAllInput() {
Expand Down