123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // EcpmConfigInitWC.m
- // UUTUtils2.1
- //
- // Created by zhuge on 2020/7/14.
- // Copyright © 2020 dym. All rights reserved.
- //
- #import "EcpmConfigInitWC.h"
- #import "EcpmConfigInit.h"
- #import "NSString+NSString_CountryCode.h"
- #import "EcpmInitBean.h"
- #import "AdIdNameUtils.h"
- #import "AdIdNameInCSVUtils.h"
- #import "EcpmConfigInitExporter.h"
- #import "ZGCommonUtils.h"
- @interface EcpmConfigInitWC ()
- @property (strong) EcpmConfigInit *config;
- @property (weak) IBOutlet NSTextField *tf_admob;
- @property (weak) IBOutlet NSTextField *tf_facebook;
- @property (weak) IBOutlet NSTextField *lb_admob;
- @property (weak) IBOutlet NSTextField *lb_facebook;
- @property (weak) IBOutlet NSTableView *tv_admob;
- @property (strong) NSArrayController *ac_admob;
- @property (weak) IBOutlet NSTableView *tv_facebook;
- @property (strong) NSArrayController *ac_facebook;
- @end
- @implementation EcpmConfigInitWC
- - (void)windowDidLoad {
- [super windowDidLoad];
- // 设置Title
- self.window.title = [self.projectInfo description];
-
- // 绑定名字
- [[AdIdNameUtils shared] initWithProjectPath:self.projectInfo];
- [[AdIdNameInCSVUtils shared] initWithProjectPath:self.projectInfo];
-
- // 加载Server数据
- [self.projectInfo loadServerData];
- [self.projectInfo.server initWithDic:nil];
-
- // csv文件配置
- self.config = [[EcpmConfigInit alloc] init];
-
- // 检测ecpm文件
- [self onTextChanged_admob:nil];
- [self onTextChanged_facebook:nil];
-
- // admob名字配置
- NSArray<ProjectInfo_Server_AdId*> *arrAdmobIds = [self.projectInfo allAdmobAdIds];
- NSMutableArray<EcpmInitBean*> *maAdmobBean = [[NSMutableArray alloc] initWithCapacity:0];
- for (ProjectInfo_Server_AdId *adid in arrAdmobIds) {
- EcpmInitBean *bean = [[EcpmInitBean alloc] initWithAdId:adid];
- [maAdmobBean addObject:bean];
- }
- self.ac_admob = [[NSArrayController alloc] initWithContent:maAdmobBean];
-
- // facebook 名字配置
- NSMutableArray<EcpmInitBean*> *maFacebookBean = [NSMutableArray arrayWithCapacity:0];
- for (ProjectInfo_Server_AdId *adid in [self.projectInfo allFacebookAdIds]) {
- EcpmInitBean *bean = [[EcpmInitBean alloc] initWithAdId:adid];
- [maFacebookBean addObject:bean];
- }
- self.ac_facebook = [[NSArrayController alloc] initWithContent:maFacebookBean];
-
- // 绑定表格
- NSArray *arrProperties = @[@"idIndex", @"adName", @"adId", @"worthMul", @"nameInCSV"];
- NSDictionary *dicOptions = @{
- NSContinuouslyUpdatesValueBindingOption : @(YES)
- };
- for (NSString *property in arrProperties) {
- NSString *keyPath = [NSString stringWithFormat:@"arrangedObjects.%@", property];
- [[self.tv_admob tableColumnWithIdentifier:property] bind:NSValueBinding toObject:self.ac_admob withKeyPath:keyPath options:dicOptions];
- [[self.tv_facebook tableColumnWithIdentifier:property] bind:NSValueBinding toObject:self.ac_facebook withKeyPath:keyPath options:dicOptions];
- }
- }
- #pragma mark - 文本框
- - (IBAction)onTextChanged_admob:(id)sender {
- self.config.isAdmobOK = NO;
- self.lb_admob.stringValue = @"";
- NSString *path = self.tf_admob.stringValue;
- NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
- NSArray *arrLines = [content componentsSeparatedByString:@"\n"];
- if (arrLines.count >= 1) {
- NSString *firstLine = [arrLines firstObject];
- NSArray *arr = [firstLine componentsSeparatedByString:@","];
- if (arr.count == 3) {
- self.config.isAdmobOK = YES;
- self.lb_admob.stringValue = @"ok";
- } else {
- self.lb_admob.stringValue = @"列数不对";
- }
- } else {
- if (sender == nil) {
- self.tf_admob.stringValue = @"";
- self.lb_admob.stringValue = @"csv拖入文本框后按回车";
- } else {
- self.lb_admob.stringValue = @"文件为空";
- }
- }
- }
- - (IBAction)onTextChanged_facebook:(id)sender {
- self.config.isFacebookOK = NO;
- self.lb_facebook.stringValue = @"";
- NSString *path = self.tf_facebook.stringValue;
- NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
- NSArray *arrLines = [content componentsSeparatedByString:@"\n"];
- if (arrLines.count >= 1) {
- NSString *firstLine = [arrLines firstObject];
- NSArray *arr = [firstLine componentsSeparatedByString:@","];
- if (arr.count == 3) {
- self.config.isFacebookOK = YES;
- self.lb_facebook.stringValue = @"ok";
- } else {
- self.lb_facebook.stringValue = @"列数不对";
- }
- } else {
- if (sender == nil) {
- self.tf_facebook.stringValue = @"";
- self.lb_facebook.stringValue = @"csv拖入文本框后按回车";
- } else {
- self.lb_facebook.stringValue = @"文件为空";
- }
- }
- }
- #pragma mark - 按钮
- - (IBAction)onBtnExport:(id)sender {
- NSString *str = [self.config isCanExport];
- if ([str isEqualToString:@"ok"]) {
- EcpmConfigInitExporter *exporter = [[EcpmConfigInitExporter alloc] init];
- NSString *str = [exporter doExport:self.projectInfo admobFilePath:self.tf_admob.stringValue facebookFilePath:self.tf_facebook.stringValue];
- [str writeToFile:self.projectInfo.path.adWorthJsonPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
- [ZGCommonUtils openFinder:self.projectInfo.path.adWorthJsonPath];
- } else {
- NSLog(@"%@", str);
- }
- }
- // 保存广告Id在csv中的名字
- - (IBAction)onBtnSave:(id)sender {
- [[AdIdNameInCSVUtils shared] save];
- }
- @end
|