KMVerificationMessageViewController.m 37 KB

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