237 lines
9.1 KiB
Objective-C
237 lines
9.1 KiB
Objective-C
//
|
|
// NotiCenterViewController.m
|
|
// ShenQi
|
|
//
|
|
// Created by twotutoo on 2025/1/11.
|
|
//
|
|
|
|
#import "NotiCenterViewController.h"
|
|
|
|
#import "NotiCenterTableViewCell.h"
|
|
#import "NotiCenterContentTableViewCell.h"
|
|
#import "NotiCenterImageTableViewCell.h"
|
|
#import "NotiCenterJumpLinkTableViewCell.h"
|
|
|
|
#import "MacroDefine.h"
|
|
#import <SVProgressHUD.h>
|
|
#import <SDWebImage.h>
|
|
#import "DataModels.h"
|
|
#import "UIButton+DSButtonBlock.h"
|
|
#import <MJRefresh.h>
|
|
|
|
#import "MainOldViewController.h"
|
|
|
|
static NSString *identifier = @"NotiCenterTableViewCell";
|
|
static NSString *contentidentifier = @"NotiCenterContentTableViewCell";
|
|
static NSString *imageidentifier = @"NotiCenterImageTableViewCell";
|
|
static NSString *linkidentifier = @"NotiCenterJumpLinkTableViewCell";
|
|
|
|
@interface NotiCenterViewController () <UITableViewDelegate,UITableViewDataSource>
|
|
|
|
@property (weak, nonatomic) IBOutlet UITableView *tableView;
|
|
|
|
@property (nonatomic, strong) NSString *mainUserId;
|
|
@property (nonatomic, strong) NSMutableArray *notiArray;
|
|
|
|
@property (nonatomic, assign) NSInteger page;
|
|
|
|
@end
|
|
|
|
@implementation NotiCenterViewController
|
|
|
|
- (IBAction)gobackAction:(id)sender
|
|
{
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
self.mainUserId = TESTUserID;
|
|
|
|
self.tableView.delegate = self;
|
|
self.tableView.dataSource = self;
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
self.tableView.sectionHeaderHeight = 10;
|
|
self.tableView.sectionFooterHeight = 0;
|
|
self.tableView.backgroundColor = UIColorFromRGB(0xFAFAFA);
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"NotiCenterTableViewCell" bundle:nil] forCellReuseIdentifier:identifier];
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"NotiCenterContentTableViewCell" bundle:nil] forCellReuseIdentifier:contentidentifier];
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"NotiCenterImageTableViewCell" bundle:nil] forCellReuseIdentifier:imageidentifier];
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"NotiCenterJumpLinkTableViewCell" bundle:nil] forCellReuseIdentifier:linkidentifier];
|
|
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
self.notiArray = @[].mutableCopy;
|
|
self.page = 1;
|
|
[self refreshDatasource];
|
|
}];
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
self.tableView.tableFooterView = [UIView new];
|
|
|
|
self.notiArray = @[].mutableCopy;
|
|
self.page = 1;
|
|
[self refreshDatasource];
|
|
}
|
|
|
|
-(void)refreshDatasource
|
|
{
|
|
NSString *urlstring = [NSString stringWithFormat:@"%@?userId=%@&page=%ld&size=20",PushRecordsURL,self.mainUserId,(long)self.page];
|
|
NSURL *url = [NSURL URLWithString:urlstring];
|
|
|
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
|
|
request.HTTPMethod = @"GET";
|
|
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
|
|
|
NSURLSession *session = [NSURLSession sharedSession];
|
|
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (error) {
|
|
[SVProgressHUD showInfoWithStatus:error.localizedDescription];
|
|
}else{
|
|
NSError *error;
|
|
NSMutableDictionary *responseObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
|
|
if (error) {
|
|
[SVProgressHUD showInfoWithStatus:error.localizedDescription];
|
|
}else{
|
|
if (ISNULL(error) && !ISNULL(responseObject) && [[responseObject objectForKey:@"code"] integerValue] == 1) {
|
|
PushRecordDataModel *model = [[PushRecordDataModel alloc] initWithDictionary:responseObject];
|
|
for (PushRecordList *list in model.data.list) {
|
|
if (list.type == 2) {
|
|
list.imageHeight = SCREEN_WIDTH-30;
|
|
}
|
|
}
|
|
[self.notiArray addObjectsFromArray:model.data.list];
|
|
if (model.data.list.count == 20) {
|
|
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
self.page++;
|
|
[self refreshDatasource];
|
|
}];
|
|
}else{
|
|
self.tableView.mj_footer = nil;
|
|
}
|
|
[self.tableView reloadData];
|
|
[self refreshImageDatasource];
|
|
[self scrollViewToRecordIDSection];
|
|
}
|
|
}
|
|
}
|
|
[self.tableView.mj_header endRefreshing];
|
|
[self.tableView.mj_footer endRefreshing];
|
|
});
|
|
}];
|
|
[dataTask resume];
|
|
}
|
|
|
|
-(void)refreshImageDatasource
|
|
{
|
|
for (NSInteger i=0; i<self.notiArray.count; i++) {
|
|
PushRecordList *list = self.notiArray[i];
|
|
NSURL *url = [NSURL URLWithString:list.image];
|
|
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:url completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
|
if (image && error == nil) {
|
|
list.imageHeight = (SCREEN_WIDTH-30)*image.size.height/image.size.width;
|
|
if (list.isOpen == YES) {
|
|
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:i]] withRowAnimation:(UITableViewRowAnimationNone)];
|
|
}
|
|
}
|
|
}];
|
|
}
|
|
}
|
|
|
|
-(void)scrollViewToRecordIDSection
|
|
{
|
|
if (self.pushId > 0) {
|
|
for (NSInteger i=0; i<self.notiArray.count; i++) {
|
|
PushRecordList *list = self.notiArray[i];
|
|
if (list.recordId == self.pushId) {
|
|
list.isOpen = YES;
|
|
[self.tableView reloadData];
|
|
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:i] atScrollPosition:(UITableViewScrollPositionNone) animated:YES];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
{
|
|
return self.notiArray.count;
|
|
}
|
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
PushRecordList *list = self.notiArray[section];
|
|
if (list.isOpen == YES) {
|
|
return 2;
|
|
}else{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
return UITableViewAutomaticDimension;
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
{
|
|
return 10;
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
|
{
|
|
return CGFLOAT_MIN;
|
|
}
|
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
PushRecordList *list = self.notiArray[indexPath.section];
|
|
if (indexPath.row == 0) {
|
|
NotiCenterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
|
cell.list = list;
|
|
if (list.isOpen == YES) {
|
|
[cell.arrowBtn setImage:[UIImage imageNamed:@"s"] forState:(UIControlStateNormal)];
|
|
}else{
|
|
[cell.arrowBtn setImage:[UIImage imageNamed:@"xaingxia"] forState:(UIControlStateNormal)];
|
|
}
|
|
[cell.arrowBtn addAction:^(UIButton * _Nullable btn) {
|
|
list.isOpen = !list.isOpen;
|
|
[self.tableView reloadData];
|
|
}];
|
|
return cell;
|
|
}else if (indexPath.row == 1) {
|
|
if (list.type == 1) {
|
|
NotiCenterContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:contentidentifier];
|
|
cell.list = list;
|
|
return cell;
|
|
}else if (list.type == 2) {
|
|
NotiCenterImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:imageidentifier];
|
|
cell.list = list;
|
|
return cell;
|
|
}else if (list.type == 3) {
|
|
NotiCenterJumpLinkTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:linkidentifier];
|
|
cell.list = list;
|
|
[cell.linkBtn addAction:^(UIButton * _Nullable btn) {
|
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
|
MainOldViewController *view = [sb instantiateViewControllerWithIdentifier:@"MainOldViewController"];
|
|
view.isPresent = YES;
|
|
view.gameURLString = list.jumpUrl;
|
|
view.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
[self presentViewController:view animated:YES completion:^{}];
|
|
}];
|
|
return cell;
|
|
}
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
PushRecordList *list = self.notiArray[indexPath.section];
|
|
if (indexPath.row == 0) {
|
|
list.isOpen = !list.isOpen;
|
|
[self.tableView reloadData];
|
|
}
|
|
}
|
|
|
|
@end
|