Skip to content

Commit

Permalink
Added swipe left to delete to the history views.
Browse files Browse the repository at this point in the history
  • Loading branch information
msimms committed May 22, 2024
1 parent a5c890f commit 4a62c5d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 36 deletions.
37 changes: 24 additions & 13 deletions Watch App/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,38 @@ struct HistoryView: View {
}
}

private func delete(at offsets: IndexSet) {
for offset in offsets {
let item = self.historyVM.historicalActivities[offset]
let activityVM = StoredActivityVM(activitySummary: item)
let _ = activityVM.deleteActivity()
}
}

var body: some View {
switch self.historyVM.state {
case HistoryVM.VmState.loaded:
VStack(alignment: .leading) {
if self.historyVM.historicalActivities.count > 0 {
List(self.historyVM.historicalActivities, id: \.self) { item in
NavigationLink(destination: HistoryDetailsView(activityVM: StoredActivityVM(activitySummary: item))) {
VStack(alignment: .leading) {
if item.name.count > 0 {
Text(item.name)
.bold()
}
HStack() {
Image(systemName: HistoryVM.imageNameForActivityType(activityType: item.type))
Text(item.type)
.bold()
Spacer()
Text("\(self.dateFormatter.string(from: item.startTime))")
List {
ForEach(self.historyVM.historicalActivities) { item in
NavigationLink(destination: HistoryDetailsView(activityVM: StoredActivityVM(activitySummary: item))) {
VStack(alignment: .leading) {
if item.name.count > 0 {
Text(item.name)
.bold()
}
HStack() {
Image(systemName: HistoryVM.imageNameForActivityType(activityType: item.type))
Text(item.type)
.bold()
Spacer()
Text("\(self.dateFormatter.string(from: item.startTime))")
}
}
}
}
.onDelete(perform: delete)
}
.listStyle(.plain)
}
Expand Down
57 changes: 34 additions & 23 deletions iPhone App/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ struct HistoryView: View {
}
}

private func delete(at offsets: IndexSet) {
for offset in offsets {
let item = self.historyVM.historicalActivities[offset]
let activityVM = StoredActivityVM(activitySummary: item)
let _ = activityVM.deleteActivity()
}
}

var body: some View {
ZStack() {
// The user has connected the app to the server, but we don't have a valid session, move to the login screen.
Expand All @@ -45,34 +53,37 @@ struct HistoryView: View {
// The list of stored activities.
VStack(alignment: .center) {
if self.historyVM.historicalActivities.count > 0 {
List(self.historyVM.historicalActivities, id: \.self) { item in
NavigationLink(destination: HistoryDetailsView(activityVM: StoredActivityVM(activitySummary: item))) {
HStack() {
Image(systemName: HistoryVM.imageNameForActivityType(activityType: item.type))
.frame(width: 32)
VStack(alignment: .leading) {
if item.name.count > 0 {
Text(item.name)
.bold()
.font(Font.headline)
List {
ForEach(self.historyVM.historicalActivities) { item in
NavigationLink(destination: HistoryDetailsView(activityVM: StoredActivityVM(activitySummary: item))) {
HStack() {
Image(systemName: HistoryVM.imageNameForActivityType(activityType: item.type))
.frame(width: 32)
VStack(alignment: .leading) {
if item.name.count > 0 {
Text(item.name)
.bold()
.font(Font.headline)
}
Text("\(self.dateFormatter.string(from: item.startTime))")
if item.source == ActivitySummary.Source.healthkit {
Text("HealthKit")
.bold()
.foregroundColor(.gray)
.font(Font.subheadline)
}
}
Text("\(self.dateFormatter.string(from: item.startTime))")
if item.source == ActivitySummary.Source.healthkit {
Text("HealthKit")
.bold()
.foregroundColor(.gray)
.font(Font.subheadline)
.onAppear() {
item.requestMetadata()
self.displayedDates.insert(item.startTime)
}
.onDisappear {
self.displayedDates.remove(item.startTime)
}
}
.onAppear() {
item.requestMetadata()
self.displayedDates.insert(item.startTime)
}
.onDisappear {
self.displayedDates.remove(item.startTime)
}
}
}
.onDelete(perform: delete)
}
.listStyle(.plain)
.gesture(
Expand Down

0 comments on commit 4a62c5d

Please sign in to comment.