Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
6914dab5
Commit
6914dab5
authored
Mar 28, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on settings storage
parent
fb14d803
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
107 additions
and
122 deletions
+107
-122
1Weather.xcodeproj/project.pbxproj
+4
-0
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
1Weather/Extensions/Dimension+Name.swift
+4
-0
1Weather/Extensions/Measurement+String.swift
+1
-1
1Weather/Extensions/UnitPressure+Atmosphere.swift
+12
-0
1Weather/Model/HelperTypes.swift
+0
-74
1Weather/Model/Settings.swift
+17
-7
1Weather/UI/View controllers/Settings/Cells/SettingsCellFactory.swift
+8
-8
1Weather/UI/View controllers/Settings/Cells/SettingsDetailsCell.swift
+1
-2
1Weather/UI/View controllers/Settings/Cells/SettingsDetailsCellFactory.swift
+6
-5
1Weather/UI/View controllers/Settings/SettingsDetailsViewController.swift
+10
-1
1Weather/ViewModels/SettingsDetailsViewModel.swift
+40
-19
PG.playground/Contents.swift
+0
-1
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+3
-3
No files found.
1Weather.xcodeproj/project.pbxproj
View file @
6914dab5
...
@@ -94,6 +94,7 @@
...
@@ -94,6 +94,7 @@
CDC6126225E8DAB800188DA7
/* CityMoonCell.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDC6126125E8DAB800188DA7
/* CityMoonCell.swift */
;
};
CDC6126225E8DAB800188DA7
/* CityMoonCell.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDC6126125E8DAB800188DA7
/* CityMoonCell.swift */
;
};
CDC6126625E9085600188DA7
/* GraphLine.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDC6126525E9085600188DA7
/* GraphLine.swift */
;
};
CDC6126625E9085600188DA7
/* GraphLine.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDC6126525E9085600188DA7
/* GraphLine.swift */
;
};
CDC6126A25E90C8800188DA7
/* GraphLineSettings.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDC6126925E90C8800188DA7
/* GraphLineSettings.swift */
;
};
CDC6126A25E90C8800188DA7
/* GraphLineSettings.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDC6126925E90C8800188DA7
/* GraphLineSettings.swift */
;
};
CDC70833260FBFD4004A1974
/* UnitPressure+Atmosphere.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDC70832260FBFD3004A1974
/* UnitPressure+Atmosphere.swift */
;
};
CDD0F1E52572425200CF5017
/* SF-Pro.ttf in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDD0F1E42572425200CF5017
/* SF-Pro.ttf */
;
};
CDD0F1E52572425200CF5017
/* SF-Pro.ttf in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDD0F1E42572425200CF5017
/* SF-Pro.ttf */
;
};
CDD0F1E82572429E00CF5017
/* AppFont.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDD0F1E72572429E00CF5017
/* AppFont.swift */
;
};
CDD0F1E82572429E00CF5017
/* AppFont.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDD0F1E72572429E00CF5017
/* AppFont.swift */
;
};
CDD0F1EE25725BCF00CF5017
/* ThemeManager.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDD0F1ED25725BCF00CF5017
/* ThemeManager.swift */
;
};
CDD0F1EE25725BCF00CF5017
/* ThemeManager.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CDD0F1ED25725BCF00CF5017
/* ThemeManager.swift */
;
};
...
@@ -222,6 +223,7 @@
...
@@ -222,6 +223,7 @@
CDC6126125E8DAB800188DA7
/* CityMoonCell.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CityMoonCell.swift
;
sourceTree
=
"<group>"
;
};
CDC6126125E8DAB800188DA7
/* CityMoonCell.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CityMoonCell.swift
;
sourceTree
=
"<group>"
;
};
CDC6126525E9085600188DA7
/* GraphLine.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
GraphLine.swift
;
sourceTree
=
"<group>"
;
};
CDC6126525E9085600188DA7
/* GraphLine.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
GraphLine.swift
;
sourceTree
=
"<group>"
;
};
CDC6126925E90C8800188DA7
/* GraphLineSettings.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
GraphLineSettings.swift
;
sourceTree
=
"<group>"
;
};
CDC6126925E90C8800188DA7
/* GraphLineSettings.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
GraphLineSettings.swift
;
sourceTree
=
"<group>"
;
};
CDC70832260FBFD3004A1974
/* UnitPressure+Atmosphere.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"UnitPressure+Atmosphere.swift"
;
sourceTree
=
"<group>"
;
};
CDD0F1E42572425200CF5017
/* SF-Pro.ttf */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
"SF-Pro.ttf"
;
sourceTree
=
"<group>"
;
};
CDD0F1E42572425200CF5017
/* SF-Pro.ttf */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
"SF-Pro.ttf"
;
sourceTree
=
"<group>"
;
};
CDD0F1E72572429E00CF5017
/* AppFont.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppFont.swift
;
sourceTree
=
"<group>"
;
};
CDD0F1E72572429E00CF5017
/* AppFont.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppFont.swift
;
sourceTree
=
"<group>"
;
};
CDD0F1ED25725BCF00CF5017
/* ThemeManager.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ThemeManager.swift
;
sourceTree
=
"<group>"
;
};
CDD0F1ED25725BCF00CF5017
/* ThemeManager.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ThemeManager.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -348,6 +350,7 @@
...
@@ -348,6 +350,7 @@
CD593BDB2608CDF100C93428
/* Date+Now.swift */
,
CD593BDB2608CDF100C93428
/* Date+Now.swift */
,
CD2B213F260A366B00AB918A
/* UIView+InterfaceStyle.swift */
,
CD2B213F260A366B00AB918A
/* UIView+InterfaceStyle.swift */
,
CD866A61260F596B00E96A5C
/* Dimension+Name.swift */
,
CD866A61260F596B00E96A5C
/* Dimension+Name.swift */
,
CDC70832260FBFD3004A1974
/* UnitPressure+Atmosphere.swift */
,
);
);
path
=
Extensions
;
path
=
Extensions
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
...
@@ -907,6 +910,7 @@
...
@@ -907,6 +910,7 @@
CEDE4E8325EEFD56007457E9
/* WdtLocationResponse.swift in Sources */
,
CEDE4E8325EEFD56007457E9
/* WdtLocationResponse.swift in Sources */
,
CD37D3FE260DF726002669D6
/* SettingsCellFactory.swift in Sources */
,
CD37D3FE260DF726002669D6
/* SettingsCellFactory.swift in Sources */
,
CD8E041625F8F91B001785B6
/* ForecastCellFactory.swift in Sources */
,
CD8E041625F8F91B001785B6
/* ForecastCellFactory.swift in Sources */
,
CDC70833260FBFD4004A1974
/* UnitPressure+Atmosphere.swift in Sources */
,
CDC6125325E79C8F00188DA7
/* DayTimeView.swift in Sources */
,
CDC6125325E79C8F00188DA7
/* DayTimeView.swift in Sources */
,
CD251EDC26036E5400ED7A65
/* DayTimePrecipitationView.swift in Sources */
,
CD251EDC26036E5400ED7A65
/* DayTimePrecipitationView.swift in Sources */
,
CD32CE04260C742300235081
/* MenuViewController.swift in Sources */
,
CD32CE04260C742300235081
/* MenuViewController.swift in Sources */
,
...
...
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
6914dab5
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<
k
e
y
>
1Weather.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
k
e
y
>
1Weather.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
3
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
...
...
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
View file @
6914dab5
No preview for this file type
1Weather/Extensions/Dimension+Name.swift
View file @
6914dab5
...
@@ -17,5 +17,9 @@ extension Dimension {
...
@@ -17,5 +17,9 @@ extension Dimension {
var
name
:
String
{
var
name
:
String
{
return
Dimension
.
fmt
.
string
(
from
:
self
)
return
Dimension
.
fmt
.
string
(
from
:
self
)
}
}
var
identifier
:
String
{
return
"self."
}
}
}
1Weather/Extensions/Measurement+String.swift
View file @
6914dab5
...
@@ -31,6 +31,6 @@ extension Measurement {
...
@@ -31,6 +31,6 @@ extension Measurement {
extension
Temperature
{
extension
Temperature
{
var
localizedValue
:
Double
{
var
localizedValue
:
Double
{
return
self
.
converted
(
to
:
Settings
.
shared
.
temperatureType
.
unit
)
.
value
.
rounded
(
.
down
)
return
self
.
converted
(
to
:
Settings
.
shared
.
temperatureType
)
.
value
.
rounded
(
.
down
)
}
}
}
}
1Weather/Extensions/UnitPressure+Atmosphere.swift
0 → 100644
View file @
6914dab5
//
// UnitPressure+Atmosphere.swift
// 1Weather
//
// Created by Dmitry Stepanets on 28.03.2021.
//
import
UIKit
extension
UnitPressure
{
static
let
atmosphere
=
UnitPressure
(
symbol
:
"atm"
,
converter
:
UnitConverterLinear
(
coefficient
:
101325
))
}
1Weather/Model/HelperTypes.swift
View file @
6914dab5
...
@@ -50,80 +50,6 @@ public enum WeatherType: String, CaseIterable {
...
@@ -50,80 +50,6 @@ public enum WeatherType: String, CaseIterable {
}
}
}
}
public
enum
TemperatureType
:
String
,
CaseIterable
{
case
kelvin
=
"temp.kelvin"
case
celsius
=
"temp.celsius"
case
fahrenheit
=
"temp.fahrenheit"
var
unit
:
UnitTemperature
{
switch
self
{
case
.
kelvin
:
return
.
kelvin
case
.
celsius
:
return
.
celsius
case
.
fahrenheit
:
return
.
fahrenheit
}
}
}
public
enum
WindSpeedType
:
String
,
CaseIterable
{
case
metersPerSecond
=
"windSpeed.mps"
case
kilometersPerHour
=
"windSpeed.kph"
case
milesPerHour
=
"windSpeed.mph"
case
knots
=
"windSpeed.knots"
var
unit
:
UnitSpeed
{
switch
self
{
case
.
metersPerSecond
:
return
.
metersPerSecond
case
.
kilometersPerHour
:
return
.
kilometersPerHour
case
.
milesPerHour
:
return
.
milesPerHour
case
.
knots
:
return
.
knots
}
}
}
public
enum
PressureType
:
String
,
CaseIterable
{
case
inchesOfMercury
=
"pressure.inch"
case
millibars
=
"pressure.mb"
case
millimetersOfMercury
=
"pressure.mm"
case
atmosphere
=
"pressure.atm"
case
kilopascals
=
"pressure.kpa"
var
unit
:
UnitPressure
{
switch
self
{
case
.
inchesOfMercury
:
return
.
inchesOfMercury
case
.
millibars
:
return
.
millibars
case
.
millimetersOfMercury
:
return
.
millimetersOfMercury
case
.
atmosphere
:
return
UnitPressure
(
symbol
:
"atm"
,
converter
:
UnitConverterLinear
(
coefficient
:
101325
))
case
.
kilopascals
:
return
.
kilopascals
}
}
}
public
enum
DistanceType
:
String
,
CaseIterable
{
case
miles
=
"distance.mi"
case
kilometers
=
"distance.km"
var
unit
:
UnitLength
{
switch
self
{
case
.
miles
:
return
.
miles
case
.
kilometers
:
return
.
kilometers
}
}
}
public
enum
WeatherConditionType
:
CaseIterable
{
public
enum
WeatherConditionType
:
CaseIterable
{
case
precipitation
case
precipitation
case
humidity
case
humidity
...
...
1Weather/Model/Settings.swift
View file @
6914dab5
...
@@ -12,11 +12,21 @@ import Localize_Swift
...
@@ -12,11 +12,21 @@ import Localize_Swift
struct
UserDefaultsValue
<
T
>
{
struct
UserDefaultsValue
<
T
>
{
var
wrappedValue
:
T
{
var
wrappedValue
:
T
{
get
{
get
{
let
value
=
UserDefaults
.
standard
.
value
(
forKey
:
key
)
as?
T
guard
return
value
??
defaultValue
let
data
=
UserDefaults
.
standard
.
data
(
forKey
:
key
),
let
decoded
=
NSKeyedUnarchiver
.
unarchiveObject
(
with
:
data
)
as?
T
else
{
return
defaultValue
}
return
decoded
// let value = UserDefaults.standard.value(forKey: key) as? T
// return value ?? defaultValue
}
}
set
{
set
{
UserDefaults
.
standard
.
set
(
newValue
,
forKey
:
key
)
let
data
=
NSKeyedArchiver
.
archivedData
(
withRootObject
:
T
.
self
)
UserDefaults
.
standard
.
set
(
data
,
forKey
:
key
)
UserDefaults
.
standard
.
synchronize
()
UserDefaults
.
standard
.
synchronize
()
}
}
}
}
...
@@ -41,16 +51,16 @@ class Settings {
...
@@ -41,16 +51,16 @@ class Settings {
var
automaticSwitchTheme
=
false
var
automaticSwitchTheme
=
false
@UserDefaultsValue(key: "temperature_type")
@UserDefaultsValue(key: "temperature_type")
var
temperatureType
=
TemperatureTyp
e
.
celsius
var
temperatureType
=
UnitTemperatur
e
.
celsius
@UserDefaultsValue(key: "wind_speed_type")
@UserDefaultsValue(key: "wind_speed_type")
var
windSpeedType
=
WindSpeedType
.
milesPerHour
var
windSpeedType
=
UnitSpeed
.
milesPerHour
@UserDefaultsValue(key: "pressure_type")
@UserDefaultsValue(key: "pressure_type")
var
pressureType
=
PressureTyp
e
.
millibars
var
pressureType
=
UnitPressur
e
.
millibars
@UserDefaultsValue(key: "distance_type")
@UserDefaultsValue(key: "distance_type")
var
distanceType
=
DistanceType
.
miles
var
distanceType
=
UnitLength
.
miles
var
locale
:
Locale
{
var
locale
:
Locale
{
return
Locale
(
identifier
:
Localize
.
currentLanguage
())
return
Locale
(
identifier
:
Localize
.
currentLanguage
())
...
...
1Weather/UI/View controllers/Settings/Cells/SettingsCellFactory.swift
View file @
6914dab5
...
@@ -124,17 +124,17 @@ class SettingsCellFactory: CellFactoryProtocol {
...
@@ -124,17 +124,17 @@ class SettingsCellFactory: CellFactoryProtocol {
var
symbol
=
""
var
symbol
=
""
switch
rowType
{
switch
rowType
{
case
.
temperature
:
case
.
temperature
:
name
=
viewModel
.
settings
.
temperatureType
.
unit
.
name
name
=
viewModel
.
settings
.
temperatureType
.
name
symbol
=
viewModel
.
settings
.
temperatureType
.
unit
.
symbol
symbol
=
viewModel
.
settings
.
temperatureType
.
symbol
case
.
wind
:
case
.
wind
:
name
=
viewModel
.
settings
.
windSpeedType
.
unit
.
name
name
=
viewModel
.
settings
.
windSpeedType
.
name
symbol
=
viewModel
.
settings
.
windSpeedType
.
unit
.
symbol
symbol
=
viewModel
.
settings
.
windSpeedType
.
symbol
case
.
pressure
:
case
.
pressure
:
name
=
viewModel
.
settings
.
pressureType
.
unit
.
name
name
=
viewModel
.
settings
.
pressureType
.
name
symbol
=
viewModel
.
settings
.
pressureType
.
unit
.
symbol
symbol
=
viewModel
.
settings
.
pressureType
.
symbol
case
.
distance
:
case
.
distance
:
name
=
viewModel
.
settings
.
distanceType
.
unit
.
name
name
=
viewModel
.
settings
.
distanceType
.
name
symbol
=
viewModel
.
settings
.
distanceType
.
unit
.
symbol
symbol
=
viewModel
.
settings
.
distanceType
.
symbol
default
:
default
:
break
break
}
}
...
...
1Weather/UI/View controllers/Settings/Cells/SettingsDetailsCell.swift
View file @
6914dab5
...
@@ -51,10 +51,8 @@ class SettingsDetailsCell: UITableViewCell {
...
@@ -51,10 +51,8 @@ class SettingsDetailsCell: UITableViewCell {
switch
interfaceStyle
{
switch
interfaceStyle
{
case
.
light
:
case
.
light
:
label
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
label
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
checkmarkImageView
.
tintColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
case
.
dark
:
case
.
dark
:
label
.
textColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
label
.
textColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
checkmarkImageView
.
tintColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
}
}
}
}
}
}
...
@@ -89,6 +87,7 @@ private extension SettingsDetailsCell {
...
@@ -89,6 +87,7 @@ private extension SettingsDetailsCell {
func
prepareCheckmark
()
{
func
prepareCheckmark
()
{
checkmarkImageView
.
contentMode
=
.
scaleAspectFit
checkmarkImageView
.
contentMode
=
.
scaleAspectFit
checkmarkImageView
.
image
=
UIImage
(
named
:
"checkmark"
)
checkmarkImageView
.
image
=
UIImage
(
named
:
"checkmark"
)
checkmarkImageView
.
tintColor
=
ThemeManager
.
currentTheme
.
graphTintColor
container
.
addSubview
(
checkmarkImageView
)
container
.
addSubview
(
checkmarkImageView
)
checkmarkImageView
.
snp
.
makeConstraints
{
(
make
)
in
checkmarkImageView
.
snp
.
makeConstraints
{
(
make
)
in
...
...
1Weather/UI/View controllers/Settings/Cells/SettingsDetailsCellFactory.swift
View file @
6914dab5
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
//
//
import
UIKit
import
UIKit
import
Localize_Swift
class
SettingsDetailsCellFactory
:
CellFactoryProtocol
{
class
SettingsDetailsCellFactory
:
CellFactoryProtocol
{
//Private
//Private
...
@@ -56,23 +57,23 @@ class SettingsDetailsCellFactory: CellFactoryProtocol {
...
@@ -56,23 +57,23 @@ class SettingsDetailsCellFactory: CellFactoryProtocol {
switch
viewModel
.
rowType
{
switch
viewModel
.
rowType
{
case
.
temperature
:
case
.
temperature
:
cell
.
configure
(
item
:
viewModel
.
temperatures
[
indexPath
.
row
],
cell
.
configure
(
item
:
viewModel
.
temperatures
[
indexPath
.
row
]
.
name
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedTemperatureIndex
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedTemperatureIndex
,
roundedConrers
:
mask
)
roundedConrers
:
mask
)
case
.
wind
:
case
.
wind
:
cell
.
configure
(
item
:
viewModel
.
winds
[
indexPath
.
row
],
cell
.
configure
(
item
:
viewModel
.
winds
[
indexPath
.
row
]
.
name
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedWindIndex
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedWindIndex
,
roundedConrers
:
mask
)
roundedConrers
:
mask
)
case
.
pressure
:
case
.
pressure
:
cell
.
configure
(
item
:
viewModel
.
pressures
[
indexPath
.
row
],
cell
.
configure
(
item
:
viewModel
.
pressures
[
indexPath
.
row
]
.
name
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedPressureIndex
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedPressureIndex
,
roundedConrers
:
mask
)
roundedConrers
:
mask
)
case
.
distance
:
case
.
distance
:
cell
.
configure
(
item
:
viewModel
.
distances
[
indexPath
.
row
],
cell
.
configure
(
item
:
viewModel
.
distances
[
indexPath
.
row
]
.
name
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedDistanceIndex
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedDistanceIndex
,
roundedConrers
:
mask
)
roundedConrers
:
mask
)
case
.
language
:
case
.
language
:
cell
.
configure
(
item
:
viewModel
.
languages
[
indexPath
.
row
]
,
cell
.
configure
(
item
:
Localize
.
displayNameForLanguage
(
viewModel
.
languages
[
indexPath
.
row
])
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedLanguageIndex
,
isSelected
:
indexPath
.
row
==
viewModel
.
selectedLanguageIndex
,
roundedConrers
:
mask
)
roundedConrers
:
mask
)
default
:
default
:
...
...
1Weather/UI/View controllers/Settings/SettingsDetailsViewController.swift
View file @
6914dab5
...
@@ -28,6 +28,7 @@ class SettingsDetailsViewController: UIViewController {
...
@@ -28,6 +28,7 @@ class SettingsDetailsViewController: UIViewController {
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
self
.
viewModel
.
delegate
=
self
prepareController
()
prepareController
()
prepareTable
()
prepareTable
()
}
}
...
@@ -69,5 +70,13 @@ extension SettingsDetailsViewController: UITableViewDataSource {
...
@@ -69,5 +70,13 @@ extension SettingsDetailsViewController: UITableViewDataSource {
//MARK:- UITableView Delegate
//MARK:- UITableView Delegate
extension
SettingsDetailsViewController
:
UITableViewDelegate
{
extension
SettingsDetailsViewController
:
UITableViewDelegate
{
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
viewModel
.
selectUnitAtIndex
(
index
:
indexPath
.
row
)
}
}
extension
SettingsDetailsViewController
:
ViewModelDelegate
{
func
viewModelDidChange
<
P
>
(
model
:
P
)
where
P
:
ViewModelProtocol
{
tableView
.
reloadData
()
}
}
}
1Weather/ViewModels/SettingsDetailsViewModel.swift
View file @
6914dab5
...
@@ -13,40 +13,61 @@ class SettingsDetailsViewModel: ViewModelProtocol {
...
@@ -13,40 +13,61 @@ class SettingsDetailsViewModel: ViewModelProtocol {
let
rowType
:
SettingsRow
let
rowType
:
SettingsRow
weak
var
delegate
:
ViewModelDelegate
?
weak
var
delegate
:
ViewModelDelegate
?
var
temperatures
:[
String
]
{
public
var
temperatures
:[
UnitTemperature
]
{
return
TemperatureType
.
allCases
.
map
{
$0
.
rawValue
.
localized
()
}
return
[
.
kelvin
,
.
celsius
,
.
fahrenheit
]
}
}
var
winds
:[
String
]
{
public
var
winds
:[
UnitSpeed
]
{
return
WindSpeedType
.
allCases
.
map
{
$0
.
rawValue
.
localized
()
}
return
[
.
metersPerSecond
,
.
kilometersPerHour
,
.
milesPerHour
,
.
knots
]
}
}
var
pressures
:[
String
]
{
public
var
pressures
:[
UnitPressure
]
{
return
PressureType
.
allCases
.
map
{
$0
.
rawValue
.
localized
()
}
return
[
.
inchesOfMercury
,
.
millibars
,
.
millimetersOfMercury
,
.
atmosphere
,
.
kilopascals
]
}
}
var
distances
:[
String
]
{
public
var
distances
:[
UnitLength
]
{
return
DistanceType
.
allCases
.
map
{
$0
.
rawValue
.
localized
()
}
return
[
.
miles
,
.
kilometers
]
}
}
var
languages
:[
String
]
{
public
var
languages
:[
String
]
{
return
Localize
.
availableLanguages
()
return
Localize
.
availableLanguages
()
}
}
//Selected
//Selected
var
selectedTemperatureIndex
:
Int
{
public
var
selectedTemperatureIndex
:
Int
{
return
TemperatureType
.
allCases
.
firstIndex
{
Settings
.
shared
.
temperatureType
==
$0
}
??
-
1
return
temperatures
.
firstIndex
{
$0
==
Settings
.
shared
.
temperatureType
}
??
-
1
}
}
var
selectedWindIndex
:
Int
{
public
var
selectedWindIndex
:
Int
{
return
WindSpeedType
.
allCases
.
firstIndex
{
Settings
.
shared
.
windSpeedType
==
$0
}
??
-
1
return
winds
.
firstIndex
{
$0
==
Settings
.
shared
.
windSpeedType
}
??
-
1
}
}
var
selectedPressureIndex
:
Int
{
public
var
selectedPressureIndex
:
Int
{
return
PressureType
.
allCases
.
firstIndex
{
Settings
.
shared
.
pressureType
==
$0
}
??
-
1
return
pressures
.
firstIndex
{
$0
==
Settings
.
shared
.
pressureType
}
??
-
1
}
}
var
selectedDistanceIndex
:
Int
{
public
var
selectedDistanceIndex
:
Int
{
return
DistanceType
.
allCases
.
firstIndex
{
Settings
.
shared
.
distanceType
==
$0
}
??
-
1
return
distances
.
firstIndex
{
$0
==
Settings
.
shared
.
distanceType
}
??
-
1
}
}
var
selectedLanguageIndex
:
Int
{
public
var
selectedLanguageIndex
:
Int
{
return
Localize
.
availableLanguages
()
.
firstIndex
{
$0
==
Localize
.
currentLanguage
()}
??
-
1
return
Localize
.
availableLanguages
()
.
firstIndex
{
$0
==
Localize
.
currentLanguage
()
}
??
-
1
}
}
init
(
rowType
:
SettingsRow
)
{
init
(
rowType
:
SettingsRow
)
{
self
.
rowType
=
rowType
self
.
rowType
=
rowType
}
}
public
func
selectUnitAtIndex
(
index
:
Int
)
{
switch
rowType
{
case
.
temperature
:
Settings
.
shared
.
temperatureType
=
temperatures
[
index
]
case
.
wind
:
Settings
.
shared
.
windSpeedType
=
winds
[
index
]
case
.
pressure
:
Settings
.
shared
.
pressureType
=
pressures
[
index
]
case
.
distance
:
Settings
.
shared
.
distanceType
=
distances
[
index
]
default
:
break
}
delegate
?
.
viewModelDidChange
(
model
:
self
)
}
public
func
selectLaanguage
(
identifier
:
String
,
atIndex
index
:
Int
)
{
}
}
}
PG.playground/Contents.swift
View file @
6914dab5
import
Foundation
import
Foundation
import
UIKit
import
UIKit
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
6914dab5
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
<
k
e
y
>
Cirque.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
k
e
y
>
Cirque.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
6
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
4
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
Localize-Swift.xcscheme
<
/k
e
y
>
<
k
e
y
>
Localize-Swift.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
<
k
e
y
>
Localize-Swift.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
k
e
y
>
Localize-Swift.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
4
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
3
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
Pods-1Weather.xcscheme
<
/k
e
y
>
<
k
e
y
>
Pods-1Weather.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
...
@@ -52,7 +52,7 @@
...
@@ -52,7 +52,7 @@
<
k
e
y
>
XMLCoder.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
k
e
y
>
XMLCoder.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
6
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
SuppressBuildableAutocreation
<
/k
e
y
>
<
k
e
y
>
SuppressBuildableAutocreation
<
/k
e
y
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment