Skip to content

Commit

Permalink
Nc media layout header (#2986)
Browse files Browse the repository at this point in the history
* coding

Signed-off-by: Marino Faggiana <[email protected]>

* change name

Signed-off-by: Marino Faggiana <[email protected]>

* rename

Signed-off-by: Marino Faggiana <[email protected]>

* rename

Signed-off-by: Marino Faggiana <[email protected]>

* cod

Signed-off-by: Marino Faggiana <[email protected]>

* cleaning

Signed-off-by: Marino Faggiana <[email protected]>

* cleaning

Signed-off-by: Marino Faggiana <[email protected]>

* fix

Signed-off-by: Marino Faggiana <[email protected]>

* cod

Signed-off-by: Marino Faggiana <[email protected]>

* cod

Signed-off-by: Marino Faggiana <[email protected]>

---------

Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana authored Jul 20, 2024
1 parent 4080815 commit 3efb493
Show file tree
Hide file tree
Showing 27 changed files with 638 additions and 479 deletions.
96 changes: 60 additions & 36 deletions Nextcloud.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Share/NCShareCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ class NCShareCell: UITableViewCell {

if let image = UIImage.downsample(imageAt: URL(fileURLWithPath: NSTemporaryDirectory() + fileName), to: CGSize(width: 80, height: 80)) {
imageCell.image = image
imageCell.contentMode = .scaleAspectFill
} else {
if !resultInternalType.iconName.isEmpty {
imageCell?.image = UIImage(named: resultInternalType.iconName)
} else {
imageCell?.image = NCImageCache.images.file
}
imageCell.image = utility.loadImage(named: resultInternalType.iconName, useTypeIconFile: true)
imageCell.contentMode = .scaleAspectFit
}

fileNameCell?.text = fileName
Expand Down
7 changes: 2 additions & 5 deletions Share/NCShareExtension+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension NCShareExtension: UICollectionViewDelegate {

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionHeader {
guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderEmptyData", for: indexPath) as? NCSectionHeaderEmptyData else { return NCSectionHeaderEmptyData() }
guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFirstHeaderEmptyData", for: indexPath) as? NCSectionFirstHeaderEmptyData else { return NCSectionFirstHeaderEmptyData() }
if self.dataSourceTask?.state == .running {
header.emptyImage.image = utility.loadImage(named: "wifi", colors: [NCBrandColor.shared.brandElement])
header.emptyTitle.text = NSLocalizedString("_request_in_progress_", comment: "")
Expand Down Expand Up @@ -105,7 +105,6 @@ extension NCShareExtension: UICollectionViewDataSource {
setupDirectoryCell(cell, indexPath: indexPath, with: metadata)
}

// image Favorite
if metadata.favorite {
cell.imageFavorite.image = NCImageCache.images.favorite
}
Expand All @@ -114,16 +113,14 @@ extension NCShareExtension: UICollectionViewDataSource {
cell.backgroundView = nil
cell.hideButtonMore(true)
cell.hideButtonShare(true)
cell.selected(false, isEditMode: false)

// Live Photo
if metadata.isLivePhoto {
cell.imageStatus.image = NCImageCache.images.livePhoto
}

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

// Remove last separator
cell.separator.isHidden = collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1

return cell
Expand Down
3 changes: 1 addition & 2 deletions Share/NCShareExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class NCShareExtension: UIViewController {

self.navigationController?.navigationBar.prefersLargeTitles = false

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

Expand Down Expand Up @@ -395,7 +395,6 @@ extension NCShareExtension {
}

extension NCShareExtension: uploadE2EEDelegate {

func start() {
self.hud.progress = 0
}
Expand Down
5 changes: 5 additions & 0 deletions iOSClient/Data/NCManageDatabase+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class tableMetadata: Object, NCUserBaseUrl {
self.favorite == object.favorite,
self.livePhotoFile == object.livePhotoFile,
self.sharePermissionsCollaborationServices == object.sharePermissionsCollaborationServices,
self.height == object.height,
self.width == object.width,
self.latitude == object.latitude,
self.longitude == object.longitude,
self.altitude == object.altitude,
Array(self.tags).elementsEqual(Array(object.tags)),
Array(self.shareType).elementsEqual(Array(object.shareType)),
Array(self.sharePermissionsCloudMesh).elementsEqual(Array(object.sharePermissionsCloudMesh)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {

if dataSource.getMetadataSourceForAllSections().isEmpty {

guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderEmptyData", for: indexPath) as? NCSectionHeaderEmptyData else { return NCSectionHeaderEmptyData() }
self.headerEmptyData = header
guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFirstHeaderEmptyData", for: indexPath) as? NCSectionFirstHeaderEmptyData else { return NCSectionFirstHeaderEmptyData() }
self.sectionFirstHeaderEmptyData = header
header.delegate = self

if !isSearchingMode, headerMenuTransferView, let ocId = NCNetworking.shared.transferInForegorund?.ocId {
Expand Down Expand Up @@ -423,9 +423,9 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {

} else if indexPath.section == 0 {

guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as? NCSectionHeaderMenu else { return NCSectionHeaderMenu() }
guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFirstHeader", for: indexPath) as? NCSectionFirstHeader else { return NCSectionFirstHeader() }
let (_, heightHeaderRichWorkspace, heightHeaderSection) = getHeaderHeight(section: indexPath.section)
self.headerMenu = header
self.sectionFirstHeader = header
header.delegate = self

if !isSearchingMode, headerMenuTransferView, let ocId = NCNetworking.shared.transferInForegorund?.ocId {
Expand Down Expand Up @@ -506,4 +506,23 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
return footer
}
}

// MARK: -

func getAvatarFromIconUrl(metadata: tableMetadata) -> String? {
var ownerId: String?

if metadata.iconUrl.contains("http") && metadata.iconUrl.contains("avatar") {
let splitIconUrl = metadata.iconUrl.components(separatedBy: "/")
var found: Bool = false
for item in splitIconUrl {
if found {
ownerId = item
break
}
if item == "avatar" { found = true}
}
}
return ownerId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// NCCollectionViewCommon+CollectionViewDelegateFlowLayout.swift
// Nextcloud
//
// Created by Marino Faggiana on 19/07/24.
// Copyright © 2024 Marino Faggiana. All rights reserved.
//
// Author Marino Faggiana <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

import Foundation
import UIKit

extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout {
func isHeaderMenuTransferViewEnabled() -> Bool {
if headerMenuTransferView, let metadata = NCManageDatabase.shared.getMetadataFromOcId(NCNetworking.shared.transferInForegorund?.ocId), metadata.isTransferInForeground {
return true
}
return false
}

func getHeaderHeight() -> CGFloat {
var size: CGFloat = 0

if isHeaderMenuTransferViewEnabled() {
if !isSearchingMode {
size += NCGlobal.shared.heightHeaderTransfer
}
} else {
NCNetworking.shared.transferInForegorund = nil
}
return size
}

func getHeaderHeight(section: Int) -> (heightHeaderCommands: CGFloat, heightHeaderRichWorkspace: CGFloat, heightHeaderSection: CGFloat) {
var headerRichWorkspace: CGFloat = 0

if let richWorkspaceText = richWorkspaceText, showDescription {
let trimmed = richWorkspaceText.trimmingCharacters(in: .whitespaces)
if !trimmed.isEmpty && !isSearchingMode {
headerRichWorkspace = UIScreen.main.bounds.size.height / 6
}
}

if isSearchingMode || layoutForView?.groupBy != "none" || dataSource.numberOfSections() > 1 {
if section == 0 {
return (getHeaderHeight(), headerRichWorkspace, NCGlobal.shared.heightSection)
} else {
return (0, 0, NCGlobal.shared.heightSection)
}
} else {
return (getHeaderHeight(), headerRichWorkspace, 0)
}
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
var height: CGFloat = 0

if isEditMode {
return CGSize.zero
} else if dataSource.getMetadataSourceForAllSections().isEmpty {
height = NCGlobal.shared.getHeightHeaderEmptyData(view: view, portraitOffset: emptyDataPortaitOffset, landscapeOffset: emptyDataLandscapeOffset, isHeaderMenuTransferViewEnabled: isHeaderMenuTransferViewEnabled())
} else {
let (heightHeaderCommands, heightHeaderRichWorkspace, heightHeaderSection) = getHeaderHeight(section: section)
height = heightHeaderCommands + heightHeaderRichWorkspace + heightHeaderSection
}
return CGSize(width: collectionView.frame.width, height: height)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
let sections = dataSource.numberOfSections()
let metadataForSection = self.dataSource.getMetadataForSection(section)
let isPaginated = metadataForSection?.lastSearchResult?.isPaginated ?? false
let metadatasCount: Int = metadataForSection?.lastSearchResult?.entries.count ?? 0
var size = CGSize(width: collectionView.frame.width, height: 0)

if section == sections - 1 {
size.height += NCGlobal.shared.endHeightFooter
} else {
size.height += NCGlobal.shared.heightFooter
}

if isSearchingMode && isPaginated && metadatasCount > 0 {
size.height += NCGlobal.shared.heightFooterButton
}
return size
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// NCCollectionViewCommon+EasyTipView.swift
// Nextcloud
//
// Created by Marino Faggiana on 20/07/24.
// Copyright © 2024 Marino Faggiana. All rights reserved.
//
// Author Marino Faggiana <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

import Foundation
import UIKit
import EasyTipView

extension NCCollectionViewCommon: EasyTipViewDelegate {
func showTip() {
guard !appDelegate.account.isEmpty,
self is NCFiles,
self.view.window != nil,
!NCBrandOptions.shared.disable_multiaccount,
self.serverUrl == utilityFileSystem.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId),
let view = self.navigationItem.leftBarButtonItem?.customView,
!NCManageDatabase.shared.tipExists(NCGlobal.shared.tipNCCollectionViewCommonAccountRequest) else { return }
var preferences = EasyTipView.Preferences()

preferences.drawing.foregroundColor = .white
preferences.drawing.backgroundColor = NCBrandColor.shared.nextcloud
preferences.drawing.textAlignment = .left
preferences.drawing.arrowPosition = .top
preferences.drawing.cornerRadius = 10

preferences.animating.dismissTransform = CGAffineTransform(translationX: 0, y: 100)
preferences.animating.showInitialTransform = CGAffineTransform(translationX: 0, y: -100)
preferences.animating.showInitialAlpha = 0
preferences.animating.showDuration = 1.5
preferences.animating.dismissDuration = 1.5

if appDelegate.tipView == nil {
appDelegate.tipView = EasyTipView(text: NSLocalizedString("_tip_accountrequest_", comment: ""), preferences: preferences, delegate: self)
appDelegate.tipView?.show(forView: view)
}
}

func easyTipViewDidTap(_ tipView: EasyTipView) {
NCManageDatabase.shared.addTip(NCGlobal.shared.tipNCCollectionViewCommonAccountRequest)
}

func easyTipViewDidDismiss(_ tipView: EasyTipView) { }

func dismissTip() {
if !NCManageDatabase.shared.tipExists(NCGlobal.shared.tipNCCollectionViewCommonAccountRequest) {
NCManageDatabase.shared.addTip(NCGlobal.shared.tipNCCollectionViewCommonAccountRequest)
}
appDelegate.tipView?.dismiss()
appDelegate.tipView = nil
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// NCCollectionViewCommon+EndToEndInitialize.swift
// Nextcloud
//
// Created by Marino Faggiana on 20/07/24.
// Copyright © 2024 Marino Faggiana. All rights reserved.
//
// Author Marino Faggiana <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

import Foundation
import UIKit

extension NCCollectionViewCommon: NCEndToEndInitializeDelegate {
func endToEndInitializeSuccess(metadata: tableMetadata?) {
if let metadata {
pushMetadata(metadata)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
//
// File.swift
// NCCollectionViewCommon+PhotoLayout.swift
// Nextcloud
//
// Created by Marino Faggiana on 13/07/24.
// Copyright © 2024 Marino Faggiana. All rights reserved.
//
// Author Marino Faggiana <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

import Foundation
import UIKit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// NCCollectionViewCommon+SelectTabBarDelegate.swift
// NCCollectionViewCommon+SelectTabBar.swift
// Nextcloud
//
// Created by Milen on 01.03.24.
Expand Down
Loading

0 comments on commit 3efb493

Please sign in to comment.