Skip to content

Commit

Permalink
Merge pull request #38 from didi/feature_support_translate
Browse files Browse the repository at this point in the history
Feature support translate
  • Loading branch information
ronghaopger authored May 18, 2022
2 parents 6dbfa5a + 762ede5 commit 85d8759
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ typedef NS_ENUM(NSUInteger, PrismBehaviorDescType) {
};

@interface PrismBehaviorTextModel : NSObject
@property (nonatomic, copy) NSString *operationName;
@property (nonatomic, assign) PrismBehaviorDescType descType;
@property (nonatomic, copy) NSString *descContent;
@property (nonatomic, copy) NSString *descTime;
@property (nonatomic, assign) PrismInstructionArea areaInfo;
@property (nonatomic, copy) NSString *operationName; //操作文案
@property (nonatomic, assign) PrismInstructionArea areaInfo; //区位信息
@property (nonatomic, copy) NSString *areaText; //区位信息文案
@property (nonatomic, copy) NSString *moduleText; //模块名称
@property (nonatomic, copy) NSString *elementName; //操作元素类型名称
@property (nonatomic, assign) PrismBehaviorDescType descType; //操作内容呈现类型
@property (nonatomic, copy) NSString *descContent; //操作内容
@property (nonatomic, copy) NSString *descTime; //间隔时长
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
NS_ASSUME_NONNULL_BEGIN

@interface PrismBehaviorTranslater : NSObject

+ (void)setCustomTranslater:(void(^)(PrismBehaviorVideoModel*,PrismBehaviorTextModel*))customTranslater;
+ (PrismBehaviorTextModel*)translateWithModel:(PrismBehaviorVideoModel*)model;
@end

Expand Down
240 changes: 169 additions & 71 deletions iOS/DiDiPrism/Src/Ability/BehaviorReplay/Model/PrismBehaviorTranslater.m

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ + (NSString*)getViewContentOfControl:(UIControl*)control {
// 获取有代表性的内容便于更好的定位view
viewContent = [PrismInstructionContentUtil getRepresentativeContentOfView:control needRecursive:YES];
}
// 兜底考虑把UIButton仅作为给父View添加触控能力的工具控件的场景(此时UIButton通常就是个空白按钮),此时向上遍历真正有意义的父级View。
if (!viewContent.length && [control isKindOfClass:[UIButton class]]) {
UIView *superView = control.superview;
if (superView && !CGRectIsEmpty(superView.bounds)) {
if (CGRectEqualToRect(control.frame, superView.bounds)
|| ((control.frame.size.width * control.frame.size.height) / (superView.bounds.size.width * superView.bounds.size.height) > 0.99)) {
viewContent = [PrismInstructionContentUtil getRepresentativeContentOfView:superView needRecursive:YES];
}
}
}
return viewContent;
}

Expand All @@ -70,7 +80,7 @@ + (NSString*)getViewContentOfButton:(UIButton*)button {
else if (button.titleLabel.attributedText.length) {
return [NSString stringWithFormat:@"%@%@", kViewRepresentativeContentTypeText, button.titleLabel.attributedText.string];
}
else if (button.imageView.image) {
else if (button.imageView.image && button.imageView.image.prismAutoDotImageName.length) {
return [NSString stringWithFormat:@"%@%@", kViewRepresentativeContentTypeLocalImage, button.imageView.image.prismAutoDotImageName];
}
return nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef NS_ENUM(NSUInteger, PrismInstructionArea) {
*/
+ (NSArray<NSString*>*)getAreaInfoWithElement:(UIView *)element;
+ (NSInteger)getIndexOf:(UIView*)element fromScrollView:(UIScrollView*)scrollView;
+ (NSString*)getAreaTextWithInfo:(PrismInstructionArea)areaInfo;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,44 @@ + (NSInteger)getIndexOf:(UIView*)element fromScrollView:(UIScrollView*)scrollVie
return [sortedSubviews indexOfObject:element];
}

+ (NSString *)getAreaTextWithInfo:(PrismInstructionArea)areaInfo {
NSString *text = nil;
switch (areaInfo) {
case PrismInstructionAreaCenter:
text = @"[屏幕中央]";
break;
case PrismInstructionAreaUp:
text = @"[屏幕上方]";
break;
case PrismInstructionAreaBottom:
text = @"[屏幕下方]";
break;
case PrismInstructionAreaLeft:
text = @"[屏幕左方]";
break;
case PrismInstructionAreaRight:
text = @"[屏幕右方]";
break;
case PrismInstructionAreaUpLeft:
text = @"[屏幕左上]";
break;
case PrismInstructionAreaUpRight:
text = @"[屏幕右上]";
break;
case PrismInstructionAreaBottomLeft:
text = @"[屏幕左下]";
break;
case PrismInstructionAreaBottomRight:
text = @"[屏幕右下]";
break;
case PrismInstructionAreaCanScroll:
text = @"[列表]";
break;
default:
break;
}
return text;
}

#pragma mark - private method
@end
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ + (NSString*)getRepresentativeContentOfView:(UIView*)view needRecursive:(BOOL)ne
}
if ([view isKindOfClass:[UIImageView class]]) {
UIImageView *imageView = (UIImageView*)view;
SEL sd_selector = NSSelectorFromString(@"sd_imageURL");
if (imageView.image.prismAutoDotImageName.length) {
return [NSString stringWithFormat:@"%@%@", kViewRepresentativeContentTypeLocalImage, imageView.image.prismAutoDotImageName];
}
else if ([imageView respondsToSelector:sd_selector]) {
NSURL *imageUrl = [imageView performSelector:sd_selector];
if ([imageUrl isKindOfClass:[NSURL class]] && imageUrl.absoluteString.length) {
return [NSString stringWithFormat:@"%@%@", kViewRepresentativeContentTypeNetworkImage, imageUrl.absoluteString];
}
}
}
if ([wxComponent isKindOfClass:NSClassFromString(@"WXImageComponent")]) {
NSString *src = [[wxComponent valueForKey:@"attributes"] valueForKey:@"src"];
Expand Down
93 changes: 66 additions & 27 deletions iOS/DiDiPrismDemo/DiDiPrismDemo/View/BehaviorTextDescViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @interface BehaviorTextDescViewCell()
@property (nonatomic, strong) UILabel *phoneView;
@property (nonatomic, strong) UIView *phoneBarView;
@property (nonatomic, strong) UIView *locationView;
@property (nonatomic, strong) UILabel *locationLabel;

@end

Expand All @@ -40,30 +41,30 @@ - (void)updateConstraints {
CGFloat height = _textModel.descType == PrismBehaviorDescTypeNetworkImage ? 100 : 30;
[self.contentLabel removeConstraints:self.contentLabel.constraints];
[self.contentImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(140);
make.right.equalTo(self.timeLabel.mas_left).offset(-20);
make.top.equalTo(self.contentView).offset(13);
make.bottom.equalTo(self.contentView).offset(-13);
make.left.equalTo(self.contentView).offset(125);
make.right.equalTo(self.timeLabel.mas_left).offset(-15);
make.top.equalTo(self.contentView).offset(20);
make.bottom.equalTo(self.contentView).offset(-20);
make.height.mas_equalTo(height);
}];
}
else if (_textModel.descType == PrismBehaviorDescTypeNone) {
[self.contentImageView removeConstraints:self.contentImageView.constraints];
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(140);
make.right.equalTo(self.timeLabel.mas_left).offset(-20);
make.top.equalTo(self.contentView).offset(13);
make.bottom.equalTo(self.contentView).offset(-13);
make.left.equalTo(self.contentView).offset(125);
make.right.equalTo(self.timeLabel.mas_left).offset(-15);
make.top.equalTo(self.contentView).offset(20);
make.bottom.equalTo(self.contentView).offset(-20);
make.height.mas_equalTo(20);
}];
}
else {
[self.contentImageView removeConstraints:self.contentImageView.constraints];
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(140);
make.right.equalTo(self.timeLabel.mas_left).offset(-20);
make.top.equalTo(self.contentView).offset(13);
make.bottom.equalTo(self.contentView).offset(-13);
make.left.equalTo(self.contentView).offset(125);
make.right.equalTo(self.timeLabel.mas_left).offset(-15);
make.top.equalTo(self.contentView).offset(20);
make.bottom.equalTo(self.contentView).offset(-20);
make.height.mas_equalTo(30);
}];
}
Expand All @@ -88,13 +89,14 @@ - (void)initView {
[self.contentView addSubview:self.phoneView];
[self.contentView addSubview:self.phoneBarView];
[self.contentView addSubview:self.locationView];
[self.contentView addSubview:self.locationLabel];

[self.indexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(18);
make.left.equalTo(self.contentView).offset(15);
make.centerY.equalTo(self.contentView);
}];
[self.operationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(55);
make.left.equalTo(self.contentView).offset(37);
make.centerY.equalTo(self.contentView);
}];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
Expand All @@ -105,8 +107,8 @@ - (void)initView {
make.left.top.equalTo(self.contentView).offset(1);
}];
[self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(120);
make.centerY.equalTo(self.contentView);
make.left.equalTo(self.contentView).offset(95);
make.top.equalTo(self.contentView).offset(7);
make.width.mas_equalTo(kPhoneWidth);
make.height.mas_equalTo(kPhoneHeight);
}];
Expand All @@ -116,6 +118,10 @@ - (void)initView {
make.width.mas_equalTo(10);
make.height.mas_equalTo(4);
}];
[self.locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.phoneView);
make.top.equalTo(self.phoneView.mas_bottom).offset(2);
}];
}

#pragma mark - setters
Expand All @@ -124,17 +130,27 @@ - (void)setTextModel:(PrismBehaviorTextModel *)textModel {

self.operationLabel.text = _textModel.operationName;
self.timeLabel.text = _textModel.descTime;
self.locationLabel.text = _textModel.areaText;
switch (_textModel.descType) {
case PrismBehaviorDescTypeNone:
{
self.contentLabel.text = @"[无法翻译]";
NSString *moduleText = _textModel.moduleText.length ? [NSString stringWithFormat:@"%@ - ", _textModel.moduleText] : @"";
NSString *elementName = _textModel.elementName.length ? [NSString stringWithFormat:@"%@", _textModel.elementName] : @"";
if (moduleText.length || elementName.length) {
self.contentLabel.text = [NSString stringWithFormat:@"%@%@%@", moduleText, _textModel.descContent ?: @"", elementName];
}
else {
self.contentLabel.text = @"[无法翻译]";
}
self.contentLabel.hidden = NO;
self.contentImageView.hidden = YES;
}
break;
case PrismBehaviorDescTypeText:
{
self.contentLabel.text = _textModel.descContent;
NSString *moduleText = _textModel.moduleText.length ? [NSString stringWithFormat:@"%@ - ", _textModel.moduleText] : @"";
NSString *elementName = _textModel.elementName.length ? [NSString stringWithFormat:@"%@", _textModel.elementName] : @"";
self.contentLabel.text = [NSString stringWithFormat:@"%@%@%@", moduleText, _textModel.descContent, elementName];
self.contentLabel.hidden = NO;
self.contentImageView.hidden = YES;
}
Expand Down Expand Up @@ -171,6 +187,15 @@ - (void)setTextModel:(PrismBehaviorTextModel *)textModel {
self.contentLabel.hidden = YES;
}
break;
case PrismBehaviorDescTypeCode:
{
NSString *moduleText = _textModel.moduleText.length ? [NSString stringWithFormat:@"%@ - ", _textModel.moduleText] : @"";
NSString *elementName = _textModel.elementName.length ? [NSString stringWithFormat:@"%@", _textModel.elementName] : @"";
self.contentLabel.text = [NSString stringWithFormat:@"%@[函数名]%@%@", moduleText, _textModel.descContent, elementName];
self.contentLabel.hidden = NO;
self.contentImageView.hidden = YES;
}
break;
default:
break;
}
Expand All @@ -185,21 +210,22 @@ - (void)setTextModel:(PrismBehaviorTextModel *)textModel {
self.phoneView.text = nil;
self.phoneBarView.hidden = NO;
self.locationView.hidden = NO;
self.locationLabel.hidden = NO;

switch (_textModel.areaInfo) {
case PrismInstructionAreaUp:
{
width = 6;
width = kPhoneWidth;
height = kPhoneHeight / 2;
left = kPhoneWidth / 2 - 3;
left = 0;
top = 0;
}
break;
case PrismInstructionAreaBottom:
{
width = 6;
width = kPhoneWidth;
height = kPhoneHeight / 2;
left = kPhoneWidth / 2 - 3;
left = 0;
top = kPhoneHeight / 2;
}
break;
Expand Down Expand Up @@ -261,14 +287,15 @@ - (void)setTextModel:(PrismBehaviorTextModel *)textModel {
break;
case PrismInstructionAreaCanScroll:
{
self.phoneView.text = @"列表";
self.phoneView.text = @"---\r\n---\r\n---";
}
break;
default:
{
self.phoneView.hidden = YES;
self.phoneBarView.hidden = YES;
self.locationView.hidden = YES;
self.locationLabel.hidden = YES;
}
break;
}
Expand All @@ -289,7 +316,7 @@ - (void)setTextModel:(PrismBehaviorTextModel *)textModel {
- (UILabel *)indexLabel {
if (!_indexLabel) {
_indexLabel = [[UILabel alloc] init];
_indexLabel.font = [UIFont systemFontOfSize:14];
_indexLabel.font = [UIFont systemFontOfSize:12];
_indexLabel.textColor = [UIColor prism_colorWithHexString:@"#666666"];
_indexLabel.textAlignment = NSTextAlignmentCenter;
}
Expand All @@ -299,7 +326,7 @@ - (UILabel *)indexLabel {
- (UILabel *)operationLabel {
if (!_operationLabel) {
_operationLabel = [[UILabel alloc] init];
_operationLabel.font = [UIFont systemFontOfSize:14];
_operationLabel.font = [UIFont systemFontOfSize:12];
_operationLabel.textColor = [UIColor prism_colorWithHexString:@"#666666"];
_operationLabel.textAlignment = NSTextAlignmentCenter;
}
Expand All @@ -309,9 +336,10 @@ - (UILabel *)operationLabel {
- (UILabel *)contentLabel {
if (!_contentLabel) {
_contentLabel = [[UILabel alloc] init];
_contentLabel.font = [UIFont boldSystemFontOfSize:14];
_contentLabel.font = [UIFont boldSystemFontOfSize:12];
_contentLabel.textColor = [UIColor prism_colorWithHexString:@"#333333"];
_contentLabel.textAlignment = NSTextAlignmentCenter;
_contentLabel.numberOfLines = 0;
}
return _contentLabel;
}
Expand All @@ -327,7 +355,7 @@ - (UIImageView *)contentImageView {
- (UILabel *)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc] init];
_timeLabel.font = [UIFont boldSystemFontOfSize:14];
_timeLabel.font = [UIFont boldSystemFontOfSize:12];
_timeLabel.textColor = [UIColor prism_colorWithHexString:@"#333333"];
_timeLabel.textAlignment = NSTextAlignmentRight;
}
Expand Down Expand Up @@ -355,6 +383,7 @@ - (UILabel *)phoneView {
_phoneView.textColor = [UIColor prism_colorWithHexString:@"#666666"];
_phoneView.font = [UIFont systemFontOfSize:8];
_phoneView.textAlignment = NSTextAlignmentCenter;
_phoneView.numberOfLines = 0;
}
return _phoneView;
}
Expand All @@ -375,4 +404,14 @@ - (UIView *)locationView {
}
return _locationView;
}

- (UILabel *)locationLabel {
if (!_locationLabel) {
_locationLabel = [[UILabel alloc] init];
_locationLabel.font = [UIFont systemFontOfSize:10];
_locationLabel.textColor = [UIColor prism_colorWithHexString:@"#666666"];
_locationLabel.textAlignment = NSTextAlignmentCenter;
}
return _locationLabel;
}
@end

0 comments on commit 85d8759

Please sign in to comment.