From 87a9bf9bce0e00a3bedc18bea6f9a3a46de0d48f Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 8 Jul 2022 14:40:48 +1000 Subject: [PATCH] feat: add view for empty and loading state of document view --- .../DocumentTitleViewController.swift | 98 ++++++++++++++----- .../Translations/en.lproj/Localizable.strings | 3 + 2 files changed, 79 insertions(+), 22 deletions(-) diff --git a/Session/Media Viewing & Editing/DocumentTitleViewController.swift b/Session/Media Viewing & Editing/DocumentTitleViewController.swift index 08b544d21..5c8a8e6cf 100644 --- a/Session/Media Viewing & Editing/DocumentTitleViewController.swift +++ b/Session/Media Viewing & Editing/DocumentTitleViewController.swift @@ -246,30 +246,22 @@ public class DocumentTileViewController: UIViewController, UITableViewDelegate, switch section.model { case .emptyGallery, .loadOlder, .loadNewer: - return nil + let headerView: DocumentStaticHeaderView = DocumentStaticHeaderView() + headerView.configure( + title: { + switch section.model { + case .emptyGallery: return "DOCUMENT_TILES_EMPTY_DOCUMENT".localized() + case .loadOlder: return "DOCUMENT_TILES_LOADING_OLDER_LABEL".localized() + case .loadNewer: return "DOCUMENT_TILES_LOADING_MORE_RECENT_LABEL".localized() + case .galleryMonth: return "" // Impossible case + } + }() + ) + return headerView case .galleryMonth(let date): - let headerView: UIView = UIView() - let label = UILabel() - label.textColor = Colors.text - label.text = date.localizedString - - let blurEffect = UIBlurEffect(style: .dark) - let blurEffectView = UIVisualEffectView(effect: blurEffect) - - blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - - headerView.backgroundColor = isLightMode ? Colors.cellBackground : UIColor.ows_black.withAlphaComponent(OWSNavigationBar.backgroundBlurMutingFactor) - - headerView.addSubview(blurEffectView) - headerView.addSubview(label) - - blurEffectView.autoPinEdgesToSuperviewEdges() - blurEffectView.isHidden = isLightMode - label.autoPinEdge(toSuperviewMargin: .trailing) - label.autoPinEdge(toSuperviewMargin: .leading) - label.autoVCenterInSuperview() - + let headerView: DocumentSectionHeaderView = DocumentSectionHeaderView() + headerView.configure(title: date.localizedString) return headerView } } @@ -381,3 +373,65 @@ class DocumentCell: UITableViewCell { detailLabel.text = "\(OWSFormat.formatFileSize(UInt(attachment.byteCount)))" } } + +class DocumentSectionHeaderView: UIView { + + let label: UILabel + + override init(frame: CGRect) { + label = UILabel() + label.textColor = Colors.text + + let blurEffect = UIBlurEffect(style: .dark) + let blurEffectView = UIVisualEffectView(effect: blurEffect) + + blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + + super.init(frame: frame) + + self.backgroundColor = isLightMode ? Colors.cellBackground : UIColor.ows_black.withAlphaComponent(OWSNavigationBar.backgroundBlurMutingFactor) + + self.addSubview(blurEffectView) + self.addSubview(label) + + blurEffectView.autoPinEdgesToSuperviewEdges() + blurEffectView.isHidden = isLightMode + label.autoPinEdge(toSuperviewMargin: .trailing) + label.autoPinEdge(toSuperviewMargin: .leading) + label.autoVCenterInSuperview() + } + + @available(*, unavailable, message: "Unimplemented") + required init?(coder aDecoder: NSCoder) { + notImplemented() + } + + public func configure(title: String) { + self.label.text = title + } +} + +class DocumentStaticHeaderView: UIView { + + let label = UILabel() + + override init(frame: CGRect) { + super.init(frame: frame) + + addSubview(label) + + label.textColor = Colors.text + label.textAlignment = .center + label.numberOfLines = 0 + label.autoPinEdgesToSuperviewMargins(with: UIEdgeInsets(top: 0, leading: Values.largeSpacing, bottom: 0, trailing: Values.largeSpacing)) + } + + @available(*, unavailable, message: "Unimplemented") + required public init?(coder aDecoder: NSCoder) { + notImplemented() + } + + public func configure(title: String) { + self.label.text = title + } +} diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 499183d79..5fb9780e8 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -662,3 +662,6 @@ "MESSAGE_TRIMMING_OPEN_GROUP_DESCRIPTION" = "Automatically delete open group messages which are older than 6 months when starting the app"; "MEDIA_TAB_TITLE" = "Media"; "DOCUMENT_TAB_TITLE" = "Document"; +"DOCUMENT_TILES_EMPTY_DOCUMENT" = "You don't have any document in this conversation."; +"DOCUMENT_TILES_LOADING_MORE_RECENT_LABEL" = "Loading Newer Document…"; +"DOCUMENT_TILES_LOADING_OLDER_LABEL" = "Loading Older Document…";