123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- //
- // TenantDarkViewController.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2023/9/12.
- //
- #import "TenantDarkViewController.h"
- #import "InstitutionNomalNavView.h"
- #import "TenantDarkSearhView.h"
- #import "KSBaseWKWebViewController.h"
- #import "TenantDragView.h"
- #import "ToneTuningViewController.h"
- #import "TenantDarkEmptyView.h"
- #import "TYCyclePagerView.h"
- #import "TenantHomeSubjectListCell.h"
- #import "UserInfoManager.h"
- #import "TenantTicketAlert.h"
- #import "AppDelegate+AppService.h"
- #import "TenantAlbumModel.h"
- #import "AlbumSwitchView.h"
- @interface TenantDarkViewController ()<TYCyclePagerViewDelegate, TYCyclePagerViewDataSource>
- @property (nonatomic, copy) SwitchMoreCallback callback;
- @property (nonatomic, strong) InstitutionNomalNavView *navView;
- @property (nonatomic, strong) TenantDarkSearhView *searchView;
- @property (nonatomic, strong) TenantDragView *suspendButton;
- @property (nonatomic, strong) TenantDarkEmptyView *emptyAniView;
- @property (nonatomic, strong) TYCyclePagerView *pagerView;
- @property (nonatomic, strong) NSMutableArray *animationNameArray;
- @property (nonatomic, strong) UserInfo *mineInfo;
- @property (nonatomic, strong) dispatch_group_t requestGroup;
- @property (nonatomic, strong) TenantTicketAlert *alert;
- @property (nonatomic, assign) BOOL hasShowTipsView;
- @property (nonatomic, assign) BOOL isFirstLoad;
- @property (nonatomic, strong) NSMutableArray *sourceArray; // 分类数据
- @property (nonatomic, assign) NSInteger albumCount; // 专辑数量
- @property (nonatomic, strong) NSString *chooseAlbumId; // 选择的专辑编号
- @property (nonatomic, strong) NSMutableArray *albumListArray; // 专辑数据
- @property (nonatomic, strong) GroupAlbumModel *albumModel; // 小组专辑信息
- @end
- @implementation TenantDarkViewController
- - (void)swithToMorePageAction:(SwitchMoreCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self configUI];
- self.isFirstLoad = YES;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive) name:@"appDidBecomeActive" object:nil];
- self.chooseAlbumId = UserDefault(TENANT_ALBUMID);
- }
- - (void)didBecomeActive {
- if (self.sourceArray.count == 0) {
- [self.emptyAniView startPlay];
- }
- else {
- TenantHomeSubjectListCell *cell = (TenantHomeSubjectListCell *)[self.pagerView curIndexCell];
- [cell startAnimation];
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self requestSource];
- if (self.isFirstLoad == YES) {
- self.isFirstLoad = NO;
- [self requestTrackAuth];
- }
- else {
- NSLog(@"view app");
- [self didBecomeActive];
- }
- }
- - (void)requestTrackAuth {
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate appTrackActionAuth];
- [appDelegate handleNotiferSource];
- }
- - (void)requestSource {
- [self requestUserInfo];
- [self requestData];
- [self requsetTicket];
- dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
- [self refreshView];
- });
- }
- - (void)requestUserInfo {
- dispatch_group_enter(self.requestGroup);
- [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
- dispatch_group_leave(self.requestGroup);
- self.mineInfo = userInfo;
- }];
- }
- - (void)ticketCheck:(NSInteger)count {
- if (self.hasShowTipsView == YES) {
- return;
- }
- AppDelegate *appDelegate = [AppDelegate shareAppDelegate];
- if (appDelegate.isShowMemoAlert) {
- return;
- }
- if (count > 0) {
- appDelegate.isShowFlashAlert = YES;
- self.alert = [TenantTicketAlert shareInstance];
- MJWeakSelf;
- [self.alert configCount:count callback:^(BOOL isActivate) {
- if (isActivate) {
- appDelegate.isShowFlashAlert = NO;
- [weakSelf showActivateView];
- }
- [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新
- }];
- [self.alert showAlert];
- self.hasShowTipsView = YES;
- }
- }
- - (void)showActivateView {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/activation-code", TENANT_WEBHOST];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- - (void)requsetTicket {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager tenantActivationCodeRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
-
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSInteger count = [[dic ks_dictionaryValueForKey:@"data"] ks_integerValueForKey:@"total"];
- [self ticketCheck:count];
- }
- else {
-
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
-
- }];
- }
- - (void)requestData {
-
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager userTenantAlbumListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
-
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *albumList = [dic ks_arrayValueForKey:@"data"];
- NSMutableArray *list = [NSMutableArray array];
- for (NSDictionary *parm in albumList) {
- GroupAlbumModel *model = [[GroupAlbumModel alloc] initWithDictionary:parm];
- [list addObject:model];
- }
- self.albumListArray = [NSMutableArray arrayWithArray:list];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
-
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)showEmptyView {
- self.emptyAniView.hidden = NO;
- [self.emptyAniView startPlay];
- }
- - (void)hideEmptyView {
- self.emptyAniView.hidden = YES;
- [self.emptyAniView stopPlay];
- }
- - (void)refreshView {
- self.navView.tenantName.text = [NSString returnNoNullStringWithString:self.mineInfo.tenantName];
- self.albumCount = self.albumListArray.count;
- // 有专辑数据
- if (self.albumListArray.count > 0) {
- // 如果没有选择专辑 取第一个
- GroupAlbumModel *displayModel = nil;
- if ([NSString isEmptyString:self.chooseAlbumId]) {
- GroupAlbumModel *model = self.albumListArray[0];
- displayModel = model;
- }
- else {
- // 数据处理
- for (GroupAlbumModel *model in self.albumListArray) {
- if ([self.chooseAlbumId isEqualToString:model.internalBaseClassIdentifier]) {
- displayModel = model;
- }
- }
- if (displayModel == nil) {
- GroupAlbumModel *model = self.albumListArray[0];
- displayModel = model;
- }
- }
-
- [self refreshWithModel:displayModel];
- }
- else { // 空
- self.sourceArray = [NSMutableArray array];
- self.animationNameArray = [NSMutableArray array];
- [self showEmptyView];
- [self.pagerView reloadData];
- }
- }
- - (void)refreshWithModel:(GroupAlbumModel *)displayModel {
- self.albumModel = displayModel;
- self.chooseAlbumId = displayModel.internalBaseClassIdentifier;
- UserDefaultSet(self.chooseAlbumId, TENANT_ALBUMID);
-
- [self.navView configAlbumName:displayModel.name];
- NSMutableArray *sourceArray = [NSMutableArray array];
- NSMutableArray *aniArray = [NSMutableArray array];
-
- // COURSEWARE
- if (displayModel.coursewareCounts > 0) {
- TenantAlbumModel *model = [[TenantAlbumModel alloc] init];
- model.subjectType = @"COURSEWARE";
- [sourceArray addObject:model];
- [aniArray addObject:@"cloudCourse_Ani.json"];
- }
-
- // 声部
- if (displayModel.subjectCounts > 0) {
- TenantAlbumModel *model = [[TenantAlbumModel alloc] init];
- model.subjectType = @"SUBJECT";
- [sourceArray addObject:model];
- [aniArray addObject:@"subject_Ani.json"];
- }
-
- // 独奏
- if (displayModel.musicCounts > 0) {
- TenantAlbumModel *model = [[TenantAlbumModel alloc] init];
- model.subjectType = @"MUSIC";
- [sourceArray addObject:model];
- [aniArray addObject:@"singleMusic_Ani.json"];
- }
-
- // 合奏
- if (displayModel.ensembleCounts > 0) {
- TenantAlbumModel *model = [[TenantAlbumModel alloc] init];
- model.subjectType = @"ENSEMBLE";
- [sourceArray addObject:model];
- [aniArray addObject:@"mutiMusic_Ani.json"];
- }
-
- self.sourceArray = [NSMutableArray arrayWithArray:sourceArray];
- self.animationNameArray = [NSMutableArray arrayWithArray:aniArray];
- [self.pagerView reloadData];
-
- if (self.sourceArray.count > 0) {
- [self hideEmptyView];
- }
- else {
- [self showEmptyView];
- }
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tenant_bg_dark"]];
- bgImageView.contentMode = UIViewContentModeRedraw;
- [self.view addSubview:bgImageView];
- [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self.view);
- }];
-
- [self.view addSubview:self.navView];
- CGFloat navHeight = [InstitutionNomalNavView getViewHeight];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(navHeight);
- }];
- [self.view addSubview:self.searchView];
- CGFloat searchHeight = [TenantDarkSearhView getViewHeight];
- [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.navView.mas_bottom);
- make.height.mas_equalTo(searchHeight);
- }];
- // collec
- [self.view addSubview:self.pagerView];
- [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.searchView.mas_bottom);
- make.left.right.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-16);
- }];
-
-
- [self.view addSubview:self.emptyAniView];
- [self.emptyAniView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.searchView.mas_bottom);
- make.left.right.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-16);
- }];
- self.emptyAniView.hidden = YES;
- [self showFloatingWindow];
- }
- - (void)showFloatingWindow {
- if (![self.view.subviews containsObject:self.suspendButton]) {
- [self.view addSubview:self.suspendButton];
- }
- [self.view bringSubviewToFront:self.suspendButton];
- }
- #pragma mark ------ TYCyclePagerViewDataSource
- - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
- return self.sourceArray.count;
- }
- - (__kindof UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
- BOOL isLock = self.albumModel.status == YES ? NO : YES;
- TenantHomeSubjectListCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"TenantHomeSubjectListCell" forIndex:index];
- [cell configWithJsonSting:self.animationNameArray[index] isLock:isLock];
- if (pagerView.curIndex == index) {
- [cell startAnimation];
- }
- else {
- [cell stopAnimation];
- }
- return cell;
- }
- - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
- CGFloat navHeight = [InstitutionNomalNavView getViewHeight];
- CGFloat searchHeight = [TenantDarkSearhView getViewHeight];
- CGFloat height = (KPortraitHeight - navHeight - searchHeight - kTabBarHeight - 16);
- TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc] init];
- CGFloat width = height / 571 * 296;
- layout.itemSize = CGSizeMake(width, height);
- layout.itemSpacing = 16.0f;
- layout.layoutType = TYCyclePagerTransformLayoutLinear;
- layout.sectionInset = UIEdgeInsetsMake(0, (KPortraitWidth - width) / 2.0f, 0, (KPortraitWidth - width) / 2.0f);
- return layout;
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
- BOOL isLock = self.albumModel.status == YES ? NO : YES;
- if (isLock) {
- TenantAlbumModel *model = self.sourceArray[index];
- NSString *subjectType = model.subjectType;
-
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@?subjectType=%@&albumId=%@",TENANT_WEBHOST,@"/#/train-tool",subjectType,self.albumModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else { // 跳转到对应页面
- TenantAlbumModel *model = self.sourceArray[index];
- NSString *subjectType = model.subjectType;
- if ([subjectType isEqualToString:@"COURSEWARE"]) { // 云教程
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/lessonCourseware?albumId=%@", TENANT_WEBHOST, self.albumModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- else {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/train-list?subjectType=%@&albumId=%@", TENANT_WEBHOST,subjectType, self.albumModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
-
- }
- }
- - (void)pagerViewDidScroll:(TYCyclePagerView *)pageView {
- TenantHomeSubjectListCell *cell = (TenantHomeSubjectListCell *)[pageView curIndexCell];
- [cell stopAnimation];
- }
- - (void)pagerViewDidEndDecelerating:(TYCyclePagerView *)pageView {
- TenantHomeSubjectListCell *cell = (TenantHomeSubjectListCell *)[pageView curIndexCell];
- [cell startAnimation];
- }
- #pragma mark --- lazying
- - (NSMutableArray *)albumListArray {
- if (!_albumListArray) {
- _albumListArray = [NSMutableArray array];
- }
- return _albumListArray;
- }
- - (NSMutableArray *)animationNameArray {
- if (!_animationNameArray) {
- _animationNameArray = [NSMutableArray array];
- }
- return _animationNameArray;
- }
- -(TYCyclePagerView *)pagerView {
- if (!_pagerView) {
- _pagerView = [[TYCyclePagerView alloc] init];
- _pagerView.backgroundColor = [UIColor clearColor];
- _pagerView.isInfiniteLoop = NO;
-
- _pagerView.reloadDataNeedResetIndex = NO;
- _pagerView.delegate = self;
- _pagerView.dataSource = self;
- [_pagerView registerNib:[UINib nibWithNibName:@"TenantHomeSubjectListCell" bundle:nil] forCellWithReuseIdentifier:@"TenantHomeSubjectListCell"];
- if (@available(iOS 11.0, *)) {
- _pagerView.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _pagerView.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- }
- return _pagerView;
- }
- - (InstitutionNomalNavView *)navView {
- if (!_navView) {
- _navView = [InstitutionNomalNavView shareInstance];
- MJWeakSelf;
- [_navView moreSwitch:^{
- [weakSelf switchAlbumAction];
- }];
- }
- return _navView;
- }
- - (void)switchAlbumAction {
- AlbumSwitchView *transferView = [AlbumSwitchView shareInstance];
- NSInteger lastChooseIndex = 0;
- for (NSInteger index = 0; index < self.albumListArray.count; index++) {
- GroupAlbumModel *model = self.albumListArray[index];
- model.isChoose = NO;
- if ([self.chooseAlbumId isEqualToString:model.internalBaseClassIdentifier]) {
- lastChooseIndex = index;
- }
- }
- [transferView albumChooseCallback:^(ALBUMSWITCH_TYPE type, NSInteger chooseIndex) {
- if (type == ALBUMSWITCH_TYPE_SWITCH) {
- GroupAlbumModel *model = self.albumListArray[chooseIndex];
- [self queryAlbumMessage:model.internalBaseClassIdentifier];
- }
- }];
- [transferView configWithSource:self.albumListArray lastChooseIndex:lastChooseIndex];
- [transferView showInDisplayView:self.view];
- }
- - (void)queryAlbumMessage:(NSString *)tenantAlbumId {
- // [LOADING_MANAGER showHUD];
- [KSNetworkingManager userBuyAlbumInfoDetailRequest:KS_GET tenantAlbumId:tenantAlbumId success:^(NSDictionary * _Nonnull dic) {
- // [LOADING_MANAGER removeHUD];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *parm = [dic ks_dictionaryValueForKey:@"data"];
- GroupAlbumModel *model = [[GroupAlbumModel alloc] initWithDictionary:parm];
- [self refreshWithModel:model];
- [self.pagerView scrollToItemAtIndex:0 animate:NO];
- }
- else {
-
- }
- } faliure:^(NSError * _Nonnull error) {
- // [LOADING_MANAGER removeHUD];
- }];
- }
- /*
- - (void)switchMoreAction {
- if (self.callback) {
- self.callback();
- }
- }
- */
- - (TenantDarkSearhView *)searchView {
- if (!_searchView) {
- _searchView = [TenantDarkSearhView shareInstance];
- MJWeakSelf;
- [_searchView searchAction:^{
- [weakSelf showSearchView];
- }];
- }
- return _searchView;
- }
- - (void)showSearchView {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/music-songbook/searchAlbum", TENANT_WEBHOST];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- - (TenantDragView *)suspendButton {
- if (!_suspendButton) {
- _suspendButton = [[TenantDragView alloc] initWithFrame:CGRectMake(KPortraitWidth - TenantDragButtonWidth, KPortraitHeight - kTabBarHeight - TenantDragButtonHeight - 100, TenantDragButtonWidth, TenantDragButtonHeight)];
- MJWeakSelf;
- [_suspendButton clickAction:^{
- [weakSelf showDragWindowDetail];
- }];
- }
- return _suspendButton;
- }
- - (void)showDragWindowDetail {
- ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (TenantDarkEmptyView *)emptyAniView {
- if (!_emptyAniView) {
- _emptyAniView = [TenantDarkEmptyView shareInstance];
- }
- return _emptyAniView;
- }
- - (dispatch_group_t)requestGroup {
- if (!_requestGroup) {
- _requestGroup = dispatch_group_create();
- }
- return _requestGroup;
- }
- - (void)setAlbumCount:(NSInteger)albumCount {
- _albumCount = albumCount;
- if (albumCount > 1) { // 显示切换
- self.navView.needSwitchButton = YES;
- }
- else { // 隐藏切换
- self.navView.needSwitchButton = NO;
- }
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|