Skip to content

Commit 4239f5f

Browse files
authored
Develop/refactor (#62)
* Добавил гит хук на проверку swiftformat * Добавил проверку на main-ветку при коммитах * Добавил swiftformat и обновил README * Доработки - Поднял версию CachedAcyncImage - Не меняю фильтр по городу при каждом появлении экрана с картой - Мелкий рефактор - Поднял версию до 3.1.4
1 parent 9d75026 commit 4239f5f

File tree

5 files changed

+46
-54
lines changed

5 files changed

+46
-54
lines changed

SwiftUI-WorkoutApp.xcodeproj/project.pbxproj

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
67515699283FEC3100501346 /* PickedImagesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67515698283FEC3100501346 /* PickedImagesList.swift */; };
4949
6751569B2841316400501346 /* MediaFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6751569A2841316400501346 /* MediaFile.swift */; };
5050
6751569F28423B6F00501346 /* AddPhotoButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6751569E28423B6F00501346 /* AddPhotoButton.swift */; };
51+
6751DA3D299784C900A13CD5 /* CachedAcyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 6751DA3C299784C900A13CD5 /* CachedAcyncImage */; };
5152
675462FB282F8CBF005BC86A /* ChatBubble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 675462FA282F8CBF005BC86A /* ChatBubble.swift */; };
5253
675462FF282FC6E6005BC86A /* MainUserForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 675462FE282FC6E6005BC86A /* MainUserForm.swift */; };
5354
6758463B2965B0F6000BA5E0 /* UIImage+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6758463A2965B0F6000BA5E0 /* UIImage+.swift */; };
@@ -149,7 +150,6 @@
149150
67FBF64928337876008A7968 /* EventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67FBF64828337876008A7968 /* EventType.swift */; };
150151
67FBF64B283379D9008A7968 /* EventsListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67FBF64A283379D9008A7968 /* EventsListViewModel.swift */; };
151152
67FBF64F28338A2E008A7968 /* EventDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67FBF64E28338A2E008A7968 /* EventDetailsView.swift */; };
152-
67FE5582297BF46100DC52BF /* CachedAcyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 67FE5581297BF46100DC52BF /* CachedAcyncImage */; };
153153
67FE5585297BF82000DC52BF /* ShortAddressService in Frameworks */ = {isa = PBXBuildFile; productRef = 67FE5584297BF82000DC52BF /* ShortAddressService */; };
154154
/* End PBXBuildFile section */
155155

@@ -337,7 +337,7 @@
337337
buildActionMask = 2147483647;
338338
files = (
339339
670431512964544D0090CAC3 /* FeedbackSender in Frameworks */,
340-
67FE5582297BF46100DC52BF /* CachedAcyncImage in Frameworks */,
340+
6751DA3D299784C900A13CD5 /* CachedAcyncImage in Frameworks */,
341341
67FE5585297BF82000DC52BF /* ShortAddressService in Frameworks */,
342342
67CB32D4297BE872009380DF /* DateFormatterService in Frameworks */,
343343
672609522977256900042226 /* CachedAcyncImage in Frameworks */,
@@ -942,8 +942,8 @@
942942
672609512977256900042226 /* CachedAcyncImage */,
943943
67CB32D0297BE0F8009380DF /* NetworkStatus */,
944944
67CB32D3297BE872009380DF /* DateFormatterService */,
945-
67FE5581297BF46100DC52BF /* CachedAcyncImage */,
946945
67FE5584297BF82000DC52BF /* ShortAddressService */,
946+
6751DA3C299784C900A13CD5 /* CachedAcyncImage */,
947947
);
948948
productName = "SwiftUI-WorkoutApp";
949949
productReference = 6798AA3A280AEDC900DB76F1 /* WorkoutApp.app */;
@@ -986,7 +986,7 @@
986986
6704314F2964544D0090CAC3 /* XCRemoteSwiftPackageReference "FeedbackSender" */,
987987
67F9534D2964A5700077DFDC /* XCRemoteSwiftPackageReference "ImagePicker" */,
988988
67CB32CF297BE0F8009380DF /* XCRemoteSwiftPackageReference "NetworkStatus" */,
989-
67FE5580297BF46100DC52BF /* XCRemoteSwiftPackageReference "CachedAcyncImage" */,
989+
6751DA3B299784C900A13CD5 /* XCRemoteSwiftPackageReference "CachedAcyncImage" */,
990990
);
991991
productRefGroup = 6798AA3B280AEDC900DB76F1 /* Products */;
992992
projectDirPath = "";
@@ -1451,7 +1451,7 @@
14511451
"$(inherited)",
14521452
"@executable_path/Frameworks",
14531453
);
1454-
MARKETING_VERSION = 3.1.3;
1454+
MARKETING_VERSION = 3.1.4;
14551455
PRODUCT_BUNDLE_IDENTIFIER = com.FGU.WorkOut;
14561456
PRODUCT_NAME = WorkoutApp;
14571457
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -1487,7 +1487,7 @@
14871487
"$(inherited)",
14881488
"@executable_path/Frameworks",
14891489
);
1490-
MARKETING_VERSION = 3.1.3;
1490+
MARKETING_VERSION = 3.1.4;
14911491
PRODUCT_BUNDLE_IDENTIFIER = com.FGU.WorkOut;
14921492
PRODUCT_NAME = WorkoutApp;
14931493
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -1549,25 +1549,25 @@
15491549
minimumVersion = 1.0.0;
15501550
};
15511551
};
1552-
67CB32CF297BE0F8009380DF /* XCRemoteSwiftPackageReference "NetworkStatus" */ = {
1552+
6751DA3B299784C900A13CD5 /* XCRemoteSwiftPackageReference "CachedAcyncImage" */ = {
15531553
isa = XCRemoteSwiftPackageReference;
1554-
repositoryURL = "https://github.com/OlegEremenko991/NetworkStatus";
1554+
repositoryURL = "https://github.com/OlegEremenko991/CachedAcyncImage";
15551555
requirement = {
15561556
kind = upToNextMajorVersion;
15571557
minimumVersion = 1.0.0;
15581558
};
15591559
};
1560-
67F9534D2964A5700077DFDC /* XCRemoteSwiftPackageReference "ImagePicker" */ = {
1560+
67CB32CF297BE0F8009380DF /* XCRemoteSwiftPackageReference "NetworkStatus" */ = {
15611561
isa = XCRemoteSwiftPackageReference;
1562-
repositoryURL = "https://github.com/OlegEremenko991/ImagePicker";
1562+
repositoryURL = "https://github.com/OlegEremenko991/NetworkStatus";
15631563
requirement = {
15641564
kind = upToNextMajorVersion;
15651565
minimumVersion = 1.0.0;
15661566
};
15671567
};
1568-
67FE5580297BF46100DC52BF /* XCRemoteSwiftPackageReference "CachedAcyncImage" */ = {
1568+
67F9534D2964A5700077DFDC /* XCRemoteSwiftPackageReference "ImagePicker" */ = {
15691569
isa = XCRemoteSwiftPackageReference;
1570-
repositoryURL = "https://github.com/OlegEremenko991/CachedAcyncImage";
1570+
repositoryURL = "https://github.com/OlegEremenko991/ImagePicker";
15711571
requirement = {
15721572
kind = upToNextMajorVersion;
15731573
minimumVersion = 1.0.0;
@@ -1585,6 +1585,11 @@
15851585
isa = XCSwiftPackageProductDependency;
15861586
productName = CachedAcyncImage;
15871587
};
1588+
6751DA3C299784C900A13CD5 /* CachedAcyncImage */ = {
1589+
isa = XCSwiftPackageProductDependency;
1590+
package = 6751DA3B299784C900A13CD5 /* XCRemoteSwiftPackageReference "CachedAcyncImage" */;
1591+
productName = CachedAcyncImage;
1592+
};
15881593
675A37092854810B00DAE071 /* Utils */ = {
15891594
isa = XCSwiftPackageProductDependency;
15901595
productName = Utils;
@@ -1603,11 +1608,6 @@
16031608
package = 67F9534D2964A5700077DFDC /* XCRemoteSwiftPackageReference "ImagePicker" */;
16041609
productName = ImagePicker;
16051610
};
1606-
67FE5581297BF46100DC52BF /* CachedAcyncImage */ = {
1607-
isa = XCSwiftPackageProductDependency;
1608-
package = 67FE5580297BF46100DC52BF /* XCRemoteSwiftPackageReference "CachedAcyncImage" */;
1609-
productName = CachedAcyncImage;
1610-
};
16111611
67FE5584297BF82000DC52BF /* ShortAddressService */ = {
16121612
isa = XCSwiftPackageProductDependency;
16131613
productName = ShortAddressService;

SwiftUI-WorkoutApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SwiftUI-WorkoutApp/Screens/SportsGrounds/Map/MapViewUI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ struct MapViewUI: UIViewRepresentable {
5252
if needUpdateAnnotations {
5353
mapView.removeAnnotations(mapView.annotations)
5454
mapView.addAnnotations(annotations)
55-
needUpdateAnnotations.toggle()
55+
Task { @MainActor in needUpdateAnnotations.toggle() }
5656
}
5757
if needUpdateRegion {
5858
mapView.setRegion(region, animated: false)
59-
needUpdateRegion.toggle()
59+
Task { @MainActor in needUpdateRegion.toggle() }
6060
}
6161
setTrackingButtonHidden(ignoreUserLocation, on: mapView)
6262
}

SwiftUI-WorkoutApp/Screens/SportsGrounds/Map/SportsGroundsMapView.swift

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ struct SportsGroundsMapView: View {
2727
}
2828
}
2929
.onChange(of: viewModel.errorMessage, perform: setupErrorAlert)
30-
.onChange(of: defaults.mainUserInfo, perform: updateFilterForUser)
30+
.onChange(of: defaults.mainUserInfo, perform: updateUserCountryAndCity)
3131
.alert(alertMessage, isPresented: $showErrorAlert) {
3232
Button("Ok", action: closeAlert)
3333
}
3434
.task { await askForGrounds() }
3535
.onAppear {
3636
viewModel.onAppearAction()
37-
updateFilterForUser(info: defaults.mainUserInfo)
37+
updateUserCountryAndCity(with: defaults.mainUserInfo)
3838
}
3939
.onDisappear { viewModel.onDisappearAction() }
4040
.toolbar {
@@ -43,7 +43,7 @@ struct SportsGroundsMapView: View {
4343
filterButton
4444
refreshButton
4545
}
46-
.disabled(isLeftToolbarPartDisabled)
46+
.disabled(viewModel.isLoading)
4747
}
4848
ToolbarItem(placement: .navigationBarTrailing) {
4949
rightBarButton
@@ -133,25 +133,15 @@ private extension SportsGroundsMapView {
133133
var navigationTitleDisplayMode: NavigationBarItem.TitleDisplayMode {
134134
switch presentation {
135135
case .list: return .inline
136-
case .map: return needToHideMap ? .large : .inline
136+
case .map: return viewModel.shouldHideMap ? .large : .inline
137137
}
138138
}
139139

140-
var needToHideMap: Bool {
141-
!viewModel.isRegionSet && viewModel.ignoreUserLocation
142-
}
143-
144140
var mapOpacity: Double {
145-
guard !needToHideMap else { return .zero }
141+
guard !viewModel.shouldHideMap else { return .zero }
146142
return viewModel.isLoading ? 0.5 : 1
147143
}
148144

149-
var isLeftToolbarPartDisabled: Bool {
150-
viewModel.isRegionSet
151-
? viewModel.isLoading
152-
: viewModel.isLoading || viewModel.ignoreUserLocation
153-
}
154-
155145
var locationSettingsReminder: some View {
156146
VStack {
157147
Text(viewModel.locationErrorMessage)
@@ -221,11 +211,8 @@ private extension SportsGroundsMapView {
221211
viewModel.deleteSportsGroundFromList(with: groundID)
222212
}
223213

224-
/// Обновляем фильтр
225-
///
226-
/// Параметр не используем, т.к. передаем `defaults` во вьюмодель
227-
func updateFilterForUser(info _: UserResponse?) {
228-
viewModel.updateFilter(with: defaults)
214+
func updateUserCountryAndCity(with info: UserResponse?) {
215+
viewModel.updateUserCountryAndCity(with: info)
229216
}
230217

231218
func setupErrorAlert(with message: String) {

SwiftUI-WorkoutApp/Screens/SportsGrounds/Map/SportsGroundsMapViewModel.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ final class SportsGroundsMapViewModel: NSObject, ObservableObject {
8787
needUpdateAnnotations.toggle()
8888
}
8989

90-
func updateFilter(with defaults: DefaultsProtocol) {
91-
userCountryID = defaults.mainUserCountryID
92-
userCityID = defaults.mainUserCityID
93-
filter.onlyMyCity = defaults.isAuthorized
90+
func updateUserCountryAndCity(with info: UserResponse?) {
91+
guard let countryID = info?.countryID, let cityID = info?.cityID else {
92+
filter.onlyMyCity = false
93+
return
94+
}
95+
userCountryID = countryID
96+
userCityID = cityID
9497
}
9598

9699
func openAppSettings() {
@@ -108,22 +111,24 @@ final class SportsGroundsMapViewModel: NSObject, ObservableObject {
108111

109112
extension SportsGroundsMapViewModel {
110113
var isRegionSet: Bool {
111-
region.center.latitude != .zero
112-
&& region.center.longitude != .zero
114+
region.center.latitude != .zero && region.center.longitude != .zero
115+
}
116+
117+
var shouldHideMap: Bool {
118+
!isRegionSet && ignoreUserLocation
113119
}
114120
}
115121

116122
extension SportsGroundsMapViewModel: CLLocationManagerDelegate {
117-
func locationManager(
118-
_: CLLocationManager,
119-
didUpdateLocations locations: [CLLocation]
120-
) {
123+
func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
121124
if let location = locations.last {
122125
CLGeocoder().reverseGeocodeLocation(location) { [weak self] places, _ in
126+
guard let self else { return }
123127
if let target = places?.first {
124-
self?.filter.currentCity = target.locality
125-
self?.addressString = target.thoroughfare.valueOrEmpty
126-
+ " " + target.subThoroughfare.valueOrEmpty
128+
self.filter.currentCity = target.locality
129+
self.addressString = target.thoroughfare.valueOrEmpty
130+
+ " "
131+
+ target.subThoroughfare.valueOrEmpty
127132
}
128133
}
129134
let needUpdateMap = !isRegionSet

0 commit comments

Comments
 (0)