Files
peko-ios/YuMi/Structure/MVP/Presenter/BaseMvpPresenter.m

157 lines
5.1 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// BaseMvpPresenter.m
// YUMI
//
// Created by admin on 2023/3/9.
//
#import "BaseMvpPresenter.h"
#import "AccountInfoStorage.h"
#import <NIMSDK/NIMSDK.h>
#import "ClientConfig.h"
2025-03-14 19:43:04 +08:00
#import "LoginViewController.h"
2024-12-11 10:48:01 +08:00
#import "BaseNavigationController.h"
#import "FirstRechargeManager.h"
2024-12-11 10:48:01 +08:00
2023-07-14 18:50:55 +08:00
@interface BaseMvpPresenter()
@property (nonatomic, weak) id view;
@end
@implementation BaseMvpPresenter
- (void)attatchView:(id)view {
self.view = view;
}
- (id)getView {
return self.view;
}
- (void)logout {
// 1.
[[FirstRechargeManager sharedManager] stopMonitoring];
// 2. logout
2023-07-14 18:50:55 +08:00
[[AccountInfoStorage instance] saveAccountInfo:nil];
[[AccountInfoStorage instance] saveTicket:nil];
if ([NIMSDK sharedSDK].loginManager.isLogined) {
[[NIMSDK sharedSDK].loginManager logout:nil];
}
// 3.
2024-12-11 10:48:01 +08:00
[self tokenInvalid];
2023-07-14 18:50:55 +08:00
// ///
// [[ClientConfig shareConfig] resetHeartBratTimer];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success {
return [self createHttpCompletion:success fail:nil];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success showLoading:(BOOL)loading {
return [self createHttpCompletion:success fail:nil showLoading:loading];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success errorToast:(BOOL)toast {
return [self createHttpCompletion:success fail:nil errorToast:toast];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success showLoading:(BOOL)loading errorToast:(BOOL)toast {
return [self createHttpCompletion:success fail:nil showLoading:loading errorToast:toast];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail {
return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:YES];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading {
return [self createHttpCompletion:success fail:fail showLoading:loading errorToast:YES];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail errorToast:(BOOL)toast {
return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:toast];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading errorToast:(BOOL)toast {
if (loading) {
[self.view showAnchorLoading];
}
return ^(BaseModel *data, NSInteger code, NSString * _Nullable msg) {
if (loading) {
[self.view hideHUD];
}
if (code == 200) {
success(data);
return;
}
switch (code) {
case 401: //
[self logout];
return;
case 407:
case 408:
2024-12-11 10:48:01 +08:00
[self accountBanned:data];
2023-07-14 18:50:55 +08:00
return;
case 1415: //
[[self getView] completeUserInfo];
return;
case 3009: //
// [[self getView] accountCanceled:data.model2dictionary];
// return;
2023-07-14 18:50:55 +08:00
case 31005: {//
}
break;
case 30000: {// , toast
}
break;
2024-10-29 17:00:27 +08:00
case 10111: //
2023-07-14 18:50:55 +08:00
[self.view hideHUD];
[[self getView] showRealNameAuthenticationTipsAlertView];
return;
case 10108: //
[self.view hideHUD];
[[self getView] showRealNameAuthenticationTipsAlertView];
return;
case 25000: {//
}
}
2025-04-10 18:01:01 +08:00
if (toast && [self.view respondsToSelector:@selector(showErrorToast:)]) {
2023-07-14 18:50:55 +08:00
[self.view showErrorToast:msg];
}
if (fail) {
fail(code, msg);
}
};
}
- (void)detatchView {
}
2024-12-11 10:48:01 +08:00
- (void)accountBanned:(BaseModel *)data {
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = YMLocalizedString(@"MvpViewController6");
NSString *dateDes = [PLTimeUtil getDateWithYYMMDD:data.date];
NSString * title = [NSString stringWithFormat:YMLocalizedString(@"MvpViewController7"), data.reason,dateDes];
TTAlertMessageAttributedConfig * inviteAlertConfig = [[TTAlertMessageAttributedConfig alloc] init];
inviteAlertConfig.text = dateDes;
inviteAlertConfig.color = [DJDKMIMOMColor appMainColor];
inviteAlertConfig.font = [UIFont systemFontOfSize:15];
config.message = title;
config.messageAttributedConfig = @[inviteAlertConfig];
[TTPopup alertWithConfig:config confirmHandler:^{ } cancelHandler:^{ }];
}
- (void)tokenInvalid {
2025-03-14 19:43:04 +08:00
LoginViewController *loginVC = [[LoginViewController alloc] init];
2024-12-11 10:48:01 +08:00
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
kWindow.rootViewController = nav;
}
2023-07-14 18:50:55 +08:00
@end