Improve details view.

This commit is contained in:
Marcin Czachursk 2023-01-03 20:42:20 +01:00
parent 2f9fd46089
commit 89b2bdee98
5 changed files with 49 additions and 9 deletions

View File

@ -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?

View File

@ -34,11 +34,7 @@ public class TimelineService {
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

View File

@ -55,6 +55,7 @@
<attribute name="pinned" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="reblogged" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="reblogsCount" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="repliesCount" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="sensitive" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="spoilerText" optional="YES" attributeType="String"/>
<attribute name="uri" attributeType="String"/>

View File

@ -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,9 +46,23 @@ struct DetailsView: View {
}
.padding(8)
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")
.onAppear {
}

View File

@ -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) {
Menu {
Button {
// Open settings view.
// 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)