KMVerificationMessageViewController.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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. }
  175. CGFloat officeWidth = CGRectGetMaxX(self.officeButton.frame);
  176. NSRect officeRect = [self.officeButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.officeButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  177. if (fabs(officeWidth-officeRect.size.width)>50) {
  178. officeWidth = officeRect.size.width + 10;
  179. }
  180. #if VERSION_DMG
  181. self.button.hidden = YES;
  182. self.officeButton.hidden = YES;
  183. self.bgImg.hidden = YES;
  184. self.officeImg.hidden = YES;
  185. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  186. self.aiContendView.hidden = NO;
  187. totalWidth+=aiWidth;
  188. totalWidth+=4;
  189. }
  190. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  191. if (type == KMUserScenarioTypeDmg_type1 ||
  192. type == KMUserScenarioTypeDmg_type2 ||
  193. type == KMUserScenarioTypeDmg_type3 ||
  194. type == KMUserScenarioTypeDmg_type5 ||
  195. type == KMUserScenarioTypeDmg_type6 ||
  196. type == KMUserScenarioTypeDmg_type7 ||
  197. type == KMUserScenarioTypeDmg_type28 ||
  198. type == KMUserScenarioTypeDmg_type29 ||
  199. type == KMUserScenarioTypeDmg_type30 ||
  200. type == KMUserScenarioTypeDmg_type43 ||
  201. type == KMUserScenarioTypeDmg_type44 ||
  202. type == KMUserScenarioTypeDmg_type45) {
  203. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  204. } else if (type == KMUserScenarioTypeDmg_type4 ) {
  205. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  206. } else if (type == KMUserScenarioTypeDmg_type11 ||
  207. type == KMUserScenarioTypeDmg_type19 ||
  208. type == KMUserScenarioTypeDmg_type22 ||
  209. type == KMUserScenarioTypeDmg_type34 ||
  210. type == KMUserScenarioTypeDmg_type37 ) {
  211. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  212. } else if (type == KMUserScenarioTypeDmg_type18 ||
  213. type == KMUserScenarioTypeDmg_type33 ||
  214. type == KMUserScenarioTypeDmg_type48) {
  215. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  216. }
  217. if (type == KMUserScenarioTypeDmg_type2 ||
  218. type == KMUserScenarioTypeDmg_type19 ||
  219. type == KMUserScenarioTypeDmg_type20 ||
  220. type == KMUserScenarioTypeDmg_type21 ||
  221. type == KMUserScenarioTypeDmg_type22 ||
  222. type == KMUserScenarioTypeDmg_type30 ||
  223. type == KMUserScenarioTypeDmg_type31 ||
  224. type == KMUserScenarioTypeDmg_type32 ||
  225. type == KMUserScenarioTypeDmg_type33) {
  226. [self.officeButton setTitleColor:[NSColor whiteColor]];
  227. self.officeButton.hidden = NO;
  228. self.officeImg.hidden = NO;
  229. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  230. CGRect officeRect = self.officeButton.frame;
  231. self.officeImg.frame = officeRect;
  232. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  233. totalWidth+=4;
  234. }
  235. if (type == KMUserScenarioTypeDmg_type1 ||
  236. type == KMUserScenarioTypeDmg_type2 ||
  237. type == KMUserScenarioTypeDmg_type3 ||
  238. type == KMUserScenarioTypeDmg_type4 ||
  239. type == KMUserScenarioTypeDmg_type5 ||
  240. type == KMUserScenarioTypeDmg_type6 ||
  241. type == KMUserScenarioTypeDmg_type7 ||
  242. type == KMUserScenarioTypeDmg_type11 ||
  243. type == KMUserScenarioTypeDmg_type18 ||
  244. type == KMUserScenarioTypeDmg_type19 ||
  245. type == KMUserScenarioTypeDmg_type22 ||
  246. type == KMUserScenarioTypeDmg_type28 ||
  247. type == KMUserScenarioTypeDmg_type29 ||
  248. type == KMUserScenarioTypeDmg_type30 ||
  249. type == KMUserScenarioTypeDmg_type33 ||
  250. type == KMUserScenarioTypeDmg_type34 ||
  251. type == KMUserScenarioTypeDmg_type37 ||
  252. type == KMUserScenarioTypeDmg_type43 ||
  253. type == KMUserScenarioTypeDmg_type44 ||
  254. type == KMUserScenarioTypeDmg_type45 ||
  255. type == KMUserScenarioTypeDmg_type48) {
  256. [self.button setTitleColor:[NSColor whiteColor]];
  257. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  258. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  259. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  260. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  261. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  262. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  263. __weak typeof(self)weakSelf = self;
  264. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  265. if (image != nil) {
  266. weakSelf.bgImg.image = image;
  267. }
  268. }];
  269. }
  270. }
  271. self.bgImg.hidden = NO;
  272. self.button.hidden = NO;
  273. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  274. CGRect rect = self.button.frame;
  275. self.bgImg.frame = rect;
  276. totalWidth+=CGRectGetWidth(self.button.bounds);
  277. totalWidth+=4;
  278. }
  279. #else
  280. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  281. #if VERSION_FREE
  282. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_lite.isTrialPeriod == false) {
  283. self.aiContendView.hidden = NO;
  284. totalWidth+=aiWidth;
  285. totalWidth+=4;
  286. }
  287. #else
  288. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  289. self.aiContendView.hidden = NO;
  290. totalWidth+=aiWidth;
  291. totalWidth+=4;
  292. }
  293. #endif
  294. }
  295. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  296. if (type == KMUserScenarioTypeLite_type1 ||
  297. type == KMUserScenarioTypeLite_type3 ||
  298. type == KMUserScenarioTypeLite_type5 ||
  299. type == KMUserScenarioTypeLite_type7 ||
  300. type == KMUserScenarioTypeLite_type9 ||
  301. type == KMUserScenarioTypeLite_type11 ||
  302. type == KMUserScenarioTypePro_type1 ||
  303. type == KMUserScenarioTypePro_type3 ||
  304. type == KMUserScenarioTypePro_type4) {
  305. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  306. #if !VERSION_DMG
  307. if(KMMemberInfo.shared.isLogin == NO) {
  308. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  309. } else {
  310. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  311. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  312. } else {
  313. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  314. }
  315. }
  316. #else
  317. #endif
  318. } else if (type == KMUserScenarioTypeLite_type3 ) {
  319. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  320. } else if (type == KMUserScenarioTypeLite_type5) {
  321. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  322. } else if (type == KMUserScenarioTypeLite_type7) {
  323. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  324. } else if (type == KMUserScenarioTypeLite_type9) {
  325. if([KMMemberInfo shared].vip_status == 2) {
  326. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  327. } else if ([KMMemberInfo shared].vip_status == 4) {
  328. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  329. } else {
  330. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  331. }
  332. } else if (type == KMUserScenarioTypeLite_type11) {
  333. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  334. } else if (type == KMUserScenarioTypePro_type3) {
  335. if([KMMemberInfo shared].vip_status == 2) {
  336. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  337. } else {
  338. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  339. }
  340. }
  341. #if !VERSION_FREE
  342. BOOL isNoSupportMemberUpgrade = YES;
  343. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  344. isNoSupportMemberUpgrade = NO;
  345. }
  346. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  347. [self.officeButton setTitleColor:[NSColor whiteColor]];
  348. self.officeButton.hidden = NO;
  349. self.officeImg.hidden = NO;
  350. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  351. CGRect officeRect = self.officeButton.frame;
  352. self.officeImg.frame = officeRect;
  353. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  354. totalWidth+=4;
  355. } else {
  356. self.officeButton.hidden = YES;
  357. self.officeImg.hidden = YES;
  358. }
  359. #else
  360. self.officeButton.hidden = YES;
  361. self.officeImg.hidden = YES;
  362. #endif
  363. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  364. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  365. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  366. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  367. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  368. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  369. __weak typeof(self)weakSelf = self;
  370. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  371. if (image != nil) {
  372. weakSelf.bgImg.image = image;
  373. }
  374. }];
  375. }
  376. }
  377. [self.button setTitleColor:[NSColor whiteColor]];
  378. self.bgImg.hidden = NO;
  379. self.button.hidden = NO;
  380. BOOL isOldSubscribed = NO;
  381. #if VERSION_FREE
  382. #if !VERSION_DMG
  383. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  384. #endif
  385. #endif
  386. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  387. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  388. if(type == KMUserScenarioTypeLite_type9 ||
  389. type == KMUserScenarioTypeLite_type10 ||
  390. type == KMUserScenarioTypeLite_type11) {
  391. if([KMMemberInfo shared].isLogin == NO) { //未登录
  392. self.button.hidden = YES;
  393. self.bgImg.hidden = YES;
  394. } else {
  395. if(isOldSubscribed) { //老版本付费功能是订阅包
  396. self.button.hidden = YES;
  397. self.bgImg.hidden = YES;
  398. } else {
  399. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  400. self.button.hidden = YES;
  401. self.bgImg.hidden = YES;
  402. }
  403. }
  404. }
  405. }
  406. buttonWidth = CGRectGetMaxX(self.button.frame);
  407. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  408. if (fabs(buttonWidth-btnRect.size.width)>50) {
  409. buttonWidth = btnRect.size.width + 10;
  410. }
  411. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  412. CGRect rect = self.button.frame;
  413. self.bgImg.frame = rect;
  414. totalWidth+=CGRectGetWidth(self.button.bounds);
  415. totalWidth+=4;
  416. } else if (type == KMUserScenarioTypeLite_type12 ||
  417. type == KMUserScenarioTypeLite_type13 ||
  418. type == KMUserScenarioTypeLite_type2 ||
  419. type == KMUserScenarioTypeLite_type4 ||
  420. type == KMUserScenarioTypeLite_type6 ||
  421. type == KMUserScenarioTypeLite_type8 ||
  422. type == KMUserScenarioTypePro_type2 ||
  423. type == KMUserScenarioTypePro_type5) {
  424. self.button.hidden = YES;
  425. self.bgImg.hidden = YES;
  426. #if !VERSION_FREE
  427. BOOL isNoSupportMemberUpgrade = YES;
  428. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  429. isNoSupportMemberUpgrade = NO;
  430. }
  431. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  432. [self.officeButton setTitleColor:[NSColor whiteColor]];
  433. self.officeButton.hidden = NO;
  434. self.officeImg.hidden = NO;
  435. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  436. CGRect officeRect = self.officeButton.frame;
  437. self.officeImg.frame = officeRect;
  438. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  439. totalWidth+=4;
  440. } else {
  441. self.officeButton.hidden = YES;
  442. self.officeImg.hidden = YES;
  443. }
  444. #else
  445. self.officeButton.hidden = YES;
  446. self.officeImg.hidden = YES;
  447. #endif
  448. }
  449. #endif
  450. if ([KMMemberInfo shared].isLogin) {
  451. self.userButton.hidden = NO;
  452. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  453. totalWidth += userImageWidth;
  454. totalWidth += 8;
  455. } else {
  456. self.signUpView.hidden = NO;
  457. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  458. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  459. }
  460. 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);
  461. }
  462. #pragma mark - Button Actions
  463. - (IBAction)secondTrialAction:(NSButton *)sender {
  464. if ([VerificationManager manager].secondTrialEnabled) {
  465. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  466. [vc showWindow:nil];
  467. } else {
  468. [[KMMemberInfo shared] advancedFunctionUsage];
  469. }
  470. }
  471. - (IBAction)buttonAction:(id)sender {
  472. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  473. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  474. if ([KMMemberInfo shared].isLogin) {
  475. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  476. [[KMProductCompareWC shared] setOrientation:YES];
  477. #if VERSION_FREE
  478. #if VERSION_DMG
  479. // DMG
  480. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  481. #else
  482. // AppStore 免费版本
  483. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  484. #endif
  485. #else
  486. // AppStore 付费版
  487. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  488. #endif
  489. [[KMProductCompareWC shared] showWindow:nil];
  490. } else {
  491. [[KMMemberInfo shared] advancedFunctionUsage];
  492. }
  493. } else {
  494. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  495. if (success) {
  496. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  497. [[KMProductCompareWC shared] setOrientation:YES];
  498. #if VERSION_FREE
  499. #if VERSION_DMG
  500. // DMG
  501. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  502. #else
  503. // AppStore 免费版本
  504. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  505. #endif
  506. #else
  507. // AppStore 付费版
  508. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  509. #endif
  510. [[KMProductCompareWC shared] showWindow:nil];
  511. } else {
  512. [[KMMemberInfo shared] advancedFunctionUsage];
  513. }
  514. }
  515. }];
  516. }
  517. } else {
  518. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  519. if (type == KMUserScenarioTypeDmg_type4) {
  520. if ([KMMemberInfo shared].isLogin) {
  521. [[KMProductCompareWC shared] setOrientation:YES];
  522. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  523. [[KMProductCompareWC shared] showWindow:nil];
  524. } else {
  525. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  526. if (success) {
  527. [[KMProductCompareWC shared] setOrientation:YES];
  528. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  529. [[KMProductCompareWC shared] showWindow:nil];
  530. }
  531. }];
  532. }
  533. } else {
  534. [[KMMemberInfo shared] advancedFunctionUsage];
  535. }
  536. }
  537. } else {
  538. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  539. if (type == KMUserScenarioTypeDmg_type4) {
  540. if ([KMMemberInfo shared].isLogin) {
  541. [[KMProductCompareWC shared] setOrientation:YES];
  542. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  543. [[KMProductCompareWC shared] showWindow:nil];
  544. } else {
  545. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  546. if (success) {
  547. [[KMProductCompareWC shared] setOrientation:YES];
  548. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  549. [[KMProductCompareWC shared] showWindow:nil];
  550. }
  551. }];
  552. }
  553. } else {
  554. [[KMMemberInfo shared] advancedFunctionUsage];
  555. }
  556. }
  557. }
  558. - (IBAction)officeButtonAction:(id)sender {
  559. #if VERSION_FREE
  560. #if VERSION_DMG
  561. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  562. [embeddedWC showWindow:nil];
  563. [embeddedWC.window center];
  564. #endif
  565. #else
  566. [[KMProductCompareWC shared] setOrientation:YES];
  567. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  568. [[KMProductCompareWC shared] showWindow:nil];
  569. #endif
  570. }
  571. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  572. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  573. NSString *temp = nil;
  574. for (NSUInteger i = 0; i <string.length; i++) {
  575. temp = [string substringWithRange:NSMakeRange(i, 1)];
  576. if ([self isPureInt:temp]) {
  577. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  578. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  579. }
  580. }
  581. return attributedString;
  582. }
  583. - (BOOL)isPureInt:(NSString *)string {
  584. NSScanner *scan = [NSScanner scannerWithString:string];
  585. int value;
  586. return [scan scanInt:&value] && [scan isAtEnd];
  587. }
  588. - (IBAction)AIButtonAction:(NSButton *)sender {
  589. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  590. [[KMMemberPromptWC shared] showWindow:sender];
  591. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  592. } else {
  593. #if VERSION_FREE
  594. #if VERSION_DMG
  595. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  596. [winC showWindow:nil];
  597. [winC.window center];
  598. #else
  599. [[KMFreeGetAIWC shared] showWindow:nil];
  600. #endif
  601. #else
  602. [[KMFreeGetAIWC shared] showWindow:nil];
  603. #endif
  604. }
  605. }
  606. - (IBAction)userButtonAction:(NSButton *)sender {
  607. if ([KMMemberInfo shared].isLogin) {
  608. [self personalCenterAction:sender];
  609. } else {
  610. [KMLoginWindowsController.shared showWindow:nil];
  611. }
  612. }
  613. - (IBAction)personalCenterAction:(NSButton *)sender {
  614. if (![KMCloudServer isConnectionAvailable]) {
  615. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  616. defaultButton:NSLocalizedString(@"OK", nil)
  617. alternateButton:nil
  618. otherButton:nil
  619. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  620. [alert runModal];
  621. return;
  622. }
  623. // 用户头像点击事件
  624. self.userMenu = [[NSMenu alloc] init];
  625. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  626. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  627. item.target = self;
  628. item.representedObject = userInfo;
  629. item.view = userInfo.view;
  630. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  631. }
  632. - (IBAction)signUpAction:(NSButton *)sender {
  633. [KMLoginWindowsController.shared showWindow:nil];
  634. }
  635. #pragma mark - NSNotification Methods
  636. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  637. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  638. [self reloadData];
  639. });
  640. }
  641. - (void)IAPResultReceived:(NSNotification *)notification {
  642. dispatch_async(dispatch_get_main_queue(), ^{
  643. [self reloadData];
  644. });
  645. }
  646. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  647. dispatch_async(dispatch_get_main_queue(), ^{
  648. [self reloadData];
  649. });
  650. }
  651. - (void)IAPRestoreFinish:(NSNotification *)notification {
  652. dispatch_async(dispatch_get_main_queue(), ^{
  653. [self reloadData];
  654. });
  655. }
  656. #pragma mark - Event
  657. - (void)mouseEntered:(NSEvent *)event {
  658. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  659. ActivityStatusTrial == [VerificationManager manager].status) {
  660. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  661. if (!self.popover.isShown) {
  662. [self buttonAction:self.button];
  663. }
  664. }
  665. }
  666. - (void)mouseExited:(NSEvent *)event {
  667. [super mouseExited:event];
  668. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  669. }
  670. - (void)popoverDidClose:(NSNotification *)notification {
  671. self.stopPopOverHide = NO;
  672. }
  673. - (void)popoverShowNoti:(NSNotification *)noti {
  674. if (self.popover) {
  675. [self.popover close];
  676. self.stopPopOverHide = NO;
  677. }
  678. }
  679. - (void)loginSuccessNotification:(NSNotification *)noti {
  680. dispatch_async(dispatch_get_main_queue(), ^{
  681. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  682. [self reloadData];
  683. });
  684. }
  685. - (void)logoutSuccessNotification:(NSNotification *)noti {
  686. dispatch_async(dispatch_get_main_queue(), ^{
  687. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  688. [self reloadData];
  689. });
  690. }
  691. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  692. if (self.userMenu != nil) {
  693. [self personalCenterAction:_userButton];
  694. }
  695. }
  696. - (void)closeMenu:(NSNotification *)noti {
  697. if (self.userMenu != nil) {
  698. [self.userMenu cancelTracking];
  699. self.userMenu = nil;
  700. }
  701. }
  702. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  703. dispatch_async(dispatch_get_main_queue(), ^{
  704. [self reloadData];
  705. });
  706. }
  707. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  708. dispatch_async(dispatch_get_main_queue(), ^{
  709. [self reloadData];
  710. });
  711. }
  712. - (void)popOverCloseAction {
  713. if (self.stopPopOverHide == NO) {
  714. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  715. ActivityStatusTrial == [VerificationManager manager].status) {
  716. if (self.popover.isShown) {
  717. [self.popover close];
  718. self.stopPopOverHide = NO;
  719. }
  720. }
  721. }
  722. }
  723. @end