Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Jun 24, 2024
1 parent 793bcfc commit af20510
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 100 deletions.
25 changes: 12 additions & 13 deletions iOSClient/Account Settings/NCAccountSettingsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class NCAccountSettingsModel: ObservableObject, ViewOnAppearHandling {
@Published var indexActiveAccount: Int = 0
/// Current alias
@Published var alias: String = ""
/// State to control
@Published var accountRequest: Bool = false
/// Set true for dismiss the view
@Published var dismissView = false

Expand Down Expand Up @@ -97,22 +95,23 @@ class NCAccountSettingsModel: ObservableObject, ViewOnAppearHandling {

/// Triggered when the view appears.
func onViewAppear() {
accounts = NCManageDatabase.shared.getAllAccount()
activeAccount = NCManageDatabase.shared.getActiveAccount()
accountRequest = NCKeychain().accountRequest
getIndexActiveAccount()
}
var indexActiveAccount = 0
let accounts = NCManageDatabase.shared.getAllAccount()
var activeAccount = NCManageDatabase.shared.getActiveAccount()
var alias = ""

/// Internal use
func getIndexActiveAccount() {
self.indexActiveAccount = 0
for (index, account) in accounts.enumerated() {
if account.active {
self.activeAccount = account
self.indexActiveAccount = index
self.alias = account.alias
activeAccount = account
indexActiveAccount = index
alias = account.alias
}
}

self.indexActiveAccount = indexActiveAccount
self.accounts = accounts
self.activeAccount = activeAccount
self.alias = alias
}

/// Func to get the user display name + alias
Expand Down
165 changes: 78 additions & 87 deletions iOSClient/Account Settings/NCAccountSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,84 @@ struct NCAccountSettingsView: View {
Section(content: {
TabView(selection: $model.indexActiveAccount) {
ForEach(0..<model.accounts.count, id: \.self) { index in
TabContentView(index: index, model: model)
let status = model.getUserStatus()
let avatar = NCUtility().loadUserImage(for: model.accounts[index].user, displayName: model.accounts[index].displayName, userBaseUrl: model.accounts[index])
///
/// User
VStack {
ZStack {
Image(uiImage: avatar)
.resizable()
.scaledToFit()
.frame(width: UIScreen.main.bounds.width, height: 75)
ZStack {
Circle()
.fill(.white)
.frame(width: 30, height: 30)
Image(uiImage: status.statusImage)
.resizable()
.scaledToFit()
.frame(width: 30, height: 30)
}
.offset(x: 30, y: 30)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
Text(model.getUserName())
.font(.system(size: 16))
Spacer()
.frame(height: 10)
Text(status.statusMessage)
.font(.system(size: 10))
Spacer()
.frame(height: 20)
///
/// Personal data
if let activeAccount = model.activeAccount {
if !activeAccount.email.isEmpty {
HStack {
Image(systemName: "mail")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
Text(activeAccount.email)
.lineLimit(1)
.truncationMode(.middle)
.frame(maxWidth: .infinity, alignment: .leading)

}
.frame(maxWidth: .infinity, maxHeight: 30)
}
if !activeAccount.phone.isEmpty {
HStack {
Image(systemName: "phone")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
Text(activeAccount.phone)
.lineLimit(1)
.truncationMode(.middle)
.frame(maxWidth: .infinity, alignment: .leading)
}
.frame(maxWidth: .infinity, maxHeight: 30)
}
if !activeAccount.address.isEmpty {
HStack {
Image(systemName: "house")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
Text(activeAccount.address)
.lineLimit(1)
.truncationMode(.middle)
.frame(maxWidth: .infinity, alignment: .leading)
}
.frame(maxWidth: .infinity, maxHeight: 30)
}
}
}
}
}
.font(.system(size: 14))
Expand Down Expand Up @@ -201,92 +278,6 @@ struct NCAccountSettingsView: View {
}
}

struct TabContentView: View {
var index: Int
@ObservedObject var model: NCAccountSettingsModel

var body: some View {
let status = model.getUserStatus()
let avatar = NCUtility().loadUserImage(for: model.accounts[index].user, displayName: model.accounts[index].displayName, userBaseUrl: model.accounts[index])
///
/// User
VStack {
ZStack {
Image(uiImage: avatar)
.resizable()
.scaledToFit()
.frame(width: UIScreen.main.bounds.width, height: 75)
ZStack {
Circle()
.fill(.white)
.frame(width: 30, height: 30)
Image(uiImage: status.statusImage)
.resizable()
.scaledToFit()
.frame(width: 30, height: 30)
}
.offset(x: 30, y: 30)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
Text(model.getUserName())
.font(.system(size: 16))
Spacer()
.frame(height: 10)
Text(status.statusMessage)
.font(.system(size: 10))
Spacer()
.frame(height: 20)
///
/// Personal data
if let activeAccount = model.activeAccount {
if !activeAccount.email.isEmpty {
HStack {
Image(systemName: "mail")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
Text(activeAccount.email)
.lineLimit(1)
.truncationMode(.middle)
.frame(maxWidth: .infinity, alignment: .leading)

}
.frame(maxWidth: .infinity, maxHeight: 30)
}
if !activeAccount.phone.isEmpty {
HStack {
Image(systemName: "phone")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
Text(activeAccount.phone)
.lineLimit(1)
.truncationMode(.middle)
.frame(maxWidth: .infinity, alignment: .leading)
}
.frame(maxWidth: .infinity, maxHeight: 30)
}
if !activeAccount.address.isEmpty {
HStack {
Image(systemName: "house")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
Text(activeAccount.address)
.lineLimit(1)
.truncationMode(.middle)
.frame(maxWidth: .infinity, alignment: .leading)
}
.frame(maxWidth: .infinity, maxHeight: 30)
}
}
}
}
}

#Preview {
NCAccountSettingsView(model: NCAccountSettingsModel(controller: nil, delegate: nil))
}

0 comments on commit af20510

Please sign in to comment.