-
Notifications
You must be signed in to change notification settings - Fork 134
/
PodcastPickerView.swift
107 lines (97 loc) · 4.09 KB
/
PodcastPickerView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import PocketCastsDataModel
import PocketCastsUtils
import SwiftUI
struct PodcastPickerView: View {
@EnvironmentObject var theme: Theme
@ObservedObject var pickerModel: PodcastPickerModel
var body: some View {
VStack(alignment: .leading) {
Group {
HStack {
PCSearchView(searchTerm: $pickerModel.searchTerm)
.frame(height: PCSearchView.defaultHeight)
.padding(.top, 11)
.padding(.leading, -PCSearchView.defaultIndenting)
Spacer()
Menu {
SortByView(sortType: .titleAtoZ, pickerModel: pickerModel)
SortByView(sortType: .episodeDateNewestToOldest, pickerModel: pickerModel)
SortByView(sortType: .dateAddedNewestToOldest, pickerModel: pickerModel)
} label: {
Image("podcast-sort")
.accessibilityLabel(L10n.podcastsSort)
.foregroundColor(ThemeColor.primaryInteractive01(for: theme.activeTheme).color)
.frame(width: 32, height: 32)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(ThemeColor.primaryInteractive01(for: theme.activeTheme).color, lineWidth: 2)
)
}
}
.padding(.top, 3)
ThemedDivider()
Text(L10n.selectedPodcastCount(pickerModel.selectedPodcastUuids.count, capitalized: true))
.font(.subheadline)
.textStyle(PrimaryText())
.padding(.top, 3)
ThemedDivider()
}
.padding(.horizontal)
List(pickerModel.filteredPodcasts) { podcast in
Button {
pickerModel.togglePodcastSelected(podcast)
} label: {
PodcastPickerRow(pickingForFolderUuid: $pickerModel.pickingForFolderUuid, podcast: podcast, selectedPodcasts: $pickerModel.selectedPodcastUuids)
}
.listRowInsets(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 4))
.listRowBackground(ThemeColor.primaryUi01(for: theme.activeTheme).color)
.hideListRowSeperators()
.accessibilityElement(children: .ignore)
.accessibilityLabel(accessibilitySummary(podcast: podcast, selectedPodcasts: pickerModel.selectedPodcastUuids))
.accessibility(addTraits: .isButton)
}
.gesture(
DragGesture().onChanged { value in
if value.translation.height < 0 {
// hide keyboard on scroll down
UIApplication.shared.endEditing()
}
}
)
.listStyle(PlainListStyle())
}
}
private func accessibilitySummary(podcast: Podcast, selectedPodcasts: [String]) -> String {
var str = podcast.title ?? ""
if selectedPodcasts.contains(podcast.uuid) {
str += " \(L10n.statusSelected)"
} else {
str += " \(L10n.statusNotSelected)"
}
return str
}
}
struct SortByView: View {
@State var sortType: LibrarySort
@ObservedObject var pickerModel: PodcastPickerModel
var body: some View {
Button {
pickerModel.sortType = sortType
Analytics.track(.folderPodcastPickerFilterChanged, properties: ["sort_order": sortType])
} label: {
HStack {
Text(sortType.description)
Spacer()
if pickerModel.sortType == sortType {
Image(systemName: "checkmark")
}
}
}
}
}
struct PodcastPickerView_Previews: PreviewProvider {
static var previews: some View {
PodcastPickerView(pickerModel: PodcastPickerModel())
.environmentObject(Theme(previewTheme: .light))
}
}