|
@@ -17,11 +17,21 @@
|
|
|
#import "TradePublishManager.h"
|
|
|
#import "UIView+Toast.h"
|
|
|
#import "TradeTopBarItem.h"
|
|
|
+#import "SVProgressHUD.h"
|
|
|
|
|
|
|
|
|
-@interface TradeViewController () <UIScrollViewDelegate, TradeInputDelegate, TradePublishDelegate>
|
|
|
+@interface TradeViewController () <
|
|
|
+UIScrollViewDelegate,
|
|
|
+TradeInputDelegate,
|
|
|
+TradePublishDelegate,
|
|
|
+UISearchBarDelegate,
|
|
|
+UISearchControllerDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) NSMutableArray *dataList;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSString *searchKey;
|
|
|
+@property (nonatomic, strong) NSMutableArray *searchList;
|
|
|
+
|
|
|
@property (nonatomic, assign) BOOL isFetching;
|
|
|
@property (nonatomic, assign) BOOL flagRefresh;
|
|
|
@property (nonatomic, assign) TradeSort tradeSort;
|
|
@@ -42,7 +52,7 @@
|
|
|
@property (nonatomic,strong) TradeTopBarItem *tradeItem2;
|
|
|
@property (nonatomic,strong) NSTimer *timer;
|
|
|
|
|
|
-@property (nonatomic, strong) UISearchController *seachController;
|
|
|
+@property (nonatomic, strong) UISearchController *searchController;
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -75,8 +85,9 @@ float postHeight = 30;
|
|
|
|
|
|
|
|
|
float tabbarHeight = self.tabBarController.tabBar.frame.size.height;
|
|
|
- _tradeContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tradePublishView.width, 272)];
|
|
|
- _tradeContainer.bottom = _tradePublishView.bottom - tabbarHeight;
|
|
|
+ _tradeContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tradePublishView.width, 272+tabbarHeight)];
|
|
|
+ _tradeContainer.bottom = _tradePublishView.bottom;
|
|
|
+ _tradeContainer.tag = 99;
|
|
|
[_tradePublishView addSubview:_tradeContainer];
|
|
|
|
|
|
|
|
@@ -146,6 +157,9 @@ float postHeight = 30;
|
|
|
[_tradeContainer addSubview:_tradeInput];
|
|
|
|
|
|
|
|
|
+ [_tradeInput fillItemData:[User sharedInfo].tradePriorityItemArr];
|
|
|
+
|
|
|
+
|
|
|
[self hideTradeInput:nil];
|
|
|
|
|
|
|
|
@@ -164,12 +178,16 @@ float postHeight = 30;
|
|
|
|
|
|
|
|
|
|
|
|
- _seachController = [[UISearchController alloc] initWithSearchResultsController:nil];
|
|
|
- _seachController.searchBar.barTintColor = User.orangeColor;
|
|
|
- _seachController.hidesNavigationBarDuringPresentation = YES;
|
|
|
- _seachController.searchBar.tintColor = UIColor.whiteColor;
|
|
|
+ _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
|
|
|
+ _searchController.searchBar.barTintColor = User.orangeColor;
|
|
|
+ _searchController.hidesNavigationBarDuringPresentation = YES;
|
|
|
+ _searchController.searchBar.tintColor = UIColor.whiteColor;
|
|
|
+ _searchController.delegate = self;
|
|
|
+ _searchController.dimsBackgroundDuringPresentation = NO;
|
|
|
+
|
|
|
+ _searchController.searchBar.delegate = self;
|
|
|
|
|
|
- [self.view addSubview:_seachController.searchBar];
|
|
|
+ [self.view addSubview:_searchController.searchBar];
|
|
|
|
|
|
}
|
|
|
|
|
@@ -183,7 +201,7 @@ float postHeight = 30;
|
|
|
- (void)viewWillAppear:(BOOL)animated{
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
- [_timer setFireDate:[NSDate distantPast]];
|
|
|
+ //[_timer setFireDate:[NSDate distantPast]];
|
|
|
|
|
|
User *user = [User sharedInfo];
|
|
|
|
|
@@ -270,7 +288,30 @@ float postHeight = 30;
|
|
|
}
|
|
|
|
|
|
|
|
|
+- (void)onTouchSearch:(int)sender{
|
|
|
+ NSLog(@"onTouchSearch");
|
|
|
+ [_searchController setActive:YES];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
|
|
|
+ NSLog(@"searchBarTextDidEndEditing %@", searchBar.text);
|
|
|
+
|
|
|
+ if(searchBar.text.length > 0)
|
|
|
+ {
|
|
|
+ _searchKey = searchBar.text;
|
|
|
+ [SVProgressHUD show];
|
|
|
+ [self reset];
|
|
|
+ [self fetchSearchDataList];
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+- (void)didDismissSearchController:(UISearchController *)searchController{
|
|
|
+ NSLog(@"didDismissSearchController %@", searchController.searchBar.text);
|
|
|
+
|
|
|
+ [self reset];
|
|
|
+ [self fetchDataList];
|
|
|
+}
|
|
|
|
|
|
|
|
|
- (UITableView *)tableView
|
|
@@ -328,18 +369,14 @@ float postHeight = 30;
|
|
|
}
|
|
|
|
|
|
|
|
|
-- (void)onTouchSearch:(int)sender{
|
|
|
- NSLog(@"onTouchSearch");
|
|
|
- [_seachController setActive:YES];
|
|
|
-
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
|
|
|
- (void)reset{
|
|
|
|
|
|
_page = 1;
|
|
|
_dataList = nil;
|
|
|
-
|
|
|
+ _searchList = nil;
|
|
|
}
|
|
|
|
|
|
- (void)fetchDataList{
|
|
@@ -369,6 +406,38 @@ float postHeight = 30;
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+- (void)fetchSearchDataList{
|
|
|
+
|
|
|
+ if(_isFetching)
|
|
|
+ return;
|
|
|
+
|
|
|
+ _isFetching = YES;
|
|
|
+
|
|
|
+ _page = MAX(1, _page);
|
|
|
+
|
|
|
+
|
|
|
+ __weak typeof(self) wself = self;
|
|
|
+ [[HttpRequest shared] tradeSearchList:_searchKey tradeSort:_tradeSort page:_page success:^(NSMutableArray * _Nullable dataList) {
|
|
|
+ if(!wself.searchList)
|
|
|
+ wself.searchList = dataList;
|
|
|
+ else
|
|
|
+ [wself.searchList addObjectsFromArray:dataList];
|
|
|
+
|
|
|
+ [wself.tableView reloadData];
|
|
|
+
|
|
|
+ if(dataList.count > 0)
|
|
|
+ wself.page++;
|
|
|
+
|
|
|
+ wself.isFetching = NO;
|
|
|
+
|
|
|
+ [SVProgressHUD dismiss];
|
|
|
+ } failure:^{
|
|
|
+ wself.isFetching = NO;
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
@@ -376,70 +445,63 @@ float postHeight = 30;
|
|
|
}
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
- if(_dataList)
|
|
|
- return _dataList.count;
|
|
|
+
|
|
|
+ if(_searchController.isActive)
|
|
|
+ {
|
|
|
+ if(_searchList)
|
|
|
+ return _searchList.count;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(_dataList)
|
|
|
+ return _dataList.count;
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
- NSObject *dataObj = [_dataList objectAtIndex:indexPath.row];
|
|
|
+ NSObject *dataObj = nil;
|
|
|
+
|
|
|
+ if(_searchController.isActive)
|
|
|
+ {
|
|
|
+ dataObj = [_searchList objectAtIndex:indexPath.row];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dataObj = [_dataList objectAtIndex:indexPath.row];
|
|
|
+ }
|
|
|
|
|
|
UITableViewCell *baseCell = nil;
|
|
|
|
|
|
-// if([dataObj isKindOfClass:[SocialItemData class]])
|
|
|
-// {
|
|
|
-// NSString *cellId = @"social";
|
|
|
-// SocialDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
|
|
-//
|
|
|
-// if(!cell)
|
|
|
-// {
|
|
|
-// cell = [[SocialDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
|
|
|
-// [cell initWidth:self.view.frame.size.width];
|
|
|
-// }
|
|
|
-//
|
|
|
-// [cell setSocialData:(SocialItemData *)dataObj];
|
|
|
-// _infoHeight = cell.cellHeight;
|
|
|
-//
|
|
|
-// baseCell = cell;
|
|
|
-// }
|
|
|
-// else if([dataObj isKindOfClass:[SocialCommentData class]])
|
|
|
-// {
|
|
|
-// NSString *cellId = @"comment";
|
|
|
-// SocialCommentDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
|
|
-//
|
|
|
-// if(!cell)
|
|
|
-// {
|
|
|
-// cell = [[SocialCommentDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
|
|
|
-// [cell initWidth:self.view.frame.size.width];
|
|
|
-// }
|
|
|
-//
|
|
|
-// [cell setSocialCommentData:(SocialCommentData *)dataObj];
|
|
|
-// baseCell = cell;
|
|
|
-// }
|
|
|
-
|
|
|
- if(true)
|
|
|
- {
|
|
|
- NSString *cellId = @"trade";
|
|
|
- TradeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
|
|
+ NSString *cellId = @"trade";
|
|
|
+ TradeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
|
|
|
|
|
- if(!cell)
|
|
|
- {
|
|
|
- cell = [[TradeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
|
|
|
- [cell initWidth:self.view.frame.size.width];
|
|
|
- }
|
|
|
-
|
|
|
- [cell setData:(TradeData *)dataObj];
|
|
|
- baseCell = cell;
|
|
|
+ if(!cell)
|
|
|
+ {
|
|
|
+ cell = [[TradeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
|
|
|
+ [cell initWidth:self.view.frame.size.width];
|
|
|
}
|
|
|
+
|
|
|
+ [cell setData:(TradeData *)dataObj];
|
|
|
+ baseCell = cell;
|
|
|
|
|
|
return baseCell;
|
|
|
}
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
- NSObject *dataObj = [_dataList objectAtIndex:indexPath.row];
|
|
|
+ NSObject *dataObj = nil;
|
|
|
+
|
|
|
+ if(_searchController.isActive)
|
|
|
+ {
|
|
|
+ dataObj = [_searchList objectAtIndex:indexPath.row];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dataObj = [_dataList objectAtIndex:indexPath.row];
|
|
|
+ }
|
|
|
|
|
|
if([dataObj isKindOfClass:[TradeData class]])
|
|
|
{
|
|
@@ -473,7 +535,15 @@ float postHeight = 30;
|
|
|
{
|
|
|
_flagRefresh = NO;
|
|
|
NSLog(@"下拉刷新");
|
|
|
- [self fetchDataList];
|
|
|
+
|
|
|
+ if(_searchController.isActive)
|
|
|
+ {
|
|
|
+ [self fetchSearchDataList];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [self fetchDataList];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -495,6 +565,7 @@ float postHeight = 30;
|
|
|
}
|
|
|
|
|
|
- (void)hideTradeInput:(id)sender{
|
|
|
+ [_tradeInput.growTextView resignFirstResponder];
|
|
|
[_tradePublishView setHidden:YES];
|
|
|
}
|
|
|
|
|
@@ -516,7 +587,7 @@ float postHeight = 30;
|
|
|
}
|
|
|
|
|
|
|
|
|
-- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority type:(int)type{
|
|
|
+- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority priorityType:(int)priorityType type:(int)type{
|
|
|
|
|
|
if((!msg || msg.length == 0) && picArr.count == 0)
|
|
|
{
|
|
@@ -527,7 +598,7 @@ float postHeight = 30;
|
|
|
|
|
|
TradePublishManager *tradePublishManager = [[TradePublishManager alloc] init];
|
|
|
tradePublishManager.delegate = self;
|
|
|
- [tradePublishManager tradePublish:msg picArr:picArr priority:priority tradeType:type];
|
|
|
+ [tradePublishManager tradePublish:msg picArr:picArr priority:priority priorityType:priorityType tradeType:type];
|
|
|
|
|
|
[self hideTradeInput:nil];
|
|
|
}
|