Files
yinmeng-ios/xplan-ios/Main/Room/View/XPRoomModuleHelper.m
2021-10-18 19:10:13 +08:00

84 lines
2.0 KiB
Objective-C

//
// XPRoomModuleHelper.m
// xplan-ios
//
// Created by 冯硕 on 2021/10/18.
//
#import "XPRoomModuleHelper.h"
#import <ReactiveObjC/ReactiveObjC.h>
///Model
#import "RoomInfoModel.h"
///P
#import "XPRoomPresenter.h"
///VC
#import "XPRoomViewController.h"
#import "BaseNavigationController.h"
@interface XPRoomModuleHelper ()
///是否正在进房
@property (nonatomic,assign) BOOL isEntering;
///
@property (nonatomic,strong) XPRoomPresenter *roomPresenter;
@end
@implementation XPRoomModuleHelper
+ (instancetype)shareHelper {
static dispatch_once_t onceToken;
static XPRoomModuleHelper * helper;
dispatch_once(&onceToken, ^{
helper = [[XPRoomModuleHelper alloc] init];
});
return helper;
}
- (void)enterRoomVCWithRoomUid:(NSString *)roomUid viewController:(nonnull UIViewController *)viewController{
if (viewController == nil || roomUid <= 0) {
return;
}
@weakify(self);
[self.roomPresenter getRoomInfoWithUid:roomUid success:^(RoomInfoModel * _Nonnull roomInfo) {
roomInfo.valid = YES;
@strongify(self);
if (roomInfo.valid) {
self.isEntering = YES;
[self presenterRoomVCWithRoomInfo:roomInfo viewController:viewController];
} else {
#warning to do - 如果房间无效的话
}
}];
}
- (void)presenterRoomVCWithRoomInfo:(RoomInfoModel *)roomInfo viewController:(nonnull UIViewController *)viewController {
if (roomInfo == nil) {
return;
}
if (self.isEntering) {
#warning to do - 显示toast
return;
}
#warning to do - 还需完善 如果当前有房间的话 需要关闭当前的房间 然后进入需要进入的房间
XPRoomViewController * roomVC = [[XPRoomViewController alloc] init];
roomVC.roomInfo = roomInfo;
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:nav animated:YES completion:^{
self.isEntering = NO;
}];
}
- (XPRoomPresenter *)roomPresenter {
if (!_roomPresenter) {
_roomPresenter = [[XPRoomPresenter alloc] init];
}
return _roomPresenter;
}
@end