Skip to content

Commit

Permalink
Add tableviews to show groups and conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
bynil committed Jun 11, 2017
1 parent bb08b55 commit 5fed207
Show file tree
Hide file tree
Showing 15 changed files with 430 additions and 87 deletions.
26 changes: 18 additions & 8 deletions MessageJudge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@
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 */; };
C24034FE1EE9C14900AE3122 /* MJCondition.m in Sources */ = {isa = PBXBuildFile; fileRef = C293E31A1EE962BB00195831 /* MJCondition.m */; };
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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
C21D81921EE9B7C80080F8CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C21FDFED1EED74BC006B7CCB /* MJGroupViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJGroupViewController.h; sourceTree = "<group>"; };
C21FDFEE1EED74BC006B7CCB /* MJGroupViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJGroupViewController.m; sourceTree = "<group>"; };
C21FDFF01EED77B4006B7CCB /* MJConditionCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJConditionCell.h; sourceTree = "<group>"; };
C21FDFF11EED77B4006B7CCB /* MJConditionCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJConditionCell.m; sourceTree = "<group>"; };
C227FC991EEA87B6008B6F2F /* MJQueryRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJQueryRequest.h; sourceTree = "<group>"; };
C227FC9A1EEA87B6008B6F2F /* MJQueryRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJQueryRequest.m; sourceTree = "<group>"; };
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 = "<group>"; };
C247223A1EE934EF0092DF98 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
C247223C1EE934EF0092DF98 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
C247223D1EE934EF0092DF98 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
C24722401EE934EF0092DF98 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
C24722421EE934EF0092DF98 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C24722451EE934EF0092DF98 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
Expand All @@ -102,6 +105,8 @@
C24722581EE935230092DF98 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C24722601EE937120092DF98 /* MessageJudge.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MessageJudge.entitlements; sourceTree = "<group>"; };
C24722611EE937680092DF98 /* MessageJudgeExt.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MessageJudgeExt.entitlements; sourceTree = "<group>"; };
C29321BA1EED433200D60C4B /* MJGroupCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJGroupCell.h; sourceTree = "<group>"; };
C29321BB1EED433200D60C4B /* MJGroupCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJGroupCell.m; sourceTree = "<group>"; };
C293E3161EE9625800195831 /* MJJudgementRule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJJudgementRule.h; sourceTree = "<group>"; };
C293E3171EE9625800195831 /* MJJudgementRule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJJudgementRule.m; sourceTree = "<group>"; };
C293E3191EE962BB00195831 /* MJCondition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJCondition.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
2 changes: 2 additions & 0 deletions MessageJudge/GlobalDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
12 changes: 12 additions & 0 deletions MessageJudge/I18n/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "匹配正则";
19 changes: 19 additions & 0 deletions MessageJudge/Interface/GroupList/MJConditionCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// MJConditionCell.h
// MessageJudge
//
// Created by GeXiao on 11/06/2017.
// Copyright © 2017 GeXiao. All rights reserved.
//

#import <UIKit/UIKit.h>

static NSString *MJConditionCellReuseIdentifier = @"MJConditionCellReuseIdentifier";

@class MJCondition;

@interface MJConditionCell : UITableViewCell

- (void)renderCellWithCondition:(MJCondition *)condition;

@end
135 changes: 135 additions & 0 deletions MessageJudge/Interface/GroupList/MJConditionCell.m
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions MessageJudge/Interface/GroupList/MJGroupCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// MJGroupCell.h
// MessageJudge
//
// Created by GeXiao on 11/06/2017.
// Copyright © 2017 GeXiao. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "MJConditionGroup.h"

static NSString *MJGroupCellReuseIdentifier = @"MJGroupCellReuseIdentifier";

@interface MJGroupCell : UITableViewCell

- (void)renderCellWithGroup:(MJConditionGroup *)group;

@end
31 changes: 31 additions & 0 deletions MessageJudge/Interface/GroupList/MJGroupCell.m
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions MessageJudge/Interface/GroupList/MJGroupListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MJConditionGroup *> *groupList;

- (instancetype)initWithListType:(MJGroupListType)type;

Expand Down
Loading

0 comments on commit 5fed207

Please sign in to comment.