Skip to content

[stable-6.5.0] NMC/2298 - Share extension #321

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

Open
wants to merge 2 commits into
base: stable-6.5.0
Choose a base branch
from
Open
Changes from all 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
53 changes: 16 additions & 37 deletions Share/NCShareExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class NCShareExtension: UIViewController {
var filesName: [String] = []
// -------------------------------------------------------------

var emptyDataSet: NCEmptyDataSet?
let keyLayout = NCGlobal.shared.layoutViewShareExtension
var metadataFolder: tableMetadata?
var dataSourceTask: URLSessionTask?
Expand Down Expand Up @@ -89,12 +90,11 @@ class NCShareExtension: UIViewController {

self.navigationController?.navigationBar.prefersLargeTitles = false

collectionView.register(UINib(nibName: "NCSectionFirstHeaderEmptyData", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionFirstHeaderEmptyData")
collectionView.register(UINib(nibName: "NCListCell", bundle: nil), forCellWithReuseIdentifier: "listCell")
collectionView.collectionViewLayout = NCListLayout()

collectionView.refreshControl = refreshControl
refreshControl.tintColor = NCBrandColor.shared.iconImageColor
refreshControl.tintColor = NCBrandColor.shared.brandText
refreshControl.backgroundColor = .systemBackground
refreshControl.addTarget(self, action: #selector(reloadDatasource), for: .valueChanged)

Expand All @@ -108,15 +108,15 @@ class NCShareExtension: UIViewController {
commandViewHeightConstraint.constant = heightCommandView

createFolderView.layer.cornerRadius = 10
createFolderImage.image = utility.loadImage(named: "folder.badge.plus", colors: [NCBrandColor.shared.iconImageColor])
createFolderImage.image = utility.loadImage(named: "folder.badge.plus", colors: [NCBrandColor.shared.iconColor])
createFolderLabel.text = NSLocalizedString("_create_folder_", comment: "")
let createFolderGesture = UITapGestureRecognizer(target: self, action: #selector(actionCreateFolder))
createFolderView.addGestureRecognizer(createFolderGesture)

uploadView.layer.cornerRadius = 10

uploadLabel.text = NSLocalizedString("_upload_", comment: "")
uploadLabel.textColor = .systemBlue
uploadLabel.textColor = NCBrandColor.shared.customer
let uploadGesture = UITapGestureRecognizer(target: self, action: #selector(actionUpload))
uploadView.addGestureRecognizer(uploadGesture)

Expand All @@ -129,6 +129,7 @@ class NCShareExtension: UIViewController {
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Start Share session with level \(levelLog) " + versionNextcloudiOS)

NCBrandColor.shared.createUserColors()
NCImageCache.shared.createImagesCache()

NotificationCenter.default.addObserver(self, selector: #selector(didCreateFolder(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCreateFolder), object: nil)
}
Expand Down Expand Up @@ -190,14 +191,15 @@ class NCShareExtension: UIViewController {
func setNavigationBar(navigationTitle: String) {
navigationItem.title = navigationTitle
cancelButton.title = NSLocalizedString("_cancel_", comment: "")
cancelButton.tintColor = NCBrandColor.shared.customer

// BACK BUTTON
let backButton = UIButton(type: .custom)
backButton.setImage(UIImage(named: "back"), for: .normal)
backButton.tintColor = .systemBlue
backButton.setImage(UIImage(named: "back")?.imageColor(NCBrandColor.shared.customer), for: .normal)
backButton.tintColor = NCBrandColor.shared.customer
backButton.semanticContentAttribute = .forceLeftToRight
backButton.setTitle(" " + NSLocalizedString("_back_", comment: ""), for: .normal)
backButton.setTitleColor(.systemBlue, for: .normal)
backButton.setTitleColor(NCBrandColor.shared.customer, for: .normal)
backButton.action(for: .touchUpInside) { _ in
if !self.uploadStarted {
while self.serverUrl.last != "/" { self.serverUrl.removeLast() }
Expand All @@ -210,38 +212,11 @@ class NCShareExtension: UIViewController {
self.setNavigationBar(navigationTitle: navigationTitle)
}
}

let tableAccount = self.database.getTableAccount(account: session.account)
let image = utility.loadUserImage(for: session.user, displayName: tableAccount?.displayName, urlBase: session.urlBase)
let profileButton = UIButton(type: .custom)
profileButton.setImage(image, for: .normal)

if serverUrl == utilityFileSystem.getHomeServer(session: self.session) {
var title = " "
if let userAlias = tableAccount?.alias, !userAlias.isEmpty {
title += userAlias
} else {
title += tableAccount?.displayName ?? ""
}

profileButton.setTitle(title, for: .normal)
profileButton.setTitleColor(.systemBlue, for: .normal)
}

profileButton.semanticContentAttribute = .forceLeftToRight
profileButton.sizeToFit()
profileButton.action(for: .touchUpInside) { _ in
if !self.uploadStarted {
self.showAccountPicker()
}
}
var navItems = [UIBarButtonItem(customView: profileButton)]
if serverUrl != utilityFileSystem.getHomeServer(session: self.session) {
let space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
space.width = 20
navItems.append(contentsOf: [UIBarButtonItem(customView: backButton), space])
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
} else {
navigationItem.leftBarButtonItem = nil
}
navigationItem.setLeftBarButtonItems(navItems, animated: true)
}

func setCommandView() {
Expand All @@ -256,6 +231,10 @@ class NCShareExtension: UIViewController {
self.tableView.isScrollEnabled = false
}
uploadLabel.text = NSLocalizedString("_upload_", comment: "") + " \(filesName.count) " + NSLocalizedString("_files_", comment: "")

// Empty
emptyDataSet = NCEmptyDataSet(view: collectionView, offset: -50 * counter, delegate: self)

self.tableView.reloadData()
}

Expand Down