Showing with 29 additions and 18 deletions.
  1. +3 −2 Wikipedia/Code/ArticleCollectionViewController.swift
  2. +26 −16 Wikipedia/Code/WMFSearchViewController.m
@@ -4,7 +4,7 @@ fileprivate let reuseIdentifier = "ArticleCollectionViewControllerCell"

@objc(WMFArticleCollectionViewControllerDelegate)
protocol ArticleCollectionViewControllerDelegate: NSObjectProtocol {

func articleCollectionViewController(_ articleCollectionViewController: ArticleCollectionViewController, didSelectArticleWithURL: URL)
}

@objc(WMFArticleCollectionViewController)
@@ -13,7 +13,7 @@ class ArticleCollectionViewController: ColumnarCollectionViewController {
var cellLayoutEstimate: WMFLayoutEstimate?
var swipeToEditController: CollectionViewSwipeToEditController!

weak var delegate: ArticleCollectionViewControllerDelegate?
@objc weak var delegate: ArticleCollectionViewControllerDelegate?

override func viewDidLoad() {
super.viewDidLoad()
@@ -114,6 +114,7 @@ extension ArticleCollectionViewController {
collectionView.deselectItem(at: indexPath, animated: true)
return
}
delegate?.articleCollectionViewController(self, didSelectArticleWithURL: articleURL)
wmf_pushArticle(with: articleURL, dataStore: dataStore, theme: theme, animated: true)
}
}
@@ -19,7 +19,8 @@
@interface WMFSearchViewController () <UISearchBarDelegate,
WMFRecentSearchesViewControllerDelegate,
UITextFieldDelegate,
WMFSearchLanguagesBarViewControllerDelegate>
WMFSearchLanguagesBarViewControllerDelegate,
WMFArticleCollectionViewControllerDelegate>

@property (nonatomic, strong, readwrite) MWKDataStore *dataStore;
@property (nonatomic, strong, readwrite) WMFTheme *theme;
@@ -153,6 +154,7 @@ - (void)setSearchFieldText:(NSString *)text {
- (void)configureArticleList {
[self.resultsListController applyTheme:self.theme];
self.resultsListController.dataStore = self.dataStore;
self.resultsListController.delegate = self;
}

- (void)configureRecentSearchList {
@@ -172,7 +174,7 @@ - (void)viewDidLoad {

self.fakeProgressController = [[WMFFakeProgressController alloc] initWithProgressView:self.progressView];
self.recentSearchesHeaderLabel.text = [WMFLocalizedStringWithDefaultValue(@"search-recent-title", nil, nil, @"Recently searched", @"Title for list of recent search terms") uppercaseStringWithLocale:[NSLocale currentLocale]];

[self configureSearchField];

// move search field offscreen, preparing for transition in viewWillAppear
@@ -206,6 +208,7 @@ - (BOOL)prefersStatusBarHidden {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];


self.searchFieldTop.constant = 0;
[self.view setNeedsUpdateConstraints];

@@ -230,7 +233,6 @@ - (void)viewWillDisappear:(BOOL)animated {
Only perform animations & search site sync if search is being modally dismissed (as opposed to having another
view presented on top of it.
*/
[self saveLastSearch];

self.searchFieldTop.constant = -self.searchFieldHeight.constant;

@@ -393,10 +395,11 @@ - (NSURL *)currentlySelectedSearchURL {
}

- (void)didCancelSearch {
self.resultsListController.results = @[];
[self.resultsListController wmf_hideEmptyView];
[self setSearchFieldText:nil];
[self updateSearchSuggestion:nil];
[self updateRecentSearchesVisibility];
[self.resultsListController wmf_hideEmptyView];
}

- (void)searchForSearchTerm:(NSString *)searchTerm {
@@ -408,7 +411,7 @@ - (void)searchForSearchTerm:(NSString *)searchTerm {

[[AFNetworkActivityIndicatorManager sharedManager] incrementActivityCount];
[self.fakeProgressController start];

WMFErrorHandler failure = ^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount];
@@ -448,8 +451,7 @@ - (void)searchForSearchTerm:(NSString *)searchTerm {
[self.fakeProgressController finish];
return;
}



[self.fetcher fetchArticlesForSearchTerm:searchTerm
siteURL:url
resultLimit:WMFMaxSearchResultLimit
@@ -479,7 +481,7 @@ - (void)searchForSearchTerm:(NSString *)searchTerm {
success:success];
return;
}

success(results);
});
}];
@@ -520,6 +522,12 @@ - (NSAttributedString *)getAttributedStringForSuggestion:(NSString *)suggestion
substitutionAttributes:@[@{NSFontAttributeName: [UIFont italicSystemFontOfSize:18]}]];
}

#pragma mark - WMFArticleCollectionViewControllerDelegate

- (void)articleCollectionViewController:(WMFArticleCollectionViewController *)articleCollectionViewController didSelectArticleWithURL:(NSURL *)didSelectArticleWithURL {
[self saveLastSearch];
}

#pragma mark - RecentSearches

- (void)saveLastSearch {
@@ -534,7 +542,7 @@ - (void)saveLastSearch {

- (void)updateRecentSearches {
[self.recentSearchesViewController reloadRecentSearches];
self.recentSearchesHeader.hidden = self.dataStore.recentSearchList.entries.count == 0;
self.recentSearchesHeader.hidden = self.dataStore.recentSearchList.countOfEntries == 0;
}

#pragma mark - WMFRecentSearchesViewControllerDelegate
@@ -545,12 +553,14 @@ - (IBAction)clearRecentSearches:(id)sender {
[dialog addAction:[UIAlertAction actionWithTitle:WMFLocalizedStringWithDefaultValue(@"search-recent-clear-cancel", nil, nil, @"Cancel", @"Button text for cancelling delete all action\n{{Identical|Cancel}}") style:UIAlertActionStyleCancel handler:NULL]];

[dialog addAction:[UIAlertAction actionWithTitle:WMFLocalizedStringWithDefaultValue(@"search-recent-clear-delete-all", nil, nil, @"Delete All", @"Button text for confirming delete all action\n{{Identical|Delete all}}")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *_Nonnull action) {
[self.dataStore.recentSearchList removeAllEntries];
[self.dataStore.recentSearchList save];
[self updateRecentSearches];
}]];
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *_Nonnull action) {
[self didCancelSearch];
[self.dataStore.recentSearchList removeAllEntries];
[self.dataStore.recentSearchList save];
[self updateRecentSearches];
[self updateRecentSearchesVisibility:YES];
}]];

[self presentViewController:dialog animated:YES completion:NULL];
}
@@ -608,7 +618,7 @@ - (void)applyTheme:(WMFTheme *)theme {
self.searchBottomSeparatorView.backgroundColor = theme.colors.midBackground;
self.searchIconView.tintColor = theme.colors.chromeText;
self.view.tintColor = theme.colors.link;

self.recentSearchesHeader.backgroundColor = theme.colors.midBackground;
self.recentSearchesHeaderLabel.textColor = theme.colors.secondaryText;
self.clearRecentSearchesButton.tintColor = theme.colors.secondaryText;