Commit 096f59fc by 刘卓鑫

修复多彩蓝牙洗衣bug

parent b611ce6c
//
//
......@@ -33,5 +33,19 @@
@property (nonatomic, strong) NSArray *consumeRefundOrders;
@property (nonatomic, strong) NSArray *baseData;
@property (nonatomic, strong) NSArray *consumeData;
@end
@interface orderItem : NSObject
/** */
@property (nonatomic, copy) NSString *color;
/** */
@property (nonatomic, copy) NSString *name;
/** */
@property (nonatomic, copy) NSString *value;
@end
//
//
......@@ -9,5 +9,14 @@
#import "CommonModel.h"
@implementation CommonModel
/* 数组中存储模型数据,需要说明数组中存储的模型数据类型 */
+(NSDictionary *)mj_objectClassInArray
{
return @{@"baseData" : @"orderItem", @"consumeData" : @"orderItem"};
}
@end
@implementation orderItem
@end
//
//
......@@ -228,7 +228,6 @@
[ZXTool showText:@"设备开启成功"];
[self backToFirst];
}
}
});
}];
......@@ -246,9 +245,7 @@
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.bluetoothManager cutBluetoothAndSocketConnect];
self.bluetoothManager.delegate = nil;
self.bluetoothManager = nil;
[self.bluetoothManager closeSelf];
}
- (void)dealloc {
......
//
//
......@@ -49,6 +49,11 @@ NS_ASSUME_NONNULL_BEGIN
//主动断开 所有链接 在接口调用失败的时候使用
- (void) cutBluetoothAndSocketConnect;
//断开连接
- (void) closeSelf;
@end
NS_ASSUME_NONNULL_END
//
//
......@@ -64,8 +64,6 @@
- - clientSocket {
if (!_clientSocket) {
}
return _clientSocket;
}
......@@ -185,7 +183,7 @@
if (self.clientSocket.isConnected == NO) {
times += 0.5;
if (self.clientSocket.isConnected == NO) {
[self.clientSocket connectToHost:self.socketUrl onPort:self.socketPort viaInterface:nil withTimeout:-1 error:nil];
[self.clientSocket connectToHost:self.socketUrl onPort:self.socketPort viaInterface:nil withTimeout:-1 error:nil];
}
}
......@@ -574,6 +572,10 @@
[self.delegate startFireInterfaceByStatus:2];
}
}
} else if ([text containsString:[NSString stringWithFormat:@"[<%@,60", self.currentPeripheralName]]) {
NSLog(@"=============收到服务器发送给蓝牙的开启设备指令");
NSString *result = [[text componentsSeparatedByString:@","].lastObject stringByReplacingOccurrencesOfString:@">]" withString:@""];
[self.tempData addObject:[result dataUsingEncoding:NSUTF8StringEncoding]];
} else {
//发送给蓝牙
if (data.length > 100) {
......@@ -591,7 +593,7 @@
}
if (self.selectedPeripheral && self.currentCharacteristic) {
NSLog(@"😁开始发送队列消息--%@", self.tempData);
NSLog(@"😁=============开始发送队列消息--%@", self.tempData);
NSData *data = self.tempData[0];//去第一个
if (data.length > 20) {
......@@ -623,7 +625,7 @@
// 链接失败
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err{
//重连
NSLog(@"😇😇😇😇😇😇 socket连接已经断开---%@", [ZXTool getTimeNow]);
NSLog(@"==============socket链接失败或者断开===================");
if (self.isServiceCut == NO) {
......@@ -645,7 +647,7 @@
[self.clientSocket disconnect];//断开socket
self.clientSocket.delegate = nil;
self.clientSocket = nil;
// self.centralManager.delegate = nil;
// self.centralManager = nil;
self.isServiceCut = YES;//触发服务端中断指
......@@ -667,4 +669,18 @@
}
return _tempData;
}
- (void)closeSelf {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self cutBluetoothAndSocketConnect];
self.delegate = nil;
self.centralManager.delegate = nil;
self.centralManager = nil;
self.clientSocket.delegate = nil;
self.clientSocket = nil;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[self class];
});
});
}
@end
//
//
......@@ -10,9 +10,10 @@
#import "enlargeClickRegionBtn.h"
#import "ZXNewOrderDetailTableViewCell.h"
#import "ZXNewPayOrder.h"
#import "ZXNewOrderDetailCell.h"
@interface ZXNewOrderDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) ZXNewPayOrder *order;
@property (nonatomic, strong) CommonModel *order;
@end
......@@ -24,19 +25,43 @@
[self createNabar];
[self.view addSubview:self.myTableView];
[ZXTool requestDataWithType:kXMHTTPMethodGET url:[NSString stringWithFormat:@"%@/consumeOrder/getDetail?id=%ld", [kUserDefaults objectForKey:@"NEW_PAY"], (long)self.orderId] para:nil completed:^(CommonModel *common, NSString *error) {
// [ZXTool requestDataWithType:kXMHTTPMethodGET url:[NSString stringWithFormat:@"%@/consumeOrder/getDetail?id=%ld", [kUserDefaults objectForKey:@"NEW_PAY"], (long)self.orderId] para:nil completed:^(CommonModel *common, NSString *error) {
// dispatch_async(dispatch_get_main_queue(), ^{
// [ZXTool hideLoadingAnimation];
// if (error) {
// [ZXTool showErrorMsg:error];
// } else {
// ZXNewPayOrder *order = [ZXNewPayOrder mj_objectWithKeyValues:common.data];
// order.tkData = common.consumeRefundOrders;
// self.order = order;
// [self.myTableView reloadData];
// }
// });
// }];
[ZXTool requestDataWithType:kXMHTTPMethodGET url:[NSString stringWithFormat:@"%@/consumeOrder/getDetailNew?id=%ld", [kUserDefaults objectForKey:@"NEW_PAY"], (long)self.orderId] para:nil completed:^(CommonModel *common, NSString *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[ZXTool hideLoadingAnimation];
if (error) {
[ZXTool showErrorMsg:error];
} else {
ZXNewPayOrder *order = [ZXNewPayOrder mj_objectWithKeyValues:common.data];
order.tkData = common.consumeRefundOrders;
self.order = order;
for (orderItem *item in common.baseData) {
if (!item.color || [item.color isEqualToString:@""] || [item.color isKindOfClass:[NSNull class]] || [item.color isEqualToString:@"null"] || [item.color isEqualToString:@"<null>"]) {
item.color = @"#333333";
}
}
for (orderItem *item in common.consumeData) {
if (!item.color || [item.color isEqualToString:@""] || [item.color isKindOfClass:[NSNull class]] || [item.color isEqualToString:@"null"] || [item.color isEqualToString:@"<null>"]) {
item.color = @"#333333";
}
}
self.order = common;
[self.myTableView reloadData];
}
});
}];
}
- (void) createNabar {
self.view.backgroundColor = [UIColor whiteColor];
......@@ -97,12 +122,19 @@
return self.order?1:0;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ZXNewOrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZXNewOrderDetailTableViewCell"];
// ZXNewOrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZXNewOrderDetailTableViewCell"];
// if (cell == nil) {
// cell = [[ZXNewOrderDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ZXNewOrderDetailTableViewCell"];
// }
// cell.orderDetail = self.order;
// return cell;
ZXNewOrderDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZXNewOrderDetailCell"];
if (cell == nil) {
cell = [[ZXNewOrderDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ZXNewOrderDetailTableViewCell"];
cell = [[ZXNewOrderDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ZXNewOrderDetailCell"];
}
cell.order = self.order;
cell.orderDetail = self.order;
return cell;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 470 * k6Scale;
......
//
//
// ZXNewOrderDetailCell.h
// ColorfulSchool
//
// Created by 刘卓鑫 on 2019/12/3.
// Copyright © 2019 Colorful Any Door. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ZXNewOrderDetailCell : UITableViewCell
@property (nonatomic, strong) CommonModel *orderDetail;
@end
NS_ASSUME_NONNULL_END
//
//
......@@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface ZXNewOrderDetailTableViewCell : UITableViewCell
@property (nonatomic, strong) ZXNewPayOrder *order;
@property (nonatomic, strong) CommonModel *orderDetail;
@end
NS_ASSUME_NONNULL_END
//
//
......@@ -176,15 +176,14 @@
}];
self.deviceAddressLabel = [[UILabel alloc] init];
[self.contentView addSubview:self.deviceAddressLabel];
self.deviceAddressLabel.textColor = kContentGrayColor;
self.deviceAddressLabel.font = kFontSize(14 * k6Scale);
[self.deviceAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).offset(-16 * k6Scale);
make.left.equalTo(label7.mas_right).offset(10 * k6Scale);
make.width.mas_lessThanOrEqualTo(250 * k6Scale);
make.centerY.equalTo(label7);
}];
[label7 setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
UIImageView *line = [[UIImageView alloc] init];
[self.contentView addSubview:line];
......@@ -341,7 +340,11 @@
self.thirdRightLabel.textColor = kTitleBlackColor;
BOOL isHasTK = _order.tkData.count;//是否有退款
NSString *refundMoney;
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
refundMoney = [NSString stringWithFormat:@"-%.2f", [dic[@"refundMoney"] doubleValue]];
}
//同时抵扣豆和艾米
if (_order.deductionBean > 0 && _order.deductionMoney > 0) {
......@@ -360,7 +363,6 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.sixthLeftLabel.attributedText = tkType==1?[self toAtts:@"全部退款"]:[self toAtts:@"部分退款"];
self.sixthRightLabel.attributedText = [self toAtts:refundMoney];
......@@ -386,7 +388,7 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.fifthLeftLabel.attributedText = tkType==1?[self toAtts:@"全部退款"]:[self toAtts:@"部分退款"];
self.fifthRightLabel.attributedText = [self toAtts:refundMoney];
self.sixthLeftLabel.text = @"支付时间";
......@@ -422,7 +424,7 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.fifthLeftLabel.attributedText = tkType==1?[self toAtts:@"全部退款"]:[self toAtts:@"部分退款"];
self.fifthRightLabel.attributedText = [self toAtts:refundMoney];
......@@ -448,7 +450,7 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.fourthLeftLabel.attributedText = tkType==1?[self toAtts:@"全部退款"]:[self toAtts:@"部分退款"];
self.fourthRightLabel.attributedText = [self toAtts:refundMoney];
......@@ -484,7 +486,7 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.fifthLeftLabel.attributedText = tkType==1?[self toAtts:@"全部退款"]:[self toAtts:@"部分退款"];
self.fifthRightLabel.attributedText = [self toAtts:refundMoney];
self.sixthLeftLabel.text = @"支付时间";
......@@ -512,7 +514,7 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.fourthLeftLabel.attributedText = tkType==1?[self toAtts:@"全部退款"]:[self toAtts:@"部分退款"];
self.fourthRightLabel.attributedText = [self toAtts:refundMoney];
......@@ -543,7 +545,7 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.fourthLeftLabel.text = tkType==1?@"全部退款":@"部分退款";
self.fourthRightLabel.text = refundMoney;
self.fifthLeftLabel.text = @"支付时间";
......@@ -568,7 +570,7 @@
if (isHasTK) {
NSDictionary *dic = _order.tkData.firstObject;
NSInteger tkType = [dic[@"refundState"] integerValue];
NSString *refundMoney = [@"-" stringByAppendingString:[dic[@"refundMoney"] stringValue]];
self.thirdLeftLabel.attributedText = tkType==1?[self toAtts:@"全部退款"]:[self toAtts:@"部分退款"];
self.thirdRightLabel.attributedText = [self toAtts:refundMoney];
self.fourthLeftLabel.text = @"支付时间";
......@@ -599,6 +601,11 @@
self.deviceAddressLabel.text = _order.equipmentPosition;
}
- (void)setOrderDetail:(CommonModel *)orderDetail {
_orderDetail = orderDetail;
self.moneyLabel.text = _orderDetail.title;
}
- (NSString *) payType:(ZXNewPayOrder *) typeModel {
NSString *type = typeModel.payType;
......
//
//
......@@ -49,7 +49,7 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aouthSuccess:) name:kWX_AUTH_RESULT object:nil];
}
#pragma mark - 是否需要展示第三方登录按钮
......@@ -401,11 +401,11 @@
[UIApplication sharedApplication].statusBarStyle = 0;
self.navigationController.navigationBar.hidden = YES;
[UIApplication sharedApplication].statusBarHidden = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aouthSuccess:) name:kWX_AUTH_RESULT object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kWX_AUTH_RESULT object:nil];
}
#pragma mark - 微信授权成功
- (void) aouthSuccess:(NSNotification *) nof {
......@@ -473,6 +473,10 @@
};
[self.navigationController pushViewController:oauthVc animated:YES];
}
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[ZXTool showText:error];
});
}
});
......
//
//
......@@ -20,6 +20,9 @@ kSINGLETON_FOR_HEADER(ZXTaskManager)
@property (nonatomic, assign) NSInteger status;
/** 任务是否完成 */
@property (nonatomic, assign) BOOL isTaskCompleted;
@end
NS_ASSUME_NONNULL_END
//
//
......@@ -30,6 +30,11 @@
/** */
@property (nonatomic, copy) NSString *wxCode;
/** */
@property (nonatomic, strong) UIView *adSuperView;
@end
@implementation ZXTaskViewController
......@@ -46,8 +51,7 @@
[self preloadCSJRewardAd];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aouthSuccess:) name:kWX_AUTH_RESULT object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
......@@ -83,12 +87,14 @@
}
#pragma mark - 添加广告
- (void) addBannerAd {
[ZXTool requestDataHideLoadingToastWithType:kXMHTTPMethodGET url:[NSString stringWithFormat:@"%@/advert/get/initdata?pageNo=TASK_PAGE", [kUserDefaults objectForKey:@"Task"]] para:nil completed:^(CommonModel *common, NSString *error) {
if (common && common.data && common.data[@"adverts"]) {
NSArray *arr = common.data[@"adverts"];
for (NSDictionary *dic in arr) {
if ([dic[@"type"] integerValue] == 5) {
dispatch_async(dispatch_get_main_queue(), ^{
[self createBannerAd];
});
}
......@@ -98,28 +104,35 @@
}
#pragma mark - 创建广告
- (void) createBannerAd {
UIView *adSuperView = [[UIView alloc] init];
[self.view addSubview:adSuperView];
adSuperView.backgroundColor = UIColor.whiteColor;
[adSuperView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.height.mas_equalTo(kScreenWidth * 0.15);
make.bottom.equalTo(self.view.mas_bottom).offset(self.isTaskHomePage?-kTabBarHeight:0);
}];
if (self.adSuperView == nil) {
self.adSuperView = [[UIView alloc] init];
[self.view addSubview:self.adSuperView];
self.adSuperView.backgroundColor = UIColor.whiteColor;
[self.adSuperView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.height.mas_equalTo(kScreenWidth * 0.15);
make.bottom.equalTo(self.view.mas_bottom).offset(self.isTaskHomePage?-kTabBarHeight:0);
}];
enlargeClickRegionBtn *closeButton = [[enlargeClickRegionBtn alloc] init];
[adSuperView addSubview:closeButton];
[closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.top.equalTo(adSuperView);
make.width.height.mas_equalTo(30 * k6Scale);
}];
[self.adSuperView addSubview:closeButton];
[closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.top.equalTo(self.adSuperView);
make.width.height.mas_equalTo(30 * k6Scale);
}];
[[closeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
adSuperView.hidden = YES;
[adSuperView removeFromSuperview];
self.adSuperView.hidden = YES;
}];
[[[BUADTool alloc] init] loadBannerAdWithController:self superView:adSuperView];
}
for (UIView *v in self.adSuperView.subviews) {
if (![v isKindOfClass:[enlargeClickRegionBtn class]]) {
[v removeFromSuperview];
}
}
self.adSuperView.hidden = NO;
[[[BUADTool alloc] init] loadBannerAdWithController:self superView:self.adSuperView];
}
#pragma mark - ========== 加载失败的时候 创建holder ==========
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
......@@ -184,11 +197,13 @@
NSArray *arr = message.body;
NSString *classStr = arr[3];
NSInteger taskType = [arr[1] integerValue];
if (taskType == 3 && ([classStr isEqualToString:@""] || classStr == nil)) {
return;
}
self.jsFuncName = arr[0];
[ZXTaskManager sharedZXTaskManager].taskCode = arr[2];
[ZXTaskManager sharedZXTaskManager].isTaskCompleted = (taskType == 3);
switch (taskType) {
case 1: {//激励视频
[self taskRewardVideo];
......@@ -283,6 +298,8 @@
if (@available(iOS 11, *)) {
UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:kWX_AUTH_RESULT object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
......@@ -293,9 +310,12 @@
[self ba_JS_OC];
//如果有任务id 代表还有任务完成需要提示
if (ZXTaskManager.sharedZXTaskManager.taskCode && ![ZXTaskManager.sharedZXTaskManager.taskCode isEqualToString:@""]) {
if (ZXTaskManager.sharedZXTaskManager.taskCode && ![ZXTaskManager.sharedZXTaskManager.taskCode isEqualToString:@""] && ZXTaskManager.sharedZXTaskManager.isTaskCompleted) {
[self taskCompleted];
}
ZXTaskManager.sharedZXTaskManager.isTaskCompleted = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aouthSuccess:) name:kWX_AUTH_RESULT object:nil];
}
- (void)didReceiveMemoryWarning {
......@@ -313,7 +333,7 @@
- (void) preloadCSJRewardAd {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
BURewardedVideoModel *model = [[BURewardedVideoModel alloc] init];
model.userId = @"123";
model.userId = CacheUserId;
self.rewardedAd = [[BUNativeExpressRewardedVideoAd alloc] initWithSlotID:@"933112439" rewardedVideoModel:model];
self.rewardedAd.delegate = self;
[self.rewardedAd loadAdData];
......@@ -329,7 +349,6 @@
[self.rewardedAd showAdFromRootViewController:self.navigationController];
[self.reward load];
}
}
#pragma mark - BUNativeExpressRewardedVideoAdDelegate
......@@ -365,7 +384,7 @@
- (void)nativeExpressRewardedVideoAdWillClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
//关闭视频
[ZXTaskManager sharedZXTaskManager].isTaskCompleted = 1;
}
- (void)nativeExpressRewardedVideoAdDidClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
......@@ -449,8 +468,6 @@
}
});
}];
}
#pragma mark - 回调前端已经任务完成
......@@ -501,6 +518,9 @@
if (error) {
[ZXTool showText:error];
} else {
if (self.jsFuncName == nil || [self.jsFuncName isEqualToString:@""]) {
self.jsFuncName = @"bindWechatCallback";
}
[self.webView evaluateJavaScript:[NSString stringWithFormat:@"%@()", self.jsFuncName] completionHandler:^(id _Nullable res, NSError * _Nullable error) {
}];
......
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSBundle (PYSearchExtension)
/**
Get the localized string
@param key key for localized string
@return a localized string
*/
+ (NSString *)py_localizedStringForKey:(NSString *)key;
/**
Get the path of `PYSearch.bundle`.
@return path of the `PYSearch.bundle`
*/
+ (NSBundle *)py_searchBundle;
/**
Get the image in the `PYSearch.bundle` path
@param name name of image
@return a image
*/
+ (UIImage *)py_imageNamed:(NSString *)name;
@end
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import "NSBundle+PYSearchExtension.h"
#import "PYSearchViewController.h"
@implementation NSBundle (PYSearchExtension)
+ (NSBundle *)py_searchBundle
{
static NSBundle *searchBundle = nil;
if (nil == searchBundle) {
//Default use `[NSBundle mainBundle]`.
searchBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"PYSearch" ofType:@"bundle"]];
/**
If you use pod import and configure `use_frameworks` in Podfile, [NSBundle mainBundle] does not load the `PYSearch.fundle` resource file in `PYSearch.framework`.
*/
if (nil == searchBundle) { // Empty description resource file in `PYSearch.framework`.
searchBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[PYSearchViewController class]] pathForResource:@"PYSearch" ofType:@"bundle"]];
}
}
return searchBundle;
}
+ (NSString *)py_localizedStringForKey:(NSString *)key;
{
return [self py_localizedStringForKey:key value:nil];
}
+ (NSString *)py_localizedStringForKey:(NSString *)key value:(NSString *)value
{
static NSBundle *bundle = nil;
if (nil == bundle) {
NSString *language = [NSLocale preferredLanguages].firstObject;
if ([language hasPrefix:@"en"]) language = @"en";
else if ([language hasPrefix:@"es"]) language = @"es";
else if ([language hasPrefix:@"fr"]) language = @"fr";
else if ([language hasPrefix:@"zh"]) {
if ([language rangeOfString:@"Hans"].location != NSNotFound) {
language = @"zh-Hans";
} else {
language = @"zh-Hant";
}
} else {
language = @"en";
}
// Find resources from `PYSearch.bundle`
bundle = [NSBundle bundleWithPath:[[NSBundle py_searchBundle] pathForResource:language ofType:@"lproj"]];
}
value = [bundle localizedStringForKey:key value:value table:nil];
return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
}
+ (UIImage *)py_imageNamed:(NSString *)name
{
CGFloat scale = [[UIScreen mainScreen] scale];
name = 3.0 == scale ? [NSString stringWithFormat:@"%@@3x.png", name] : [NSString stringWithFormat:@"%@@2x.png", name];
UIImage *image = [UIImage imageWithContentsOfFile:[[[NSBundle py_searchBundle] resourcePath] stringByAppendingPathComponent:name]];
return image;
}
@end
"PYSearchSearchPlaceholderText" = "Search content";
"PYSearchSearchPlaceholderText" = "Search content";
"PYSearchHotSearchText" = "Popular searches";
"PYSearchSearchHistoryText" = "Search history";
"PYSearchEmptySearchHistoryText" = "Clear the search history";
"PYSearchEmptyButtonText" = "Clear";
"PYSearchEmptySearchHistoryLogText" = "Clear the search history";
"PYSearchCancelButtonText" = "Cancel";
"PYSearchBackButtonText" = "Back";
"PYSearchSearchPlaceholderText" = "Buscar contenido";
"PYSearchSearchPlaceholderText" = "Buscar contenido";
"PYSearchHotSearchText" = "Búsquedas populares";
"PYSearchSearchHistoryText" = "Buscar Historia";
"PYSearchEmptySearchHistoryText" = "Borrar el historial de búsqueda";
"PYSearchEmptyButtonText" = "Borrar";
"PYSearchEmptySearchHistoryLogText" = "Borrar el historial de búsqueda";
"PYSearchCancelButtonText" = "Cancelar";
"PYSearchBackButtonText" = "Volver a";
"PYSearchSearchPlaceholderText" = "Recherche de contenu";
"PYSearchSearchPlaceholderText" = "Recherche de contenu";
"PYSearchHotSearchText" = "Recherches populaires";
"PYSearchSearchHistoryText" = "Historique des recherches";
"PYSearchEmptySearchHistoryText" = "Effacer l'historique des recherches";
"PYSearchEmptyButtonText" = "Effacer";
"PYSearchEmptySearchHistoryLogText" = "Effacer l'historique des recherches";
"PYSearchCancelButtonText" = "Annuler";
"PYSearchBackButtonText" = "Retour à";
"PYSearchSearchPlaceholderText" = "搜索內容";
"PYSearchSearchPlaceholderText" = "搜索內容";
"PYSearchHotSearchText" = "熱門搜索";
"PYSearchSearchHistoryText" = "搜索歷史";
"PYSearchEmptySearchHistoryText" = "清空搜索歷史";
"PYSearchEmptyButtonText" = "清空";
"PYSearchEmptySearchHistoryLogText" = "清空搜索歷史";
"PYSearchCancelButtonText" = "取消";
"PYSearchBackButtonText" = "返回";
//
//
// 代码地址: https://github.com/iphone5solo/PYSearch
// 代码地址: http://www.code4app.com/thread-11175-1-1.html
// Created by CoderKo1o.
// Copyright © 2016年 iphone5solo. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PYSearchViewController.h"
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UIView+PYSearchExtension.h"
#import "UIColor+PYSearchExtension.h"
#import "NSBundle+PYSearchExtension.h"
#define PYSEARCH_MARGIN 10
#define PYSEARCH_BACKGROUND_COLOR PYSEARCH_COLOR(255, 255, 255)
#ifdef DEBUG
#define PYSEARCH_LOG(...) NSLog(__VA_ARGS__)
#else
#define PYSEARCH_LOG(...)
#endif
#define PYSEARCH_COLOR(r,g,b) [UIColor colorWithRed:(r/255.0) green:(g/255.0) blue:(b/255.0) alpha:1.0]
#define PYSEARCH_RANDOM_COLOR PYSEARCH_COLOR(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256))
#define PYSEARCH_DEPRECATED(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)
#define PYSEARCH_REALY_SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define PYSEARCH_REALY_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define PYScreenW (PYSEARCH_REALY_SCREEN_WIDTH < PYSEARCH_REALY_SCREEN_HEIGHT ? PYSEARCH_REALY_SCREEN_WIDTH : PYSEARCH_REALY_SCREEN_HEIGHT)
#define PYScreenH (PYSEARCH_REALY_SCREEN_WIDTH > PYSEARCH_REALY_SCREEN_HEIGHT ? PYSEARCH_REALY_SCREEN_WIDTH : PYSEARCH_REALY_SCREEN_HEIGHT)
#define PYSEARCH_SCREEN_SIZE CGSizeMake(PYScreenW, PYScreenH)
#define PYSEARCH_SEARCH_HISTORY_CACHE_PATH [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"PYSearchhistories.plist"] // the path of search record cached
UIKIT_EXTERN NSString *const PYSearchSearchPlaceholderText;
UIKIT_EXTERN NSString *const PYSearchHotSearchText;
UIKIT_EXTERN NSString *const PYSearchSearchHistoryText;
UIKIT_EXTERN NSString *const PYSearchEmptySearchHistoryText;
UIKIT_EXTERN NSString *const PYSearchEmptyButtonText;
UIKIT_EXTERN NSString *const PYSearchEmptySearchHistoryLogText;
UIKIT_EXTERN NSString *const PYSearchCancelButtonText;
UIKIT_EXTERN NSString *const PYSearchBackButtonText;
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import <UIKit/UIKit.h>
NSString *const PYSearchSearchPlaceholderText = @"PYSearchSearchPlaceholderText";
NSString *const PYSearchHotSearchText = @"PYSearchHotSearchText";
NSString *const PYSearchSearchHistoryText = @"PYSearchSearchHistoryText";
NSString *const PYSearchEmptySearchHistoryText = @"PYSearchEmptySearchHistoryText";
NSString *const PYSearchEmptyButtonText = @"PYSearchEmptyButtonText";
NSString *const PYSearchEmptySearchHistoryLogText = @"PYSearchEmptySearchHistoryLogText";
NSString *const PYSearchCancelButtonText = @"PYSearchCancelButtonText";
NSString *const PYSearchBackButtonText = @"PYSearchBackButtonText";
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef void(^PYSearchSuggestionDidSelectCellBlock)(UITableViewCell *selectedCell);
@protocol PYSearchSuggestionViewDataSource <NSObject, UITableViewDataSource>
@required
- (UITableViewCell *)searchSuggestionView:(UITableView *)searchSuggestionView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)searchSuggestionView:(UITableView *)searchSuggestionView numberOfRowsInSection:(NSInteger)section;
@optional
- (NSInteger)numberOfSectionsInSearchSuggestionView:(UITableView *)searchSuggestionView;
- (CGFloat)searchSuggestionView:(UITableView *)searchSuggestionView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
@end
@interface PYSearchSuggestionViewController : UITableViewController
@property (nonatomic, weak) id<PYSearchSuggestionViewDataSource> dataSource;
@property (nonatomic, copy) NSArray<NSString *> *searchSuggestions;
@property (nonatomic, copy) PYSearchSuggestionDidSelectCellBlock didSelectCellBlock;
+ (instancetype)searchSuggestionViewControllerWithDidSelectCellBlock:(PYSearchSuggestionDidSelectCellBlock)didSelectCellBlock;
@end
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import "PYSearchSuggestionViewController.h"
#import "PYSearchConst.h"
@interface PYSearchSuggestionViewController ()
@property (nonatomic, assign) UIEdgeInsets originalContentInsetWhenKeyboardShow;
@property (nonatomic, assign) UIEdgeInsets originalContentInsetWhenKeyboardHidden;
@property (nonatomic, assign) BOOL keyboardDidShow;
@end
@implementation PYSearchSuggestionViewController
+ (instancetype)searchSuggestionViewControllerWithDidSelectCellBlock:(PYSearchSuggestionDidSelectCellBlock)didSelectCellBlock
{
PYSearchSuggestionViewController *searchSuggestionVC = [[self alloc] init];
searchSuggestionVC.didSelectCellBlock = didSelectCellBlock;
searchSuggestionVC.automaticallyAdjustsScrollViewInsets = NO;
return searchSuggestionVC;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
if ([self.tableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)]) { // For the adapter iPad
self.tableView.cellLayoutMarginsFollowReadableWidth = NO;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradFrameDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradFrameDidHidden:) name:UIKeyboardDidHideNotification object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if (self.keyboardDidShow) {
self.originalContentInsetWhenKeyboardShow = self.tableView.contentInset;
} else {
self.originalContentInsetWhenKeyboardHidden = self.tableView.contentInset;
}
}
- (void)keyboradFrameDidShow:(NSNotification *)notification
{
self.keyboardDidShow = YES;
[self setSearchSuggestions:_searchSuggestions];
}
- (void)keyboradFrameDidHidden:(NSNotification *)notification
{
self.keyboardDidShow = NO;
self.originalContentInsetWhenKeyboardHidden = UIEdgeInsetsMake(-30, 0, 30, 0);
[self setSearchSuggestions:_searchSuggestions];
}
#pragma mark - setter
- (void)setSearchSuggestions:(NSArray<NSString *> *)searchSuggestions
{
_searchSuggestions = [searchSuggestions copy];
[self.tableView reloadData];
/**
* Adjust the searchSugesstionView when the keyboard changes.
* more information can see : https://github.com/iphone5solo/PYSearch/issues/61
*/
if (self.keyboardDidShow && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardShow, UIEdgeInsetsZero) && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardShow, UIEdgeInsetsMake(-30, 0, 30 - CGRectGetMaxY(self.navigationController.navigationBar.frame), 0))) {
self.tableView.contentInset = self.originalContentInsetWhenKeyboardShow;
} else if (!self.keyboardDidShow && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardHidden, UIEdgeInsetsZero) && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardHidden, UIEdgeInsetsMake(-30, 0, 30 - CGRectGetMaxY(self.navigationController.navigationBar.frame), 0))) {
self.tableView.contentInset = self.originalContentInsetWhenKeyboardHidden;
}
self.tableView.contentOffset = CGPointMake(0, -self.tableView.contentInset.top);
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0) { // iOS 11
self.tableView.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if ([self.dataSource respondsToSelector:@selector(numberOfSectionsInSearchSuggestionView:)]) {
return [self.dataSource numberOfSectionsInSearchSuggestionView:tableView];
}
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([self.dataSource respondsToSelector:@selector(searchSuggestionView:numberOfRowsInSection:)]) {
return [self.dataSource searchSuggestionView:tableView numberOfRowsInSection:section];
}
return self.searchSuggestions.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.dataSource respondsToSelector:@selector(searchSuggestionView:cellForRowAtIndexPath:)]) {
UITableViewCell *cell= [self.dataSource searchSuggestionView:tableView cellForRowAtIndexPath:indexPath];
if (cell) return cell;
}
static NSString *cellID = @"PYSearchSuggestionCellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.backgroundColor = [UIColor clearColor];
UIImageView *line = [[UIImageView alloc] initWithImage: [NSBundle py_imageNamed:@"cell-content-line"]];
line.py_height = 0.5;
line.alpha = 0.7;
line.py_x = PYSEARCH_MARGIN;
line.py_y = 43;
line.py_width = PYScreenW;
[cell.contentView addSubview:line];
}
cell.imageView.image = [NSBundle py_imageNamed:@"search"];
cell.textLabel.text = self.searchSuggestions[indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.dataSource respondsToSelector:@selector(searchSuggestionView:heightForRowAtIndexPath:)]) {
return [self.dataSource searchSuggestionView:tableView heightForRowAtIndexPath:indexPath];
}
return 44.0;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.didSelectCellBlock) self.didSelectCellBlock([tableView cellForRowAtIndexPath:indexPath]);
}
@end
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIColor (PYSearchExtension)
/**
Returns the corresponding color according to the hexadecimal string.
@param hexString hexadecimal string(eg:@"#ccff88")
@return new instance of `UIColor` class
*/
+ (instancetype)py_colorWithHexString:(NSString *)hexString;
/**
Returns the corresponding color according to the hexadecimal string and alpha.
@param hexString hexadecimal string(eg:@"#ccff88")
@param alpha alpha
@return new instance of `UIColor` class
*/
+ (instancetype)py_colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha;
@end
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import "UIColor+PYSearchExtension.h"
@implementation UIColor (PYSearchExtension)
+ (instancetype)py_colorWithHexString:(NSString *)hexString
{
NSString *colorString = [[hexString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
if (colorString.length < 6) {
return [UIColor clearColor];
}
if ([colorString hasPrefix:@"0X"]) {
colorString = [colorString substringFromIndex:2];
}
if ([colorString hasPrefix:@"#"]) {
colorString = [colorString substringFromIndex:1];
}
if (colorString.length != 6) {
return [UIColor clearColor];
}
NSRange range;
range.location = 0;
range.length = 2;
// r
NSString *rString = [colorString substringWithRange:range];
// g
range.location = 2;
NSString *gString = [colorString substringWithRange:range];
// b
range.location = 4;
NSString *bString = [colorString substringWithRange:range];
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:(float)r / 255.0 green:(float)g / 255.0 blue:(float)b / 255.0 alpha:1.0];
}
+ (instancetype)py_colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha
{
return [[self py_colorWithHexString:hexString] colorWithAlphaComponent:alpha];
}
@end
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIView (PYSearchExtension)
@property (nonatomic, assign) CGFloat py_x;
@property (nonatomic, assign) CGFloat py_y;
@property (nonatomic, assign) CGFloat py_centerX;
@property (nonatomic, assign) CGFloat py_centerY;
@property (nonatomic, assign) CGFloat py_width;
@property (nonatomic, assign) CGFloat py_height;
@property (nonatomic, assign) CGSize py_size;
@property (nonatomic, assign) CGPoint py_origin;
@end
//
//
// GitHub: https://github.com/iphone5solo/PYSearch
// Created by CoderKo1o.
// Copyright © 2016 iphone5solo. All rights reserved.
//
#import "UIView+PYSearchExtension.h"
@implementation UIView (PYSearchExtension)
- (void)setPy_x:(CGFloat)py_x
{
CGRect frame = self.frame;
frame.origin.x = py_x;
self.frame = frame;
}
- (CGFloat)py_x
{
return self.py_origin.x;
}
- (void)setPy_centerX:(CGFloat)py_centerX
{
CGPoint center = self.center;
center.x = py_centerX;
self.center = center;
}
- (CGFloat)py_centerX
{
return self.center.x;
}
-(void)setPy_centerY:(CGFloat)py_centerY
{
CGPoint center = self.center;
center.y = py_centerY;
self.center = center;
}
- (CGFloat)py_centerY
{
return self.center.y;
}
- (void)setPy_y:(CGFloat)py_y
{
CGRect frame = self.frame;
frame.origin.y = py_y;
self.frame = frame;
}
- (CGFloat)py_y
{
return self.frame.origin.y;
}
- (void)setPy_size:(CGSize)py_size
{
CGRect frame = self.frame;
frame.size = py_size;
self.frame = frame;
}
- (CGSize)py_size
{
return self.frame.size;
}
- (void)setPy_height:(CGFloat)py_height
{
CGRect frame = self.frame;
frame.size.height = py_height;
self.frame = frame;
}
- (CGFloat)py_height
{
return self.frame.size.height;
}
- (void)setPy_width:(CGFloat)py_width
{
CGRect frame = self.frame;
frame.size.width = py_width;
self.frame = frame;
}
-(CGFloat)py_width
{
return self.frame.size.width;
}
- (void)setPy_origin:(CGPoint)py_origin
{
CGRect frame = self.frame;
frame.origin = py_origin;
self.frame = frame;
}
- (CGPoint)py_origin
{
return self.frame.origin;
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment