From fc3b4d12961fbb46786231a4944615742f80644f Mon Sep 17 00:00:00 2001 From: Marcin Czachurski Date: Mon, 9 Oct 2023 16:47:20 +0200 Subject: [PATCH] Change trending people --- Vernissage.xcodeproj/project.pbxproj | 24 +++++++++---------- Vernissage/Views/AccountsPhotoView.swift | 24 +++++++++++++++++-- Vernissage/Widgets/ImageGrid.swift | 7 +++++- Vernissage/Widgets/ImagesGrid.swift | 7 ++++-- .../ViewModifiers/DeviceRotation.swift | 7 ++++-- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Vernissage.xcodeproj/project.pbxproj b/Vernissage.xcodeproj/project.pbxproj index b485c88..b917620 100644 --- a/Vernissage.xcodeproj/project.pbxproj +++ b/Vernissage.xcodeproj/project.pbxproj @@ -1348,7 +1348,7 @@ CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 256; + CURRENT_PROJECT_VERSION = 301; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageWidget/Info.plist; @@ -1360,7 +1360,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.0; + MARKETING_VERSION = 1.13.0; PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.widget; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -1379,7 +1379,7 @@ ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground; CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 256; + CURRENT_PROJECT_VERSION = 301; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageWidget/Info.plist; @@ -1391,7 +1391,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.0; + MARKETING_VERSION = 1.13.0; PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.widget; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -1409,7 +1409,7 @@ CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 256; + CURRENT_PROJECT_VERSION = 301; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageShare/Info.plist; @@ -1421,7 +1421,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.0; + MARKETING_VERSION = 1.13.0; PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.share; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -1438,7 +1438,7 @@ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = NO; CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 256; + CURRENT_PROJECT_VERSION = 301; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageShare/Info.plist; @@ -1450,7 +1450,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.0; + MARKETING_VERSION = 1.13.0; PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.share; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -1592,7 +1592,7 @@ CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 256; + CURRENT_PROJECT_VERSION = 301; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; @@ -1611,7 +1611,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.12.0; + MARKETING_VERSION = 1.13.0; PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1635,7 +1635,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 256; + CURRENT_PROJECT_VERSION = 301; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; @@ -1654,7 +1654,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.12.0; + MARKETING_VERSION = 1.13.0; PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; diff --git a/Vernissage/Views/AccountsPhotoView.swift b/Vernissage/Views/AccountsPhotoView.swift index 09b8bf4..c6fdae1 100644 --- a/Vernissage/Views/AccountsPhotoView.swift +++ b/Vernissage/Views/AccountsPhotoView.swift @@ -114,8 +114,28 @@ struct AccountsPhotoView: View { switch self.listType { case .trending: do { - let accountsFromApi = try await self.client.trends?.accounts() - return accountsFromApi ?? [] + // TODO: Trending accounts API is returning almost always the same set of accounts. Thus we can take accounts from trending statuses. + async let trendingStatusesDaily = self.client.trends?.statuses(range: .daily) + async let trendingStatusesMonthly = self.client.trends?.statuses(range: .monthly) + async let trendingStatusesYearly = self.client.trends?.statuses(range: .yearly) + async let accountsFromApi = self.client.trends?.accounts() + + let trendingStatuses = try await (dailyStatuses: trendingStatusesDaily, + monthlyStatuses: trendingStatusesMonthly, + yearlyStatuses: trendingStatusesYearly) + let allTrendingStatuses = (trendingStatuses.dailyStatuses ?? []) + (trendingStatuses.monthlyStatuses ?? []) + (trendingStatuses.yearlyStatuses ?? []) + + var allTrendingAccounts: [Account] = [] + for trendingStatus in allTrendingStatuses where allTrendingAccounts.contains(where: { $0.id == trendingStatus.account.id }) == false { + allTrendingAccounts.append(trendingStatus.account) + } + + let trendingAccounts = try await accountsFromApi ?? [] + for account in trendingAccounts where allTrendingAccounts.contains(where: { $0.id == account.id }) == false { + allTrendingAccounts.append(account) + } + + return allTrendingAccounts } catch NetworkError.notSuccessResponse(let response) { // TODO: This code can be removed when other Pixelfed server will support trending accounts. if response.statusCode() == HTTPStatusCode.notFound { diff --git a/Vernissage/Widgets/ImageGrid.swift b/Vernissage/Widgets/ImageGrid.swift index 63acfcc..d6c99d9 100644 --- a/Vernissage/Widgets/ImageGrid.swift +++ b/Vernissage/Widgets/ImageGrid.swift @@ -14,7 +14,12 @@ struct ImageGrid: View { @EnvironmentObject var routerPath: RouterPath @StateObject var photoUrl: PhotoUrl - @State var maxHeight = 120.0 + @Binding var maxHeight: Double + + init(photoUrl: PhotoUrl, maxHeight: Binding) { + self._photoUrl = StateObject(wrappedValue: photoUrl) + self._maxHeight = maxHeight + } var body: some View { if self.photoUrl.sensitive && !self.applicationState.showSensitive { diff --git a/Vernissage/Widgets/ImagesGrid.swift b/Vernissage/Widgets/ImagesGrid.swift index f463daf..7796307 100644 --- a/Vernissage/Widgets/ImagesGrid.swift +++ b/Vernissage/Widgets/ImagesGrid.swift @@ -20,9 +20,9 @@ struct ImagesGrid: View { @EnvironmentObject var routerPath: RouterPath private let maxImages = 5 - private let maxHeight = UIDevice.isIPad ? 240.0 : 120.0 @State public var gridType: GridType + @State public var maxHeight = UIDevice.isIPhone ? 120.0 : 240.0 @State private var photoUrls: [PhotoUrl] = [ PhotoUrl(id: UUID().uuidString), @@ -36,7 +36,7 @@ struct ImagesGrid: View { ScrollView(.horizontal) { LazyHGrid(rows: [GridItem(.fixed(self.maxHeight))]) { ForEach(self.photoUrls) { photoUrl in - ImageGrid(photoUrl: photoUrl, maxHeight: self.maxHeight) + ImageGrid(photoUrl: photoUrl, maxHeight: $maxHeight) } Text("more...") @@ -48,6 +48,9 @@ struct ImagesGrid: View { } } } + .gallery { properties in + self.maxHeight = properties.horizontalSize == .compact ? 120.0 : 240.0 + } .frame(height: self.maxHeight) .onFirstAppear { Task { diff --git a/WidgetsKit/Sources/WidgetsKit/ViewModifiers/DeviceRotation.swift b/WidgetsKit/Sources/WidgetsKit/ViewModifiers/DeviceRotation.swift index e2b0368..5013236 100644 --- a/WidgetsKit/Sources/WidgetsKit/ViewModifiers/DeviceRotation.swift +++ b/WidgetsKit/Sources/WidgetsKit/ViewModifiers/DeviceRotation.swift @@ -29,6 +29,7 @@ public struct GalleryProperties { public let imageColumns: Int public let containerWidth: Double public let containerHeight: Double + public let horizontalSize: UserInterfaceSizeClass } struct DeviceImageGallery: ViewModifier { @@ -66,7 +67,8 @@ struct DeviceImageGallery: ViewModifier { // View like on iPhone. return GalleryProperties(imageColumns: 1, containerWidth: geometry.size.width, - containerHeight: geometry.size.height) + containerHeight: geometry.size.height, + horizontalSize: horizontalSize) } else { // View like on iPad. let imageColumns = geometry.size.width > geometry.size.height ? 3 : 2 @@ -74,7 +76,8 @@ struct DeviceImageGallery: ViewModifier { return GalleryProperties(imageColumns: imageColumns, containerWidth: (geometry.size.width - Double(marginSpacing)) / Double(imageColumns), - containerHeight: (geometry.size.height - Double(marginSpacing)) / Double(imageColumns)) + containerHeight: (geometry.size.height - Double(marginSpacing)) / Double(imageColumns), + horizontalSize: horizontalSize) } } }