From 2e82c7f03b0833e3a149d02453d66d8db133b2ce Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 29 十一月 2021 13:36:20 +0800
Subject: [PATCH] 2021-11-29 1.实现ON+设计的UI

---
 HDLSceneSiriDemo/HDLSceneSiriDemo/HDLSceneSiri/HDLSiriSceneListViewController.m |  138 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 110 insertions(+), 28 deletions(-)

diff --git a/HDLSceneSiriDemo/HDLSceneSiriDemo/HDLSceneSiri/HDLSiriSceneListViewController.m b/HDLSceneSiriDemo/HDLSceneSiriDemo/HDLSceneSiri/HDLSiriSceneListViewController.m
index 4f27f84..1af37b7 100644
--- a/HDLSceneSiriDemo/HDLSceneSiriDemo/HDLSceneSiri/HDLSiriSceneListViewController.m
+++ b/HDLSceneSiriDemo/HDLSceneSiriDemo/HDLSceneSiri/HDLSiriSceneListViewController.m
@@ -10,9 +10,11 @@
 #import <IntentsUI/IntentsUI.h>
 #import "HDLRunSceneIntent.h"   //涓婃柟鈥滆缃瓹ustom Intents鈥濆浘涓彸杈圭澶存寚鐨勨�淐lass Name鈥�
 #import "HDLSiriSceneListCell.h"
-#import "HDLSiriSceneModel.h"
+#import "HDLSectionHeaderView.h"
 #import "HDLSceneSiri.h"
 #import "TopBarView.h"
+#import "HDLSiriShortcutModel.h"
+
 
 NSString * const HDLSiriSceneListCellIdentifier  = @"HDLSiriSceneListCellIdentifier";
 
@@ -37,17 +39,33 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     [self.navigationController setNavigationBarHidden:YES animated:YES];
-    self.view.backgroundColor = HEXCOLORA(0xF7F7FC,1.0);
+    self.view.backgroundColor = HEXCOLORA(0xF2F3F7,1.0);
     [self initView];
     // Do any additional setup after loading the view.
 }
 
+-(void)initLlanguage{
+    NSString *languageName = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
+    
+    // 绠�浣撲腑鏂�
+    if ([languageName rangeOfString:@"zh-Hans"].location != NSNotFound) {
+        //鏍囬
+        if(self.titleName == nil || [self.titleName isEqual:@""]){
+            self.titleName = @"Siri蹇嵎鎸囦护";
+        }
+        
+    }else{
+        //鏍囬
+        if(self.titleName == nil || [self.titleName isEqual:@""]){
+            self.titleName = @"Siri Shortcuts";
+        }
+        
+    }
+}
+
 /// initView
 - (void)initView{
-    //鏍囬
-    if(self.titleName == nil || [self.titleName isEqual:@""]){
-        self.titleName = @"Siri蹇嵎鎸囦护";
-    }
+    [self initLlanguage];
     [self setTopBarViewWithTitle:self.titleName];
     [self initTableView];
     [self refreshSiri];
@@ -64,7 +82,7 @@
 //璁剧疆鏍囬鍜岃繑鍥炴寜閽�
 - (void)setTopBarViewWithTitle:(NSString *)title{
     [self.view addSubview:self.topBarView];
-    self.topBarView.backgroundColor = UIColor.whiteColor;
+    self.topBarView.backgroundColor = HEXCOLORA(0xF7F7F7, 1.0);
     self.topBarView.titleLabel.text = title;
 }
 //杩斿洖
@@ -74,8 +92,15 @@
     }
     else {
         [self.navigationController popViewControllerAnimated:YES];
-//        [self.navigationController popToRootViewControllerAnimated:YES];
     }
+}
+
+#pragma NSMutableArray
+- (NSMutableArray *)dataSource {
+    if (!_dataSource) {
+        _dataSource = [NSMutableArray new];
+    }
+    return _dataSource;
 }
 
 #pragma mark - UITableView
@@ -96,16 +121,59 @@
     return _tableView;
 }
 - (void)initTableView{
-    self.tableView.frame = CGRectMake(0, APP_TOP_BAR_HEIGHT + 12, APP_SCREEN_WIDTH, APP_VISIBLE_HEIGHT - APP_TAB_BOTTOM_HEIGHT-12);
+    self.tableView.frame = CGRectMake(0, APP_TOP_BAR_HEIGHT , APP_SCREEN_WIDTH, APP_VISIBLE_HEIGHT - APP_TAB_BOTTOM_HEIGHT);
 //    self.tableView.backgroundColor = HEXCOLORA(0xF7F7FC,1.0);
     [self.view addSubview:self.tableView];
     //    [self.tableView reloadData];
     
 }
+#pragma mark - 璁﹖ableView鐨勬瘡涓猻ection鐨刪eaderview闅弔ableview涓�璧锋粴鍔�
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
+    if (scrollView == self.tableView)
+    {
+        CGFloat sectionHeaderHeight = 65.0f;
+        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
+            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
+        } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
+            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
+        }
+    }
+}
 
 #pragma mark - UITableViewDataSourceXW
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return self.dataSource.count;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
+    return 65.0f;
+}
+
+- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
+    HDLSectionHeaderView *view = [[HDLSectionHeaderView alloc]init];
+    HDLSiriShortcutModel *model = self.dataSource[section];
+    if(model){
+        view.titleLabel.text = model.title;
+        view.messageLabel.text = model.content;
+    }
+    return view;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
+    return 8.0f;
+}
+
+- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
+    return [[UIView alloc]init];
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+    HDLSiriShortcutModel *model = self.dataSource[section];
+    if(model && model.list){
+        return model.list.count;
+    }
+    return 0;
 }
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -114,11 +182,11 @@
     if (cell == nil) {
         cell = [[HDLSiriSceneListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:HDLSiriSceneListCellIdentifier];
     }
-    
-    HDLSiriSceneModel *model = self.dataSource[indexPath.row];
+    cell.homeId = self.homeId;
+    HDLSiriControlModel *model = [self getModelWithNSIndexPath:indexPath];
     if(model){
         if (@available(iOS 12.0, *)) {
-            HDLRunSceneIntent *intent = [self getSceneIntent: model.userSceneId];
+            HDLRunSceneIntent *intent = [self getSceneIntent: model.controlId];
             [cell initModel:model intent:intent];
         }
     }
@@ -126,18 +194,17 @@
 }
 
 #pragma mark - UITableViewDelegate
-
 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-    return 72;
+    return 50;
 }
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     [tableView deselectRowAtIndexPath:indexPath animated:YES];
     
     if (@available(iOS 12.0, *)) {
-        HDLSiriSceneModel *model = self.dataSource[indexPath.row];
+        HDLSiriControlModel *model = [self getModelWithNSIndexPath:indexPath];
         if(model){
-            INVoiceShortcut *voiceShortcut = [self getSceneINVoiceShortcut:model.userSceneId];
+            INVoiceShortcut *voiceShortcut = [self getSceneINVoiceShortcut:model.controlId];
             [self addOrEditVoiceShortcut:voiceShortcut model:model];
         }
         
@@ -145,11 +212,21 @@
     
 }
 
+/// 鏍规嵁NSIndexPath 鑾峰彇model
+/// @param indexPath indexPath
+-(HDLSiriControlModel *)getModelWithNSIndexPath:(NSIndexPath *)indexPath {
+    HDLSiriControlModel *model = nil;
+    HDLSiriShortcutModel *ssModel = self.dataSource[indexPath.section];
+    if(ssModel && ssModel.list && (ssModel.list.count > indexPath.row)){
+        model = ssModel.list[indexPath.row];
+    }
+    return model;
+}
 
 /// 娣诲姞鎴栬�呯紪杈戝揩鎹锋寚浠�
 /// @param voiceShortcut 蹇嵎鎸囦护
 /// @param model 鍦烘櫙
--(void)addOrEditVoiceShortcut:(INVoiceShortcut *)voiceShortcut model:(HDLSiriSceneModel*)model API_AVAILABLE(ios(12.0)){
+-(void)addOrEditVoiceShortcut:(INVoiceShortcut *)voiceShortcut model:(HDLSiriControlModel*)model API_AVAILABLE(ios(12.0)){
  
     if(voiceShortcut==nil){
         //1.濡傛灉涓嶅瓨鍦ㄥ垯娣诲姞
@@ -173,24 +250,29 @@
 }
 
 
-- (INShortcut *) getINShortcut:(HDLSiriSceneModel*)model API_AVAILABLE(ios(12.0)){
-    NSString *title = model.name;
+- (INShortcut *) getINShortcut:(HDLSiriControlModel*)sceneModel  API_AVAILABLE(ios(12.0)){
+    NSString *title = sceneModel.controlName;
     HDLRunSceneIntent *intent = [[HDLRunSceneIntent alloc] init];
-    intent.sceneId = model.userSceneId;
     intent.suggestedInvocationPhrase = title;   //鍦⊿iri璇煶璁剧疆鏃舵樉绀虹殑寤鸿璁剧疆鍞よ捣鏂囧瓧
-    intent.sceneName = title;
+    intent.controlId = sceneModel.controlId;
+    intent.controlName = title;
+    intent.homeId = self.homeId;
+    intent.controlType = sceneModel.controlType;
+    intent.controlJSONStr = sceneModel.controlJSONStr;
+    intent.actionName = sceneModel.actionName;
     INShortcut *shortCut = [[INShortcut alloc] initWithIntent:intent];
     return shortCut;
 }
 
+
 /// 鏍规嵁鍦烘櫙ID鎴栬�呬箣鍓嶉厤缃繃浣庡揩鎹锋寚浠�
-/// @param sceneId 鍦烘櫙ID
-- (HDLRunSceneIntent*)getSceneIntent:(NSString *)sceneId API_AVAILABLE(ios(12.0)){
+/// @param controlId 鍞竴鏍囪瘑ID
+- (HDLRunSceneIntent*)getSceneIntent:(NSString *)controlId API_AVAILABLE(ios(12.0)){
     HDLRunSceneIntent *intentFind = nil;
     for (INVoiceShortcut *voiceShortcut in self.siriShortcutList) {
         HDLRunSceneIntent *intent = (HDLRunSceneIntent *)voiceShortcut.shortcut.intent;
         if(intent){
-            if([intent.sceneId isEqualToString:sceneId]){
+            if([intent.controlId isEqualToString:controlId]){
                 intentFind = intent;
                 break;
             }
@@ -200,13 +282,13 @@
 }
 
 /// 鏍规嵁鍦烘櫙ID鎴栬�呬箣鍓嶉厤缃繃浣庡揩鎹锋寚浠�
-/// @param sceneId 鍦烘櫙ID
-- (INVoiceShortcut*)getSceneINVoiceShortcut:(NSString *)sceneId API_AVAILABLE(ios(12.0)){
+/// @param controlId 鍞竴鏍囪瘑ID
+- (INVoiceShortcut*)getSceneINVoiceShortcut:(NSString *)controlId API_AVAILABLE(ios(12.0)){
     INVoiceShortcut *voiceShortcutFind = nil;
     for (INVoiceShortcut *voiceShortcut in self.siriShortcutList) {
         HDLRunSceneIntent *intent = (HDLRunSceneIntent *)voiceShortcut.shortcut.intent;
         if(intent){
-            if([intent.sceneId isEqualToString:sceneId]){
+            if([intent.controlId isEqualToString:controlId]){
                 voiceShortcutFind = voiceShortcut;
                 break;
             }

--
Gitblit v1.8.0