Skip to content

Commit 8876dae

Browse files
committed
Merge branch 'trending'
Former-commit-id: ff0c693
2 parents 2ee4bf6 + c9c6e07 commit 8876dae

24 files changed

+574
-52
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
73b8fbbc0cd9853d77e7e51d8bf0b3e7554fa21a
1+
05d5f2f4536dd17e00ab3cee6cf047777b39c9a4

MVVMReactiveCocoa/MVVMReactiveCocoa-Info.plist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@
183183
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
184184
<false/>
185185
</dict>
186+
<key>trending.codehub-app.com</key>
187+
<dict>
188+
<key>NSIncludesSubdomains</key>
189+
<true/>
190+
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
191+
<true/>
192+
</dict>
186193
</dict>
187194
</dict>
188195
<key>UIAppFonts</key>

MVVMReactiveCocoa/Model/MRCRepositoryService.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212

1313
- (RACSignal *)requestRepositoryReadmeHTML:(OCTRepository *)repository reference:(NSString *)reference;
1414

15+
- (RACSignal *)requestTrendingRepositoriesSince:(NSString *)since language:(NSString *)language;
16+
1517
@end

MVVMReactiveCocoa/Model/MRCRepositoryServiceImpl.m

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,59 @@ - (RACSignal *)requestRepositoryReadmeHTML:(OCTRepository *)repository reference
4646
setNameWithFormat:@"-requestRepositoryReadmeHTML: %@ reference: %@", repository, reference];
4747
}
4848

49+
- (RACSignal *)requestTrendingRepositoriesSince:(NSString *)since language:(NSString *)language {
50+
since = since.lowercaseString;
51+
language = language.lowercaseString;
52+
53+
if ([since isEqualToString:@"today"]) {
54+
since = @"daily";
55+
} else if ([since isEqualToString:@"this week"]) {
56+
since = @"weekly";
57+
} else if ([since isEqualToString:@"this month"]) {
58+
since = @"monthly";
59+
}
60+
61+
if ([language isEqualToString:@"all languages"]) {
62+
language = nil;
63+
}
64+
65+
return [[[RACSignal
66+
createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
67+
MKNetworkEngine *networkEngine = [[MKNetworkEngine alloc] initWithHostName:@"trending.codehub-app.com" apiPath:@"v2" customHeaderFields:nil];
68+
69+
MKNetworkOperation *operation = [networkEngine operationWithPath:@"trending"
70+
params:@{ @"since": since ?: @"",
71+
@"language": language ?: @"" }];
72+
73+
[operation addCompletionHandler:^(MKNetworkOperation *completedOperation) {
74+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
75+
NSArray *JSONArray = completedOperation.responseJSON;
76+
if (JSONArray.count > 0) {
77+
NSError *error = nil;
78+
NSArray *repositories = [MTLJSONAdapter modelsOfClass:[OCTRepository class] fromJSONArray:JSONArray error:&error];
79+
80+
if (error) {
81+
NSLog(@"Error: %@", error);
82+
} else {
83+
[subscriber sendNext:repositories];
84+
}
85+
}
86+
[subscriber sendCompleted];
87+
});
88+
} errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
89+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
90+
[subscriber sendError:error];
91+
});
92+
}];
93+
94+
[networkEngine enqueueOperation:operation];
95+
96+
return [RACDisposable disposableWithBlock:^{
97+
[operation cancel];
98+
}];
99+
}]
100+
replayLazily]
101+
setNameWithFormat:@"-requestTrendingRepositoriesSince: %@ language: %@", since, language];
102+
}
103+
49104
@end

MVVMReactiveCocoa/Util/MRCRouter.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ - (NSDictionary *)viewModelViewMappings {
5656
@"MRCStarredReposViewModel": @"MRCStarredReposViewController",
5757
@"MRCPublicReposViewModel": @"MRCPublicReposViewController",
5858
@"MRCNewsViewModel": @"MRCNewsViewController",
59+
@"MRCSearchViewModel": @"MRCSearchViewController",
60+
@"MRCTrendingViewModel": @"MRCTrendingViewController",
61+
@"MRCTrendingSettingsViewModel": @"MRCTrendingSettingsViewController",
5962
};
6063
}
6164

MVVMReactiveCocoa/View/BaseClass/MRCNavigationControllerStack.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ @implementation MRCNavigationControllerStack
2121

2222
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
2323
MRCNavigationControllerStack *navigationControllerStack = [super allocWithZone:zone];
24-
24+
2525
@weakify(navigationControllerStack)
2626
[[navigationControllerStack
2727
rac_signalForSelector:@selector(initWithServices:)]
2828
subscribeNext:^(id x) {
2929
@strongify(navigationControllerStack)
3030
[navigationControllerStack registerNavigationHooks];
3131
}];
32-
32+
3333
return navigationControllerStack;
3434
}
3535

@@ -67,44 +67,44 @@ - (void)registerNavigationHooks {
6767
viewController.hidesBottomBarWhenPushed = YES;
6868
[self.navigationControllers.lastObject pushViewController:viewController animated:[tuple.second boolValue]];
6969
}];
70-
70+
7171
[[(NSObject *)self.services
7272
rac_signalForSelector:@selector(popViewModelAnimated:)]
7373
subscribeNext:^(RACTuple *tuple) {
7474
@strongify(self)
7575
[self.navigationControllers.lastObject popViewControllerAnimated:[tuple.first boolValue]];
7676
}];
77-
77+
7878
[[(NSObject *)self.services
7979
rac_signalForSelector:@selector(popToRootViewModelAnimated:)]
8080
subscribeNext:^(RACTuple *tuple) {
8181
@strongify(self)
8282
[self.navigationControllers.lastObject popToRootViewControllerAnimated:[tuple.first boolValue]];
8383
}];
84-
84+
8585
[[(NSObject *)self.services
8686
rac_signalForSelector:@selector(presentViewModel:animated:completion:)]
8787
subscribeNext:^(RACTuple *tuple) {
8888
@strongify(self)
8989
UIViewController *viewController = (UIViewController *)[MRCRouter.sharedInstance viewControllerForViewModel:tuple.first];
90-
90+
9191
UINavigationController *presentingViewController = self.navigationControllers.lastObject;
9292
if (![viewController isKindOfClass:UINavigationController.class]) {
9393
viewController = [[MRCNavigationController alloc] initWithRootViewController:viewController];
9494
}
9595
[self pushNavigationController:(UINavigationController *)viewController];
96-
96+
9797
[presentingViewController presentViewController:viewController animated:[tuple.second boolValue] completion:tuple.third];
9898
}];
99-
99+
100100
[[(NSObject *)self.services
101101
rac_signalForSelector:@selector(dismissViewModelAnimated:completion:)]
102102
subscribeNext:^(RACTuple *tuple) {
103103
@strongify(self)
104104
[self popNavigationController];
105105
[self.navigationControllers.lastObject dismissViewControllerAnimated:[tuple.first boolValue] completion:tuple.second];
106106
}];
107-
107+
108108
[[(NSObject *)self.services
109109
rac_signalForSelector:@selector(resetRootViewModel:)]
110110
subscribeNext:^(RACTuple *tuple) {
@@ -117,7 +117,7 @@ - (void)registerNavigationHooks {
117117
viewController = [[MRCNavigationController alloc] initWithRootViewController:viewController];
118118
[self pushNavigationController:(UINavigationController *)viewController];
119119
}
120-
120+
121121
MRCSharedAppDelegate.window.rootViewController = viewController;
122122
}];
123123
}

MVVMReactiveCocoa/View/BaseClass/MRCViewController.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ - (void)bindViewModel {
5858
// Double title view
5959
MRCDoubleTitleView *doubleTitleView = [[MRCDoubleTitleView alloc] init];
6060

61+
RAC(doubleTitleView.titleLabel, text) = RACObserve(self.viewModel, title);
62+
RAC(doubleTitleView.subtitleLabel, text) = RACObserve(self.viewModel, subtitle);
63+
6164
@weakify(self)
62-
[[[self
65+
[[self
6366
rac_signalForSelector:@selector(viewWillTransitionToSize:withTransitionCoordinator:)]
64-
startWith:nil]
6567
subscribeNext:^(id x) {
6668
@strongify(self)
6769
doubleTitleView.titleLabel.text = self.viewModel.title;

MVVMReactiveCocoa/View/MRCHomepageViewController.m

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "MRCNavigationController.h"
1818
#import "MRCSearchViewController.h"
1919
#import "MRCUserListViewModel.h"
20+
#import "MRCSearchViewController.h"
2021

2122
@interface MRCHomepageViewController () <UITabBarControllerDelegate>
2223

@@ -35,44 +36,44 @@ - (void)viewDidLoad {
3536

3637
UINavigationController *newsNavigationController = ({
3738
MRCNewsViewController *newsViewController = [[MRCNewsViewController alloc] initWithViewModel:self.viewModel.newsViewModel];
38-
39+
3940
UIImage *newsImage = [UIImage octicon_imageWithIdentifier:@"Rss" size:CGSizeMake(25, 25)];
4041
newsViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"News" image:newsImage tag:1];
41-
42+
4243
[[MRCNavigationController alloc] initWithRootViewController:newsViewController];
4344
});
44-
45+
4546
UINavigationController *reposNavigationController = ({
4647
MRCReposViewController *reposViewController = [[MRCReposViewController alloc] initWithViewModel:self.viewModel.reposViewModel];
47-
48+
4849
UIImage *reposImage = [UIImage octicon_imageWithIdentifier:@"Repo" size:CGSizeMake(25, 25)];
4950
reposViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Repositories" image:reposImage tag:2];
50-
51+
5152
[[MRCNavigationController alloc] initWithRootViewController:reposViewController];
5253
});
53-
54+
5455
UINavigationController *searchNavigationController = ({
5556
MRCSearchViewController *searchViewController = [[MRCSearchViewController alloc] initWithViewModel:self.viewModel.searchViewModel];
5657

5758
UIImage *searchImage = [UIImage octicon_imageWithIdentifier:@"Search" size:CGSizeMake(25, 25)];
58-
searchViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Search" image:searchImage tag:3];
59-
59+
searchViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Discover" image:searchImage tag:3];
60+
6061
[[MRCNavigationController alloc] initWithRootViewController:searchViewController];
6162
});
62-
63+
6364
UINavigationController *profileNavigationController = ({
6465
MRCProfileViewController *profileViewController = [[MRCProfileViewController alloc] initWithViewModel:self.viewModel.profileViewModel];
65-
66+
6667
UIImage *profileImage = [UIImage octicon_imageWithIdentifier:@"Person" size:CGSizeMake(25, 25)];
6768
profileViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Profile" image:profileImage tag:4];
68-
69+
6970
[[MRCNavigationController alloc] initWithRootViewController:profileViewController];
7071
});
7172

7273
self.viewControllers = @[ newsNavigationController, reposNavigationController, searchNavigationController, profileNavigationController ];
7374

7475
[MRCSharedAppDelegate.navigationControllerStack pushNavigationController:newsNavigationController];
75-
76+
7677
[[self
7778
rac_signalForSelector:@selector(tabBarController:didSelectViewController:)
7879
fromProtocol:@protocol(UITabBarControllerDelegate)]

MVVMReactiveCocoa/View/MRCNewsViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "MRCNewsTableViewCell.h"
1212
#import "MRCNewsItemViewModel.h"
1313
#import "MRCNetworkHeaderView.h"
14+
#import "MRCSearchViewModel.h"
1415

1516
@interface MRCNewsViewController ()
1617

MVVMReactiveCocoa/View/MRCNewsViewController.xib

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14C1510" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
56
</dependencies>
67
<objects>
78
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MRCNewsViewController">
@@ -17,6 +18,7 @@
1718
<subviews>
1819
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="124" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="gHx-br-G5o">
1920
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
21+
<animations/>
2022
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
2123
<connections>
2224
<outlet property="dataSource" destination="-1" id="m8z-uo-4Tl"/>
@@ -26,6 +28,7 @@
2628
</connections>
2729
</tableView>
2830
</subviews>
31+
<animations/>
2932
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
3033
<constraints>
3134
<constraint firstAttribute="trailing" secondItem="gHx-br-G5o" secondAttribute="trailing" id="9tc-Ye-sxi"/>

MVVMReactiveCocoa/View/MRCSearchViewController.m

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "MRCSearchViewController.h"
1010
#import "MRCSearchViewModel.h"
1111
#import "MRCReposSearchResultsViewController.h"
12+
#import "MRCTrendingViewModel.h"
1213

1314
@interface MRCSearchViewController () <UISearchControllerDelegate, UISearchBarDelegate>
1415

@@ -47,7 +48,17 @@ - (UIEdgeInsets)contentInset {
4748
}
4849

4950
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(MRCSearch *)search {
50-
cell.textLabel.text = search.keyword;
51+
if (indexPath.section == 0) {
52+
cell.imageView.image = [UIImage octicon_imageWithIcon:@"Flame"
53+
backgroundColor:[UIColor clearColor]
54+
iconColor:HexRGB(0x24AFFC)
55+
iconScale:1
56+
andSize:MRC_LEFT_IMAGE_SIZE];
57+
cell.textLabel.text = @"Trending";
58+
} else {
59+
cell.textLabel.text = search.keyword;
60+
}
61+
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
5162
}
5263

5364
#pragma mark - UITableViewDataSource
@@ -68,14 +79,14 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
6879
view.backgroundColor = HexRGB(0xF7F7F7);
6980

7081
UILabel *label = [[UILabel alloc] init];
71-
label.text = @"Recent Searches";
82+
label.text = section == 0 ? @"Explore" : @"Recent Searches";
7283
label.font = [UIFont systemFontOfSize:15];
7384
[label sizeToFit];
7485

7586
CGFloat height = [self tableView:tableView heightForHeaderInSection:section];
7687

7788
CGRect frame = label.frame;
78-
frame.origin.x = 20;
89+
frame.origin.x = 15;
7990
frame.origin.y = (height - frame.size.height) / 2;
8091
label.frame = frame;
8192

@@ -89,23 +100,28 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
89100
}
90101

91102
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
92-
return UITableViewCellEditingStyleDelete;
103+
return indexPath.section == 0 ? UITableViewCellEditingStyleNone : UITableViewCellEditingStyleDelete;
93104
}
94105

95106
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
96107
[tableView deselectRowAtIndexPath:indexPath animated:YES];
97108

98-
[self presentViewController:self.searchController animated:YES completion:NULL];
99-
100-
MRCSearch *search = self.viewModel.dataSource[indexPath.section][indexPath.row];
101-
self.searchController.searchBar.text = search.keyword;
102-
103-
if ([self.searchController.searchBar.delegate respondsToSelector:@selector(searchBar:textDidChange:)]) {
104-
[self.searchController.searchBar.delegate searchBar:self.searchController.searchBar textDidChange:search.keyword];
105-
}
106-
107-
if ([self.searchController.searchBar.delegate respondsToSelector:@selector(searchBarSearchButtonClicked:)]) {
108-
[self.searchController.searchBar.delegate searchBarSearchButtonClicked:self.searchController.searchBar];
109+
if (indexPath.section == 0) {
110+
MRCTrendingViewModel *trendingViewModel = [[MRCTrendingViewModel alloc] initWithServices:self.viewModel.services params:nil];
111+
[self.viewModel.services pushViewModel:trendingViewModel animated:YES];
112+
} else {
113+
[self presentViewController:self.searchController animated:YES completion:NULL];
114+
115+
MRCSearch *search = self.viewModel.dataSource[indexPath.section][indexPath.row];
116+
self.searchController.searchBar.text = search.keyword;
117+
118+
if ([self.searchController.searchBar.delegate respondsToSelector:@selector(searchBar:textDidChange:)]) {
119+
[self.searchController.searchBar.delegate searchBar:self.searchController.searchBar textDidChange:search.keyword];
120+
}
121+
122+
if ([self.searchController.searchBar.delegate respondsToSelector:@selector(searchBarSearchButtonClicked:)]) {
123+
[self.searchController.searchBar.delegate searchBarSearchButtonClicked:self.searchController.searchBar];
124+
}
109125
}
110126
}
111127

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// MRCTrendingSettingsViewController.h
3+
// MVVMReactiveCocoa
4+
//
5+
// Created by leichunfeng on 15/10/21.
6+
// Copyright © 2015年 leichunfeng. All rights reserved.
7+
//
8+
9+
#import "MRCTableViewController.h"
10+
11+
@interface MRCTrendingSettingsViewController : MRCTableViewController
12+
13+
@end

0 commit comments

Comments
 (0)