From 5fed207f1cd6d7ff0e67cc4968d04422612a482e Mon Sep 17 00:00:00 2001 From: gexiao Date: Sun, 11 Jun 2017 23:02:24 +0800 Subject: [PATCH] Add tableviews to show groups and conditions --- MessageJudge.xcodeproj/project.pbxproj | 26 ++-- MessageJudge/GlobalDefine.h | 2 + .../I18n/zh-Hans.lproj/Localizable.strings | 12 ++ .../Interface/GroupList/MJConditionCell.h | 19 +++ .../Interface/GroupList/MJConditionCell.m | 135 ++++++++++++++++++ .../Interface/GroupList/MJGroupCell.h | 18 +++ .../Interface/GroupList/MJGroupCell.m | 31 ++++ .../GroupList/MJGroupListViewController.h | 3 + .../GroupList/MJGroupListViewController.m | 58 +++++--- .../GroupList/MJGroupViewController.h | 17 +++ .../GroupList/MJGroupViewController.m | 106 ++++++++++++++ .../Interface/Tabbar/MJTabBarController.m | 27 ++++ MessageJudge/ViewController.h | 15 -- MessageJudge/ViewController.m | 47 ------ MessageJudgeExt/MessageFilterExtension.h | 1 - 15 files changed, 430 insertions(+), 87 deletions(-) create mode 100644 MessageJudge/Interface/GroupList/MJConditionCell.h create mode 100644 MessageJudge/Interface/GroupList/MJConditionCell.m create mode 100644 MessageJudge/Interface/GroupList/MJGroupCell.h create mode 100644 MessageJudge/Interface/GroupList/MJGroupCell.m create mode 100644 MessageJudge/Interface/GroupList/MJGroupViewController.h create mode 100644 MessageJudge/Interface/GroupList/MJGroupViewController.m delete mode 100644 MessageJudge/ViewController.h delete mode 100644 MessageJudge/ViewController.m diff --git a/MessageJudge.xcodeproj/project.pbxproj b/MessageJudge.xcodeproj/project.pbxproj index dbff9c6..fa1f273 100644 --- a/MessageJudge.xcodeproj/project.pbxproj +++ b/MessageJudge.xcodeproj/project.pbxproj @@ -13,6 +13,8 @@ C20FD1D61EED3DC200F14388 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C20FD1D81EED3DC200F14388 /* InfoPlist.strings */; }; C20FD1DB1EED3E6800F14388 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C20FD1DD1EED3E6800F14388 /* Localizable.strings */; }; C21D81911EE9B7C80080F8CA /* MessageJudgeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C21D81901EE9B7C80080F8CA /* MessageJudgeTests.m */; }; + C21FDFEF1EED74BC006B7CCB /* MJGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C21FDFEE1EED74BC006B7CCB /* MJGroupViewController.m */; }; + C21FDFF21EED77B4006B7CCB /* MJConditionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C21FDFF11EED77B4006B7CCB /* MJConditionCell.m */; }; C227FC9B1EEA87B6008B6F2F /* MJQueryRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C227FC9A1EEA87B6008B6F2F /* MJQueryRequest.m */; }; C227FC9C1EEA87B6008B6F2F /* MJQueryRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C227FC9A1EEA87B6008B6F2F /* MJQueryRequest.m */; }; C227FC9D1EEA87B6008B6F2F /* MJQueryRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C227FC9A1EEA87B6008B6F2F /* MJQueryRequest.m */; }; @@ -20,18 +22,17 @@ C24034FF1EE9C4A500AE3122 /* MJConditionGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E31D1EE9799200195831 /* MJConditionGroup.m */; }; C24035001EE9C4A800AE3122 /* MJJudgementRule.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E3171EE9625800195831 /* MJJudgementRule.m */; }; C247223B1EE934EF0092DF98 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C247223A1EE934EF0092DF98 /* AppDelegate.m */; }; - C247223E1EE934EF0092DF98 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C247223D1EE934EF0092DF98 /* ViewController.m */; }; C24722411EE934EF0092DF98 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C247223F1EE934EF0092DF98 /* Main.storyboard */; }; C24722431EE934EF0092DF98 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C24722421EE934EF0092DF98 /* Assets.xcassets */; }; C24722461EE934EF0092DF98 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C24722441EE934EF0092DF98 /* LaunchScreen.storyboard */; }; C24722491EE934EF0092DF98 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C24722481EE934EF0092DF98 /* main.m */; }; C24722571EE935230092DF98 /* MessageFilterExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = C24722561EE935230092DF98 /* MessageFilterExtension.m */; }; C247225B1EE935230092DF98 /* MessageJudgeExt.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = C24722531EE935230092DF98 /* MessageJudgeExt.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + C29321BC1EED433200D60C4B /* MJGroupCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C29321BB1EED433200D60C4B /* MJGroupCell.m */; }; C293E3181EE9625800195831 /* MJJudgementRule.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E3171EE9625800195831 /* MJJudgementRule.m */; }; C293E31B1EE962BB00195831 /* MJCondition.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E31A1EE962BB00195831 /* MJCondition.m */; }; C293E31E1EE9799200195831 /* MJConditionGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E31D1EE9799200195831 /* MJConditionGroup.m */; }; C2978F8D1EE9D4AD00A57597 /* MJTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = C2978F8C1EE9D4AD00A57597 /* MJTabBarController.m */; }; - C29CF8D71EE98BB9001D5EA5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C247223D1EE934EF0092DF98 /* ViewController.m */; }; C2CEAA151EE98393005E9E33 /* MJJudgementRule.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E3171EE9625800195831 /* MJJudgementRule.m */; }; C2CEAA161EE98397005E9E33 /* MJConditionGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E31D1EE9799200195831 /* MJConditionGroup.m */; }; C2CEAA171EE98399005E9E33 /* MJCondition.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E31A1EE962BB00195831 /* MJCondition.m */; }; @@ -84,13 +85,15 @@ C21D818E1EE9B7C80080F8CA /* MessageJudgeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MessageJudgeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; C21D81901EE9B7C80080F8CA /* MessageJudgeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MessageJudgeTests.m; sourceTree = ""; }; C21D81921EE9B7C80080F8CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C21FDFED1EED74BC006B7CCB /* MJGroupViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJGroupViewController.h; sourceTree = ""; }; + C21FDFEE1EED74BC006B7CCB /* MJGroupViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJGroupViewController.m; sourceTree = ""; }; + C21FDFF01EED77B4006B7CCB /* MJConditionCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJConditionCell.h; sourceTree = ""; }; + C21FDFF11EED77B4006B7CCB /* MJConditionCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJConditionCell.m; sourceTree = ""; }; C227FC991EEA87B6008B6F2F /* MJQueryRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJQueryRequest.h; sourceTree = ""; }; C227FC9A1EEA87B6008B6F2F /* MJQueryRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJQueryRequest.m; sourceTree = ""; }; C24722361EE934EF0092DF98 /* MessageJudge.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MessageJudge.app; sourceTree = BUILT_PRODUCTS_DIR; }; C24722391EE934EF0092DF98 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; C247223A1EE934EF0092DF98 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - C247223C1EE934EF0092DF98 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - C247223D1EE934EF0092DF98 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; C24722401EE934EF0092DF98 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; C24722421EE934EF0092DF98 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; C24722451EE934EF0092DF98 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -102,6 +105,8 @@ C24722581EE935230092DF98 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C24722601EE937120092DF98 /* MessageJudge.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MessageJudge.entitlements; sourceTree = ""; }; C24722611EE937680092DF98 /* MessageJudgeExt.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MessageJudgeExt.entitlements; sourceTree = ""; }; + C29321BA1EED433200D60C4B /* MJGroupCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJGroupCell.h; sourceTree = ""; }; + C29321BB1EED433200D60C4B /* MJGroupCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJGroupCell.m; sourceTree = ""; }; C293E3161EE9625800195831 /* MJJudgementRule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJJudgementRule.h; sourceTree = ""; }; C293E3171EE9625800195831 /* MJJudgementRule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJJudgementRule.m; sourceTree = ""; }; C293E3191EE962BB00195831 /* MJCondition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJCondition.h; sourceTree = ""; }; @@ -216,8 +221,6 @@ C24722601EE937120092DF98 /* MessageJudge.entitlements */, C24722391EE934EF0092DF98 /* AppDelegate.h */, C247223A1EE934EF0092DF98 /* AppDelegate.m */, - C247223C1EE934EF0092DF98 /* ViewController.h */, - C247223D1EE934EF0092DF98 /* ViewController.m */, C247223F1EE934EF0092DF98 /* Main.storyboard */, C24722421EE934EF0092DF98 /* Assets.xcassets */, C24722441EE934EF0092DF98 /* LaunchScreen.storyboard */, @@ -277,6 +280,12 @@ children = ( C2E6CD5F1EED362D00167420 /* MJGroupListViewController.h */, C2E6CD601EED362D00167420 /* MJGroupListViewController.m */, + C29321BA1EED433200D60C4B /* MJGroupCell.h */, + C29321BB1EED433200D60C4B /* MJGroupCell.m */, + C21FDFED1EED74BC006B7CCB /* MJGroupViewController.h */, + C21FDFEE1EED74BC006B7CCB /* MJGroupViewController.m */, + C21FDFF01EED77B4006B7CCB /* MJConditionCell.h */, + C21FDFF11EED77B4006B7CCB /* MJConditionCell.m */, ); path = GroupList; sourceTree = ""; @@ -566,12 +575,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C247223E1EE934EF0092DF98 /* ViewController.m in Sources */, C227FC9B1EEA87B6008B6F2F /* MJQueryRequest.m in Sources */, C24722491EE934EF0092DF98 /* main.m in Sources */, C2E6CD611EED362D00167420 /* MJGroupListViewController.m in Sources */, C293E3181EE9625800195831 /* MJJudgementRule.m in Sources */, C293E31B1EE962BB00195831 /* MJCondition.m in Sources */, + C21FDFEF1EED74BC006B7CCB /* MJGroupViewController.m in Sources */, + C29321BC1EED433200D60C4B /* MJGroupCell.m in Sources */, + C21FDFF21EED77B4006B7CCB /* MJConditionCell.m in Sources */, C293E31E1EE9799200195831 /* MJConditionGroup.m in Sources */, C247223B1EE934EF0092DF98 /* AppDelegate.m in Sources */, C2978F8D1EE9D4AD00A57597 /* MJTabBarController.m in Sources */, @@ -582,7 +593,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C29CF8D71EE98BB9001D5EA5 /* ViewController.m in Sources */, C2CEAA171EE98399005E9E33 /* MJCondition.m in Sources */, C24722571EE935230092DF98 /* MessageFilterExtension.m in Sources */, C227FC9C1EEA87B6008B6F2F /* MJQueryRequest.m in Sources */, diff --git a/MessageJudge/GlobalDefine.h b/MessageJudge/GlobalDefine.h index bdc0881..5afc53a 100644 --- a/MessageJudge/GlobalDefine.h +++ b/MessageJudge/GlobalDefine.h @@ -13,3 +13,5 @@ #endif /* GlobalDefine_h */ #define MJLocalize(key) NSLocalizedString(key, nil) + +#define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] diff --git a/MessageJudge/I18n/zh-Hans.lproj/Localizable.strings b/MessageJudge/I18n/zh-Hans.lproj/Localizable.strings index 24f24ae..fae2b84 100644 --- a/MessageJudge/I18n/zh-Hans.lproj/Localizable.strings +++ b/MessageJudge/I18n/zh-Hans.lproj/Localizable.strings @@ -9,3 +9,15 @@ "Whitelist" = "白名单"; "Blacklist" = "黑名单"; "Menu" = "选项"; + +"Whitelist Groups" = "白名单条件组"; +"Blacklist Groups" = "黑名单条件组"; + +"Sender" = "发送者"; +"Content" = "内容"; +"Invalid target" = "无效目标"; +"has prefix" = "含有前缀"; +"has suffix" = "含有后缀"; +"contains" = "包含"; +"doesn't contain" = "不包含"; +"matches regex" = "匹配正则"; diff --git a/MessageJudge/Interface/GroupList/MJConditionCell.h b/MessageJudge/Interface/GroupList/MJConditionCell.h new file mode 100644 index 0000000..3ab7042 --- /dev/null +++ b/MessageJudge/Interface/GroupList/MJConditionCell.h @@ -0,0 +1,19 @@ +// +// MJConditionCell.h +// MessageJudge +// +// Created by GeXiao on 11/06/2017. +// Copyright © 2017 GeXiao. All rights reserved. +// + +#import + +static NSString *MJConditionCellReuseIdentifier = @"MJConditionCellReuseIdentifier"; + +@class MJCondition; + +@interface MJConditionCell : UITableViewCell + +- (void)renderCellWithCondition:(MJCondition *)condition; + +@end diff --git a/MessageJudge/Interface/GroupList/MJConditionCell.m b/MessageJudge/Interface/GroupList/MJConditionCell.m new file mode 100644 index 0000000..4e8d25b --- /dev/null +++ b/MessageJudge/Interface/GroupList/MJConditionCell.m @@ -0,0 +1,135 @@ +// +// MJConditionCell.m +// MessageJudge +// +// Created by GeXiao on 11/06/2017. +// Copyright © 2017 GeXiao. All rights reserved. +// + +#import "MJConditionCell.h" +#import "Masonry.h" +#import "MJCondition.h" +#import "GlobalDefine.h" + +static CGFloat MJConditionCellTargetLabelFontSize = 17.f; +static CGFloat MJConditionCellTypeLabelFontSize = 17.f; +static CGFloat MJConditionCellKeywordLabelFontSize = 17.f; + +static CGFloat MJConditionCellLabelLeftPadding = 16.f; +static CGFloat MJConditionCellLabelSpace = 8.f; +static CGFloat MJConditionCellLabelRadius = 3.f; + +@interface MJConditionCell () + +@property (nonatomic, strong) UILabel *targeLabel; +@property (nonatomic, strong) UILabel *typeLabel; +@property (nonatomic, strong) UILabel *keywordLabel; + +@end + +@implementation MJConditionCell + +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { + if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) { + [self initUI]; + [self makeConstranits]; + } + return self; +} + +- (void)initUI { + self.targeLabel = ({ + UILabel *label = [UILabel new]; + label.numberOfLines = 1; + label.font = [UIFont systemFontOfSize:MJConditionCellTargetLabelFontSize]; + label.textColor = [UIColor whiteColor]; + label.backgroundColor = RGBColor(102, 204, 102); + label.layer.masksToBounds = true; + label.layer.cornerRadius = MJConditionCellLabelRadius; + label; + }); + [self.contentView addSubview:self.targeLabel]; + + self.typeLabel = ({ + UILabel *label = [UILabel new]; + label.numberOfLines = 1; + label.font = [UIFont systemFontOfSize:MJConditionCellTypeLabelFontSize]; + label.textColor = [UIColor blackColor]; + label.backgroundColor = RGBColor(255, 204, 153); + label.layer.masksToBounds = true; + label.layer.cornerRadius = MJConditionCellLabelRadius; + label; + }); + [self.contentView addSubview:self.typeLabel]; + + self.keywordLabel = ({ + UILabel *label = [UILabel new]; + label.numberOfLines = 1; + label.font = [UIFont systemFontOfSize:MJConditionCellKeywordLabelFontSize]; + label; + }); + [self.contentView addSubview:self.keywordLabel]; +} + +- (void)makeConstranits { + [self.targeLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.contentView).offset(MJConditionCellLabelLeftPadding); + make.centerY.equalTo(self.contentView); + }]; + + [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.targeLabel.mas_right).offset(MJConditionCellLabelSpace); + make.centerY.equalTo(self.contentView); + }]; + + [self.keywordLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.typeLabel.mas_right).offset(MJConditionCellLabelSpace); + make.centerY.equalTo(self.contentView); + make.right.lessThanOrEqualTo(self.contentView); + }]; + [self.keywordLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:UILayoutConstraintAxisHorizontal]; +} + +- (void)renderCellWithCondition:(MJCondition *)condition { + switch (condition.conditionTarget) { + case MJConditionTargetSender: + self.targeLabel.text = MJLocalize(@"Sender"); + break; + case MJConditionTargetContent: + self.targeLabel.text = MJLocalize(@"Content"); + break; + default: + self.targeLabel.text = MJLocalize(@"Invalid target"); + break; + } + + switch (condition.conditionType) { + case MJConditionTypeHasPrefix: + self.typeLabel.text = MJLocalize(@"has prefix"); + break; + case MJConditionTypeHasSuffix: + self.typeLabel.text = MJLocalize(@"has suffix"); + break; + case MJConditionTypeContains: + self.typeLabel.text = MJLocalize(@"contains"); + break; + case MJConditionTypeNotContains: + self.typeLabel.text = MJLocalize(@"doesn't contain"); + break; + case MJConditionTypeContainsRegex: + self.typeLabel.text = MJLocalize(@"matches regex"); + break; + default: + break; + } + + self.keywordLabel.text = condition.keyword; +} + +- (void)prepareForReuse { + [super prepareForReuse]; + self.targeLabel.text = @""; + self.typeLabel.text = @""; + self.keywordLabel.text = @""; +} +@end diff --git a/MessageJudge/Interface/GroupList/MJGroupCell.h b/MessageJudge/Interface/GroupList/MJGroupCell.h new file mode 100644 index 0000000..cdf0979 --- /dev/null +++ b/MessageJudge/Interface/GroupList/MJGroupCell.h @@ -0,0 +1,18 @@ +// +// MJGroupCell.h +// MessageJudge +// +// Created by GeXiao on 11/06/2017. +// Copyright © 2017 GeXiao. All rights reserved. +// + +#import +#import "MJConditionGroup.h" + +static NSString *MJGroupCellReuseIdentifier = @"MJGroupCellReuseIdentifier"; + +@interface MJGroupCell : UITableViewCell + +- (void)renderCellWithGroup:(MJConditionGroup *)group; + +@end diff --git a/MessageJudge/Interface/GroupList/MJGroupCell.m b/MessageJudge/Interface/GroupList/MJGroupCell.m new file mode 100644 index 0000000..7e200bc --- /dev/null +++ b/MessageJudge/Interface/GroupList/MJGroupCell.m @@ -0,0 +1,31 @@ +// +// MJGroupCell.m +// MessageJudge +// +// Created by GeXiao on 11/06/2017. +// Copyright © 2017 GeXiao. All rights reserved. +// + +#import "MJGroupCell.h" + +@implementation MJGroupCell + +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { + if (self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier]) { + + } + return self; +} + +- (void)renderCellWithGroup:(MJConditionGroup *)group { + self.textLabel.text = group.alias; + self.detailTextLabel.text = [NSString stringWithFormat:@"%ld conditions", (long)group.conditions.count]; +} + +- (void)prepareForReuse { + [super prepareForReuse]; + self.textLabel.text = @""; + self.detailTextLabel.text = @""; +} + +@end diff --git a/MessageJudge/Interface/GroupList/MJGroupListViewController.h b/MessageJudge/Interface/GroupList/MJGroupListViewController.h index 83a07eb..96b2c65 100644 --- a/MessageJudge/Interface/GroupList/MJGroupListViewController.h +++ b/MessageJudge/Interface/GroupList/MJGroupListViewController.h @@ -13,9 +13,12 @@ typedef NS_ENUM(NSInteger, MJGroupListType) { MJGroupListTypeBlackList, }; +@class MJConditionGroup; + @interface MJGroupListViewController : UITableViewController @property (nonatomic, assign) MJGroupListType type; +@property (nonatomic, strong, readonly) NSMutableArray *groupList; - (instancetype)initWithListType:(MJGroupListType)type; diff --git a/MessageJudge/Interface/GroupList/MJGroupListViewController.m b/MessageJudge/Interface/GroupList/MJGroupListViewController.m index 00f6577..6382ceb 100644 --- a/MessageJudge/Interface/GroupList/MJGroupListViewController.m +++ b/MessageJudge/Interface/GroupList/MJGroupListViewController.m @@ -7,6 +7,10 @@ // #import "MJGroupListViewController.h" +#import "MJGroupCell.h" +#import "MJGroupViewController.h" +#import "GlobalDefine.h" +#import "MJJudgementRule.h" @interface MJGroupListViewController () @@ -22,9 +26,31 @@ - (instancetype)initWithListType:(MJGroupListType)type { return self; } +- (NSMutableArray *)groupList { + switch (self.type) { + case MJGroupListTypeWhiteList: + return MJGlobalRule.whiteConditionGroupList; + break; + case MJGroupListTypeBlackList: + return MJGlobalRule.blackConditionGroupList; + break; + default: + return MJGlobalRule.blackConditionGroupList; + break; + } +} + - (void)viewDidLoad { [super viewDidLoad]; - + [self.tableView registerClass:MJGroupCell.class forCellReuseIdentifier:MJGroupCellReuseIdentifier]; + switch (self.type) { + case MJGroupListTypeWhiteList: + self.title = MJLocalize(@"Whitelist Groups"); + break; + case MJGroupListTypeBlackList: + self.title = MJLocalize(@"Blacklist Groups"); + break; + } // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; @@ -32,32 +58,32 @@ - (void)viewDidLoad { // self.navigationItem.rightBarButtonItem = self.editButtonItem; } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { -#warning Incomplete implementation, return the number of sections - return 0; + return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { -#warning Incomplete implementation, return the number of rows - return 0; + return self.groupList.count; } -/* - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath]; - - // Configure the cell... - + MJGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:MJGroupCellReuseIdentifier forIndexPath:indexPath]; + if (indexPath.row < self.groupList.count) { + [cell renderCellWithGroup:self.groupList[indexPath.row]]; + } return cell; } -*/ + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + if (indexPath.row < self.groupList.count) { + MJConditionGroup *group = self.groupList[indexPath.row]; + MJGroupViewController *groupViewController = [[MJGroupViewController alloc] initWithConditionGroup:group]; + [self.navigationController pushViewController:groupViewController animated:YES]; + } +} /* // Override to support conditional editing of the table view. diff --git a/MessageJudge/Interface/GroupList/MJGroupViewController.h b/MessageJudge/Interface/GroupList/MJGroupViewController.h new file mode 100644 index 0000000..23628b5 --- /dev/null +++ b/MessageJudge/Interface/GroupList/MJGroupViewController.h @@ -0,0 +1,17 @@ +// +// MJGroupViewController.h +// MessageJudge +// +// Created by GeXiao on 11/06/2017. +// Copyright © 2017 GeXiao. All rights reserved. +// + +#import + +@class MJConditionGroup; + +@interface MJGroupViewController : UITableViewController + +- (instancetype)initWithConditionGroup:(MJConditionGroup *)group; + +@end diff --git a/MessageJudge/Interface/GroupList/MJGroupViewController.m b/MessageJudge/Interface/GroupList/MJGroupViewController.m new file mode 100644 index 0000000..8ad2a53 --- /dev/null +++ b/MessageJudge/Interface/GroupList/MJGroupViewController.m @@ -0,0 +1,106 @@ +// +// MJGroupViewController.m +// MessageJudge +// +// Created by GeXiao on 11/06/2017. +// Copyright © 2017 GeXiao. All rights reserved. +// + +#import "MJGroupViewController.h" +#import "MJConditionGroup.h" +#import "MJConditionCell.h" + +@interface MJGroupViewController () + +@property (nonatomic, strong) MJConditionGroup *conditionGroup; + +@end + +@implementation MJGroupViewController + +- (instancetype)initWithConditionGroup:(MJConditionGroup *)group { + self = [super initWithStyle:UITableViewStylePlain]; + if (self) { + _conditionGroup = group; + } + return self; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + [self.tableView registerClass:MJConditionCell.class forCellReuseIdentifier:MJConditionCellReuseIdentifier]; + + // Uncomment the following line to preserve selection between presentations. + // self.clearsSelectionOnViewWillAppear = NO; + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.conditionGroup.conditions.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + MJConditionCell *cell = [tableView dequeueReusableCellWithIdentifier:MJConditionCellReuseIdentifier forIndexPath:indexPath]; + if (indexPath.row < self.conditionGroup.conditions.count) { + [cell renderCellWithCondition:self.conditionGroup.conditions[indexPath.row]]; + } + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + [tableView deselectRowAtIndexPath:indexPath animated:YES]; +} + +/* + // Override to support conditional editing of the table view. + - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { + // Return NO if you do not want the specified item to be editable. + return YES; + } + */ + +/* + // Override to support editing the table view. + - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + if (editingStyle == UITableViewCellEditingStyleDelete) { + // Delete the row from the data source + [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; + } else if (editingStyle == UITableViewCellEditingStyleInsert) { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } + } + */ + +/* + // Override to support rearranging the table view. + - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { + } + */ + +/* + // Override to support conditional rearranging of the table view. + - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { + // Return NO if you do not want the item to be re-orderable. + return YES; + } + */ + +/* + #pragma mark - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. + } + */ + +@end diff --git a/MessageJudge/Interface/Tabbar/MJTabBarController.m b/MessageJudge/Interface/Tabbar/MJTabBarController.m index cb33be9..3f36cd9 100644 --- a/MessageJudge/Interface/Tabbar/MJTabBarController.m +++ b/MessageJudge/Interface/Tabbar/MJTabBarController.m @@ -9,6 +9,8 @@ #import "MJTabBarController.h" #import "MJGroupListViewController.h" #import "GlobalDefine.h" +#import "MJJudgementRule.h" +#import "YYModel.h" @interface MJTabBarController () @@ -18,6 +20,31 @@ @implementation MJTabBarController - (void)viewDidLoad { [super viewDidLoad]; + + MJCondition *condition = [MJCondition new]; + condition.keyword = @"屏蔽屏蔽短信短信测试测试"; + condition.conditionType = MJConditionTypeHasPrefix; + condition.conditionTarget = MJConditionTargetContent; + + MJConditionGroup *blackGroup = [MJConditionGroup new]; + blackGroup.alias = @"黑名单别称"; + blackGroup.conditions = [@[condition] mutableCopy]; + + MJConditionGroup *whiteGroup = [MJConditionGroup new]; + whiteGroup.alias = @"别称"; + [whiteGroup.conditions addObject:condition]; + + [MJGlobalRule.whiteConditionGroupList addObject:whiteGroup]; + MJGlobalRule.blackConditionGroupList = [@[blackGroup] mutableCopy]; + + NSUserDefaults *extDefaults = [[NSUserDefaults alloc] initWithSuiteName:MJExtentsionAppGroupName]; + NSString *ruleString = [extDefaults objectForKey:MJExtentsionRuleKey]; + ruleString = [MJGlobalRule yy_modelToJSONString]; + if (ruleString) { + [extDefaults setObject:ruleString forKey:MJExtentsionRuleKey]; + } + + MJGroupListViewController *whiteListViewController = [[MJGroupListViewController alloc] initWithListType:MJGroupListTypeWhiteList]; MJGroupListViewController *blackListViewController = [[MJGroupListViewController alloc] initWithListType:MJGroupListTypeBlackList]; diff --git a/MessageJudge/ViewController.h b/MessageJudge/ViewController.h deleted file mode 100644 index a941edd..0000000 --- a/MessageJudge/ViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ViewController.h -// MessageJudge -// -// Created by GeXiao on 08/06/2017. -// Copyright © 2017 GeXiao. All rights reserved. -// - -#import - -@interface ViewController : UIViewController - - -@end - diff --git a/MessageJudge/ViewController.m b/MessageJudge/ViewController.m deleted file mode 100644 index 64705c8..0000000 --- a/MessageJudge/ViewController.m +++ /dev/null @@ -1,47 +0,0 @@ -// -// ViewController.m -// MessageJudge -// -// Created by GeXiao on 08/06/2017. -// Copyright © 2017 GeXiao. All rights reserved. -// - -#import "ViewController.h" -#import "MJJudgementRule.h" -#import "YYModel.h" - -@interface ViewController () - -@end - -@implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - - MJCondition *condition = [MJCondition new]; - condition.keyword = @"屏蔽"; - condition.conditionType = MJConditionTypeHasPrefix; - - MJConditionGroup *blackGroup = [MJConditionGroup new]; - blackGroup.conditions = [@[condition] mutableCopy]; - - MJJudgementRule *rule = [MJJudgementRule new]; - rule.blackConditionGroupList = [@[blackGroup] mutableCopy]; - - NSUserDefaults *extDefaults = [[NSUserDefaults alloc] initWithSuiteName:MJExtentsionAppGroupName]; - NSString *ruleString = [extDefaults objectForKey:MJExtentsionRuleKey]; - ruleString = [rule yy_modelToJSONString]; - if (ruleString) { - [extDefaults setObject:ruleString forKey:MJExtentsionRuleKey]; - } -} - - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - - -@end diff --git a/MessageJudgeExt/MessageFilterExtension.h b/MessageJudgeExt/MessageFilterExtension.h index 3b720de..f55f38b 100644 --- a/MessageJudgeExt/MessageFilterExtension.h +++ b/MessageJudgeExt/MessageFilterExtension.h @@ -7,7 +7,6 @@ // #import -#import "ViewController.h" @interface MessageFilterExtension : ILMessageFilterExtension