Skip to content

Commit

Permalink
Merge pull request #1417 from nextcloud/user-status-swift-ui-follow-up
Browse files Browse the repository at this point in the history
User status SwiftUI fixes
  • Loading branch information
SystemKeeper authored Nov 13, 2023
2 parents 703d737 + 9a40c20 commit 75de573
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
12 changes: 8 additions & 4 deletions NextcloudTalk/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum AboutSection: Int {
case kAboutSectionNumber
}

class SettingsTableViewController: UITableViewController, UITextFieldDelegate {
class SettingsTableViewController: UITableViewController, UITextFieldDelegate, UserStatusViewDelegate {
let kPhoneTextFieldTag = 99
let kUserSettingsCellIdentifier = "UserSettingsCellIdentifier"
let kUserSettingsTableCellNibName = "UserSettingsTableViewCell"
Expand Down Expand Up @@ -317,17 +317,22 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate {
let userProfileVC = UserProfileTableViewController(withAccount: activeAccount)
self.navigationController?.pushViewController(userProfileVC, animated: true)
}

// MARK: User Status (SwiftUI)

func presentUserStatusOptions() {
if let activeUserStatus = activeUserStatus {
let userStatusView = UserStatusSwiftUIView(userStatus: activeUserStatus)
var userStatusView = UserStatusSwiftUIView(userStatus: activeUserStatus)
userStatusView.delegate = self
let hostingController = UIHostingController(rootView: userStatusView)
self.present(hostingController, animated: true)
}
}

func userStatusViewDidDisappear() {
self.getActiveUserStatus()
}

// MARK: User phone number

func checkUserPhoneNumber() {
Expand Down Expand Up @@ -733,7 +738,6 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate {
} else {
cell.textLabel?.text = NSLocalizedString("Fetching status …", comment: "")
}
cell.accessoryType = .disclosureIndicator
return cell
case SettingsSection.kSettingsSectionAccountSettings.rawValue:
cell = userSettingsCell(for: indexPath)
Expand Down
7 changes: 6 additions & 1 deletion NextcloudTalk/UserStatusMessageSwiftUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,29 @@ struct UserStatusMessageSwiftUIView: View {
action: setActiveUserStatus,
style: .primary, height: 40,
disabled: Binding.constant(selectedMessage.isEmpty))
.padding(.bottom, 16)
}
}else {
} else {
HStack(spacing: 10) {
Spacer()
NCButtonSwiftUI(title: NSLocalizedString("Clear status message",
comment: ""),
action: clearActiveUserStatus,
style: .tertiary, height: 40,
disabled: Binding.constant(selectedMessage.isEmpty))
.padding(.bottom, 16)
NCButtonSwiftUI(title: NSLocalizedString("Set status message", comment: ""),
action: setActiveUserStatus,
style: .primary, height: 40,
disabled: Binding.constant(selectedMessage.isEmpty))
.padding(.bottom, 16)
Spacer()
}
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(uiColor: .systemGroupedBackground))
.navigationBarTitle(Text(NSLocalizedString("Status message", comment: "")), displayMode: .inline)
.navigationBarHidden(false)
.onAppear {
Expand Down
12 changes: 12 additions & 0 deletions NextcloudTalk/UserStatusSwiftUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import UIKit
import SwiftUI
import SwiftUIIntrospect

protocol UserStatusViewDelegate: AnyObject {
func userStatusViewDidDisappear()
}

struct UserStatusSwiftUIView: View {

@Environment(\.dismiss) var dismiss
Expand All @@ -33,6 +37,8 @@ struct UserStatusSwiftUIView: View {
_userStatus = State(initialValue: userStatus)
}

weak var delegate: UserStatusViewDelegate?

var body: some View {
NavigationView {
VStack {
Expand Down Expand Up @@ -75,10 +81,12 @@ struct UserStatusSwiftUIView: View {
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = NCAppBranding.themeColor()
appearance.titleTextAttributes = [.foregroundColor: NCAppBranding.themeTextColor()]
navController.navigationBar.tintColor = NCAppBranding.themeTextColor()
navController.navigationBar.standardAppearance = appearance
navController.navigationBar.compactAppearance = appearance
navController.navigationBar.scrollEdgeAppearance = appearance
}
.navigationViewStyle(StackNavigationViewStyle())
.tint(Color(NCAppBranding.themeTextColor()))
.onAppear {
getUserStatus()
Expand All @@ -89,6 +97,10 @@ struct UserStatusSwiftUIView: View {
changed = false
}
}
.onDisappear {
delegate?.userStatusViewDidDisappear()
}

}

func getUserStatus() {
Expand Down

0 comments on commit 75de573

Please sign in to comment.