diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift index 329a7f39c..3e767f2d3 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift @@ -5,6 +5,7 @@ // Created by MainasuK on 2022-1-26. // +import os.log import UIKit import CoreDataStack import MastodonUI @@ -153,6 +154,8 @@ extension DataSourceFacade { user: ManagedObjectRecord, previewContext: ImagePreviewContext ) async throws { + let logger = Logger(subsystem: "DataSourceFacade", category: "Media") + let managedObjectContext = dependency.context.managedObjectContext var _avatarAssetURL: String? @@ -216,13 +219,18 @@ extension DataSourceFacade { thumbnail: thumbnail )) case .profileBanner: - return .profileAvatar(.init( + return .profileBanner(.init( assetURL: _headerAssetURL, thumbnail: thumbnail )) } }() + guard mediaPreviewItem.isAssetURLValid else { + logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): discard preview due to assetURL invalid") + return + } + coordinateToMediaPreviewScene( dependency: dependency, mediaPreviewItem: mediaPreviewItem, diff --git a/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift b/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift index 5912e559a..2fbc5f0ac 100644 --- a/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift +++ b/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift @@ -116,6 +116,19 @@ extension MediaPreviewViewModel { case profileAvatar(ProfileAvatarPreviewContext) case profileBanner(ProfileBannerPreviewContext) // case local(LocalImagePreviewMeta) + + var isAssetURLValid: Bool { + switch self { + case .attachment: + return true // default valid + case .profileAvatar: + return true // default valid + case .profileBanner(let item): + guard let assertURL = item.assetURL else { return false } + guard !assertURL.hasSuffix("missing.png") else { return false } + return true + } + } } struct AttachmentPreviewContext { diff --git a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift index ac71c0a5f..e68fd9c7b 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift @@ -37,7 +37,8 @@ final class ProfileHeaderView: UIView { weak var delegate: ProfileHeaderViewDelegate? var disposeBag = Set() - + private var _disposeBag = Set() + func prepareForReuse() { disposeBag.removeAll() } @@ -237,7 +238,7 @@ extension ProfileHeaderView { guard let self = self else { return } self.backgroundColor = theme.systemBackgroundColor } - .store(in: &disposeBag) + .store(in: &_disposeBag) // banner bannerContainerView.translatesAutoresizingMaskIntoConstraints = false diff --git a/Mastodon/Scene/Profile/Paging/ProfilePagingViewController.swift b/Mastodon/Scene/Profile/Paging/ProfilePagingViewController.swift index bfbe45471..cc798b6cf 100644 --- a/Mastodon/Scene/Profile/Paging/ProfilePagingViewController.swift +++ b/Mastodon/Scene/Profile/Paging/ProfilePagingViewController.swift @@ -11,6 +11,7 @@ import Combine import XLPagerTabStrip import TabBarPager import MastodonAsset +import MastodonUI protocol ProfilePagingViewControllerDelegate: AnyObject { func profilePagingViewController(_ viewController: ProfilePagingViewController, didScrollToPostCustomScrollViewContainerController customScrollViewContainerController: ScrollViewContainer, atIndex index: Int) @@ -87,6 +88,7 @@ extension ProfilePagingViewController { .sink { [weak self] theme in guard let self = self else { return } self.settings.style.buttonBarBackgroundColor = theme.systemBackgroundColor + self.buttonBarView.backgroundColor = self.settings.style.buttonBarBackgroundColor self.barButtonLayout?.invalidateLayout() } .store(in: &disposeBag) diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+ViewModel.swift b/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+ViewModel.swift index 0003e82b6..90fedf034 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+ViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+ViewModel.swift @@ -58,7 +58,12 @@ extension ProfileCardView { guard let userInterfaceStyle = userInterfaceStyle else { return } switch userInterfaceStyle { case .dark: - self.backgroundColor = theme.systemBackgroundColor + switch theme.themeName { + case .mastodon: + self.backgroundColor = theme.systemBackgroundColor + case .system: + self.backgroundColor = theme.secondarySystemBackgroundColor + } case .light, .unspecified: self.backgroundColor = Asset.Scene.Discovery.profileCardBackground.color @unknown default: @@ -99,7 +104,10 @@ extension ProfileCardView.ViewModel { private func bindHeader(view: ProfileCardView) { $authorBannerImageURL .sink { url in - guard let url = url else { return } + guard let url = url, !url.absoluteString.hasSuffix("missing.png") else { + view.bannerImageView.image = .placeholder(color: .systemGray3) + return + } view.bannerImageView.af.setImage( withURL: url, placeholderImage: .placeholder(color: .systemGray3),