Commit ba0c3a1688757c7a8d5e4843e6d2a83aa852b546
1 parent
a5062ade
直播与首页增加缓存效果
Showing
5 changed files
with
261 additions
and
170 deletions
CNLiveScioLive/Pages/Home/CNHomeViewController.m
| @@ -27,86 +27,52 @@ | @@ -27,86 +27,52 @@ | ||
| 27 | 27 | ||
| 28 | NSDictionary *parameters = @{@"params":@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"pageUUID\":\"852cde69-ecd8-11e6-b52e-c7d8a7a18cc4\",\"pageType\":\"channelList\"}"}; | 28 | NSDictionary *parameters = @{@"params":@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"pageUUID\":\"852cde69-ecd8-11e6-b52e-c7d8a7a18cc4\",\"pageType\":\"channelList\"}"}; |
| 29 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { | 29 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { |
| 30 | - [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; | ||
| 31 | - if (!_reFreshBtn &&self.data.count == 0) { | ||
| 32 | - [self.view addSubview:self.reFreshBtn]; | 30 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"homeList"]; |
| 31 | + if (data) { | ||
| 32 | + [self dealDictionaryData:data]; | ||
| 33 | } | 33 | } |
| 34 | + [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; | ||
| 35 | +// if (!_reFreshBtn &&self.data.count == 0) { | ||
| 36 | +// [self.view addSubview:self.reFreshBtn]; | ||
| 37 | +// } | ||
| 34 | return; | 38 | return; |
| 35 | } | 39 | } |
| 36 | [AlertViewTool showHUDView]; | 40 | [AlertViewTool showHUDView]; |
| 37 | 41 | ||
| 38 | [XWHTTPTool POST:strUrl params:parameters success:^(id json) { | 42 | [XWHTTPTool POST:strUrl params:parameters success:^(id json) { |
| 39 | 43 | ||
| 40 | - if (self->_reFreshBtn) { | ||
| 41 | - [self->_reFreshBtn removeFromSuperview]; | ||
| 42 | - } | 44 | +// if (self->_reFreshBtn) { |
| 45 | +// [self->_reFreshBtn removeFromSuperview]; | ||
| 46 | +// } | ||
| 43 | [AlertViewTool hideHUDView]; | 47 | [AlertViewTool hideHUDView]; |
| 44 | 48 | ||
| 45 | // 请求成功,解析数据 | 49 | // 请求成功,解析数据 |
| 46 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; | 50 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; |
| 47 | 51 | ||
| 48 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { | 52 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { |
| 49 | - | ||
| 50 | - NSDictionary *ininav = dic[@"ininav"]; | ||
| 51 | - NSArray *ininavArray = ininav[@"programs"]; | ||
| 52 | - | ||
| 53 | - if ([ininavArray isKindOfClass:[NSArray class]]) { | ||
| 54 | - for (NSDictionary *dics in ininavArray) { | ||
| 55 | - [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 56 | - return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 57 | - }]; | ||
| 58 | - | ||
| 59 | - NSLog(@"%@",dics); | ||
| 60 | - [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 61 | - | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - NSMutableArray *controllers = [NSMutableArray array]; | ||
| 67 | - NSMutableArray *titles = [NSMutableArray array]; | ||
| 68 | - NSMutableArray *colors = [NSMutableArray array]; | ||
| 69 | - for(int i = 0; i < self.data.count; i++){ | ||
| 70 | - CNHomeModel *model = self.data[i]; | ||
| 71 | - [titles addObject:model.title]; | ||
| 72 | - if (!model.textColor) { | ||
| 73 | - model.textColor = @""; | ||
| 74 | - } | ||
| 75 | - [colors addObject:model.textColor]; | ||
| 76 | - if ([model.cid isEqualToString:@"spzl/djzw/"]) { | ||
| 77 | - //答记者问 | ||
| 78 | - CNLiveReporterAskedViewController *vc = [[CNLiveReporterAskedViewController alloc] init]; | ||
| 79 | - vc.cid = model.cid; | ||
| 80 | - [controllers addObject:vc]; | ||
| 81 | - | ||
| 82 | - }else{ | ||
| 83 | - //其他 | ||
| 84 | - CNLiveHeraldedNewsViewController *vc = [[CNLiveHeraldedNewsViewController alloc] init]; | ||
| 85 | - vc.cid = model.cid; | ||
| 86 | - [controllers addObject:vc]; | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - } | ||
| 90 | - if(controllers.count > 0){ | ||
| 91 | - NSMutableArray *textArray = [NSMutableArray array]; | ||
| 92 | - [textArray addObject:titles]; | ||
| 93 | - [textArray addObject:colors]; | ||
| 94 | - self.segmentControl.titles = textArray; | ||
| 95 | - self.segmentControl.viewControllers = controllers; | ||
| 96 | - } | ||
| 97 | - NSDictionary *dic = @{@"titles":titles}; | ||
| 98 | - [[NSNotificationCenter defaultCenter] postNotificationName:@"CNHomeRightViewController" object:nil userInfo:dic]; | 53 | + NSData *data = [dic mj_JSONData]; |
| 54 | + [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"homeList"]; | ||
| 55 | + [self dealDictionaryData:data]; | ||
| 99 | 56 | ||
| 100 | } else { | 57 | } else { |
| 58 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"homeList"]; | ||
| 59 | + if (data) { | ||
| 60 | + [self dealDictionaryData:data]; | ||
| 61 | + } | ||
| 101 | [AlertViewTool hideHUDView]; | 62 | [AlertViewTool hideHUDView]; |
| 102 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; | 63 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; |
| 103 | - if (!self->_reFreshBtn &&self.data.count == 0) { | ||
| 104 | - [self.view addSubview:self.reFreshBtn]; | ||
| 105 | - } | 64 | +// if (!self->_reFreshBtn &&self.data.count == 0) { |
| 65 | +// [self.view addSubview:self.reFreshBtn]; | ||
| 66 | +// } | ||
| 106 | } | 67 | } |
| 107 | 68 | ||
| 108 | 69 | ||
| 109 | } failure:^(NSError *error) { | 70 | } failure:^(NSError *error) { |
| 71 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"homeList"]; | ||
| 72 | + if (data) { | ||
| 73 | + [self dealDictionaryData:data]; | ||
| 74 | + } | ||
| 75 | + | ||
| 110 | [AlertViewTool hideHUDView]; | 76 | [AlertViewTool hideHUDView]; |
| 111 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; | 77 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; |
| 112 | if (!self->_reFreshBtn &&self.data.count == 0) { | 78 | if (!self->_reFreshBtn &&self.data.count == 0) { |
| @@ -114,6 +80,59 @@ | @@ -114,6 +80,59 @@ | ||
| 114 | } | 80 | } |
| 115 | }]; | 81 | }]; |
| 116 | } | 82 | } |
| 83 | +-(void)dealDictionaryData:(NSData *)data | ||
| 84 | +{ | ||
| 85 | + NSDictionary *dic = [data mj_JSONObject]; | ||
| 86 | + NSDictionary *ininav = dic[@"ininav"]; | ||
| 87 | + NSArray *ininavArray = ininav[@"programs"]; | ||
| 88 | + | ||
| 89 | + if ([ininavArray isKindOfClass:[NSArray class]]) { | ||
| 90 | + for (NSDictionary *dics in ininavArray) { | ||
| 91 | + [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 92 | + return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 93 | + }]; | ||
| 94 | + | ||
| 95 | + NSLog(@"%@",dics); | ||
| 96 | + [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 97 | + | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + NSMutableArray *controllers = [NSMutableArray array]; | ||
| 103 | + NSMutableArray *titles = [NSMutableArray array]; | ||
| 104 | + NSMutableArray *colors = [NSMutableArray array]; | ||
| 105 | + for(int i = 0; i < self.data.count; i++){ | ||
| 106 | + CNHomeModel *model = self.data[i]; | ||
| 107 | + [titles addObject:model.title]; | ||
| 108 | + if (!model.textColor) { | ||
| 109 | + model.textColor = @""; | ||
| 110 | + } | ||
| 111 | + [colors addObject:model.textColor]; | ||
| 112 | + if ([model.cid isEqualToString:@"spzl/djzw/"]) { | ||
| 113 | + //答记者问 | ||
| 114 | + CNLiveReporterAskedViewController *vc = [[CNLiveReporterAskedViewController alloc] init]; | ||
| 115 | + vc.cid = model.cid; | ||
| 116 | + [controllers addObject:vc]; | ||
| 117 | + | ||
| 118 | + }else{ | ||
| 119 | + //其他 | ||
| 120 | + CNLiveHeraldedNewsViewController *vc = [[CNLiveHeraldedNewsViewController alloc] init]; | ||
| 121 | + vc.cid = model.cid; | ||
| 122 | + [controllers addObject:vc]; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + } | ||
| 126 | + if(controllers.count > 0){ | ||
| 127 | + NSMutableArray *textArray = [NSMutableArray array]; | ||
| 128 | + [textArray addObject:titles]; | ||
| 129 | + [textArray addObject:colors]; | ||
| 130 | + self.segmentControl.titles = textArray; | ||
| 131 | + self.segmentControl.viewControllers = controllers; | ||
| 132 | + } | ||
| 133 | + NSDictionary *dic1 = @{@"titles":titles}; | ||
| 134 | + [[NSNotificationCenter defaultCenter] postNotificationName:@"CNHomeRightViewController" object:nil userInfo:dic1]; | ||
| 135 | +} | ||
| 117 | - (void)viewWillAppear:(BOOL)animated { | 136 | - (void)viewWillAppear:(BOOL)animated { |
| 118 | [super viewWillAppear:animated]; | 137 | [super viewWillAppear:animated]; |
| 119 | [self.navigationController setNavigationBarHidden:NO]; | 138 | [self.navigationController setNavigationBarHidden:NO]; |
CNLiveScioLive/Pages/Home/外宣要闻/Controller/CNLiveHeraldedNewsViewController.m
| @@ -41,6 +41,10 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -41,6 +41,10 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 41 | NSDictionary *parameters = @{@"params":categoryId}; | 41 | NSDictionary *parameters = @{@"params":categoryId}; |
| 42 | 42 | ||
| 43 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { | 43 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { |
| 44 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:self.cid]; | ||
| 45 | + if (data && self.pageNo == 1) { | ||
| 46 | + [self dealDictionaryData:data]; | ||
| 47 | + } | ||
| 44 | [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; | 48 | [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; |
| 45 | [self.tableView.mj_header endRefreshing]; | 49 | [self.tableView.mj_header endRefreshing]; |
| 46 | [self.tableView.mj_footer endRefreshing]; | 50 | [self.tableView.mj_footer endRefreshing]; |
| @@ -57,60 +61,18 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -57,60 +61,18 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 57 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; | 61 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; |
| 58 | 62 | ||
| 59 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { | 63 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { |
| 60 | - if ([dic[@"programs"] isKindOfClass:[NSArray class]]) { | ||
| 61 | - NSArray *lists = dic[@"programs"]; | ||
| 62 | - if(self->_pageNo == 1&&lists.count > 0){ | ||
| 63 | - [self.data removeAllObjects]; | ||
| 64 | - | ||
| 65 | - } | ||
| 66 | - self->_pageNo++; | ||
| 67 | - | ||
| 68 | - for (NSDictionary *dics in lists) { | ||
| 69 | - [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 70 | - return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 71 | - }]; | ||
| 72 | - NSLog(@"%@",dics); | ||
| 73 | - [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 74 | - | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - } | ||
| 78 | - NSDictionary *ttName = dic[@"ttName"]; | ||
| 79 | - NSArray *programs = ttName[@"programs"]; | ||
| 80 | - | ||
| 81 | - if ([programs isKindOfClass:[NSArray class]]) { | ||
| 82 | - [self.banner removeAllObjects]; | ||
| 83 | - for (NSDictionary *dics in programs) { | ||
| 84 | - [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 85 | - return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 86 | - }]; | ||
| 87 | - | ||
| 88 | - NSLog(@"%@",dics); | ||
| 89 | - [self.banner addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 90 | - } | 64 | + NSData *data = [dic mj_JSONData]; |
| 65 | + if (self -> _pageNo == 1) { | ||
| 91 | 66 | ||
| 92 | - NSMutableArray *titles = [NSMutableArray array]; | ||
| 93 | - NSMutableArray *imagesURLStrings = [NSMutableArray array]; | ||
| 94 | - for(int i = 0; i < self.banner.count; i++){ | ||
| 95 | - CNHomeModel *model = self.banner[i]; | ||
| 96 | - [titles addObject:model.title]; | ||
| 97 | - [imagesURLStrings addObject:model.img]; | ||
| 98 | - | ||
| 99 | - } | ||
| 100 | - if (titles.count!=0) { | ||
| 101 | - self.tableView.tableHeaderView = self.cycleScrollView; | ||
| 102 | - self.cycleScrollView.titlesGroup = titles; | ||
| 103 | - self.cycleScrollView.imageURLStringsGroup = imagesURLStrings; | ||
| 104 | - } | ||
| 105 | - }else | ||
| 106 | - { | ||
| 107 | - if (self.pageNo == 2) { | ||
| 108 | - self.tableView.tableHeaderView = nil; | ||
| 109 | - } | 67 | + [[NSUserDefaults standardUserDefaults] setObject:data forKey:self.cid]; |
| 110 | } | 68 | } |
| 69 | + [self dealDictionaryData:data]; | ||
| 111 | } else { | 70 | } else { |
| 112 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; | 71 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; |
| 113 | - | 72 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:self.cid]; |
| 73 | + if (data &&self.pageNo == 1) { | ||
| 74 | + [self dealDictionaryData:data]; | ||
| 75 | + } | ||
| 114 | } | 76 | } |
| 115 | [self.tableView.mj_header endRefreshing]; | 77 | [self.tableView.mj_header endRefreshing]; |
| 116 | 78 | ||
| @@ -121,11 +83,15 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -121,11 +83,15 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 121 | [self.tableView.mj_footer endRefreshing]; | 83 | [self.tableView.mj_footer endRefreshing]; |
| 122 | 84 | ||
| 123 | } | 85 | } |
| 124 | - [self.tableView reloadData]; | 86 | + |
| 125 | self->_isRefreshing = NO; | 87 | self->_isRefreshing = NO; |
| 126 | 88 | ||
| 127 | 89 | ||
| 128 | } failure:^(NSError *error) { | 90 | } failure:^(NSError *error) { |
| 91 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:self.cid]; | ||
| 92 | + if (data &&self.pageNo == 1) { | ||
| 93 | + [self dealDictionaryData:data]; | ||
| 94 | + } | ||
| 129 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; | 95 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; |
| 130 | self->_isRefreshing = NO; | 96 | self->_isRefreshing = NO; |
| 131 | [AlertViewTool hideHUDView]; | 97 | [AlertViewTool hideHUDView]; |
| @@ -133,6 +99,65 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -133,6 +99,65 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 133 | }]; | 99 | }]; |
| 134 | } | 100 | } |
| 135 | 101 | ||
| 102 | +-(void)dealDictionaryData:(NSData *)data | ||
| 103 | +{ | ||
| 104 | + NSDictionary *dic = [data mj_JSONObject]; | ||
| 105 | + if ([dic[@"programs"] isKindOfClass:[NSArray class]]) { | ||
| 106 | + NSArray *lists = dic[@"programs"]; | ||
| 107 | + if(self->_pageNo == 1&&lists.count > 0){ | ||
| 108 | + [self.data removeAllObjects]; | ||
| 109 | + | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + | ||
| 113 | + self->_pageNo++; | ||
| 114 | + | ||
| 115 | + for (NSDictionary *dics in lists) { | ||
| 116 | + [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 117 | + return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 118 | + }]; | ||
| 119 | + NSLog(@"%@",dics); | ||
| 120 | + [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 121 | + | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + } | ||
| 125 | + NSDictionary *ttName = dic[@"ttName"]; | ||
| 126 | + NSArray *programs = ttName[@"programs"]; | ||
| 127 | + | ||
| 128 | + if ([programs isKindOfClass:[NSArray class]]) { | ||
| 129 | + [self.banner removeAllObjects]; | ||
| 130 | + for (NSDictionary *dics in programs) { | ||
| 131 | + [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 132 | + return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 133 | + }]; | ||
| 134 | + | ||
| 135 | + NSLog(@"%@",dics); | ||
| 136 | + [self.banner addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + NSMutableArray *titles = [NSMutableArray array]; | ||
| 140 | + NSMutableArray *imagesURLStrings = [NSMutableArray array]; | ||
| 141 | + for(int i = 0; i < self.banner.count; i++){ | ||
| 142 | + CNHomeModel *model = self.banner[i]; | ||
| 143 | + [titles addObject:model.title]; | ||
| 144 | + [imagesURLStrings addObject:model.img]; | ||
| 145 | + | ||
| 146 | + } | ||
| 147 | + if (titles.count!=0) { | ||
| 148 | + self.tableView.tableHeaderView = self.cycleScrollView; | ||
| 149 | + self.cycleScrollView.titlesGroup = titles; | ||
| 150 | + self.cycleScrollView.imageURLStringsGroup = imagesURLStrings; | ||
| 151 | + } | ||
| 152 | + }else | ||
| 153 | + { | ||
| 154 | + if (self.pageNo == 2) { | ||
| 155 | + self.tableView.tableHeaderView = nil; | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + [self.tableView reloadData]; | ||
| 159 | +} | ||
| 160 | + | ||
| 136 | - (void)loadUpData{ | 161 | - (void)loadUpData{ |
| 137 | _pageNo = 1; | 162 | _pageNo = 1; |
| 138 | if(!_isRefreshing){ | 163 | if(!_isRefreshing){ |
CNLiveScioLive/Pages/Home/答记者问/Controller/CNLiveReporterAskedViewController.m
| @@ -36,6 +36,10 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -36,6 +36,10 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 36 | NSDictionary *parameters = @{@"params":categoryId}; | 36 | NSDictionary *parameters = @{@"params":categoryId}; |
| 37 | 37 | ||
| 38 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { | 38 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { |
| 39 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:self.cid]; | ||
| 40 | + if (data &&self.pageNo == 1) { | ||
| 41 | + [self dealDictionaryData:data]; | ||
| 42 | + } | ||
| 39 | [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; | 43 | [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; |
| 40 | [self.tableView.mj_header endRefreshing]; | 44 | [self.tableView.mj_header endRefreshing]; |
| 41 | [self.tableView.mj_footer endRefreshing]; | 45 | [self.tableView.mj_footer endRefreshing]; |
| @@ -52,29 +56,15 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -52,29 +56,15 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 52 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; | 56 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; |
| 53 | 57 | ||
| 54 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { | 58 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { |
| 55 | - if ([dic[@"programs"] isKindOfClass:[NSArray class]]) { | ||
| 56 | - NSArray *lists = dic[@"programs"]; | ||
| 57 | - | ||
| 58 | - if(self->_pageNo == 1&&lists.count > 0){ | ||
| 59 | - [self.data removeAllObjects]; | ||
| 60 | - | ||
| 61 | - } | ||
| 62 | - self->_pageNo++; | ||
| 63 | - | ||
| 64 | - for (NSDictionary *dics in lists) { | ||
| 65 | - [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 66 | - return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 67 | - }]; | ||
| 68 | - | ||
| 69 | - NSLog(@"%@",dics); | ||
| 70 | - [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 71 | - | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - } | 59 | + NSData *data = [dic mj_JSONData]; |
| 60 | + [[NSUserDefaults standardUserDefaults] setObject:data forKey:self.cid]; | ||
| 61 | + [self dealDictionaryData:data]; | ||
| 75 | 62 | ||
| 76 | } else { | 63 | } else { |
| 77 | - | 64 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:self.cid]; |
| 65 | + if (data &&self.pageNo == 1) { | ||
| 66 | + [self dealDictionaryData:data]; | ||
| 67 | + } | ||
| 78 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; | 68 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; |
| 79 | 69 | ||
| 80 | } | 70 | } |
| @@ -87,11 +77,15 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -87,11 +77,15 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 87 | [self.tableView.mj_footer endRefreshing]; | 77 | [self.tableView.mj_footer endRefreshing]; |
| 88 | 78 | ||
| 89 | } | 79 | } |
| 90 | - [self.tableView reloadData]; | 80 | + |
| 91 | self->_isRefreshing = NO; | 81 | self->_isRefreshing = NO; |
| 92 | 82 | ||
| 93 | 83 | ||
| 94 | } failure:^(NSError *error) { | 84 | } failure:^(NSError *error) { |
| 85 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:self.cid]; | ||
| 86 | + if (data &&self.pageNo == 1) { | ||
| 87 | + [self dealDictionaryData:data]; | ||
| 88 | + } | ||
| 95 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; | 89 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; |
| 96 | self->_isRefreshing = NO; | 90 | self->_isRefreshing = NO; |
| 97 | [AlertViewTool hideHUDView]; | 91 | [AlertViewTool hideHUDView]; |
| @@ -99,6 +93,32 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -99,6 +93,32 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 99 | }]; | 93 | }]; |
| 100 | } | 94 | } |
| 101 | 95 | ||
| 96 | +-(void)dealDictionaryData:(NSData *)data | ||
| 97 | +{ | ||
| 98 | + NSDictionary *dic = [data mj_JSONObject]; | ||
| 99 | + if ([dic[@"programs"] isKindOfClass:[NSArray class]]) { | ||
| 100 | + NSArray *lists = dic[@"programs"]; | ||
| 101 | + | ||
| 102 | + if(self->_pageNo == 1&&lists.count > 0){ | ||
| 103 | + [self.data removeAllObjects]; | ||
| 104 | + | ||
| 105 | + } | ||
| 106 | + self->_pageNo++; | ||
| 107 | + | ||
| 108 | + for (NSDictionary *dics in lists) { | ||
| 109 | + [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 110 | + return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 111 | + }]; | ||
| 112 | + | ||
| 113 | + NSLog(@"%@",dics); | ||
| 114 | + [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | ||
| 115 | + | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + } | ||
| 119 | + [self.tableView reloadData]; | ||
| 120 | +} | ||
| 121 | + | ||
| 102 | - (void)loadUpData{ | 122 | - (void)loadUpData{ |
| 103 | _pageNo = 1; | 123 | _pageNo = 1; |
| 104 | if(!_isRefreshing){ | 124 | if(!_isRefreshing){ |
CNLiveScioLive/Pages/Live/Controller/CNLiveViewController.m
| @@ -42,6 +42,11 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | @@ -42,6 +42,11 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | ||
| 42 | - (void)getData{ | 42 | - (void)getData{ |
| 43 | [MBProgressHUD showHUDAddedTo:self.view animated:YES]; | 43 | [MBProgressHUD showHUDAddedTo:self.view animated:YES]; |
| 44 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { | 44 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { |
| 45 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"LiveHeader"]; | ||
| 46 | + if (data) { | ||
| 47 | + [self dealDictionaryData:data]; | ||
| 48 | + } | ||
| 49 | + [MBProgressHUD hideHUDForView:self.view animated:YES]; | ||
| 45 | [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; | 50 | [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")]; |
| 46 | return; | 51 | return; |
| 47 | } | 52 | } |
| @@ -51,20 +56,31 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | @@ -51,20 +56,31 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | ||
| 51 | 56 | ||
| 52 | // 请求成功,解析数据 | 57 | // 请求成功,解析数据 |
| 53 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; | 58 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; |
| 54 | - [CNLiveModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 55 | - return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 56 | - }]; | ||
| 57 | - self.liveModel = [CNLiveModel mj_objectWithKeyValues:dic]; | ||
| 58 | - self.header.model = [CNLiveModel mj_objectWithKeyValues:dic]; | ||
| 59 | - [self.tableView reloadData]; | 59 | + NSData *data = [dic mj_JSONData]; |
| 60 | + [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"LiveHeader"]; | ||
| 61 | + [self dealDictionaryData:data]; | ||
| 60 | // self->_isLoaded = YES; | 62 | // self->_isLoaded = YES; |
| 61 | 63 | ||
| 62 | } failure:^(NSError *error) { | 64 | } failure:^(NSError *error) { |
| 65 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"LiveHeader"]; | ||
| 66 | + if (data) { | ||
| 67 | + [self dealDictionaryData:data]; | ||
| 68 | + } | ||
| 63 | [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")]; | 69 | [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")]; |
| 64 | [MBProgressHUD hideHUDForView:self.view animated:YES]; | 70 | [MBProgressHUD hideHUDForView:self.view animated:YES]; |
| 65 | 71 | ||
| 66 | }]; | 72 | }]; |
| 67 | } | 73 | } |
| 74 | +-(void)dealDictionaryData:(NSData *)data | ||
| 75 | +{ | ||
| 76 | + NSDictionary *dic = [data mj_JSONObject]; | ||
| 77 | + [CNLiveModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 78 | + return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 79 | + }]; | ||
| 80 | + self.liveModel = [CNLiveModel mj_objectWithKeyValues:dic]; | ||
| 81 | + self.header.model = [CNLiveModel mj_objectWithKeyValues:dic]; | ||
| 82 | + [self.tableView reloadData]; | ||
| 83 | +} | ||
| 68 | - (void)loadData{ | 84 | - (void)loadData{ |
| 69 | NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest"); | 85 | NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest"); |
| 70 | NSLog(@"%@",strUrl); | 86 | NSLog(@"%@",strUrl); |
| @@ -74,6 +90,10 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | @@ -74,6 +90,10 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | ||
| 74 | NSLog(@"%@",parameters); | 90 | NSLog(@"%@",parameters); |
| 75 | 91 | ||
| 76 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { | 92 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { |
| 93 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"liveList"]; | ||
| 94 | + if (data && self.pageNo == 1) { | ||
| 95 | + [self dealDictionaryListData:data]; | ||
| 96 | + } | ||
| 77 | [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"NetworkiInterruption")]; | 97 | [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"NetworkiInterruption")]; |
| 78 | [self.tableView.mj_header endRefreshing]; | 98 | [self.tableView.mj_header endRefreshing]; |
| 79 | [self.tableView.mj_footer endRefreshing]; | 99 | [self.tableView.mj_footer endRefreshing]; |
| @@ -90,38 +110,17 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | @@ -90,38 +110,17 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | ||
| 90 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; | 110 | NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json]; |
| 91 | 111 | ||
| 92 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { | 112 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { |
| 93 | -// if ([dic[@"programs"] isKindOfClass:[NSDictionary class]] && [dic[@"programs"] count]) { | ||
| 94 | -// NSDictionary *dics = dic[@"programs"]; | ||
| 95 | -// [CNLiveModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 96 | -// return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 97 | -// }]; | ||
| 98 | -// [self.data addObject:[CNLiveModel mj_objectWithKeyValues:dics]]; | ||
| 99 | -// } | ||
| 100 | - | ||
| 101 | - if ([dic[@"programs"] isKindOfClass:[NSArray class]]) { | ||
| 102 | - self->_newsArray = dic[@"programs"]; | ||
| 103 | - NSArray *lists = dic[@"programs"]; | ||
| 104 | - | ||
| 105 | - if(self->_pageNo == 1&&lists.count > 0){ | ||
| 106 | - [self.data removeAllObjects]; | ||
| 107 | - | ||
| 108 | - } | ||
| 109 | - self->_pageNo++; | ||
| 110 | - | ||
| 111 | - for (NSDictionary *dics in lists) { | ||
| 112 | - [CNLiveModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 113 | - return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 114 | - }]; | ||
| 115 | - | ||
| 116 | - NSLog(@"%@",dics); | ||
| 117 | - [self.data addObject:[CNLiveModel mj_objectWithKeyValues:dics]]; | ||
| 118 | - | ||
| 119 | - } | ||
| 120 | - | 113 | + NSData *data = [dic mj_JSONData]; |
| 114 | + if ( self.pageNo ==1 ) { | ||
| 115 | + [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"liveList"]; | ||
| 121 | } | 116 | } |
| 122 | - | 117 | + [self dealDictionaryListData:data]; |
| 123 | 118 | ||
| 124 | } else { | 119 | } else { |
| 120 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"liveList"]; | ||
| 121 | + if (data && self.pageNo == 1) { | ||
| 122 | + [self dealDictionaryListData:data]; | ||
| 123 | + } | ||
| 125 | [AlertViewTool showHUDAddedToView:self.view text:dic[@"errorMessage"]]; | 124 | [AlertViewTool showHUDAddedToView:self.view text:dic[@"errorMessage"]]; |
| 126 | 125 | ||
| 127 | } | 126 | } |
| @@ -134,17 +133,46 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | @@ -134,17 +133,46 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; | ||
| 134 | [self.tableView.mj_footer endRefreshing]; | 133 | [self.tableView.mj_footer endRefreshing]; |
| 135 | 134 | ||
| 136 | } | 135 | } |
| 137 | - [self.tableView reloadData]; | 136 | + |
| 138 | self->_isRefreshing = NO; | 137 | self->_isRefreshing = NO; |
| 139 | 138 | ||
| 140 | 139 | ||
| 141 | } failure:^(NSError *error) { | 140 | } failure:^(NSError *error) { |
| 141 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"liveList"]; | ||
| 142 | + if (data && self.pageNo == 1) { | ||
| 143 | + [self dealDictionaryListData:data]; | ||
| 144 | + } | ||
| 142 | self->_isRefreshing = NO; | 145 | self->_isRefreshing = NO; |
| 143 | [AlertViewTool hideHUDView]; | 146 | [AlertViewTool hideHUDView]; |
| 144 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; | 147 | [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; |
| 145 | 148 | ||
| 146 | }]; | 149 | }]; |
| 147 | } | 150 | } |
| 151 | +-(void)dealDictionaryListData:(NSData *)data{ | ||
| 152 | + NSDictionary *dic = [data mj_JSONObject]; | ||
| 153 | + if ([dic[@"programs"] isKindOfClass:[NSArray class]]) { | ||
| 154 | + self->_newsArray = dic[@"programs"]; | ||
| 155 | + NSArray *lists = dic[@"programs"]; | ||
| 156 | + | ||
| 157 | + if(self->_pageNo == 1&&lists.count > 0){ | ||
| 158 | + [self.data removeAllObjects]; | ||
| 159 | + | ||
| 160 | + } | ||
| 161 | + self->_pageNo++; | ||
| 162 | + | ||
| 163 | + for (NSDictionary *dics in lists) { | ||
| 164 | + [CNLiveModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | ||
| 165 | + return @{ @"ID" : @"id" ,@"Description" : @"description" }; | ||
| 166 | + }]; | ||
| 167 | + | ||
| 168 | + NSLog(@"%@",dics); | ||
| 169 | + [self.data addObject:[CNLiveModel mj_objectWithKeyValues:dics]]; | ||
| 170 | + | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + } | ||
| 174 | + [self.tableView reloadData]; | ||
| 175 | +} | ||
| 148 | - (void)loadYGData { | 176 | - (void)loadYGData { |
| 149 | NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest"); | 177 | NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest"); |
| 150 | //NSLog(@"%@",strUrl); | 178 | //NSLog(@"%@",strUrl); |
CNLiveScioLive/Pages/Live/View/CNLiveHeaderView.m
| @@ -29,7 +29,6 @@ | @@ -29,7 +29,6 @@ | ||
| 29 | _backgroundImage.contentMode = UIViewContentModeScaleAspectFill; | 29 | _backgroundImage.contentMode = UIViewContentModeScaleAspectFill; |
| 30 | _backgroundImage.layer.masksToBounds = YES; | 30 | _backgroundImage.layer.masksToBounds = YES; |
| 31 | _backgroundImage.layer.cornerRadius = 2.0; | 31 | _backgroundImage.layer.cornerRadius = 2.0; |
| 32 | - _backgroundImage.image = [UIImage imageNamed:@"cnlive_placeholder"]; | ||
| 33 | [self addSubview:_backgroundImage]; | 32 | [self addSubview:_backgroundImage]; |
| 34 | 33 | ||
| 35 | _playImage = [UIButton buttonWithType:UIButtonTypeCustom]; | 34 | _playImage = [UIButton buttonWithType:UIButtonTypeCustom]; |
| @@ -61,7 +60,7 @@ | @@ -61,7 +60,7 @@ | ||
| 61 | } | 60 | } |
| 62 | - (void)setModel:(CNLiveModel *)model{ | 61 | - (void)setModel:(CNLiveModel *)model{ |
| 63 | _model = model; | 62 | _model = model; |
| 64 | - [_backgroundImage sd_setImageWithURL:[NSURL URLWithString:model.poster] placeholderImage:[UIImage imageNamed:@"cnlive_placeholder"]]; | 63 | + [_backgroundImage sd_setImageWithURL:[NSURL URLWithString:model.poster] placeholderImage:[UIImage imageNamed:@"placeholder"]]; |
| 65 | switch ([model.status intValue]) { | 64 | switch ([model.status intValue]) { |
| 66 | case 0: { | 65 | case 0: { |
| 67 | _stateLabel.text = @"直播准备"; | 66 | _stateLabel.text = @"直播准备"; |