From 89b2bdee98b7e856a9083d55d8f9e6973355af88 Mon Sep 17 00:00:00 2001 From: Marcin Czachursk Date: Tue, 3 Jan 2023 20:42:20 +0100 Subject: [PATCH] Improve details view. --- .../StatusData+CoreDataProperties.swift | 1 + Vernissage/Services/TimelineService.swift | 9 +++---- .../Vernissage.xcdatamodel/contents | 1 + Vernissage/Views/DetailsView.swift | 20 +++++++++++++- Vernissage/Views/MainView.swift | 27 +++++++++++++++++-- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Vernissage/CoreData/StatusData+CoreDataProperties.swift b/Vernissage/CoreData/StatusData+CoreDataProperties.swift index 52cbbbb..1a704db 100644 --- a/Vernissage/CoreData/StatusData+CoreDataProperties.swift +++ b/Vernissage/CoreData/StatusData+CoreDataProperties.swift @@ -34,6 +34,7 @@ extension StatusData { @NSManaged public var pinned: Bool @NSManaged public var reblogged: Bool @NSManaged public var reblogsCount: Int32 + @NSManaged public var repliesCount: Int32 @NSManaged public var sensitive: Bool @NSManaged public var spoilerText: String? @NSManaged public var uri: String? diff --git a/Vernissage/Services/TimelineService.swift b/Vernissage/Services/TimelineService.swift index 1a13049..e495ce5 100644 --- a/Vernissage/Services/TimelineService.swift +++ b/Vernissage/Services/TimelineService.swift @@ -33,12 +33,8 @@ public class TimelineService { // Get maximimum downloaded stauts id. let statusDataHandler = StatusDataHandler() let newestStatus = statusDataHandler.getMaximumStatus(viewContext: backgroundContext) - - guard let newestStatus = newestStatus else { - return - } - - try await self.loadData(for: accountData, on: backgroundContext, minId: newestStatus.id) + + try await self.loadData(for: accountData, on: backgroundContext, minId: newestStatus?.id) } public func getComments(for statusId: String, and accountData: AccountData) async throws -> Context { @@ -82,6 +78,7 @@ public class TimelineService { statusDataEntity.pinned = status.pinned statusDataEntity.reblogged = status.reblogged statusDataEntity.reblogsCount = Int32(status.reblogsCount) + statusDataEntity.repliesCount = Int32(status.repliesCount) statusDataEntity.sensitive = status.sensitive statusDataEntity.spoilerText = status.spoilerText statusDataEntity.uri = status.uri diff --git a/Vernissage/Vernissage.xcdatamodeld/Vernissage.xcdatamodel/contents b/Vernissage/Vernissage.xcdatamodeld/Vernissage.xcdatamodel/contents index 9fdca4d..5b5612d 100644 --- a/Vernissage/Vernissage.xcdatamodeld/Vernissage.xcdatamodel/contents +++ b/Vernissage/Vernissage.xcdatamodeld/Vernissage.xcdatamodel/contents @@ -55,6 +55,7 @@ + diff --git a/Vernissage/Views/DetailsView.swift b/Vernissage/Views/DetailsView.swift index e64aaed..a4322da 100644 --- a/Vernissage/Views/DetailsView.swift +++ b/Vernissage/Views/DetailsView.swift @@ -34,6 +34,10 @@ struct DetailsView: View { Text(statusData.createdAt.toDate(.isoDateTimeMilliSec) ?? Date(), style: .relative) .padding(.horizontal, -4) Text("ago") + if let applicationName = statusData.applicationName { + Text("via \(applicationName)") + .padding(.horizontal, -4) + } } .foregroundColor(Color("lightGrayColor")) .font(.footnote) @@ -42,7 +46,21 @@ struct DetailsView: View { } .padding(8) - CommentsSection(statusId: statusData.id) + if statusData.repliesCount > 0 { + HStack (alignment: .center) { + Image(systemName: "message") + .padding(.leading, 8) + .padding(.vertical, 8) + Text("\(statusData.repliesCount) replies") + Spacer() + } + .font(.footnote) + .frame(maxWidth: .infinity) + .background(Color("mainTextColor").opacity(0.05)) + .foregroundColor(Color("lightGrayColor")) + + CommentsSection(statusId: statusData.id) + } } } .navigationBarTitle("Details") diff --git a/Vernissage/Views/MainView.swift b/Vernissage/Views/MainView.swift index 7c885c1..fceff25 100644 --- a/Vernissage/Views/MainView.swift +++ b/Vernissage/Views/MainView.swift @@ -79,6 +79,8 @@ struct MainView: View { } } + Divider() + Button { viewMode = .notifications } label: { @@ -103,8 +105,29 @@ struct MainView: View { @ToolbarContentBuilder private func getLeadingToolbar() -> some ToolbarContent { ToolbarItem(placement: .navigationBarLeading) { - Button { - // Open settings view. + Menu { + + Button { + // Switch accounts... + } label: { + HStack { + Text(self.applicationState.accountData?.displayName ?? self.applicationState.accountData?.username ?? "") + Image(systemName: "person.circle.fill") + .resizable() + .foregroundColor(Color("mainTextColor")) + } + } + + Divider() + + Button { + // Open settings... + } label: { + HStack { + Text("Settings") + Image(systemName: "gear") + } + } } label: { if let avatarData = self.applicationState.accountData?.avatarData, let uiImage = UIImage(data: avatarData) { Image(uiImage: uiImage)