KMVerificationMessageViewController.m 34 KB

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