Initial commit
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
//
|
||||
// IfishUserObsever.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 17/3/3.
|
||||
// Copyright © 2017年 lianlian. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IfishUserObsever.h"
|
||||
#import "IfishLevelUpView.h"
|
||||
#import "IfishHelperUtils.h"
|
||||
#import "IfishUserDefaultHelper.h"
|
||||
#import "IfishGoldAndExpTostView.h"
|
||||
#import "IifishGetGoldTaskHelper.h"
|
||||
#import "IifshGetExpHelper.h"
|
||||
@implementation IfishUserObsever
|
||||
+ (IfishUserObsever *)sharedInstance
|
||||
{
|
||||
static IfishUserObsever *sharedInstace = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
|
||||
sharedInstace = [[self alloc] init];
|
||||
sharedInstace.userAsset = [dataContorl getAllIfishUserAsset];
|
||||
});
|
||||
|
||||
return sharedInstace;
|
||||
}
|
||||
|
||||
//备用KVO
|
||||
-(void)userAssetAddObserver
|
||||
{
|
||||
//self.userAsset = [dataContorl getAllIfishUserAsset];
|
||||
//[self.userAsset addObserver:self forKeyPath:@"gradeNum" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
|
||||
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
|
||||
if([keyPath isEqualToString:@"gradeNum"])
|
||||
{
|
||||
//NSString *newValue = change[@"new"];
|
||||
//BOOL isUP = [IfishHelperUtils diagnoseLevelIsUp:newValue];
|
||||
//if (isUP) {
|
||||
// [self addAdViewWith:newValue];
|
||||
//}
|
||||
|
||||
NSLog(@"change**************%@",change);
|
||||
}
|
||||
}
|
||||
|
||||
-(void)showLevelUpWith:(NSString*)newValue{
|
||||
|
||||
IfishLevelUpView *levelUpView =[[IfishLevelUpView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
|
||||
levelUpView.imgName = [IfishHelperUtils getLeveloacalImgName:newValue];
|
||||
|
||||
[[UIApplication sharedApplication].keyWindow addSubview:levelUpView];
|
||||
}
|
||||
|
||||
-(void)dealloc{
|
||||
//[self.userAsset removeObserver:self forKeyPath:@"gradeNum"];
|
||||
}
|
||||
|
||||
//增加经验
|
||||
-(void)xinZengJingYanZhi:(NSString *)ruleTyp addType:(NSString*)addType
|
||||
{
|
||||
// 每日加经验接口是否调用 一次性加经验不做处理直接请求
|
||||
|
||||
if ([addType isEqualToString:IFISHADDEXPTYPE0]) {
|
||||
BOOL iscanAdd = [IfishHelperUtils dignoseIsAddExpToday:ruleTyp];
|
||||
if (!iscanAdd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NSString *userId =[dataContorl dataControlGetUserIdInfo];
|
||||
__weak typeof (self) weakself = self;
|
||||
[AFHttpTool addLevelValueWith:userId ruleType:ruleTyp success:^(id response) {
|
||||
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
||||
|
||||
if ([reDic[@"result"] isEqualToString:@"100"]){
|
||||
NSDictionary *data=reDic[@"data"];
|
||||
|
||||
if (![data isKindOfClass:[NSNull class]]&&data) {
|
||||
IfishUserAsset *userAsset = [[IfishUserAsset alloc] initWithDict:data];
|
||||
[dataContorl resetUserAsset:userAsset];
|
||||
//每日加经验 完成后 mark 一下
|
||||
if ([addType isEqualToString:IFISHADDEXPTYPE0]) {
|
||||
[IifshGetExpHelper everyDayExpMark:userAsset.lastLoginDate withRuleType:ruleTyp];
|
||||
}
|
||||
|
||||
NSString *oldGradeNum = [IfishUserDefaultHelper getDefualtGradNum];
|
||||
NSString *gradeNum = userAsset.gradeNum;
|
||||
NSLog(@"oldGradeNum%@",oldGradeNum);
|
||||
|
||||
//加经验 tost
|
||||
NSString *addvalue = [NSString stringWithFormat:@"%ld",(long)userAsset.addValue];
|
||||
//一次性任务 addValue 0 不show
|
||||
if (userAsset.addValue !=0) {
|
||||
[weakself showAddExp:addvalue];
|
||||
}
|
||||
|
||||
if ([oldGradeNum intValue]<[gradeNum intValue]){
|
||||
[weakself showLevelUpWith:gradeNum];
|
||||
[IfishUserDefaultHelper chageLevlelGrad:gradeNum];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"添加经验请求出错"];
|
||||
}
|
||||
|
||||
} failure:^(NSError *err) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)addGoldWith:(NSString *)ruleType addType:(NSString*)addType
|
||||
{
|
||||
//判断是否今天任务 每日任务判断 是否完成 一次性任务不做处理直接请求
|
||||
if ([addType isEqualToString:IFISHADDGOLDTYPE0]) {
|
||||
BOOL iscanAdd = [IfishHelperUtils dignoseIsRequestDataToday:ruleType];
|
||||
if (!iscanAdd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NSString *userId =[dataContorl dataControlGetUserIdInfo];
|
||||
__weak typeof (self) weakself = self;
|
||||
[AFHttpTool addGoldValue:userId ruleType:ruleType success:^(id response) {
|
||||
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
||||
|
||||
if ([reDic[@"result"] isEqualToString:@"100"]){
|
||||
NSDictionary *data=reDic[@"data"];
|
||||
if (![data isKindOfClass:[NSNull class]]&&data) {
|
||||
|
||||
IfishUserAsset *userAsset = [[IfishUserAsset alloc] initWithDict:data];
|
||||
[dataContorl resetUserAsset:userAsset];
|
||||
//每日任务 完成后 mark 一下 保证每日一次
|
||||
NSString *date = userAsset.lastLoginDate;
|
||||
if ([addType isEqualToString:IFISHADDGOLDTYPE0]) {
|
||||
[IifishGetGoldTaskHelper everyDayTaskMark:date withRuleType:ruleType];
|
||||
}
|
||||
|
||||
//加金币 tost
|
||||
NSString *addvalue = [NSString stringWithFormat:@"%ld",(long)userAsset.addValue];
|
||||
// addValue 0 不show
|
||||
if (userAsset.addValue !=0) {
|
||||
|
||||
[weakself showAddGoldWith:addvalue];
|
||||
//更新任务列表数据 签到的数据在签到接口中处理
|
||||
[IfishHelperUtils updateTask:ruleType];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"添加金币请求出错"];
|
||||
}
|
||||
} failure:^(NSError *err) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)showAddGoldWith:(NSString *)addValue
|
||||
{
|
||||
IfishGoldAndExpTostView *levelUpView =[[IfishGoldAndExpTostView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
|
||||
[[UIApplication sharedApplication].keyWindow addSubview:levelUpView];
|
||||
[levelUpView showGoldToastView:addValue];
|
||||
|
||||
}
|
||||
|
||||
-(void)showAddExp:(NSString *)addValue
|
||||
{
|
||||
|
||||
IfishGoldAndExpTostView *levelUpView =[[IfishGoldAndExpTostView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
|
||||
[[UIApplication sharedApplication].keyWindow addSubview:levelUpView];
|
||||
[levelUpView showExpTostView:addValue];
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user