CNLiveCommuntServiceViewController.m
6.41 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// CNLiveCommuntServiceViewController.m
// CNLiveCommunitModule
//
// Created by open on 2022/2/1.
//
#import "CNLiveCommuntServiceViewController.h"
#import "CNLiveCommuntyColGridViewLayout.h"
#define kGNCOLGRIDVIEWID @"GNCOLGRIDVIEWID"
@interface CNLiveCommuntServiceViewController ()
@property (nonatomic, strong) CNLiveCommuntyHomeModel * homeModel;
@property (nonatomic, strong) CNLiveCommuntySubHomeModel * homeSubModel;
@property (nonatomic, assign) BOOL isRootVC;
@property (nonatomic, assign) BOOL isLoading;
@property (nonatomic, assign) BOOL isShowLocation;
@end
@implementation CNLiveCommuntServiceViewController
- (instancetype)initWithHomeModel:(CNLiveCommuntyHomeModel *)homeModel isRootVC:(BOOL)isRootVC isShowLocation:(BOOL)isShowLocation
{
self = [super init];
if (self) {
_isShowLocation = isShowLocation;
_isRootVC = isRootVC;
_homeModel = homeModel;
_isRootVC = isRootVC;
}
return self;
}
- (instancetype)initWithHomeSubModel:(CNLiveCommuntySubHomeModel *)homeSubModel isRootVC:(BOOL)isRootVC isShowLocation:(BOOL)isShowLocation
{
self = [super init];
if (self) {
_isShowLocation = isShowLocation;
_isRootVC = isRootVC;
_homeSubModel = homeSubModel;
_isRootVC = isRootVC;
}
return self;
}
- (void)dealloc
{
if (self.childViewControllers.count > 0) {
UIViewController *vc = self.childViewControllers[0];
if (([self searchProperties:[vc class] string:@"collectionView"] || [self searchProperties:[vc.superclass class] string:@"collectionView"])&&[vc valueForKey:@"collectionView"]&&[[vc valueForKey:@"collectionView"] isKindOfClass:[UICollectionView class]]) {
UICollectionView *collectionView = (UICollectionView *)[vc valueForKey:@"collectionView"];
if ([collectionView valueForKey:@"mj_header"]) {
id header = [collectionView valueForKey:@"mj_header"];
[header removeObserver:self forKeyPath:@"state"];
}
}
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
NSString * cmsPageId = self.homeModel?self.homeModel.cmsPageId:self.homeSubModel.cmsPageId;
NSString * cmsColumnId = self.homeModel?self.homeModel.cmsColumnId:self.homeSubModel.cmsColumnId;
NSString * cmsPageUrl = self.homeModel?self.homeModel.cmsPageUrl:self.homeSubModel.cmsPageUrl;
UIViewController * subVC = [[CNLiveCommuntyModule shareInstance].protocol pushLiveViewWithMainProjectWithPageId:cmsPageId ChannelName:self.homeModel.cmsColumnName ChannelId:cmsColumnId WebUrl:cmsPageUrl];
subVC.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:subVC.view];
[self addChildViewController:subVC];
[subVC didMoveToParentViewController:self];
if (self.isRootVC) {
[subVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kNavigationBarHeight);
make.left.bottom.right.mas_equalTo(self.view);
}];
}
UIViewController *vc = self.childViewControllers[0];
if ([self searchProperties:[vc class] string:@"collectionView"]&&[vc valueForKey:@"collectionView"] && [[vc valueForKey:@"collectionView"] isKindOfClass:[UICollectionView class]]){
UICollectionView *collectionView = (UICollectionView *)[vc valueForKey:@"collectionView"];
if (!self.isLoading) [collectionView.mj_header beginRefreshing];
if ([collectionView valueForKey:@"mj_header"]) {
id header = [collectionView valueForKey:@"mj_header"];
[header addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:nil];
}
}
if (self.isRootVC) [self initNav];
}
- (BOOL)searchProperties:(Class)cls string:(NSString *)key
{
unsigned int count;
objc_property_t *properties = class_copyPropertyList(cls, &count);
for (int i = 0; i < count; i++) {
objc_property_t property = properties[i];
const char *cName = property_getName(property);
NSString *name = [NSString stringWithCString:cName encoding:NSUTF8StringEncoding];
if ([name isEqualToString:key]) {
return YES;
}
}
return NO;
}
#pragma mark - KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
NSLog(@"%@:%@",object,change);
if ([keyPath isEqualToString:@"state"]) {
NSString *state = change[NSKeyValueChangeNewKey];
if (state.integerValue == 1) {
[self performSelector:@selector(delayAction) afterDelay:1];
}else{
self.isLoading = YES;
}
}
}
- (void)delayAction{
self.isLoading = NO;
}
-(void)initNav
{
self.topNavView.backgroundColor = [UIColor whiteColor];
self.topLine.backgroundColor = [UIColor whiteColor];
DSNavButton * searchBtn = [[DSNavButton alloc] initWithImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_communit_back"]];
[searchBtn addTarget:self action:@selector(leftNavBtnAction) forControlEvents:UIControlEventTouchUpInside];
self.leftNavBtns = @[searchBtn];
NSString * nb_info = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@",kCNLiveCommuntyNBhdInfoIdentifier,[CNUserInfoManager manager].userInfoModel.uid]];
if (self.isShowLocation && [nb_info isNotBlank]) {
CNLiveCommuntyHomeListModel * listModel = [CNLiveCommuntyHomeListModel mj_objectWithKeyValues:nb_info];
DSNavButton * rightBtn = [[DSNavButton alloc] initWithImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_service_location"] imageSize:CGSizeMake(15, 15) title:listModel.name font:[UIFont systemFontOfSize:10] titleColor:UIColorHex(#333333) imagePosition:DSImagePositionLeft];
rightBtn.size = CGSizeMake(80, self.topNavViewHeight - kStatusHeight);
[rightBtn addTarget:self action:@selector(rightNavBtnAction) forControlEvents:UIControlEventTouchUpInside];
self.rightNavBtns = @[rightBtn];
}
}
-(void)rightNavBtnAction
{
CNLiveCommuntyHomeListViewController * listView = [[CNLiveCommuntyHomeListViewController alloc] init];
[[self displayViewController] dsPushViewController:listView animated:YES];
}
-(void)leftNavBtnAction
{
[self.navigationController popViewControllerAnimated:YES];
}
- (UIView *)listView {
return self.view;
}
@end