From 85b6a2749db0ccb69382623313415309d84f1f48 Mon Sep 17 00:00:00 2001
From: lee <627051222@qq.com>
Date: Thu, 13 Jul 2017 16:33:16 +0800
Subject: [PATCH] a deep blog home com

---
 iCemarose/Class/AppDelegate+Deeplink.m                |  7 +++++++
 iCemarose/Class/Classify/UIViewController+HTTP.m      | 10 +++++++---
 iCemarose/Class/UI/Home/Home.storyboard               | 17 +++++++++--------
 iCemarose/Class/UI/Home/KWMBlogDetailVC.h             |  3 +++
 iCemarose/Class/UI/Home/KWMBlogDetailVC.m             | 25 +++++++++++++++++++++++--
 iCemarose/Class/UI/Home/KWMHomeVC.m                   |  1 +
 iCemarose/Class/UI/NewHome/Cell/KWMHotSalesHeader.xib |  2 +-
 iCemarose/Class/UI/NewHome/KWMNewHomeVC.m             |  1 +
 8 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/iCemarose/Class/AppDelegate+Deeplink.m b/iCemarose/Class/AppDelegate+Deeplink.m
index 8e15e37..f9d54e5 100644
--- a/iCemarose/Class/AppDelegate+Deeplink.m
+++ b/iCemarose/Class/AppDelegate+Deeplink.m
@@ -11,6 +11,7 @@
 #import "AppDelegate.h"
 #import "KWMProductDetailVC.h"
 #import "KWMSelectedGoodsVC.h"
+#import "KWMBlogDetailVC.h"
 
 @implementation AppDelegate (Deeplink)
 
@@ -36,6 +37,12 @@
         [[AppDelegate mainViewController].selectedViewController pushViewController:productDetailVC animated:YES];
         return YES;
     }];
+    [routes addRoute:@"/blogs/:blog/:handle" handler:^BOOL(NSDictionary<NSString *,id> * _Nonnull parameters) {
+        KWMBlogDetailVC *blogDetailVC = (KWMBlogDetailVC *)[KWMBlogDetailVC findControllerBy:@"KWMBlogDetailVC" fromStoryboard:@"Home"];
+        blogDetailVC.handle = parameters[@"handle"];
+        [[AppDelegate mainViewController].selectedViewController pushViewController:blogDetailVC animated:YES];
+        return YES;
+    }];
 }
 
 - (BOOL)handleURL:(NSURL *)url {
diff --git a/iCemarose/Class/Classify/UIViewController+HTTP.m b/iCemarose/Class/Classify/UIViewController+HTTP.m
index 352b832..e418610 100644
--- a/iCemarose/Class/Classify/UIViewController+HTTP.m
+++ b/iCemarose/Class/Classify/UIViewController+HTTP.m
@@ -9,6 +9,8 @@
 #import "UIViewController+HTTP.h"
 #import <JLRoutes/JLRoutes.h> 
 #import <RegexKitLite/RegexKitLite.h>
+#import <TOWebViewController/TOWebViewController.h>
+#import "AppDelegate.h"
 
 @implementation UIViewController (HTTP)
 
@@ -17,10 +19,12 @@
     NSURL *url = [[NSURL alloc] initWithString:[URLString stringByReplacingOccurrencesOfRegex:@"^https?" withString:@"cemarose"]];
     if ([JLRoutes canRouteURL:url]) {
         [JLRoutes routeURL:url];
-    }else if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
-        [application openURL:[NSURL URLWithString:URLString] options:@{} completionHandler:nil];
+//    }else if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
+//        [application openURL:[NSURL URLWithString:URLString] options:@{} completionHandler:nil];
     } else {
-        [application openURL:[NSURL URLWithString:URLString]];
+//        [application openURL:[NSURL URLWithString:URLString]];
+        TOWebViewController *wv = [[TOWebViewController alloc] initWithURLString:URLString];
+        [[AppDelegate mainViewController].selectedViewController pushViewController:wv animated:YES];
     }
 }
 
diff --git a/iCemarose/Class/UI/Home/Home.storyboard b/iCemarose/Class/UI/Home/Home.storyboard
index 9a28d6c..302c407 100644
--- a/iCemarose/Class/UI/Home/Home.storyboard
+++ b/iCemarose/Class/UI/Home/Home.storyboard
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
     <device id="retina4_7" orientation="portrait">
         <adaptation id="fullscreen"/>
     </device>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -32,7 +32,7 @@
                                     <rect key="frame" x="0.0" y="0.0" width="375" height="648"/>
                                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                     <subviews>
-                                        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_ home_content_title" translatesAutoresizingMaskIntoConstraints="NO" id="6b3-4L-fqj">
+                                        <imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_ home_content_title" translatesAutoresizingMaskIntoConstraints="NO" id="6b3-4L-fqj">
                                             <rect key="frame" x="20" y="10" width="14" height="9"/>
                                             <constraints>
                                                 <constraint firstAttribute="height" constant="9" id="SlC-wh-5e0"/>
@@ -40,17 +40,17 @@
                                             </constraints>
                                         </imageView>
                                         <webView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XjH-A0-ATq">
-                                            <rect key="frame" x="0.0" y="83.5" width="375" height="564.5"/>
+                                            <rect key="frame" x="0.0" y="34" width="375" height="614"/>
                                             <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                         </webView>
-                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="35I-9E-t9l">
-                                            <rect key="frame" x="20" y="23" width="325" height="32.5"/>
+                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="35I-9E-t9l">
+                                            <rect key="frame" x="20" y="23" width="325" height="0.0"/>
                                             <fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="23"/>
                                             <color key="textColor" red="0.29803921568627451" green="0.34901960784313724" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
                                             <nil key="highlightedColor"/>
                                         </label>
-                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gjF-Th-7MU">
-                                            <rect key="frame" x="20" y="66.5" width="345" height="17"/>
+                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gjF-Th-7MU">
+                                            <rect key="frame" x="20" y="34" width="345" height="0.0"/>
                                             <fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="12"/>
                                             <color key="textColor" red="0.29803921570000003" green="0.34901960780000002" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
                                             <nil key="highlightedColor"/>
@@ -83,6 +83,7 @@
                         </constraints>
                     </view>
                     <connections>
+                        <outlet property="flagImg" destination="6b3-4L-fqj" id="Zw9-1P-Fjp"/>
                         <outlet property="lbTitle" destination="35I-9E-t9l" id="zpt-Oq-Rhh"/>
                         <outlet property="publishTime" destination="gjF-Th-7MU" id="HE9-1B-5Yl"/>
                         <outlet property="tbvArticle" destination="XdN-GP-LIS" id="3qw-6w-72k"/>
diff --git a/iCemarose/Class/UI/Home/KWMBlogDetailVC.h b/iCemarose/Class/UI/Home/KWMBlogDetailVC.h
index 091f78b..12e0029 100644
--- a/iCemarose/Class/UI/Home/KWMBlogDetailVC.h
+++ b/iCemarose/Class/UI/Home/KWMBlogDetailVC.h
@@ -16,5 +16,8 @@
 @property (weak, nonatomic) IBOutlet UILabel *lbTitle;
 @property (weak, nonatomic) IBOutlet UILabel *publishTime;
 @property (weak, nonatomic) IBOutlet UIView *vHeader;
+@property (weak, nonatomic) IBOutlet UIImageView *flagImg;
 @property (nonatomic) KWMArticlesResult *article;
+@property (nonatomic) NSString *handle;
+
 @end
diff --git a/iCemarose/Class/UI/Home/KWMBlogDetailVC.m b/iCemarose/Class/UI/Home/KWMBlogDetailVC.m
index d6bee6c..184a894 100644
--- a/iCemarose/Class/UI/Home/KWMBlogDetailVC.m
+++ b/iCemarose/Class/UI/Home/KWMBlogDetailVC.m
@@ -23,15 +23,36 @@
     // Do any additional setup after loading the view
     self.title = @"正文";
     self.automaticallyAdjustsScrollViewInsets = NO;
+    if (!self.handle) {
+        [self initData];
+    }else{
+        [self requestData];
+    }
+}
+
+- (void) requestData {
+    [self showLoading];
+    [self.api getAllBlog:@{@"handle":self.handle} success:^(NSURLSessionDataTask *task, KWMBlogResult *result) {
+        [self hideLoading];
+        self.article = result.blogs.firstObject;
+        [self initData];
+    } failure:^(NSURLSessionDataTask *task, NSError *error) {
+        [self showError:error];
+        NSLog(@"error:%@",error);
+        self.view.hidden = NO;
+    }];
+}
 
+- (void) initData {
+    self.flagImg.hidden = NO;
     self.wbArticle.delegate = self;
     self.wbArticle.scrollView.scrollEnabled = NO;
     self.lbTitle.text = _article.title;
-
+    
     self.publishTime.text = [self returnTimeStr:_article.published_at];
     self.tbvArticle.backgroundColor = [UIColor clearColor];
     self.tbvArticle.separatorStyle = UITableViewCellSeparatorStyleNone;
-
+    
     [self initWebView];
 }
 
diff --git a/iCemarose/Class/UI/Home/KWMHomeVC.m b/iCemarose/Class/UI/Home/KWMHomeVC.m
index aaa94be..038a899 100644
--- a/iCemarose/Class/UI/Home/KWMHomeVC.m
+++ b/iCemarose/Class/UI/Home/KWMHomeVC.m
@@ -43,6 +43,7 @@
     [super viewDidLoad];
     _dataArr = [NSArray array];
     [self requestBlogAPI];
+    // FIXME: mo to main
     [self.api loginWebSuccess:nil failure:nil];
 }
 
diff --git a/iCemarose/Class/UI/NewHome/Cell/KWMHotSalesHeader.xib b/iCemarose/Class/UI/NewHome/Cell/KWMHotSalesHeader.xib
index efe2c60..ee2bb17 100644
--- a/iCemarose/Class/UI/NewHome/Cell/KWMHotSalesHeader.xib
+++ b/iCemarose/Class/UI/NewHome/Cell/KWMHotSalesHeader.xib
@@ -67,7 +67,7 @@
                         <constraint firstAttribute="height" constant="190" id="NbW-Kh-s5O"/>
                     </constraints>
                 </view>
-                <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="UGY-II-IMu">
+                <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="UGY-II-IMu">
                     <rect key="frame" x="0.0" y="250" width="375" height="0.0"/>
                     <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                     <constraints>
diff --git a/iCemarose/Class/UI/NewHome/KWMNewHomeVC.m b/iCemarose/Class/UI/NewHome/KWMNewHomeVC.m
index 5ff5502..a8566c8 100644
--- a/iCemarose/Class/UI/NewHome/KWMNewHomeVC.m
+++ b/iCemarose/Class/UI/NewHome/KWMNewHomeVC.m
@@ -345,6 +345,7 @@ typedef enum{
 
 - (void)setHomeData:(KWMHomeData *)homeData {
     _homeData = homeData;
+    [homeData.ad_banner[0] setUrl:@"https://www.cemarose.com/blogs/news/article-1"];
     self.adHeader.adArray = self.homeData.ad_banner;
 //    self.recommendHeader.productArray = self.productArray;
 //    self.clothingSetsHeader.productArray = self.productArray;
--
libgit2 0.26.0