//
//  std.h
//  IOSDuoduo
//
//  Created by 东邪 on 14-5-23.
//  Copyright (c) 2014年 dujia. All rights reserved.
//
/**
 *  系统字体调整
 */
typedef enum{
    FontTypeChooseLarger = 1,
    FontTypeChooseSmail = 0//默认为小字体
}FontTypeChoose;
#import <Foundation/Foundation.h>
//#import "XLog.h"
#import "Utils.h"
#import "MD5.h"
#import "SettingUserDefaultKey.h"
#import "GlobalData.h"
#import "HostConfig.h"
#import "NSString+Additions.h"
#import "CoreDataSelectStatusModel.h"
#import "GeneralSetting.h"

#define USERDEFAULT_APP_NAME (@"USERDEFAULT_APP_NAME")
#define USERDEFAULT_USER_NAME (@"USERDEFAULT_USER_NAME")
#define USERDEFAULT_LOGIN_NAME (@"USERDEFAULT_LOGIN_NAME")
#define USERDEFAULT_USER_ID (@"USERDEFAULT_USER_ID")
#define USERDEFAULT_PASSWORD (@"USERDEFAULT_PASSWORD")
#define USERDEFAULT_SERVER_ID (@"USERDEFAULT_SERVER_ID")
#define USERDEFAULT_APP_TOKEN (@"USERDEFAULT_APP_TOKEN")
#define USERDEFAULT_ROOT_NAME (@"USERDEFAULT_ROOT_NAME")

//联系人VC 单位 全市（服务端 rootName） 通讯录
#define ROOT_NAME [userDefaults objectForKey:USERDEFAULT_ROOT_NAME]
#define USERDEFAULT_REMBER_LOGIN_NAME (@"USERDEFAULT_REMBER_LOGIN_NAME")
//
#define USERDEFAULT_NEW_VERSION (@"USERDEFAULT_NEW_VERSION")
//#define APP_NAME (@"办公微助手")
#define APP_NAME [userDefaults objectForKey:USERDEFAULT_APP_NAME]

#define DEFAULT_AVATAR ([UIImage imageNamed:@"avatar"])


#define TICK   NSDate *startTime = [NSDate date];
#define TOCK   NSLog(@"Time: %f ms", -[startTime timeIntervalSinceNow] * 1000);

#define objectOrNull(obj) ((obj) ? (obj) : [NSNull null])
#define objectOrEmptyStr(obj) ((obj) ? (obj) : @"")

#define isNull(x)             (!x || [x isKindOfClass:[NSNull class]])
#define toInt(x)              (isNull(x) ? 0 : [x intValue])
#define isEmptyString(x)      (isNull(x) || [x isEqual:@""] || [x isEqual:@"(null)"])

#define sleep(s);             [NSThread sleepForTimeInterval:s];
#define Syn(x)                @synthesize x = _##x

#define LineForDrawColor [UIColor lightGrayColor]
#define LineForSubLineViewColor RGB(214, 215, 217)

#define RGBA(r,g,b,a)         [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
#define RGB(r,g,b)            [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
#define SahreColorRGB(r,g,b)  [UIColor colorWithRed:r green:g blue:b alpha:1.000]
#define BoldSystemFont(size)  [UIFont boldSystemFontOfSize:size]
#define systemFont(size)      [UIFont systemFontOfSize:size]
#define beginAutoPool         NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; {
#define endAutoPool           } [pool release];
#define skipspace(c)          while (isspace(*c)) ++c
#define skipUntil(c,x)        while (x != *c) ++c
#define TheWindowHeight      ([UIDevice isAfterOS7] ? [UIScreen mainScreen].bounds.size.height : ([UIScreen mainScreen].bounds.size.height - 20))
#define IntToNumber(int)        ([NSNumber numberWithInt:int])
#define isIOS7 [[UIDevice currentDevice].systemVersion doubleValue]>=7.0?YES:NO
#define isIOS8 [[UIDevice currentDevice].systemVersion doubleValue]>=8.0?YES:NO
#define SYSTEM_VERSION        [[[UIDevice currentDevice] systemVersion] floatValue]
#define STATUSBAR_HEIGHT      [[UIApplication sharedApplication] statusBarFrame].size.height
#define NAVBAR_HEIGHT         ((SYSTEM_VERSION >= 7) ? 44 : 20)
#define FULL_WIDTH            SCREEN_WIDTH
#define FULL_HEIGHT           (SCREEN_HEIGHT - ((SYSTEM_VERSION >= 7) ? 0 : STATUSBAR_HEIGHT))
#define CONTENT_HEIGHT        (FULL_HEIGHT - NAVBAR_HEIGHT)
// 屏幕高度
#define SCREEN_HEIGHT         [[UIScreen mainScreen] bounds].size.height

// 屏幕宽度
#define SCREEN_WIDTH          [[UIScreen mainScreen] bounds].size.width

//([[NSString documentPath] stringByAppendingPathComponent:@"/PhotosMessageDir/"])
#define IPHONE4 ( [ [ UIScreen mainScreen ] bounds ].size.height == 480 )
//字体颜色
#define GRAYCOLOR RGB(137, 139, 144)



#define FileManager     ([NSFileManager defaultManager])
#define TheUserDefaults ([NSUserDefaults standardUserDefaults])
#define VoiceMessageDir ([[NSString documentPath] stringByAppendingPathComponent:@"/VoiceMessageDir/"])
#define BlacklistDir ([[NSString documentPath] stringByAppendingPathComponent:@"/BlacklistDir/"])
#define Departmentlist ([[NSString documentPath] stringByAppendingPathComponent:@"/department.plist"])
#define fixedlist ([[NSString documentPath] stringByAppendingPathComponent:@"/fixed.plist"])
#define shieldinglist ([[NSString documentPath] stringByAppendingPathComponent:@"/shieldingArray.plist"])
#define TheBundleVerison (bundleVerison())
#undef	AS_SINGLETON
#define AS_SINGLETON( __class ) \
+ (__class *)sharedInstance;

#undef	DEF_SINGLETON
#define DEF_SINGLETON( __class ) \
+ (__class *)sharedInstance \
{ \
static dispatch_once_t once; \
static __class * __singleton__; \
dispatch_once( &once, ^{ __singleton__ = [[__class alloc] init]; } ); \
return __singleton__; \
}
#define userDefaults     [NSUserDefaults standardUserDefaults]
#define Server_ID        [userDefaults objectForKey:USERDEFAULT_SERVER_ID]

//#define FontTypeUserDetaultKey @"FontTypeUserDetaultKey"
//#define FontTypeUserDetaultValue [userDefaults objectForKey:FontTypeUserDetaultKey]
//#define SetFontTypeUserDefault(FontTypeChoose) [userDefaults setObject:@(FontTypeChoose) forKey:FontTypeUserDetaultKey]

/**
 *  动态返回字体Font
 *
 *  @param LargeFont 大字体
 *  @param SmailFont 小字体
 *
 *  @return 最终Font
 */
//#define FontType(LargeFloatFont,SmailFloatFont)  [FontTypeUserDetaultValue intValue] == FontTypeChooseLarger?[UIFont systemFontOfSize:LargeFloatFont]:[UIFont systemFontOfSize:SmailFloatFont]
#define FontType(LargeFloatFont,SmailFloatFont)  [GeneralSetting returnGeneralSetting].appFontModel.intValue == FontTypeChooseLarger?[UIFont systemFontOfSize:LargeFloatFont]:[UIFont systemFontOfSize:SmailFloatFont]

//#define FontTypeWithFontName(FontName,LargeFloatFont,SmailFloatFont) [FontTypeUserDetaultValue intValue] == FontTypeChooseLarger?[UIFont fontWithName:FontName size:LargeFloatFont]:[UIFont fontWithName:FontName size:SmailFloatFont]

#define FontTypeWithFontName(FontName,LargeFloatFont,SmailFloatFont) [GeneralSetting returnGeneralSetting].appFontModel.intValue  == FontTypeChooseLarger?[UIFont fontWithName:FontName size:LargeFloatFont]:[UIFont fontWithName:FontName size:SmailFloatFont]
//User_Name格式 : serverId-loginName
#define User_Name        [userDefaults objectForKey:USERDEFAULT_USER_NAME]
#define Login_Word       [userDefaults objectForKey: USERDEFAULT_PASSWORD]
#define User_ID        [userDefaults objectForKey:USERDEFAULT_USER_ID]
#define Login_Name        [userDefaults objectForKey:USERDEFAULT_LOGIN_NAME]
#define SESSION_ID(serverId, loginName)    [NSString stringWithFormat:@"%@-%@",serverId,loginName]
//获取服务器编号和+,如0578+
#define ContentServerID(userdefault_serverId)    [NSString stringWithFormat:@"%@+",[userDefaults objectForKey:userdefault_serverId]]
#define GET_LOGIN_NAME [userDefaults objectForKey:USERDEFAULT_REMBER_LOGIN_NAME]

/**
 *  文件相关的绝对路径.
 */
#define FileAbsoluteSaveRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@",@"Library",Login_Name]]
#define CloudStorageFullRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"cloudstorage"]]
#define FileFolderFullRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"file"]]
#define VoiceFolderFullRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"voice"]]
#define PhotosMessageDir  [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"photo"]]
/**
 *  检查字典中是否有该key
 *
 *  @param A 字典
 *  @param B key
 *
 *  @return 字典A中是否包含key为B的内容
 */
#define CheckDictionaryKey(A,B) ((!!A)&&(![A isKindOfClass:[NSNull class]])&&A.count>0&&[A.allKeys containsObject:B]&&(![[A objectForKey:B] isKindOfClass:[NSNull class]]))

#define DateStringFromDictionary(DIC,KEY) ([Utils getDateFromString:[DIC objectForKey:KEY]])
#define DateFromSecDic(DIC,KEY) ([Utils getDateFromNumber:[DIC objectForKey:KEY]])

//通过key 从字典中获取对象
#define Dictionary2Object(DIC,KEY,OBJ) if (CheckDictionaryKey(DIC, KEY)) { \
OBJ = [DIC objectForKey:KEY];\
}

#define Dictionary2TimeObject(DIC,KEY,OBJ) if (CheckDictionaryKey(DIC, KEY)) { \
if ([[DIC objectForKey:KEY ] isKindOfClass:[NSString class]]) {\
OBJ = DateStringFromDictionary(DIC, KEY);\
}else{\
OBJ = DateFromSecDic(DIC, KEY);\
}\
}


#define CURRENT_VERSION [[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"]
//AppDelegate
#define APPDELEGATE (AppDelegate*)[[UIApplication sharedApplication] delegate]
@protocol DDShareObjDelegate <NSObject>

- (NSString*)shareTypeName;

@end
char pinyinFirstLetter(unsigned short hanzi);
char getFirstChar(const NSString * str);
