Skip to content

Commit

Permalink
minor fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepanokdev committed Oct 26, 2023
1 parent 4837926 commit 83e1f2b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class SignInViewModel: ObservableObject {
router.showMainScreen()
} catch let error {
isShowProgress = false
if error.asAFError?.responseCode == 426 {
if error.isUpdateRequeiredError {
if config.appUpdateEnabled {
router.showUpdateRequiredView(showAccountLink: false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class SignUpViewModel: ObservableObject {
isShowProgress = false
if error.isInternetError {
errorMessage = CoreLocalization.Error.slowOrNoInternetConnection
} else if error.asAFError?.responseCode == 426 {
} else if error.isUpdateRequeiredError {
if config.appUpdateEnabled {
router.showUpdateRequiredView(showAccountLink: false)
}
Expand Down
12 changes: 12 additions & 0 deletions Core/Core/Domain/Model/UserProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ public struct UserProfile: Hashable {
self.shortBiography = shortBiography
self.isFullProfile = isFullProfile
}

public init() {
self.avatarUrl = ""
self.name = ""
self.username = ""
self.dateJoined = Date()
self.yearOfBirth = 0
self.country = ""
self.spokenLanguage = ""
self.shortBiography = ""
self.isFullProfile = true
}
}
4 changes: 4 additions & 0 deletions Core/Core/Network/Alamofire+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import Alamofire

public extension Error {
var isUpdateRequeiredError: Bool {
self.asAFError?.responseCode == 426
}

var isInternetError: Bool {
guard let afError = self.asAFError,
let urlError = afError.underlyingError as? URLError else {
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Network/RequestInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final public class RequestInterceptor: Alamofire.RequestInterceptor {

let userAgent: String = {
if let info = Bundle.main.infoDictionary {
let bundle: AnyObject = "edX/org.edx.mobile" as AnyObject
let bundle: AnyObject = info[kCFBundleIdentifierKey as String] as AnyObject? ?? "Unknown" as AnyObject
let version: AnyObject = info["CFBundleShortVersionString"] as AnyObject? ?? "Unknown" as AnyObject
let os: AnyObject = ProcessInfo.processInfo.operatingSystemVersionString as AnyObject
var mutableUserAgent = NSMutableString(string: "\(bundle) (\(version); OS \(os))") as CFMutableString
Expand Down
3 changes: 1 addition & 2 deletions Discovery/Discovery/Presentation/DiscoveryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public class DiscoveryViewModel: ObservableObject {
self?.router.showUpdateRecomendedView()
self?.updateShowedOnce = true
}
NotificationCenter.default.post(name: .showUpdateNotification, object: "update")
case .orderedSame, .none, .orderedDescending:
return
}
Expand Down Expand Up @@ -121,7 +120,7 @@ public class DiscoveryViewModel: ObservableObject {
fetchInProgress = false
if error.isInternetError || error is NoCachedDataError {
errorMessage = CoreLocalization.Error.slowOrNoInternetConnection
} else if error.asAFError?.responseCode == 426 {
} else if error.isUpdateRequeiredError {
if self.config.appUpdateEnabled {
DispatchQueue.main.async {
self.router.showUpdateRequiredView(showAccountLink: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,31 @@ public struct UpdateRecommendedView: View {
.ignoresSafeArea()
.onTapGesture {
router.dismiss(animated: true)
NotificationCenter.default.post(name: .showUpdateNotification, object: "update")
}
VStack(spacing: 10) {
Image(systemName: "arrow.up.circle")
.resizable()
.frame(width: isHorizontal ? 50 : 110,
height: isHorizontal ? 50 : 110)
.foregroundColor(Theme.Colors.accentColor)
.padding(.bottom, isHorizontal ? 0 : 20)
Text(DiscoveryLocalization.updateNeededTitle)
.font(Theme.Fonts.titleMedium)
Text(DiscoveryLocalization.updateNeededDescription)
.font(Theme.Fonts.titleSmall)
.foregroundColor(Theme.Colors.avatarStroke)
.multilineTextAlignment(.center)

HStack(spacing: 28) {
Button(action: {
router.dismiss(animated: true)
NotificationCenter.default.post(name: .showUpdateNotification, object: "update")
}, label: {
HStack {
Text(DiscoveryLocalization.updateNeededNotNow)
.font(Theme.Fonts.labelLarge)
.foregroundColor(Theme.Colors.accentColor)
}.padding(8)
})

Expand Down
27 changes: 13 additions & 14 deletions Profile/Profile/Presentation/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,20 @@ public struct ProfileView: View {
}.frameLimit(sizePortrait: 420)
.padding(.top, 8)
.onChange(of: settingsTapped, perform: { _ in
if let userModel = viewModel.userModel {
viewModel.trackProfileEditClicked()
viewModel.router.showEditProfile(
userModel: userModel,
avatar: viewModel.updatedAvatar,
profileDidEdit: { updatedProfile, updatedImage in
if let updatedProfile {
self.viewModel.userModel = updatedProfile
}
if let updatedImage {
self.viewModel.updatedAvatar = updatedImage
}
let userModel = viewModel.userModel ?? UserProfile()
viewModel.trackProfileEditClicked()
viewModel.router.showEditProfile(
userModel: userModel,
avatar: viewModel.updatedAvatar,
profileDidEdit: { updatedProfile, updatedImage in
if let updatedProfile {
self.viewModel.userModel = updatedProfile
}
)
}
if let updatedImage {
self.viewModel.updatedAvatar = updatedImage
}
}
)
})
.navigationBarHidden(false)
.navigationBarBackButtonHidden(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class ProfileViewModel: ObservableObject {
}
} catch let error {
isShowProgress = false
if error.asAFError?.responseCode == 426 {
if error.isUpdateRequeiredError {
DispatchQueue.main.async {
self.versionState = .updateRequired
}
Expand Down

0 comments on commit 83e1f2b

Please sign in to comment.