Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/single-accouont-display-name] Show Display Name in Branded Single Account View #1049

Merged
merged 6 commits into from
Nov 17, 2021
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import UIKit
import ownCloudSDK
import ownCloudAppShared
import CoreMedia

class StaticLoginSingleAccountServerListViewController: ServerListTableViewController {
// Sections in the table view controller
Expand Down Expand Up @@ -48,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()
Expand All @@ -59,6 +61,7 @@ class StaticLoginSingleAccountServerListViewController: ServerListTableViewContr
if !VendorServices.shared.canEditAccount {
actionRows = [.manageStorage, .logout]
}
retrieveDisplayName()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -160,9 +163,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 userName = bookmark.userName {
let headerText = String(format: "You are connected as\n%@".localized, userName)
headerView = StaticTableViewSection.buildHeader(title: headerText)
if headerView == nil, let bookmark : OCBookmark = OCBookmarkManager.shared.bookmarks.first {
if let displayName = self.displayName ?? bookmark.userName {
let headerText = String(format: "You are connected as\n%@".localized, displayName)
self.headerView = StaticTableViewSection.buildHeader(title: headerText)
}
}

return headerView
Expand Down Expand Up @@ -244,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 {
}
}
}

}