Skip to content

Commit

Permalink
NMC 2172 - dashboard theming customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
TSI-amrutwaghmare committed Dec 5, 2023
1 parent 9b5e1ea commit fdf5978
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 324 deletions.
4 changes: 2 additions & 2 deletions iOSClient/Extensions/UINavigationController+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension UINavigationController {

func setFileAppreance() {

navigationBar.tintColor = .systemBlue
navigationBar.tintColor = NCBrandColor.shared.brand

let standardAppearance = UINavigationBarAppearance()
standardAppearance.configureWithDefaultBackground()
Expand All @@ -53,7 +53,7 @@ extension UINavigationController {

func setGroupAppearance() {

navigationBar.tintColor = .systemBlue
navigationBar.tintColor = NCBrandColor.shared.brand

let standardAppearance = UINavigationBarAppearance()
standardAppearance.configureWithDefaultBackground()
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Favorites/NCFavorite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NCFavorite: NCCollectionViewCommon {

titleCurrentFolder = NSLocalizedString("_favorites_", comment: "")
layoutKey = NCGlobal.shared.layoutViewFavorite
enableSearchBar = false
enableSearchBar = true
headerMenuButtonsView = true
headerRichWorkspaceDisable = true
emptyImage = UIImage(named: "star.fill")?.image(color: NCBrandColor.shared.yellowFavorite, size: UIScreen.main.bounds.width)
Expand Down
148 changes: 36 additions & 112 deletions iOSClient/Main/Collection Common/NCCollectionViewCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
searchController?.searchBar.delegate = self
searchController?.searchBar.autocapitalizationType = .none
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
navigationItem.hidesSearchBarWhenScrolling = false
navigationItem.backBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_back_", comment: ""), style: .plain, target: nil, action: nil)
}

// Cell
Expand Down Expand Up @@ -164,6 +165,11 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

// Deselect items when back to previous view controller
if isEditMode {
self.tapSelect()
}

appDelegate.activeViewController = self

layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl)
Expand Down Expand Up @@ -264,10 +270,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
self.collectionView?.collectionViewLayout.invalidateLayout()
self.collectionView?.reloadData()
self.tipView?.dismiss()

coordinator.animate(alongsideTransition: nil) { _ in
self.showTip()
}
}

override var canBecomeFirstResponder: Bool {
Expand All @@ -281,11 +283,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
}

@objc func reloadAvatar(_ notification: NSNotification) {

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.showTip()
}

guard let userInfo = notification.userInfo as NSDictionary?,
let error = userInfo["error"] as? NKError,
error.errorCode != NCGlobal.shared.errorNotModified else { return }
Expand Down Expand Up @@ -573,70 +570,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
navigationItem.title = titleCurrentFolder

guard layoutKey == NCGlobal.shared.layoutViewFiles else { return }

// PROFILE BUTTON

let activeAccount = NCManageDatabase.shared.getActiveAccount()

let image = utility.loadUserImage(
for: appDelegate.user,
displayName: activeAccount?.displayName,
userBaseUrl: appDelegate)

let button = UIButton(type: .custom)
button.setImage(image, for: .normal)

if serverUrl == utilityFileSystem.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId) {

var titleButton = " "

if getNavigationTitle() == activeAccount?.alias {
titleButton = ""
} else {
titleButton += activeAccount?.displayName ?? ""
}

button.setTitle(titleButton, for: .normal)
button.setTitleColor(.systemBlue, for: .normal)
}

button.semanticContentAttribute = .forceLeftToRight
button.sizeToFit()
button.action(for: .touchUpInside) { _ in

let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
if !accounts.isEmpty, !NCBrandOptions.shared.disable_multiaccount, !NCBrandOptions.shared.disable_manage_account {

if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {

vcAccountRequest.activeAccount = NCManageDatabase.shared.getActiveAccount()
vcAccountRequest.accounts = accounts
vcAccountRequest.enableTimerProgress = false
vcAccountRequest.enableAddAccount = true
vcAccountRequest.delegate = self
vcAccountRequest.dismissDidEnterBackground = true

let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height / 5)
let numberCell = accounts.count + 1
let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)

let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height)

self.present(popup, animated: true)
}

// TIP
self.dismissTip()
}
}
navigationItem.setLeftBarButton(UIBarButtonItem(customView: button), animated: true)
navigationItem.leftItemsSupplementBackButton = true
if titlePreviusFolder == nil {
navigationController?.navigationBar.topItem?.title = getNavigationTitle()
} else {
navigationController?.navigationBar.topItem?.title = titlePreviusFolder
}
navigationItem.title = titleCurrentFolder
}

func getNavigationTitle() -> String {
Expand Down Expand Up @@ -671,7 +610,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
view.emptyTitle.text = NSLocalizedString(emptyTitle, comment: "")
view.emptyDescription.text = NSLocalizedString(emptyDescription, comment: "")
} else {
view.emptyImage.image = UIImage(named: "folder")?.image(color: NCBrandColor.shared.brandElement, size: UIScreen.main.bounds.width)
view.emptyImage.image = UIImage(named: "folder_nmcloud")
view.emptyTitle.text = NSLocalizedString("_files_no_files_", comment: "")
view.emptyDescription.text = NSLocalizedString("_no_file_pull_down_", comment: "")
}
Expand Down Expand Up @@ -1240,15 +1179,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
}
}
}

// Avatar
if !metadata.ownerId.isEmpty,
metadata.ownerId != appDelegate.userId,
appDelegate.account == metadata.account,
let cell = cell as? NCCellProtocol {
let fileName = metadata.userBaseUrl + "-" + metadata.ownerId + ".png"
NCNetworking.shared.downloadAvatar(user: metadata.ownerId, dispalyName: metadata.ownerDisplayName, fileName: fileName, cell: cell, view: collectionView, cellImageView: cell.fileAvatarImageView)
}
}

func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
Expand Down Expand Up @@ -1298,7 +1228,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
var isShare = false
var isMounted = false
var a11yValues: [String] = []

let shares = NCManageDatabase.shared.getTableShares(metadata: metadata)
if metadataFolder != nil {
isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionShared)
isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionMounted)
Expand All @@ -1325,7 +1255,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
cell.fileTitleLabel?.text = metadata.fileName
cell.fileTitleLabel?.lineBreakMode = .byTruncatingTail
if metadata.name == NCGlobal.shared.appName {
cell.fileInfoLabel?.text = NSLocalizedString("_in_", comment: "") + " " + utilityFileSystem.getPath(path: metadata.path, user: metadata.user)
cell.fileInfoLabel?.text = utility.dateDiff(metadata.date as Date) + " · " + utilityFileSystem.transformedSize(metadata.size)
} else {
cell.fileInfoLabel?.text = metadata.subline
}
Expand All @@ -1352,7 +1282,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
cell.filePreviewImageView?.image = NCImageCache.images.folderEncrypted
} else if isShare {
cell.filePreviewImageView?.image = NCImageCache.images.folderSharedWithMe
} else if !metadata.shareType.isEmpty {
} else if (!metadata.shareType.isEmpty || !(shares.share?.isEmpty ?? true) || (shares.firstShareLink != nil)) {
metadata.shareType.contains(3) ?
(cell.filePreviewImageView?.image = NCImageCache.images.folderPublic) :
(cell.filePreviewImageView?.image = NCImageCache.images.folderSharedWithMe)
Expand Down Expand Up @@ -1399,14 +1329,24 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
if isShare {
cell.fileSharedImage?.image = NCImageCache.images.shared
} else if !metadata.shareType.isEmpty {
metadata.shareType.contains(3) ?
(cell.fileSharedImage?.image = NCImageCache.images.shareByLink) :
(cell.fileSharedImage?.image = NCImageCache.images.shared)
} else {
cell.fileSharedImage?.image = NCImageCache.images.canShare
cell.fileSharedImage?.image = NCImageCache.images.canShare.image(color: NCBrandColor.shared.gray60, size: 50)
cell.fileSharedLabel?.text = ""
}
if appDelegate.account != metadata.account {
cell.fileSharedImage?.image = NCImageCache.images.shared
cell.fileSharedLabel?.text = NSLocalizedString("_shared_", comment: "")
cell.fileSharedLabel?.textColor = NCBrandColor.shared.customer
if (!metadata.shareType.isEmpty || !(shares.share?.isEmpty ?? true) || (shares.firstShareLink != nil)){
cell.fileSharedImage?.image = cell.fileSharedImage?.image?.imageColor(NCBrandColor.shared.customer)
} else {
cell.fileSharedImage?.image = NCImageCache.images.canShare.image(color: NCBrandColor.shared.gray60, size: 50)
cell.fileSharedLabel?.text = ""
}

if metadata.permissions.contains("S"), (metadata.permissions.range(of: "S") != nil) {
cell.fileSharedImage?.image = NCImageCache.images.sharedWithMe
cell.fileSharedLabel?.text = NSLocalizedString("_recieved_", comment: "")
cell.fileSharedLabel?.textColor = NCBrandColor.shared.notificationAction
}

// Button More
Expand Down Expand Up @@ -1462,6 +1402,15 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
}
}

// Hide lines on iPhone
if !UIDevice.current.orientation.isLandscape && UIDevice.current.model.hasPrefix("iPhone") {
cell.cellSeparatorView?.isHidden = true
cell.fileSharedLabel?.isHidden = true
}else{
cell.cellSeparatorView?.isHidden = false
cell.fileSharedLabel?.isHidden = false
}

// Separator
if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 || isSearchingMode {
cell.cellSeparatorView?.isHidden = true
Expand All @@ -1485,14 +1434,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
// Accessibility
cell.setAccessibility(label: metadata.fileNameView + ", " + (cell.fileInfoLabel?.text ?? ""), value: a11yValues.joined(separator: ", "))

// Color string find in search
if isSearchingMode, let literalSearch = self.literalSearch, let title = cell.fileTitleLabel?.text {
let longestWordRange = (title.lowercased() as NSString).range(of: literalSearch)
let attributedString = NSMutableAttributedString(string: title, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15)])
attributedString.setAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15), NSAttributedString.Key.foregroundColor: UIColor.systemBlue], range: longestWordRange)
cell.fileTitleLabel?.attributedText = attributedString
}

// Add TAGS
cell.setTags(tags: Array(metadata.tags))

Expand Down Expand Up @@ -1527,13 +1468,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {

header.delegate = self

if !isSearchingMode, headerMenuTransferView, let ocId = NCNetworking.shared.transferInForegorund?.ocId {
let text = String(format: NSLocalizedString("_upload_foreground_msg_", comment: ""), NCBrandOptions.shared.brand)
header.setViewTransfer(isHidden: false, ocId: ocId, text: text, progress: NCNetworking.shared.transferInForegorund?.progress)
} else {
header.setViewTransfer(isHidden: true)
}

if headerMenuButtonsView {
header.setStatusButtonsView(enable: !dataSource.getMetadataSourceForAllSections().isEmpty)
header.setButtonsView(height: NCGlobal.shared.heightButtonsView)
Expand Down Expand Up @@ -1580,6 +1514,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {

footer.setTitleLabel("")
footer.setButtonText(NSLocalizedString("_show_more_results_", comment: ""))
footer.buttonSection.setTitleColor(NCBrandColor.shared.customer, for: .normal)
footer.separatorIsHidden(true)
footer.buttonIsHidden(true)
footer.hideActivityIndicatorSection()
Expand Down Expand Up @@ -1621,17 +1556,6 @@ extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout {

var size: CGFloat = 0

// transfer in progress
if headerMenuTransferView,
let metadata = NCManageDatabase.shared.getMetadataFromOcId(NCNetworking.shared.transferInForegorund?.ocId),
metadata.isTransferInForeground {
if !isSearchingMode {
size += NCGlobal.shared.heightHeaderTransfer
}
} else {
NCNetworking.shared.transferInForegorund = nil
}

if headerMenuButtonsView {
size += NCGlobal.shared.heightButtonsView
}
Expand Down
32 changes: 6 additions & 26 deletions iOSClient/Main/Collection Common/NCListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
@IBOutlet weak var buttonMore: UIButton!
@IBOutlet weak var progressView: UIProgressView!
@IBOutlet weak var separator: UIView!
@IBOutlet weak var tag0: UILabel!
@IBOutlet weak var tag1: UILabel!

@IBOutlet weak var labelShared: UILabel!
@IBOutlet weak var imageItemLeftConstraint: NSLayoutConstraint!
@IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var titleTrailingConstraint: NSLayoutConstraint!
@IBOutlet weak var infoTrailingConstraint: NSLayoutConstraint!

private var objectId = ""
Expand Down Expand Up @@ -108,7 +105,11 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
get { return separator }
set { separator = newValue }
}


var fileSharedLabel: UILabel? {
get { return labelShared }
set { labelShared = newValue }
}
override func awakeFromNib() {
super.awakeFromNib()

Expand Down Expand Up @@ -189,12 +190,10 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
}

func titleInfoTrailingFull() {
titleTrailingConstraint.constant = 10
infoTrailingConstraint.constant = 10
}

func titleInfoTrailingDefault() {
titleTrailingConstraint.constant = 90
infoTrailingConstraint.constant = 90
}

Expand Down Expand Up @@ -278,25 +277,6 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
accessibilityLabel = label
accessibilityValue = value
}

func setTags(tags: [String]) {
if tags.isEmpty {
tag0.isHidden = true
tag1.isHidden = true
labelInfo.isHidden = false
} else {
tag0.isHidden = false
tag1.isHidden = true
labelInfo.isHidden = true
if let tag = tags.first {
tag0.text = tag
if tags.count > 1 {
tag1.isHidden = false
tag1.text = "+\(tags.count - 1)"
}
}
}
}
}

protocol NCListCellDelegate: AnyObject {
Expand Down
Loading

0 comments on commit fdf5978

Please sign in to comment.