From 77fe6c3725b0fb081e6d6fcfd2f63c26972f8218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=BChne?= Date: Thu, 14 Oct 2021 15:55:18 +0200 Subject: [PATCH 1/5] username could be like a uuid, which is not user readable. Instead now showing the displayName and if not available, the userName --- .../StaticLoginSingleAccountServerListViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift index 3acf9c597..039117581 100644 --- a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift +++ b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift @@ -160,8 +160,8 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if SingleAccountSection(rawValue: section) == .accessFiles { - if headerView == nil, let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first, let userName = bookmark.userName { - let headerText = String(format: "You are connected as\n%@".localized, userName) + if headerView == nil, let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first { + let headerText = String(format: "You are connected as\n%@".localized, bookmark.displayName ?? bookmark.userName) headerView = StaticTableViewSection.buildHeader(title: headerText) } From 96ae32c531cf88eab45d9bbe9202af129bd3d470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=BChne?= Date: Thu, 14 Oct 2021 16:17:39 +0200 Subject: [PATCH 2/5] fixed syntax error --- .../StaticLoginSingleAccountServerListViewController.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift index 039117581..e48ce8610 100644 --- a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift +++ b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift @@ -161,8 +161,11 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if SingleAccountSection(rawValue: section) == .accessFiles { if headerView == nil, let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first { - let headerText = String(format: "You are connected as\n%@".localized, bookmark.displayName ?? bookmark.userName) - headerView = StaticTableViewSection.buildHeader(title: headerText) + let displayName = bookmark.displayName ?? bookmark.userName + if let displayName = displayName { + let headerText = String(format: "You are connected as\n%@".localized, userName) + headerView = StaticTableViewSection.buildHeader(title: headerText) + } } return headerView From aa4373d97a87708d1258291d61a3a20f5de7d6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=BChne?= Date: Wed, 20 Oct 2021 10:00:09 +0200 Subject: [PATCH 3/5] fixed compile error --- .../StaticLoginSingleAccountServerListViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift index e48ce8610..da8286d3e 100644 --- a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift +++ b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift @@ -163,7 +163,7 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr if headerView == nil, let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first { let displayName = bookmark.displayName ?? bookmark.userName if let displayName = displayName { - let headerText = String(format: "You are connected as\n%@".localized, userName) + let headerText = String(format: "You are connected as\n%@".localized, displayName) headerView = StaticTableViewSection.buildHeader(title: headerText) } } From 2b52eb7b0a553d6ed32c0a30f0bba0bb08339a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Hu=CC=88hne?= Date: Fri, 12 Nov 2021 08:12:40 +0100 Subject: [PATCH 4/5] first draft for retrieving the user display name for the header view --- ...LoginSingleAccountServerListViewController.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift index da8286d3e..7b4b3faf3 100644 --- a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift +++ b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift @@ -19,6 +19,7 @@ import UIKit import ownCloudSDK import ownCloudAppShared +import CoreMedia class StaticLoginSingleAccountServerListViewController: ServerListTableViewController { // Sections in the table view controller @@ -161,10 +162,14 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if SingleAccountSection(rawValue: section) == .accessFiles { if headerView == nil, let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first { - let displayName = bookmark.displayName ?? bookmark.userName - if let displayName = displayName { - let headerText = String(format: "You are connected as\n%@".localized, displayName) - headerView = StaticTableViewSection.buildHeader(title: headerText) + + let connection = OCConnection(bookmark: bookmark) + connection.connect { error, issue in + let displayName = connection.loggedInUser?.displayName ?? bookmark.userName + if let displayName = displayName { + let headerText = String(format: "You are connected as\n%@".localized, displayName) + self.headerView = StaticTableViewSection.buildHeader(title: headerText) + } } } From d449b3890b93ad0d1989af3ffe21a3f9fe119a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Hu=CC=88hne?= Date: Mon, 15 Nov 2021 15:46:24 +0100 Subject: [PATCH 5/5] retrieving the users display name by init a connection and reloading the table view --- ...ingleAccountServerListViewController.swift | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift index 7b4b3faf3..9aaf5f331 100644 --- a/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift +++ b/ownCloud/Static Login/Interface/StaticLoginSingleAccountServerListViewController.swift @@ -49,6 +49,7 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr weak var staticLoginViewController : StaticLoginViewController? var canConfigureURL: Bool = true private var actionRows: [ActionRowIndex] = [.editLogin, .manageStorage, .logout] + var displayName: String? override func viewDidLoad() { super.viewDidLoad() @@ -60,6 +61,7 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr if !VendorServices.shared.canEditAccount { actionRows = [.manageStorage, .logout] } + retrieveDisplayName() } override func viewWillAppear(_ animated: Bool) { @@ -162,14 +164,9 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if SingleAccountSection(rawValue: section) == .accessFiles { if headerView == nil, let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first { - - let connection = OCConnection(bookmark: bookmark) - connection.connect { error, issue in - let displayName = connection.loggedInUser?.displayName ?? bookmark.userName - if let displayName = displayName { - let headerText = String(format: "You are connected as\n%@".localized, displayName) - self.headerView = StaticTableViewSection.buildHeader(title: headerText) - } + if let displayName = self.displayName ?? bookmark.userName { + let headerText = String(format: "You are connected as\n%@".localized, displayName) + self.headerView = StaticTableViewSection.buildHeader(title: headerText) } } @@ -252,3 +249,23 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr self.showModal(viewController: navigationController) } } + +extension StaticLoginSingleAccountServerListViewController { + + func retrieveDisplayName() { + guard let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first else { return } + let connection = OCConnection(bookmark: bookmark) + + connection.connect { error, issue in + guard error == nil, issue == nil, let displayName = connection.loggedInUser?.displayName else { return } + self.displayName = displayName + self.headerView = nil + OnMainThread { + self.tableView.reloadData() + } + connection.disconnect { + } + } + } + +}