萤石云 iOSSDK,移植跨平台相关工程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
//  HDLEZDeviceMsgListViewController.m
//  EZSDK
//
//  Created by 陈启扬 on 2023/3/16.
//
 
#import "HDLEZDeviceMsgListViewController.h"
#import "HDLEZDeviceMsgListView.h"
#import "MJRefreshNormalHeader.h"
#import "MJRefreshAutoNormalFooter.h"
#import "HDLEZDevMsgListModel.h"
@interface HDLEZDeviceMsgListViewController ()
@property (nonatomic, strong) HDLEZDeviceMsgListView *msgListV;//消息列表view
 
@property (nonatomic, strong) MJRefreshNormalHeader *header;//刷新header
 
@property (nonatomic, strong) MJRefreshAutoNormalFooter *footer;//加载footer
 
@property (nonatomic, strong) HDLEZDevMsgListModel *msgListModel;//消息列表model
 
@property (nonatomic, strong) NSMutableArray<HDLEZDeviceMsgInfoModel*> *msgList;//消息列表(分页获取到的所有消息)
 
@property (nonatomic, assign) NSInteger currentPageNo;//当前页码
 
@property (nonatomic, assign) NSInteger pageSize;//分页容量
 
@end
 
@implementation HDLEZDeviceMsgListViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTopBarViewWithTitle:HDLEZLocallizedString(@"device_history")];
    [self.topBarView.bottomLine setHidden:YES];
    // Do any additional setup after loading the view.
}
 
-(void)addSubViews{
    
    //
    _msgListV=[[HDLEZDeviceMsgListView alloc] init];
    [self.view addSubview:_msgListV];
    [_msgListV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(HDLEZ_APP_TOP_BAR_HEIGHT);
        make.left.bottom.right.equalTo(self.view);
    }];
//    _msgListV.choseDelegate=self;
    
    //下拉刷新
    // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
    _header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshData)];
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    _header.automaticallyChangeAlpha = YES;
    // 隐藏时间
    _header.lastUpdatedTimeLabel.hidden = YES;
    // 隐藏刷新状态文本
    _header.stateLabel.hidden = YES;
    _msgListV.mj_header=_header;
    
    //上拉加载更多
    _footer=[MJRefreshAutoNormalFooter  footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    _footer.refreshingTitleHidden=YES;
    [_footer setTitle:@"" forState:MJRefreshStateIdle];
    [_footer setTitle:HDLEZLocallizedString(@"device_his_no_more_data") forState:MJRefreshStateNoMoreData];
    _footer.stateLabel.textColor=HDLEZ_COLOR_TEXT_LIGHT_GRAY;
    _msgListV.mj_footer=_footer;
 
    //开始加载数据
    [_header beginRefreshing];
    
    
}
 
/*刷新数据
 */
-(void)refreshData{
    self.msgList=[[NSMutableArray alloc] init];
    _currentPageNo=1;
    _pageSize=20;
    
    [self getMsgList];
}
 
/*加载更多
 */
-(void)loadMore{
//    _currentPageNo+=1;
    
    [self getMsgList];
 
}
 
/*获取历史记录
 */
-(void)getMsgList{
    __weak __typeof(self)weakSelf = self;
    [[EZHttpUtil sharedManager] getDeviceMessageByHDL:self.deviceId pageSize:_pageSize pageNo:_currentPageNo completion:^(ResponseData * _Nonnull responseData) {
        [weakSelf.header endRefreshing];
        [weakSelf.footer endRefreshing];
        weakSelf.msgListModel=[HDLEZDevMsgListModel yy_modelWithDictionary:responseData.data];
        if (responseData.success) {
            weakSelf.msgListModel=[HDLEZDevMsgListModel yy_modelWithDictionary:responseData.data];
            if (weakSelf.msgListModel.list.count!=0) {
                [weakSelf.msgList addObjectsFromArray:weakSelf.msgListModel.list];
                weakSelf.msgListV.msgList=weakSelf.msgList;
                weakSelf.currentPageNo+=1;
            }else{
                [weakSelf.footer endRefreshingWithNoMoreData];
            }
            
        }else{
            [weakSelf.view makeToast:responseData.message
                            duration:1.5
                            position:@"center"];
        }
    }];
}
 
 
@end