KMVerificationMessageViewController.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. //
  2. // KMVerificationMessageViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 王帅 on 2018/5/9.
  6. //
  7. #import "KMVerificationMessageViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. #import "VerificationManager.h"
  10. #import "AIInfoManager.h"
  11. #import "KMVerificationWindowController.h"
  12. #import "KMUnlockAlertViewController.h"
  13. #define kbottomGap 0
  14. @interface KMVerificationMessageViewController ()<
  15. NSPopoverDelegate>
  16. @property (nonatomic, assign) IBOutlet NSTextField *label;
  17. @property (nonatomic, assign) IBOutlet NSButton *button;
  18. @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
  19. @property (assign) IBOutlet NSView *labelContentView;
  20. @property (assign) IBOutlet NSImageView *bgImg;
  21. @property (assign) IBOutlet NSView *aiContendView;
  22. @property (assign) IBOutlet NSImageView *aiIconImg;
  23. @property (assign) IBOutlet NSTextField *aiLabel;
  24. @property (weak) IBOutlet NSButton *userButton;
  25. @property (assign) IBOutlet NSView *signUpView;
  26. @property (assign) IBOutlet NSImageView *signUpImg;
  27. @property (assign) IBOutlet NSTextField *signUpLabel;
  28. @property (weak) IBOutlet NSButton *officeButton;
  29. @property (assign) IBOutlet NSImageView *officeImg;
  30. @property (nonatomic, retain) NSTrackingArea *trackingArea;
  31. @property (nonatomic, retain) NSPopover *popover;
  32. @property (nonatomic, assign) BOOL isPopoverShow;
  33. @property (nonatomic, assign) BOOL checkValue;
  34. @property (nonatomic, assign) BOOL stopPopOverHide;
  35. @property (nonatomic, retain) KMUnlockAlertViewController *testVC;
  36. @property (nonatomic, retain) NSMenu *userMenu;
  37. @end
  38. @implementation KMVerificationMessageViewController
  39. #pragma mark Init Methods
  40. - (instancetype)init {
  41. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  42. #if VERSION_DMG
  43. [[NSNotificationCenter defaultCenter] addObserver:self
  44. selector:@selector(deviceActivateStatusChangeNotification:)
  45. name:kDeviceActivateStatusChangeNotification
  46. object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self
  48. selector:@selector(deviceActivateStatusChangeNotification:)
  49. name:KMIAPSubscriptionLoadedNotification
  50. object:nil];
  51. #else
  52. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  55. #endif
  56. }
  57. return self;
  58. }
  59. - (void)dealloc {
  60. [[NSNotificationCenter defaultCenter] removeObserver:self];
  61. if (self.trackingArea) {
  62. [self.button removeTrackingArea:self.trackingArea];
  63. }
  64. }
  65. #pragma mark Setter Methods
  66. - (void)loadView {
  67. [super loadView];
  68. // Do view setup here.
  69. self.button.wantsLayer = YES;
  70. self.button.layer.masksToBounds = YES;
  71. self.button.layer.cornerRadius = 4.0;
  72. self.button.font = [NSFont SFProTextSemiboldFont:11];
  73. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  74. [self.button setAlignment:NSTextAlignmentCenter];
  75. self.userButton.font = [NSFont SFProTextSemiboldFont:11];
  76. self.secondTrialBtn.wantsLayer = YES;
  77. self.secondTrialBtn.layer.masksToBounds = YES;
  78. self.secondTrialBtn.layer.cornerRadius = 4.0;
  79. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  80. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  81. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  82. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  83. #if VERSION_DMG
  84. tTips = @"";
  85. #else
  86. tTips = [NSString stringWithFormat:@"%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil)];
  87. #endif
  88. self.button.toolTip = tTips;
  89. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  90. [self.button setTitleColor:[NSColor whiteColor]];
  91. [self.button setAlignment:NSTextAlignmentCenter];
  92. self.secondTrialBtn.toolTip = tTips;
  93. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  94. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  95. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  96. self.secondTrialBtn.hidden = YES;
  97. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  98. self.bgImg.wantsLayer = YES;
  99. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  100. self.bgImg.layer.masksToBounds = YES;
  101. self.bgImg.layer.cornerRadius = 4.;
  102. self.bgImg.hidden = YES;
  103. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  104. self.aiLabel.textColor = [NSColor whiteColor];
  105. [self reloadData];
  106. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  107. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  108. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  109. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  110. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  111. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memberInfoChangeNotification:) name:KMMemberInfoChangeNotification object:nil];
  112. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionLoadedNotification:) name:KMIAPSubscriptionLoadedNotification object:nil];
  113. }
  114. - (void)reloadData {
  115. self.label.textColor = [NSColor blackColor];
  116. self.label.hidden = NO;
  117. self.secondTrialBtn.hidden = YES;
  118. if (self.frameUpdateHandle) {
  119. self.frameUpdateHandle(self.view.frame);
  120. }
  121. CGFloat totalWidth = 8;
  122. self.button.hidden = NO;
  123. self.officeButton.hidden = NO;
  124. self.bgImg.hidden = NO;
  125. self.officeImg.hidden = NO;
  126. self.label.hidden = YES;
  127. self.secondTrialBtn.hidden = YES;
  128. self.labelContentView.hidden = YES;
  129. self.aiContendView.hidden = YES;
  130. self.userButton.hidden = YES;
  131. self.signUpView.hidden = YES;
  132. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  133. self.signUpLabel.font = [NSFont SFProTextSemiboldFont:11];
  134. [self.signUpLabel sizeToFit];
  135. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  136. signUpWidth += 4;
  137. signUpWidth += 8;
  138. signUpWidth += 8;
  139. signUpWidth += 12;
  140. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  141. CGRect signUplabelRect = self.signUpLabel.frame;
  142. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  143. self.signUpLabel.frame = signUplabelRect;
  144. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  145. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  146. [self.button setTitleColor:[NSColor whiteColor]];
  147. self.officeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  148. self.officeButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office", nil)];
  149. [self.officeButton setTitleColor:[NSColor whiteColor]];
  150. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"MemberCenterLocalizable", nil);
  151. [self.aiLabel sizeToFit];
  152. CGFloat aiWidth = self.aiLabel.frame.size.width;
  153. aiWidth += 4;
  154. aiWidth += 16;
  155. aiWidth += 16;
  156. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  157. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  158. CGRect ailabelRect = self.aiLabel.frame;
  159. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  160. self.aiLabel.frame = ailabelRect;
  161. // totalWidth+=aiWidth;
  162. // totalWidth+=4;
  163. // self.aiContendView.hidden = NO;
  164. CGFloat userImageWidth = 24;
  165. if ([KMMemberInfo shared].isLogin) {
  166. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  167. } else {
  168. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  169. }
  170. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  171. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  172. if (fabs(buttonWidth-btnRect.size.width)>50) {
  173. // buttonWidth = btnRect.size.width + 10;
  174. buttonWidth += 10;
  175. }
  176. CGFloat officeWidth = CGRectGetMaxX(self.officeButton.frame);
  177. NSRect officeRect = [self.officeButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.officeButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  178. if (fabs(officeWidth-officeRect.size.width)>50) {
  179. officeWidth = officeRect.size.width + 10;
  180. }
  181. #if VERSION_DMG
  182. self.button.hidden = YES;
  183. self.officeButton.hidden = YES;
  184. self.bgImg.hidden = YES;
  185. self.officeImg.hidden = YES;
  186. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  187. self.aiContendView.hidden = NO;
  188. totalWidth+=aiWidth;
  189. totalWidth+=4;
  190. }
  191. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  192. if (type == KMUserScenarioTypeDmg_type1 ||
  193. type == KMUserScenarioTypeDmg_type2 ||
  194. type == KMUserScenarioTypeDmg_type3 ||
  195. type == KMUserScenarioTypeDmg_type5 ||
  196. type == KMUserScenarioTypeDmg_type6 ||
  197. type == KMUserScenarioTypeDmg_type7 ||
  198. type == KMUserScenarioTypeDmg_type28 ||
  199. type == KMUserScenarioTypeDmg_type29 ||
  200. type == KMUserScenarioTypeDmg_type30 ||
  201. type == KMUserScenarioTypeDmg_type43 ||
  202. type == KMUserScenarioTypeDmg_type44 ||
  203. type == KMUserScenarioTypeDmg_type45) {
  204. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  205. } else if (type == KMUserScenarioTypeDmg_type4 ) {
  206. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  207. } else if (type == KMUserScenarioTypeDmg_type11 ||
  208. type == KMUserScenarioTypeDmg_type19 ||
  209. type == KMUserScenarioTypeDmg_type22 ||
  210. type == KMUserScenarioTypeDmg_type34 ||
  211. type == KMUserScenarioTypeDmg_type37 ) {
  212. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  213. } else if (type == KMUserScenarioTypeDmg_type18 ||
  214. type == KMUserScenarioTypeDmg_type33 ||
  215. type == KMUserScenarioTypeDmg_type48) {
  216. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  217. }
  218. if (type == KMUserScenarioTypeDmg_type2 ||
  219. type == KMUserScenarioTypeDmg_type19 ||
  220. type == KMUserScenarioTypeDmg_type20 ||
  221. type == KMUserScenarioTypeDmg_type21 ||
  222. type == KMUserScenarioTypeDmg_type22 ||
  223. type == KMUserScenarioTypeDmg_type30 ||
  224. type == KMUserScenarioTypeDmg_type31 ||
  225. type == KMUserScenarioTypeDmg_type32 ||
  226. type == KMUserScenarioTypeDmg_type33) {
  227. [self.officeButton setTitleColor:[NSColor whiteColor]];
  228. self.officeButton.hidden = NO;
  229. self.officeImg.hidden = NO;
  230. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  231. CGRect officeRect = self.officeButton.frame;
  232. self.officeImg.frame = officeRect;
  233. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  234. totalWidth+=4;
  235. }
  236. if (type == KMUserScenarioTypeDmg_type1 ||
  237. type == KMUserScenarioTypeDmg_type2 ||
  238. type == KMUserScenarioTypeDmg_type3 ||
  239. type == KMUserScenarioTypeDmg_type4 ||
  240. type == KMUserScenarioTypeDmg_type5 ||
  241. type == KMUserScenarioTypeDmg_type6 ||
  242. type == KMUserScenarioTypeDmg_type7 ||
  243. type == KMUserScenarioTypeDmg_type11 ||
  244. type == KMUserScenarioTypeDmg_type18 ||
  245. type == KMUserScenarioTypeDmg_type19 ||
  246. type == KMUserScenarioTypeDmg_type22 ||
  247. type == KMUserScenarioTypeDmg_type28 ||
  248. type == KMUserScenarioTypeDmg_type29 ||
  249. type == KMUserScenarioTypeDmg_type30 ||
  250. type == KMUserScenarioTypeDmg_type33 ||
  251. type == KMUserScenarioTypeDmg_type34 ||
  252. type == KMUserScenarioTypeDmg_type37 ||
  253. type == KMUserScenarioTypeDmg_type43 ||
  254. type == KMUserScenarioTypeDmg_type44 ||
  255. type == KMUserScenarioTypeDmg_type45 ||
  256. type == KMUserScenarioTypeDmg_type48) {
  257. [self.button setTitleColor:[NSColor whiteColor]];
  258. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  259. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  260. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  261. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  262. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  263. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  264. __weak typeof(self)weakSelf = self;
  265. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  266. if (image != nil) {
  267. weakSelf.bgImg.image = image;
  268. }
  269. }];
  270. }
  271. }
  272. self.bgImg.hidden = NO;
  273. self.button.hidden = NO;
  274. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  275. CGRect rect = self.button.frame;
  276. self.bgImg.frame = rect;
  277. totalWidth+=CGRectGetWidth(self.button.bounds);
  278. totalWidth+=4;
  279. }
  280. #else
  281. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  282. #if VERSION_FREE
  283. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_lite.isTrialPeriod == false) {
  284. self.aiContendView.hidden = NO;
  285. totalWidth+=aiWidth;
  286. totalWidth+=4;
  287. }
  288. #else
  289. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  290. self.aiContendView.hidden = NO;
  291. totalWidth+=aiWidth;
  292. totalWidth+=4;
  293. }
  294. #endif
  295. }
  296. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  297. if (type == KMUserScenarioTypeLite_type1 ||
  298. type == KMUserScenarioTypeLite_type3 ||
  299. type == KMUserScenarioTypeLite_type5 ||
  300. type == KMUserScenarioTypeLite_type7 ||
  301. type == KMUserScenarioTypeLite_type9 ||
  302. type == KMUserScenarioTypeLite_type11 ||
  303. type == KMUserScenarioTypePro_type1 ||
  304. type == KMUserScenarioTypePro_type3 ||
  305. type == KMUserScenarioTypePro_type4) {
  306. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  307. #if !VERSION_DMG
  308. if(KMMemberInfo.shared.isLogin == NO) {
  309. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  310. } else {
  311. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  312. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  313. } else {
  314. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  315. }
  316. }
  317. #else
  318. #endif
  319. } else if (type == KMUserScenarioTypeLite_type3 ) {
  320. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  321. } else if (type == KMUserScenarioTypeLite_type5) {
  322. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  323. } else if (type == KMUserScenarioTypeLite_type7) {
  324. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  325. } else if (type == KMUserScenarioTypeLite_type9) {
  326. if([KMMemberInfo shared].vip_status == 2) {
  327. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  328. } else if ([KMMemberInfo shared].vip_status == 4) {
  329. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  330. } else {
  331. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  332. }
  333. } else if (type == KMUserScenarioTypeLite_type11) {
  334. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  335. } else if (type == KMUserScenarioTypePro_type3) {
  336. if([KMMemberInfo shared].vip_status == 2) {
  337. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  338. } else {
  339. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  340. }
  341. }
  342. #if !VERSION_FREE
  343. BOOL isNoSupportMemberUpgrade = YES;
  344. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  345. isNoSupportMemberUpgrade = NO;
  346. }
  347. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  348. [self.officeButton setTitleColor:[NSColor whiteColor]];
  349. self.officeButton.hidden = NO;
  350. self.officeImg.hidden = NO;
  351. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  352. CGRect officeRect = self.officeButton.frame;
  353. self.officeImg.frame = officeRect;
  354. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  355. totalWidth+=4;
  356. } else {
  357. self.officeButton.hidden = YES;
  358. self.officeImg.hidden = YES;
  359. }
  360. #else
  361. self.officeButton.hidden = YES;
  362. self.officeImg.hidden = YES;
  363. #endif
  364. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  365. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  366. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  367. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  368. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  369. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  370. __weak typeof(self)weakSelf = self;
  371. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  372. if (image != nil) {
  373. weakSelf.bgImg.image = image;
  374. }
  375. }];
  376. }
  377. }
  378. [self.button setTitleColor:[NSColor whiteColor]];
  379. self.bgImg.hidden = NO;
  380. self.button.hidden = NO;
  381. BOOL isOldSubscribed = NO;
  382. #if VERSION_FREE
  383. #if !VERSION_DMG
  384. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  385. #endif
  386. #endif
  387. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  388. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  389. if(type == KMUserScenarioTypeLite_type9 ||
  390. type == KMUserScenarioTypeLite_type10 ||
  391. type == KMUserScenarioTypeLite_type11) {
  392. if([KMMemberInfo shared].isLogin == NO) { //未登录
  393. self.button.hidden = YES;
  394. self.bgImg.hidden = YES;
  395. } else {
  396. if(isOldSubscribed) { //老版本付费功能是订阅包
  397. self.button.hidden = YES;
  398. self.bgImg.hidden = YES;
  399. } else {
  400. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  401. self.button.hidden = YES;
  402. self.bgImg.hidden = YES;
  403. }
  404. }
  405. }
  406. }
  407. buttonWidth = CGRectGetWidth(self.button.frame);
  408. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  409. if (fabs(buttonWidth-btnRect.size.width)>50) {
  410. // buttonWidth = btnRect.size.width + 10;
  411. buttonWidth += 10;
  412. }
  413. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  414. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  415. buttonWidth += 10;
  416. }
  417. }
  418. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  419. CGRect rect = self.button.frame;
  420. self.bgImg.frame = rect;
  421. totalWidth+=CGRectGetWidth(self.button.bounds);
  422. totalWidth+=4;
  423. } else if (type == KMUserScenarioTypeLite_type12 ||
  424. type == KMUserScenarioTypeLite_type13 ||
  425. type == KMUserScenarioTypeLite_type2 ||
  426. type == KMUserScenarioTypeLite_type4 ||
  427. type == KMUserScenarioTypeLite_type6 ||
  428. type == KMUserScenarioTypeLite_type8 ||
  429. type == KMUserScenarioTypePro_type2 ||
  430. type == KMUserScenarioTypePro_type5) {
  431. self.button.hidden = YES;
  432. self.bgImg.hidden = YES;
  433. #if !VERSION_FREE
  434. BOOL isNoSupportMemberUpgrade = YES;
  435. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  436. isNoSupportMemberUpgrade = NO;
  437. }
  438. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  439. [self.officeButton setTitleColor:[NSColor whiteColor]];
  440. self.officeButton.hidden = NO;
  441. self.officeImg.hidden = NO;
  442. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  443. CGRect officeRect = self.officeButton.frame;
  444. self.officeImg.frame = officeRect;
  445. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  446. totalWidth+=4;
  447. } else {
  448. self.officeButton.hidden = YES;
  449. self.officeImg.hidden = YES;
  450. }
  451. #else
  452. self.officeButton.hidden = YES;
  453. self.officeImg.hidden = YES;
  454. #endif
  455. }
  456. #endif
  457. if ([KMMemberInfo shared].isLogin) {
  458. self.userButton.hidden = NO;
  459. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  460. totalWidth += userImageWidth;
  461. totalWidth += 8;
  462. } else {
  463. self.signUpView.hidden = NO;
  464. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  465. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  466. }
  467. self.view.frame = CGRectMake(MAX(0, CGRectGetWidth(self.view.superview.frame)-totalWidth - 8), (CGRectGetHeight(self.view.superview.frame)-CGRectGetHeight(self.view.frame))/2., totalWidth, self.view.frame.size.height);
  468. }
  469. #pragma mark - Button Actions
  470. - (IBAction)secondTrialAction:(NSButton *)sender {
  471. if ([VerificationManager manager].secondTrialEnabled) {
  472. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  473. [vc showWindow:nil];
  474. } else {
  475. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  476. }
  477. }
  478. - (IBAction)buttonAction:(id)sender {
  479. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  480. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  481. if ([KMMemberInfo shared].isLogin) {
  482. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  483. [[KMProductCompareWC shared] setOrientation:YES];
  484. #if VERSION_FREE
  485. #if VERSION_DMG
  486. // DMG
  487. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  488. #else
  489. // AppStore 免费版本
  490. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  491. #endif
  492. #else
  493. // AppStore 付费版
  494. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  495. #endif
  496. [[KMProductCompareWC shared] showWindow:nil];
  497. } else {
  498. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  499. }
  500. } else {
  501. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  502. if (success) {
  503. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  504. [[KMProductCompareWC shared] setOrientation:YES];
  505. #if VERSION_FREE
  506. #if VERSION_DMG
  507. // DMG
  508. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  509. #else
  510. // AppStore 免费版本
  511. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  512. #endif
  513. #else
  514. // AppStore 付费版
  515. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  516. #endif
  517. [[KMProductCompareWC shared] showWindow:nil];
  518. } else {
  519. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  520. }
  521. }
  522. }];
  523. }
  524. } else {
  525. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  526. if (type == KMUserScenarioTypeDmg_type4) {
  527. if ([KMMemberInfo shared].isLogin) {
  528. [[KMProductCompareWC shared] setOrientation:YES];
  529. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  530. [[KMProductCompareWC shared] showWindow:nil];
  531. } else {
  532. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  533. if (success) {
  534. [[KMProductCompareWC shared] setOrientation:YES];
  535. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  536. [[KMProductCompareWC shared] showWindow:nil];
  537. }
  538. }];
  539. }
  540. } else {
  541. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  542. }
  543. }
  544. } else {
  545. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  546. if (type == KMUserScenarioTypeDmg_type4) {
  547. if ([KMMemberInfo shared].isLogin) {
  548. [[KMProductCompareWC shared] setOrientation:YES];
  549. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  550. [[KMProductCompareWC shared] showWindow:nil];
  551. } else {
  552. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  553. if (success) {
  554. [[KMProductCompareWC shared] setOrientation:YES];
  555. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  556. [[KMProductCompareWC shared] showWindow:nil];
  557. }
  558. }];
  559. }
  560. } else {
  561. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  562. }
  563. }
  564. }
  565. - (IBAction)officeButtonAction:(id)sender {
  566. #if VERSION_FREE
  567. #if VERSION_DMG
  568. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  569. [embeddedWC showWindow:nil];
  570. [embeddedWC.window center];
  571. #endif
  572. #else
  573. if ([KMMemberInfo shared].isLogin) {
  574. [[KMMemberInfo shared] productCompareShow];
  575. } else {
  576. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  577. if (success) {
  578. [[KMMemberInfo shared] productCompareShow];
  579. }
  580. }];
  581. }
  582. #endif
  583. }
  584. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  585. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  586. NSString *temp = nil;
  587. for (NSUInteger i = 0; i <string.length; i++) {
  588. temp = [string substringWithRange:NSMakeRange(i, 1)];
  589. if ([self isPureInt:temp]) {
  590. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  591. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  592. }
  593. }
  594. return attributedString;
  595. }
  596. - (BOOL)isPureInt:(NSString *)string {
  597. NSScanner *scan = [NSScanner scannerWithString:string];
  598. int value;
  599. return [scan scanInt:&value] && [scan isAtEnd];
  600. }
  601. - (IBAction)AIButtonAction:(NSButton *)sender {
  602. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  603. [[KMMemberPromptWC shared] showWindow:sender];
  604. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  605. } else {
  606. #if VERSION_FREE
  607. #if VERSION_DMG
  608. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  609. [winC showWindow:nil];
  610. [winC.window center];
  611. #else
  612. [[KMFreeGetAIWC shared] showWindow:nil];
  613. #endif
  614. #else
  615. [[KMFreeGetAIWC shared] showWindow:nil];
  616. #endif
  617. }
  618. }
  619. - (IBAction)userButtonAction:(NSButton *)sender {
  620. if ([KMMemberInfo shared].isLogin) {
  621. [self personalCenterAction:sender];
  622. } else {
  623. [KMLoginWindowsController.shared showWindow:nil];
  624. }
  625. }
  626. - (IBAction)personalCenterAction:(NSButton *)sender {
  627. if (![KMCloudServer isConnectionAvailable]) {
  628. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  629. defaultButton:NSLocalizedString(@"OK", nil)
  630. alternateButton:nil
  631. otherButton:nil
  632. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  633. [alert runModal];
  634. return;
  635. }
  636. // 用户头像点击事件
  637. self.userMenu = [[NSMenu alloc] init];
  638. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  639. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  640. item.target = self;
  641. item.representedObject = userInfo;
  642. item.view = userInfo.view;
  643. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  644. }
  645. - (IBAction)signUpAction:(NSButton *)sender {
  646. [KMLoginWindowsController.shared showWindow:nil];
  647. }
  648. #pragma mark - NSNotification Methods
  649. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  650. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  651. [self reloadData];
  652. });
  653. }
  654. - (void)IAPResultReceived:(NSNotification *)notification {
  655. dispatch_async(dispatch_get_main_queue(), ^{
  656. [self reloadData];
  657. });
  658. }
  659. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  660. dispatch_async(dispatch_get_main_queue(), ^{
  661. [self reloadData];
  662. });
  663. }
  664. - (void)IAPRestoreFinish:(NSNotification *)notification {
  665. dispatch_async(dispatch_get_main_queue(), ^{
  666. [self reloadData];
  667. });
  668. }
  669. #pragma mark - Event
  670. - (void)mouseEntered:(NSEvent *)event {
  671. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  672. ActivityStatusTrial == [VerificationManager manager].status) {
  673. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  674. if (!self.popover.isShown) {
  675. [self buttonAction:self.button];
  676. }
  677. }
  678. }
  679. - (void)mouseExited:(NSEvent *)event {
  680. [super mouseExited:event];
  681. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  682. }
  683. - (void)popoverDidClose:(NSNotification *)notification {
  684. self.stopPopOverHide = NO;
  685. }
  686. - (void)popoverShowNoti:(NSNotification *)noti {
  687. if (self.popover) {
  688. [self.popover close];
  689. self.stopPopOverHide = NO;
  690. }
  691. }
  692. - (void)loginSuccessNotification:(NSNotification *)noti {
  693. dispatch_async(dispatch_get_main_queue(), ^{
  694. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  695. [self reloadData];
  696. });
  697. }
  698. - (void)logoutSuccessNotification:(NSNotification *)noti {
  699. dispatch_async(dispatch_get_main_queue(), ^{
  700. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  701. [self reloadData];
  702. });
  703. }
  704. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  705. if (self.userMenu != nil) {
  706. [self personalCenterAction:_userButton];
  707. }
  708. }
  709. - (void)closeMenu:(NSNotification *)noti {
  710. if (self.userMenu != nil) {
  711. [self.userMenu cancelTracking];
  712. self.userMenu = nil;
  713. }
  714. }
  715. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  716. dispatch_async(dispatch_get_main_queue(), ^{
  717. [self reloadData];
  718. });
  719. }
  720. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  721. dispatch_async(dispatch_get_main_queue(), ^{
  722. [self reloadData];
  723. });
  724. }
  725. - (void)popOverCloseAction {
  726. if (self.stopPopOverHide == NO) {
  727. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  728. ActivityStatusTrial == [VerificationManager manager].status) {
  729. if (self.popover.isShown) {
  730. [self.popover close];
  731. self.stopPopOverHide = NO;
  732. }
  733. }
  734. }
  735. }
  736. @end