@@ -28,72 +28,11 @@ final class SearchViewController: UIViewController, SearchView {
28
28
searchBar. delegate = self
29
29
return searchBar
30
30
} ( )
31
-
32
- <<<<<<< HEAD
31
+
33
32
fileprivate let loadingView = LoadingView . makeFromNib ( )
34
-
33
+
35
34
var favoritePresenter : FavoritePresenter ?
36
- =======
37
- private var query : String = " " {
38
- didSet {
39
- if query != oldValue {
40
- users. removeAll ( )
41
- pageInfo = nil
42
- totalCount = 0
43
- }
44
- task? . cancel ( )
45
- task = nil
46
- fetchUsers ( )
47
- }
48
- }
49
- private var task : URLSessionTask ? = nil
50
- private var pageInfo : PageInfo ? = nil
51
- private var totalCount : Int = 0 {
52
- didSet {
53
- totalCountLabel. text = " \( users. count) / \( totalCount) "
54
- }
55
- }
56
- private var users : [ User ] = [ ] {
57
- didSet {
58
- totalCountLabel. text = " \( users. count) / \( totalCount) "
59
- tableView. reloadData ( )
60
- }
61
- }
62
- private let debounce : ( _ action: @escaping ( ) -> ( ) ) -> ( ) = {
63
- var lastFireTime : DispatchTime = . now( )
64
- let delay : DispatchTimeInterval = . milliseconds( 500 )
65
- return { [ delay] action in
66
- let deadline : DispatchTime = . now( ) + delay
67
- lastFireTime = . now( )
68
- DispatchQueue . global ( ) . asyncAfter ( deadline: deadline) { [ delay] in
69
- let now : DispatchTime = . now( )
70
- let when : DispatchTime = lastFireTime + delay
71
- if now < when { return }
72
- lastFireTime = . now( )
73
- DispatchQueue . main. async {
74
- action ( )
75
- }
76
- }
77
- }
78
- } ( )
79
- private var isFetchingUsers = false {
80
- didSet {
81
- tableView. reloadData ( )
82
- }
83
- }
84
- private var pool = Notice . ObserverPool ( )
85
-
86
- private let loadingView = LoadingView . makeFromNib ( )
87
-
88
- private var isReachedBottom : Bool = false {
89
- didSet {
90
- if isReachedBottom && isReachedBottom != oldValue {
91
- fetchUsers ( )
92
- }
93
- }
94
- }
95
- > >>>>>> mvc
96
-
35
+
97
36
private lazy var presenter : SearchPresenter = SearchViewPresenter ( view: self )
98
37
private lazy var dataSource : SearchViewDataSource = . init( presenter: self . presenter)
99
38
@@ -102,32 +41,27 @@ final class SearchViewController: UIViewController, SearchView {
102
41
103
42
navigationItem. titleView = searchBar
104
43
searchBar. placeholder = " Input user name "
105
-
44
+
106
45
dataSource. configure ( with: tableView)
107
46
}
108
-
47
+
109
48
override func viewWillAppear( _ animated: Bool ) {
110
49
super. viewWillAppear ( animated)
111
50
presenter. viewWillAppear ( )
112
51
}
113
-
52
+
114
53
override func viewWillDisappear( _ animated: Bool ) {
115
54
super. viewWillDisappear ( animated)
116
55
if searchBar. isFirstResponder {
117
56
searchBar. resignFirstResponder ( )
118
57
}
119
- <<<<<<< HEAD
120
58
presenter. viewWillDisappear ( )
121
- =======
122
- pool = Notice . ObserverPool ( )
123
- >>>>>>> mvc
124
59
}
125
-
60
+
126
61
func reloadData( ) {
127
62
tableView. reloadData ( )
128
63
}
129
-
130
- < <<<<<< HEAD
64
+
131
65
func keyboardWillShow( with keyboardInfo: UIKeyboardInfo ) {
132
66
view. layoutIfNeeded ( )
133
67
let extra = tabBarController? . tabBar. bounds. height ?? 0
@@ -137,29 +71,8 @@ final class SearchViewController: UIViewController, SearchView {
137
71
options: keyboardInfo. animationCurve,
138
72
animations: { self . view. layoutIfNeeded ( ) } ,
139
73
completion: nil )
140
- =======
141
- private func observeKeyboard( ) {
142
- NotificationCenter . default. nok. observe ( name: . keyboardWillShow) { [ weak self] in
143
- self ? . view. layoutIfNeeded ( )
144
- let extra = self ? . tabBarController? . tabBar. bounds. height ?? 0
145
- self ? . tableViewBottomConstraint. constant = $0. frame. size. height - extra
146
- UIView . animate ( withDuration: $0. animationDuration, delay: 0 , options: $0. animationCurve, animations: {
147
- self ? . view. layoutIfNeeded ( )
148
- } , completion: nil )
149
- }
150
- . invalidated ( by: pool)
151
-
152
- NotificationCenter . default. nok. observe ( name: . keyboardWillHide) { [ weak self] in
153
- self ? . view. layoutIfNeeded ( )
154
- self ? . tableViewBottomConstraint. constant = 0
155
- UIView . animate ( withDuration: $0. animationDuration, delay: 0 , options: $0. animationCurve, animations: {
156
- self ? . view. layoutIfNeeded ( )
157
- } , completion: nil )
158
- }
159
- . invalidated ( by: pool)
160
- >>>>>>> mvc
161
74
}
162
-
75
+
163
76
func keyboardWillHide( with keyboardInfo: UIKeyboardInfo ) {
164
77
view. layoutIfNeeded ( )
165
78
tableViewBottomConstraint. constant = 0
@@ -169,23 +82,17 @@ final class SearchViewController: UIViewController, SearchView {
169
82
animations: { self . view. layoutIfNeeded ( ) } ,
170
83
completion: nil )
171
84
}
172
-
173
- <<<<<<< HEAD
85
+
174
86
func showUserRepository( with user: User ) {
175
87
guard let presenter = favoritePresenter else { return }
176
88
let vc = UserRepositoryViewController ( user: user, favoritePresenter: presenter)
177
- =======
178
- private func showUserRepository( with user: User) {
179
- guard let favoriteModel = favoriteModel else { return }
180
- let vc = UserRepositoryViewController ( user: user, favoriteModel: favoriteModel)
181
- >>>>>>> mvc
182
89
navigationController? . pushViewController ( vc, animated: true )
183
90
}
184
-
91
+
185
92
func updateTotalCountLabel( _ countText: String ) {
186
93
totalCountLabel. text = countText
187
94
}
188
-
95
+
189
96
func updateLoadingView( with view: UIView , isLoading: Bool ) {
190
97
loadingView. removeFromSuperview ( )
191
98
loadingView. isLoading = isLoading
@@ -205,16 +112,16 @@ extension SearchViewController: UISearchBarDelegate {
205
112
searchBar. resignFirstResponder ( )
206
113
searchBar. showsCancelButton = false
207
114
}
208
-
115
+
209
116
func searchBarSearchButtonClicked( _ searchBar: UISearchBar ) {
210
117
searchBar. resignFirstResponder ( )
211
118
searchBar. showsCancelButton = false
212
119
}
213
-
120
+
214
121
func searchBarTextDidBeginEditing( _ searchBar: UISearchBar ) {
215
122
searchBar. showsCancelButton = true
216
123
}
217
-
124
+
218
125
func searchBar( _ searchBar: UISearchBar , textDidChange searchText: String ) {
219
126
presenter. search ( queryIfNeeded: searchText)
220
127
}
0 commit comments