123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- //
- // YMHomePageViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/4.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMHomePageViewModel.h"
- #import "YMAdvertModel.h"
- #import "YMAdolescentModelViewModel.h"
- @interface YMHomePageViewModel ()
- /// 首页BannerVM
- @property (nonatomic, strong, readwrite) YMHomePageBannerViewModel *bannerVM;
- /// 首页ViewModel列表
- @property (nonatomic, strong, readwrite) NSArray <YMHomePageListViewModel *>*homePageVMListDataArray;
- ///// 推荐VM
- //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *recommendVM;
- /////男神VM
- //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *maleGoldVM;
- ///// 在线VM
- //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *onlineVM;
- ///// 同城
- //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *sameCityVM;
- ///// 推荐for男性(登录男号)
- //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *recommendForMaleVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeIndexVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeSkillAnchorsVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeRecommendAnchorsVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeRecommendVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeWCWVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeOnlineListVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeOnlineVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeGetDesignatedVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeGetSameCityUserVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeActiveAnchorsVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeNewAnchorsVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeCityAnchorsVM;
- @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeBannerVM;
- @end
- @implementation YMHomePageViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- if(self.isFemaleGender){
- self.homePageVMListDataArray = @[
- self.homeWCWVM,
- self.homeGetDesignatedVM,
- self.homeOnlineVM,
- self.homeRecommendVM,
- ];
- } else {
- self.homePageVMListDataArray = @[
- self.homeWCWVM,
- self.homeGetDesignatedVM,
- self.homeOnlineVM,
- ];
- }
- }
- - (void)judgementsIsOpenAdolescentModel{
- [self getAdolescentModelStatusData];
- // //先判断是否设置了青少年模式
- // kAppDelegate.kadolescentStatus = [LCSaveData getYoungMode];
- // if(kAppDelegate.kadolescentStatus == 1){
- // [self closeAdolescentModelPopup];
- // }else{
- // ///在判断是否提醒过
- // ///检查更新 根据时间戳 设定12小时/一天之内调用一次
- // NSString* updateTime = [LCSaveData getYoungNoticeTime];
- // NSDate * newData = [NSDate date];
- // NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- // [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- // if (!updateTime) {
- // NSString* dataString = [dateFormatter stringFromDate:newData];
- // [LCSaveData saveYoungNoticeTime:dataString];
- // ///弹出设置青少年模式弹窗
- // ///要不要检查一下status 防止卸载后重装
- // [self getAdolescentModelStatusData];
- //
- // }else{
- // //获取与当前的时间差
- // NSDate *timeDate = [dateFormatter dateFromString:updateTime];
- // NSTimeInterval timeInterval = [timeDate timeIntervalSinceNow];
- // timeInterval = -timeInterval;
- // //超过30天
- // if (timeInterval > 60 * 60 * 24) {
- // NSString* dataString = [dateFormatter stringFromDate:newData];
- // [LCSaveData saveYoungNoticeTime:dataString];
- // //弹出青少年模式弹窗
- // [self openAdolescentModelPopup];
- // }
- // }
- // }
- }
- - (void)getAdolescentModelStatusData {
- [LCHttpHelper requestWithURLString:GetAdolescentStatus parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSInteger adoleStatus = [data integerValueForKey:@"is_set_adolescent" defaultValue:0];
- [LCSaveData saveYoungMode:adoleStatus];
- if(adoleStatus == 1){
- [self closeAdolescentModelPopup];
- }else{
- ///在判断是否提醒过
- ///检查更新 根据时间戳 设定12小时/一天之内调用一次
- NSString* updateTime = [LCSaveData getYoungNoticeTime];
- NSDate * newData = [NSDate date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- if (!updateTime) {
- NSString* dataString = [dateFormatter stringFromDate:newData];
- [LCSaveData saveYoungNoticeTime:dataString];
- ///弹出设置青少年模式弹窗
- ///要不要检查一下status 防止卸载后重装
-
- }else{
- //获取与当前的时间差
- NSDate *timeDate = [dateFormatter dateFromString:updateTime];
- NSTimeInterval timeInterval = [timeDate timeIntervalSinceNow];
- timeInterval = -timeInterval;
- //超过30天
- if (timeInterval > 60 * 60 * 24) {
- NSString* dataString = [dateFormatter stringFromDate:newData];
- [LCSaveData saveYoungNoticeTime:dataString];
- //弹出青少年模式弹窗
- [self openAdolescentModelPopup];
- }
- }
-
- }
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)zhidingData{
- [LCHttpHelper requestWithURLString:HomeZhiDing parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *dataDic = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSString *str = [dataDic objectForKey:@"msg"];
- [ZCHUDHelper showTitle:[NSString stringWithFormat:@"置顶成功,%@",str]];
- if(self.refreshHomeListData){
- self.refreshHomeListData();
- }
-
- }
- } failure:^(NSError *error) {
-
- }];
- }
- /// 群打招呼
- - (void)groupGreetingData {
- [LCHttpHelper requestWithURLString:HomeZhiDing parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *dataDic = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSString *str = [dataDic objectForKey:@"msg"];
- [ZCHUDHelper showTitle:[NSString stringWithFormat:@"置顶成功,%@",str]];
- if(self.refreshHomeListData){
- self.refreshHomeListData();
- }
-
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)getAdvertData{
- [LCHttpHelper requestWithURLString:GetAdvert parameters:@{
- @"source_id":@"2"
- } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- YMAdvertModel *model = [YMAdvertModel yy_modelWithJSON:[data dictionaryValueForKey:@"advert" defaultValue:@{}]];
-
- NSInteger link_type = [dict[@"data"][@"advert"][@"link_type"] integerValue];
- NSString *link_url = dict[@"data"][@"advert"][@"link_url"];
- NSInteger window_type = [dict[@"data"][@"advert"][@"window_type"] integerValue];
- if (model.status == 1 && model.image.length>5) {
- if (window_type == 2) {
- // YOUPAIHRWebWindow *window = [[YOUPAIHRWebWindow alloc] init];
- // window.isTouchDismiss = YES;
- // window.youpaipurl = dict[@"data"][@"advert"][@"window_link"];
- // window.youpaipwidth = [dict[@"data"][@"advert"][@"width"] floatValue];
- // window.youpaipheight = [dict[@"data"][@"advert"][@"height"] floatValue];
- // window.youpaipgravity = dict[@"data"][@"advert"][@"gravity"];
- // [self TFPresentVC:window completion:^{}];
- }else{
- // YOUPAIZYAdvertWindow *VC= [[YOUPAIZYAdvertWindow alloc]init];
- // VC.youpaipdelegate = self;
- // VC.vWidth = KScreenWidth -30;
- // VC.vHeight = KScreenWidth-30;
- // VC.youpaipimageurl = image;
- // VC.youpaiplink_type = link_type;
- // VC.youpaiplink_url = link_url;
- // VC.isTouchDismiss = YES;
- // [self TFPresentVC:VC completion:^{}];
- }
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- /// 获取等级图标数据
- - (void)getLevelIconData{
- [LCHttpHelper requestWithURLString:LevelInfo parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- [LCSaveData saveLevelInfo:data];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- /// 获取徽章和贵族图标数据
- - (void)getBadgesAndNobilityIconData{
- [LCHttpHelper requestWithURLString:AllBadge parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSDictionary* badge = [data dictionaryValueForKey:@"badge" defaultValue:@{}];
- NSDictionary* noble = [data dictionaryValueForKey:@"noble" defaultValue:@{}];
-
- [LCSaveData saveBadgeInfo:badge];
- [LCSaveData saveNobleInfo:noble];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)gotoSearchUser{
- YMSearchUserViewModel *searchUserVM = [[YMSearchUserViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_SEARCH_USER) withUserInfo:@{
- RouterViewModel:searchUserVM
- } completion:nil];
- }
- - (void)openAdolescentModelPopup{
- YMOpenAdolescentModelPopupView *customView = [[YMOpenAdolescentModelPopupView alloc]init];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
- popupView.priority = 998;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerAllCorners;
- popupView.positionStyle = YMPositionStyleCenter;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.3;
- @weakify(popupView)
- customView.noMoreRemindersButtonBlock = ^{
- @strongify(popupView)
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- };
- customView.gotoAdolescentModelButtonBlock = ^{
- @strongify(popupView)
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
- ParamsCategoryType:@(YMAdolescentModelTypeSettingPassword)
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
- RouterViewModel:adolescentModelVM
- } completion:nil];
-
- };
- [popupView pop];
- }
- - (void)closeAdolescentModelPopup{
- YMCloseAdolescentModelPopupView *customView = [[YMCloseAdolescentModelPopupView alloc]init];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
- popupView.priority = 998;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerAllCorners;
- popupView.positionStyle = YMPositionStyleCenter;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.3;
- @weakify(popupView)
- customView.openOrCloseAdolescentModelButtonBlock = ^{
- @strongify(popupView)
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
- ParamsCategoryType:@(YMAdolescentModelTypeClosePassword)
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
- RouterViewModel:adolescentModelVM
- } completion:nil];
- };
- customView.forgotPasswordBlock = ^{
- @strongify(popupView)
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- };
- [popupView pop];
- }
- - (YMHomePageBannerViewModel *)bannerVM{
- if (!_bannerVM) {
- _bannerVM = [[YMHomePageBannerViewModel alloc]initWithParams:@{}];
- }
- return _bannerVM;
- }
- //- (YMHomePageListViewModel *)recommendVM{
- // if (!_recommendVM) {
- // _recommendVM = [[YMHomePageListViewModel alloc]initWithParams:@{
- // ParamsCategoryType:@(YMHomePageCategoryTypeRecommend)
- // }];
- // }
- // return _recommendVM;
- //}
- //
- //- (YMHomePageListViewModel *)maleGoldVM{
- // if (!_maleGoldVM) {
- // _maleGoldVM = [[YMHomePageListViewModel alloc]initWithParams:@{
- // ParamsCategoryType:@(YMHomePageCategoryTypeMaleGold)
- // }];
- // }
- // return _maleGoldVM;
- //}
- //
- //- (YMHomePageListViewModel *)onlineVM{
- // if (!_onlineVM) {
- // _onlineVM = [[YMHomePageListViewModel alloc]initWithParams:@{
- // ParamsCategoryType:@(YMHomePageCategoryTypeOnline)
- // }];
- // }
- // return _onlineVM;
- //}
- //
- //- (YMHomePageListViewModel *)sameCityVM{
- // if (!_sameCityVM) {
- // _sameCityVM = [[YMHomePageListViewModel alloc]initWithParams:@{
- // ParamsCategoryType:@(YMHomePageCategoryTypeSameCity)
- // }];
- // }
- // return _sameCityVM;
- //}
- //
- //- (YMHomePageListViewModel *)recommendForMaleVM{
- // if (!_recommendForMaleVM) {
- // _recommendForMaleVM = [[YMHomePageListViewModel alloc]initWithParams:@{
- // ParamsCategoryType:@(YMHomePageCategoryTypeRecommendForMale)
- // }];
- // }
- // return _recommendForMaleVM;
- //}
- - (YMHomePageListViewModel *)homeIndexVM {
- if (!_homeIndexVM) {
- _homeIndexVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeIndex)}];
- _homeIndexVM.tabTitle = @"";
- _homeIndexVM.tabURLStr = HomeIndex;
- }
- return _homeIndexVM;
- }
- - (YMHomePageListViewModel *)homeSkillAnchorsVM {
- if (!_homeSkillAnchorsVM) {
- _homeSkillAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeSkillAnchors)}];
- _homeSkillAnchorsVM.tabTitle = @"";
- _homeSkillAnchorsVM.tabURLStr = HomeSkillAnchors;
- }
- return _homeSkillAnchorsVM;
- }
- - (YMHomePageListViewModel *)homeRecommendAnchorsVM {
- if (!_homeRecommendAnchorsVM) {
- _homeRecommendAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeRecommendAnchors)}];
- _homeRecommendAnchorsVM.tabTitle = @"";
- _homeRecommendAnchorsVM.tabURLStr = HomeRecommendAnchors;
- }
- return _homeRecommendAnchorsVM;
- }
- - (YMHomePageListViewModel *)homeRecommendVM {
- if (!_homeRecommendVM) {
- _homeRecommendVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeRecommend)}];
- _homeRecommendVM.tabTitle = @"";
- _homeRecommendVM.tabURLStr = HomeRecommend;
- }
- return _homeRecommendVM;
- }
- - (YMHomePageListViewModel *)homeWCWVM {
- if (!_homeWCWVM) {
- _homeWCWVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeWCW)}];
- _homeWCWVM.tabTitle = @"";
- _homeWCWVM.tabURLStr = HomeWCW;
- }
- return _homeWCWVM;
- }
- - (YMHomePageListViewModel *)homeOnlineListVM {
- if (!_homeOnlineListVM) {
- _homeOnlineListVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeOnlineList)}];
- _homeOnlineListVM.tabTitle = @"";
- _homeOnlineListVM.tabURLStr = HomeOnlineList;
- }
- return _homeOnlineListVM;
- }
- - (YMHomePageListViewModel *)homeOnlineVM {
- if (!_homeOnlineVM) {
- _homeOnlineVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeOnline)}];
- _homeOnlineVM.tabTitle = @"";
- _homeOnlineVM.tabURLStr = HomeOnline;
- }
- return _homeOnlineVM;
- }
- - (YMHomePageListViewModel *)homeGetDesignatedVM {
- if (!_homeGetDesignatedVM) {
- _homeGetDesignatedVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeGetDesignated)}];
- _homeGetDesignatedVM.tabTitle = @"";
- _homeGetDesignatedVM.tabURLStr = HomeGetDesignated;
- }
- return _homeGetDesignatedVM;
- }
- - (YMHomePageListViewModel *)homeGetSameCityUserVM {
- if (!_homeGetSameCityUserVM) {
- _homeGetSameCityUserVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeGetSameCityUser)}];
- _homeGetSameCityUserVM.tabTitle = @"";
- _homeGetSameCityUserVM.tabURLStr = HomeGetSameCityUser;
- }
- return _homeGetSameCityUserVM;
- }
- - (YMHomePageListViewModel *)homeActiveAnchorsVM {
- if (!_homeActiveAnchorsVM) {
- _homeActiveAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeActiveAnchors)}];
- _homeActiveAnchorsVM.tabTitle = @"";
- _homeActiveAnchorsVM.tabURLStr = HomeActiveAnchors;
- }
- return _homeActiveAnchorsVM;
- }
- - (YMHomePageListViewModel *)homeNewAnchorsVM {
- if (!_homeNewAnchorsVM) {
- _homeNewAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeNewAnchors)}];
- _homeNewAnchorsVM.tabTitle = @"";
- _homeNewAnchorsVM.tabURLStr = HomeNewAnchors;
- }
- return _homeNewAnchorsVM;
- }
- - (YMHomePageListViewModel *)homeCityAnchorsVM {
- if (!_homeCityAnchorsVM) {
- _homeCityAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeCityAnchors)}];
- _homeCityAnchorsVM.tabTitle = @"";
- _homeCityAnchorsVM.tabURLStr = HomeCityAnchors;
- }
- return _homeCityAnchorsVM;
- }
- - (YMHomePageListViewModel *)homeBannerVM {
- if (!_homeBannerVM) {
- _homeBannerVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeBanner)}];
- _homeBannerVM.tabTitle = @"";
- _homeBannerVM.tabURLStr = HomeBanner;
- }
- return _homeBannerVM;
- }
- @end
|