From 2988e71611dcdfe14d7292f73d9a798e2f942717 Mon Sep 17 00:00:00 2001 From: CMK Date: Wed, 24 Feb 2021 18:40:47 +0800 Subject: [PATCH] chore: update UI appearance. remove not used separator line component --- Mastodon/Diffiable/Item/Item.swift | 12 +----------- Mastodon/Extension/UIView.swift | 4 ---- .../StatusProvider/StatusProviderFacade.swift | 2 +- .../HomeTimelineViewModel+Diffable.swift | 8 ++------ .../View/TableviewCell/StatusTableViewCell.swift | 11 ++++++++++- .../TimelineLoaderTableViewCell.swift | 14 ++++++++------ .../TimelineMiddleLoaderTableViewCell.swift | 10 ---------- .../Service/APIService/APIService+Favorite.swift | 2 +- 8 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Mastodon/Diffiable/Item/Item.swift b/Mastodon/Diffiable/Item/Item.swift index 2b34753b3..2ab198226 100644 --- a/Mastodon/Diffiable/Item/Item.swift +++ b/Mastodon/Diffiable/Item/Item.swift @@ -30,32 +30,22 @@ protocol StatusContentWarningAttribute { extension Item { class StatusTimelineAttribute: Hashable, StatusContentWarningAttribute { - var separatorLineStyle: SeparatorLineStyle = .indent var isStatusTextSensitive: Bool = false public init( - separatorLineStyle: Item.StatusTimelineAttribute.SeparatorLineStyle = .indent, isStatusTextSensitive: Bool ) { - self.separatorLineStyle = separatorLineStyle self.isStatusTextSensitive = isStatusTextSensitive } static func == (lhs: Item.StatusTimelineAttribute, rhs: Item.StatusTimelineAttribute) -> Bool { - return lhs.separatorLineStyle == rhs.separatorLineStyle && - lhs.isStatusTextSensitive == rhs.isStatusTextSensitive + return lhs.isStatusTextSensitive == rhs.isStatusTextSensitive } func hash(into hasher: inout Hasher) { - hasher.combine(separatorLineStyle) hasher.combine(isStatusTextSensitive) } - enum SeparatorLineStyle { - case indent // alignment to name label - case expand // alignment to table view two edges - case normal // alignment to readable guideline - } } } diff --git a/Mastodon/Extension/UIView.swift b/Mastodon/Extension/UIView.swift index 7e1ba379e..d9e3af5b5 100644 --- a/Mastodon/Extension/UIView.swift +++ b/Mastodon/Extension/UIView.swift @@ -20,10 +20,6 @@ extension UIView { return 1.0 / view.traitCollection.displayScale } - static var floatyButtonBottomMargin: CGFloat { - return 16 - } - } // MARK: - Convinience view appearance modification method diff --git a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift index eaf202c01..894461566 100644 --- a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift +++ b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift @@ -85,7 +85,7 @@ extension StatusProviderFacade { os_log("%{public}s[%{public}ld], %{public}s: [Like] update local toot like status to: %s", ((#file as NSString).lastPathComponent), #line, #function, favoriteKind == .create ? "like" : "unlike") } receiveCompletion: { completion in switch completion { - case .failure(let error): + case .failure: // TODO: handle error break case .finished: diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift index 0091f06bf..8f74b81a4 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift @@ -90,16 +90,12 @@ extension HomeTimelineViewModel: NSFetchedResultsControllerDelegate { let isLast = i == timelineIndexes.count - 1 switch (isLast, timelineIndex.hasMore) { - case (true, false): - attribute.separatorLineStyle = .normal case (false, true): - attribute.separatorLineStyle = .expand newTimelineItems.append(.homeMiddleLoader(upperTimelineIndexAnchorObjectID: timelineIndex.objectID)) case (true, true): - attribute.separatorLineStyle = .normal shouldAddBottomLoader = true - case (false, false): - attribute.separatorLineStyle = .indent + default: + break } } // end for diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift index ed1d083cc..758beed0c 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift @@ -18,6 +18,7 @@ protocol StatusTableViewCellDelegate: class { final class StatusTableViewCell: UITableViewCell { + static let bottomPaddingHeight: CGFloat = 10 weak var delegate: StatusTableViewCellDelegate? @@ -28,6 +29,7 @@ final class StatusTableViewCell: UITableViewCell { override func prepareForReuse() { super.prepareForReuse() + statusView.isStatusTextSensitive = false statusView.cleanUpContentWarning() disposeBag.removeAll() observations.removeAll() @@ -43,6 +45,13 @@ final class StatusTableViewCell: UITableViewCell { _init() } + override func layoutSubviews() { + super.layoutSubviews() + DispatchQueue.main.async { + self.statusView.drawContentWarningImageView() + } + } + } extension StatusTableViewCell { @@ -68,7 +77,7 @@ extension StatusTableViewCell { bottomPaddingView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), bottomPaddingView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), bottomPaddingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), - bottomPaddingView.heightAnchor.constraint(equalToConstant: 10).priority(.defaultHigh), + bottomPaddingView.heightAnchor.constraint(equalToConstant: StatusTableViewCell.bottomPaddingHeight).priority(.defaultHigh), ]) statusView.delegate = self diff --git a/Mastodon/Scene/Share/View/TableviewCell/TimelineLoaderTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/TimelineLoaderTableViewCell.swift index 676f44ff2..f9508894a 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/TimelineLoaderTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/TimelineLoaderTableViewCell.swift @@ -10,7 +10,9 @@ import Combine class TimelineLoaderTableViewCell: UITableViewCell { - static let cellHeight: CGFloat = 48 + static let cellHeight: CGFloat = 44 + TimelineLoaderTableViewCell.extraTopPadding + TimelineLoaderTableViewCell.bottomPadding + static let extraTopPadding: CGFloat = 3 // the status cell already has 10pt bottom padding + static let bottomPadding: CGFloat = StatusTableViewCell.bottomPaddingHeight + TimelineLoaderTableViewCell.extraTopPadding // make balance var disposeBag = Set() @@ -50,18 +52,18 @@ class TimelineLoaderTableViewCell: UITableViewCell { loadMoreButton.translatesAutoresizingMaskIntoConstraints = false contentView.addSubview(loadMoreButton) NSLayoutConstraint.activate([ - loadMoreButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8), + loadMoreButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: TimelineLoaderTableViewCell.extraTopPadding), loadMoreButton.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor), contentView.readableContentGuide.trailingAnchor.constraint(equalTo: loadMoreButton.trailingAnchor), - contentView.bottomAnchor.constraint(equalTo: loadMoreButton.bottomAnchor, constant: 8), - loadMoreButton.heightAnchor.constraint(equalToConstant: TimelineLoaderTableViewCell.cellHeight - 2 * 8).priority(.defaultHigh), + contentView.bottomAnchor.constraint(equalTo: loadMoreButton.bottomAnchor, constant: TimelineLoaderTableViewCell.bottomPadding), + loadMoreButton.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh), ]) activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false addSubview(activityIndicatorView) NSLayoutConstraint.activate([ - activityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor), - activityIndicatorView.centerYAnchor.constraint(equalTo: centerYAnchor), + activityIndicatorView.centerXAnchor.constraint(equalTo: loadMoreButton.centerXAnchor), + activityIndicatorView.centerYAnchor.constraint(equalTo: loadMoreButton.centerYAnchor), ]) loadMoreButton.isHidden = true diff --git a/Mastodon/Scene/Share/View/TableviewCell/TimelineMiddleLoaderTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/TimelineMiddleLoaderTableViewCell.swift index d768865d6..6c692b646 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/TimelineMiddleLoaderTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/TimelineMiddleLoaderTableViewCell.swift @@ -23,16 +23,6 @@ final class TimelineMiddleLoaderTableViewCell: TimelineLoaderTableViewCell { backgroundColor = .clear - let separatorLine = UIView.separatorLine - separatorLine.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(separatorLine) - NSLayoutConstraint.activate([ - separatorLine.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - contentView.trailingAnchor.constraint(equalTo: separatorLine.trailingAnchor), - contentView.bottomAnchor.constraint(equalTo: separatorLine.bottomAnchor), - separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: separatorLine)) - ]) - loadMoreButton.isHidden = false loadMoreButton.setImage(Asset.Arrows.arrowTriangle2Circlepath.image.withRenderingMode(.alwaysTemplate), for: .normal) loadMoreButton.setInsets(forContentPadding: .zero, imageTitlePadding: 4) diff --git a/Mastodon/Service/APIService/APIService+Favorite.swift b/Mastodon/Service/APIService/APIService+Favorite.swift index 8dd4839ac..34bd3f0e4 100644 --- a/Mastodon/Service/APIService/APIService+Favorite.swift +++ b/Mastodon/Service/APIService/APIService+Favorite.swift @@ -139,7 +139,7 @@ extension APIService { return APIService.Persist.persistTimeline( managedObjectContext: self.backgroundManagedObjectContext, domain: mastodonAuthenticationBox.domain, - query: query as! TimelineQueryType, + query: query, response: response, persistType: .likeList, requestMastodonUserID: requestMastodonUserID,