KMVerificationMessageViewController.m 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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. BOOL buttonHiddenFlag = false;
  302. if (type == KMUserScenarioTypeLite_type1 ||
  303. type == KMUserScenarioTypeLite_type3 ||
  304. type == KMUserScenarioTypeLite_type5 ||
  305. type == KMUserScenarioTypeLite_type7 ||
  306. type == KMUserScenarioTypeLite_type9 ||
  307. type == KMUserScenarioTypeLite_type11 ||
  308. type == KMUserScenarioTypePro_type1 ||
  309. type == KMUserScenarioTypePro_type3 ||
  310. type == KMUserScenarioTypePro_type4) {
  311. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  312. #if !VERSION_DMG
  313. if(KMMemberInfo.shared.isLogin == NO) {
  314. #if VERSION_FREE
  315. if (IAPProductsManager.defaultManager.isAvailableAllFunction) {
  316. if (IAPProductsManager.defaultManager.isAvailableAdvancedPDFToOffice) {
  317. self.button.title = @"";
  318. buttonHiddenFlag = true;
  319. } else {
  320. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  321. }
  322. } else {
  323. self.button.title = [self _getAppStoreFreeVersionBuyNowTitle];
  324. }
  325. #else
  326. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  327. #endif
  328. } else {
  329. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  330. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  331. } else {
  332. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  333. }
  334. }
  335. #else
  336. #endif
  337. } else if (type == KMUserScenarioTypeLite_type3 ) {
  338. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  339. } else if (type == KMUserScenarioTypeLite_type5) {
  340. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  341. } else if (type == KMUserScenarioTypeLite_type7) {
  342. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  343. } else if (type == KMUserScenarioTypeLite_type9) {
  344. if([KMMemberInfo shared].vip_status == 2) {
  345. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  346. } else if ([KMMemberInfo shared].vip_status == 4) {
  347. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  348. } else {
  349. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  350. }
  351. } else if (type == KMUserScenarioTypeLite_type11) {
  352. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  353. } else if (type == KMUserScenarioTypePro_type3) {
  354. if([KMMemberInfo shared].vip_status == 2) {
  355. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  356. } else {
  357. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  358. }
  359. }
  360. #if !VERSION_FREE
  361. BOOL isNoSupportMemberUpgrade = YES;
  362. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  363. isNoSupportMemberUpgrade = NO;
  364. }
  365. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  366. [self.officeButton setTitleColor:[NSColor whiteColor]];
  367. self.officeButton.hidden = NO;
  368. self.officeImg.hidden = NO;
  369. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  370. CGRect officeRect = self.officeButton.frame;
  371. self.officeImg.frame = officeRect;
  372. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  373. totalWidth+=4;
  374. } else {
  375. self.officeButton.hidden = YES;
  376. self.officeImg.hidden = YES;
  377. }
  378. #else
  379. self.officeButton.hidden = YES;
  380. self.officeImg.hidden = YES;
  381. #endif
  382. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  383. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  384. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  385. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  386. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  387. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  388. __weak typeof(self)weakSelf = self;
  389. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  390. if (image != nil) {
  391. weakSelf.bgImg.image = image;
  392. }
  393. }];
  394. }
  395. }
  396. [self.button setTitleColor:[NSColor whiteColor]];
  397. self.bgImg.hidden = NO;
  398. self.button.hidden = NO;
  399. BOOL isOldSubscribed = NO;
  400. #if VERSION_FREE
  401. #if !VERSION_DMG
  402. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  403. #endif
  404. #endif
  405. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  406. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  407. if(type == KMUserScenarioTypeLite_type9 ||
  408. type == KMUserScenarioTypeLite_type10 ||
  409. type == KMUserScenarioTypeLite_type11) {
  410. if([KMMemberInfo shared].isLogin == NO) { //未登录
  411. self.button.hidden = YES;
  412. self.bgImg.hidden = YES;
  413. } else {
  414. if(isOldSubscribed) { //老版本付费功能是订阅包
  415. self.button.hidden = YES;
  416. self.bgImg.hidden = YES;
  417. } else {
  418. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  419. self.button.hidden = YES;
  420. self.bgImg.hidden = YES;
  421. }
  422. }
  423. }
  424. }
  425. #if VERSION_FREE
  426. #if !VERSION_DMG
  427. if (buttonHiddenFlag) {
  428. self.bgImg.hidden = YES;
  429. self.button.hidden = YES;
  430. }
  431. #endif
  432. #endif
  433. buttonWidth = CGRectGetWidth(self.button.frame);
  434. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  435. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  436. buttonWidth = btnRect.size.width + 10;
  437. // buttonWidth += 10;
  438. // }
  439. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  440. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  441. buttonWidth += 10;
  442. }
  443. }
  444. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  445. CGRect rect = self.button.frame;
  446. self.bgImg.frame = rect;
  447. totalWidth+=CGRectGetWidth(self.button.bounds);
  448. totalWidth+=4;
  449. } else if (type == KMUserScenarioTypeLite_type12 ||
  450. type == KMUserScenarioTypeLite_type13 ||
  451. type == KMUserScenarioTypeLite_type2 ||
  452. type == KMUserScenarioTypeLite_type4 ||
  453. type == KMUserScenarioTypeLite_type6 ||
  454. type == KMUserScenarioTypeLite_type8 ||
  455. type == KMUserScenarioTypePro_type2 ||
  456. type == KMUserScenarioTypePro_type5) {
  457. self.button.hidden = YES;
  458. self.bgImg.hidden = YES;
  459. #if !VERSION_FREE
  460. BOOL isNoSupportMemberUpgrade = YES;
  461. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  462. isNoSupportMemberUpgrade = NO;
  463. }
  464. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  465. [self.officeButton setTitleColor:[NSColor whiteColor]];
  466. self.officeButton.hidden = NO;
  467. self.officeImg.hidden = NO;
  468. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  469. CGRect officeRect = self.officeButton.frame;
  470. self.officeImg.frame = officeRect;
  471. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  472. totalWidth+=4;
  473. } else {
  474. self.officeButton.hidden = YES;
  475. self.officeImg.hidden = YES;
  476. }
  477. #else
  478. self.officeButton.hidden = YES;
  479. self.officeImg.hidden = YES;
  480. #endif
  481. }
  482. #endif
  483. if ([KMMemberInfo shared].isLogin) {
  484. self.userButton.hidden = NO;
  485. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  486. totalWidth += userImageWidth;
  487. totalWidth += 8;
  488. } else {
  489. self.signUpView.hidden = NO;
  490. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  491. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  492. }
  493. 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);
  494. }
  495. #pragma mark - Button Actions
  496. - (IBAction)secondTrialAction:(NSButton *)sender {
  497. if ([VerificationManager manager].secondTrialEnabled) {
  498. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  499. [vc showWindow:nil];
  500. } else {
  501. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  502. }
  503. }
  504. - (IBAction)buttonAction:(id)sender {
  505. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  506. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  507. if ([KMMemberInfo shared].isLogin) {
  508. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  509. [[KMProductCompareWC shared] setOrientation:YES];
  510. #if VERSION_FREE
  511. #if VERSION_DMG
  512. // DMG
  513. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  514. #else
  515. // AppStore 免费版本
  516. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  517. #endif
  518. #else
  519. // AppStore 付费版
  520. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  521. #endif
  522. [[KMProductCompareWC shared] showWindow:nil];
  523. } else {
  524. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  525. }
  526. } else {
  527. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  528. if (success) {
  529. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  530. [[KMProductCompareWC shared] setOrientation:YES];
  531. #if VERSION_FREE
  532. #if VERSION_DMG
  533. // DMG
  534. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  535. #else
  536. // AppStore 免费版本
  537. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  538. #endif
  539. #else
  540. // AppStore 付费版
  541. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  542. #endif
  543. [[KMProductCompareWC shared] showWindow:nil];
  544. } else {
  545. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  546. }
  547. }
  548. }];
  549. }
  550. } else {
  551. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  552. if (type == KMUserScenarioTypeDmg_type4) {
  553. if ([KMMemberInfo shared].isLogin) {
  554. [[KMProductCompareWC shared] setOrientation:YES];
  555. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  556. [[KMProductCompareWC shared] showWindow:nil];
  557. } else {
  558. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  559. if (success) {
  560. [[KMProductCompareWC shared] setOrientation:YES];
  561. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  562. [[KMProductCompareWC shared] showWindow:nil];
  563. }
  564. }];
  565. }
  566. } else {
  567. if ([self.button.title isEqualToString:[self _getAppStoreFreeVersionBuyNowTitle]]) {
  568. KMProductCompareWC *winC = [KMProductCompareWC shared];
  569. // 定向跳转
  570. winC.orientation = true;
  571. // App Store 免费版 基础比较表
  572. winC.orientationType = KMCompareTableTypeLite_Base;
  573. [winC showWindow:nil];
  574. } else {
  575. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  576. }
  577. }
  578. }
  579. } else {
  580. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  581. if (type == KMUserScenarioTypeDmg_type4) {
  582. if ([KMMemberInfo shared].isLogin) {
  583. [[KMProductCompareWC shared] setOrientation:YES];
  584. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  585. [[KMProductCompareWC shared] showWindow:nil];
  586. } else {
  587. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  588. if (success) {
  589. [[KMProductCompareWC shared] setOrientation:YES];
  590. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  591. [[KMProductCompareWC shared] showWindow:nil];
  592. }
  593. }];
  594. }
  595. } else {
  596. if ([self.button.title isEqualToString:[self _getAppStoreFreeVersionBuyNowTitle]]) {
  597. KMProductCompareWC *winC = [KMProductCompareWC shared];
  598. // 定向跳转
  599. winC.orientation = true;
  600. // App Store 免费版 基础比较表
  601. winC.orientationType = KMCompareTableTypeLite_Base;
  602. [winC showWindow:nil];
  603. } else {
  604. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  605. }
  606. }
  607. }
  608. }
  609. - (IBAction)officeButtonAction:(id)sender {
  610. #if VERSION_FREE
  611. #if VERSION_DMG
  612. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  613. [embeddedWC showWindow:nil];
  614. [embeddedWC.window center];
  615. #endif
  616. #else
  617. if ([KMMemberInfo shared].isLogin) {
  618. [[KMMemberInfo shared] productCompareShow];
  619. } else {
  620. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  621. if (success) {
  622. [[KMMemberInfo shared] productCompareShow];
  623. }
  624. }];
  625. }
  626. #endif
  627. }
  628. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  629. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  630. NSString *temp = nil;
  631. for (NSUInteger i = 0; i <string.length; i++) {
  632. temp = [string substringWithRange:NSMakeRange(i, 1)];
  633. if ([self isPureInt:temp]) {
  634. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  635. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  636. }
  637. }
  638. return attributedString;
  639. }
  640. - (BOOL)isPureInt:(NSString *)string {
  641. NSScanner *scan = [NSScanner scannerWithString:string];
  642. int value;
  643. return [scan scanInt:&value] && [scan isAtEnd];
  644. }
  645. - (IBAction)AIButtonAction:(NSButton *)sender {
  646. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  647. [[KMMemberPromptWC shared] showWindow:sender];
  648. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  649. } else {
  650. #if VERSION_FREE
  651. #if VERSION_DMG
  652. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  653. [winC showWindow:nil];
  654. [winC.window center];
  655. #else
  656. [[KMFreeGetAIWC shared] showWindow:nil];
  657. #endif
  658. #else
  659. [[KMFreeGetAIWC shared] showWindow:nil];
  660. #endif
  661. }
  662. }
  663. - (IBAction)userButtonAction:(NSButton *)sender {
  664. if ([KMMemberInfo shared].isLogin) {
  665. [self personalCenterAction:sender];
  666. } else {
  667. [KMLoginWindowsController.shared showWindow:nil];
  668. }
  669. }
  670. - (IBAction)personalCenterAction:(NSButton *)sender {
  671. if (![KMCloudServer isConnectionAvailable]) {
  672. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  673. defaultButton:NSLocalizedString(@"OK", nil)
  674. alternateButton:nil
  675. otherButton:nil
  676. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  677. [alert runModal];
  678. return;
  679. }
  680. // 用户头像点击事件
  681. self.userMenu = [[NSMenu alloc] init];
  682. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  683. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  684. item.target = self;
  685. item.representedObject = userInfo;
  686. item.view = userInfo.view;
  687. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  688. }
  689. - (IBAction)signUpAction:(NSButton *)sender {
  690. [KMLoginWindowsController.shared showWindow:nil];
  691. }
  692. #pragma mark - NSNotification Methods
  693. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  694. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  695. [self reloadData];
  696. });
  697. }
  698. - (void)IAPResultReceived:(NSNotification *)notification {
  699. dispatch_async(dispatch_get_main_queue(), ^{
  700. [self reloadData];
  701. });
  702. }
  703. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  704. dispatch_async(dispatch_get_main_queue(), ^{
  705. [self reloadData];
  706. #if VERSION_FREE
  707. #if VERSION_DMG
  708. #else
  709. [[KMProductCompareWC shared] closeAction];
  710. #endif
  711. #endif
  712. });
  713. }
  714. - (void)IAPRestoreFinish:(NSNotification *)notification {
  715. dispatch_async(dispatch_get_main_queue(), ^{
  716. [self reloadData];
  717. });
  718. }
  719. #pragma mark - Event
  720. - (void)mouseEntered:(NSEvent *)event {
  721. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  722. ActivityStatusTrial == [VerificationManager manager].status) {
  723. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  724. if (!self.popover.isShown) {
  725. [self buttonAction:self.button];
  726. }
  727. }
  728. }
  729. - (void)mouseExited:(NSEvent *)event {
  730. [super mouseExited:event];
  731. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  732. }
  733. - (void)popoverDidClose:(NSNotification *)notification {
  734. self.stopPopOverHide = NO;
  735. }
  736. - (void)popoverShowNoti:(NSNotification *)noti {
  737. if (self.popover) {
  738. [self.popover close];
  739. self.stopPopOverHide = NO;
  740. }
  741. }
  742. - (void)loginSuccessNotification:(NSNotification *)noti {
  743. dispatch_async(dispatch_get_main_queue(), ^{
  744. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  745. [self reloadData];
  746. });
  747. }
  748. - (void)logoutSuccessNotification:(NSNotification *)noti {
  749. dispatch_async(dispatch_get_main_queue(), ^{
  750. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  751. [self reloadData];
  752. });
  753. }
  754. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  755. if (self.userMenu != nil) {
  756. [self personalCenterAction:_userButton];
  757. }
  758. }
  759. - (void)closeMenu:(NSNotification *)noti {
  760. if (self.userMenu != nil) {
  761. [self.userMenu cancelTracking];
  762. self.userMenu = nil;
  763. }
  764. }
  765. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  766. dispatch_async(dispatch_get_main_queue(), ^{
  767. [self reloadData];
  768. });
  769. }
  770. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  771. dispatch_async(dispatch_get_main_queue(), ^{
  772. [self reloadData];
  773. });
  774. }
  775. - (void)popOverCloseAction {
  776. if (self.stopPopOverHide == NO) {
  777. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  778. ActivityStatusTrial == [VerificationManager manager].status) {
  779. if (self.popover.isShown) {
  780. [self.popover close];
  781. self.stopPopOverHide = NO;
  782. }
  783. }
  784. }
  785. }
  786. @end