Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
caonongyun authored and caonongyun committed Mar 16, 2017
1 parent 9c317fc commit bc33226
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 154 deletions.
8 changes: 8 additions & 0 deletions zhuishushenqi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@
B2B40B4F1DA39FB7001F972B /* UINavigationItem+BackItem.m in Sources */ = {isa = PBXBuildFile; fileRef = B2B40B4E1DA39FB7001F972B /* UINavigationItem+BackItem.m */; };
B2B40B511DA3E84A001F972B /* BookDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B40B501DA3E84A001F972B /* BookDetail.swift */; };
B2B40B531DA3EE27001F972B /* BookDetailAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B40B521DA3EE27001F972B /* BookDetailAPI.swift */; };
B2B58B411E7A2A320054FE84 /* UIImageView+zhuishu.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B58B401E7A2A320054FE84 /* UIImageView+zhuishu.swift */; };
B2B58B4B1E7A2D8E0054FE84 /* UILabel+zhuishu.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B58B4A1E7A2D8E0054FE84 /* UILabel+zhuishu.swift */; };
B2BB5B9A1D8BDF8E00379217 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2BB5B991D8BDF8E00379217 /* AppDelegate.swift */; };
B2BB5B9C1D8BDF8E00379217 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2BB5B9B1D8BDF8E00379217 /* ViewController.swift */; };
B2BB5B9F1D8BDF8E00379217 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B2BB5B9D1D8BDF8E00379217 /* Main.storyboard */; };
Expand Down Expand Up @@ -574,6 +576,8 @@
B2B40B4E1DA39FB7001F972B /* UINavigationItem+BackItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UINavigationItem+BackItem.m"; path = "../Controllers/UINavigationItem+BackItem.m"; sourceTree = "<group>"; };
B2B40B501DA3E84A001F972B /* BookDetail.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookDetail.swift; sourceTree = "<group>"; };
B2B40B521DA3EE27001F972B /* BookDetailAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookDetailAPI.swift; sourceTree = "<group>"; };
B2B58B401E7A2A320054FE84 /* UIImageView+zhuishu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+zhuishu.swift"; sourceTree = "<group>"; };
B2B58B4A1E7A2D8E0054FE84 /* UILabel+zhuishu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILabel+zhuishu.swift"; sourceTree = "<group>"; };
B2BB5B961D8BDF8E00379217 /* zhuishushenqi.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = zhuishushenqi.app; sourceTree = BUILT_PRODUCTS_DIR; };
B2BB5B991D8BDF8E00379217 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
B2BB5B9B1D8BDF8E00379217 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1154,6 +1158,8 @@
B2A8BA4C1E784398001506EF /* NSDate+Date.m */,
B2BB78C21E794489005FD8EB /* DateIntervalFormatter+formatter.swift */,
B2BB78CF1E794E8B005FD8EB /* Date+Extension.swift */,
B2B58B401E7A2A320054FE84 /* UIImageView+zhuishu.swift */,
B2B58B4A1E7A2D8E0054FE84 /* UILabel+zhuishu.swift */,
);
path = Category;
sourceTree = "<group>";
Expand Down Expand Up @@ -1603,6 +1609,7 @@
B22182661DA40326002458D2 /* NSArray+YYAdd.m in Sources */,
B238C2FB1E76937B00332BB9 /* BookCommentViewController.swift in Sources */,
B23FDB461DA69DAC0084B413 /* XYCActionSheet.swift in Sources */,
B2B58B411E7A2A320054FE84 /* UIImageView+zhuishu.swift in Sources */,
B221828F1DA40326002458D2 /* YYImage.m in Sources */,
B22182A21DA40326002458D2 /* UIPasteboard+YYText.m in Sources */,
B2260F561D8D508800581DD8 /* XYCNetworkConfig.swift in Sources */,
Expand Down Expand Up @@ -1640,6 +1647,7 @@
B2260F571D8D508800581DD8 /* XYCNetworkPrivate.swift in Sources */,
B221827E1DA40326002458D2 /* UIImage+YYAdd.m in Sources */,
B221828A1DA40326002458D2 /* MKAnnotationView+YYWebImage.m in Sources */,
B2B58B4B1E7A2D8E0054FE84 /* UILabel+zhuishu.swift in Sources */,
B2B297C91E6D5E600044E539 /* SwiftyJSON.swift in Sources */,
B2260F551D8D508800581DD8 /* XYCNetworkAgent.swift in Sources */,
B22182A01DA40326002458D2 /* NSAttributedString+YYText.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extension DateIntervalFormatter{
}else {
if abs(year) <= 1 {
if year == 0 {//同年
return String(format: "%d个月前",abs(month))
return String(format: "%d个月前",
(month))
}
}
if month < 0 { //未满一年不计算
Expand Down
39 changes: 39 additions & 0 deletions zhuishushenqi/Main/Category/UIImageView+zhuishu.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// UIImageView+zhuishu.swift
// zhuishushenqi
//
// Created by caonongyun on 2017/3/16.
// Copyright © 2017年 QS. All rights reserved.
//

import Foundation
import UIKit

extension UIImageView{
func qs_setBookCoverWithURLString(urlString:String){
self.image = UIImage(named: "default_book_cover")
var urlStr = urlString
if urlStr.contains("http") == false {
urlStr = "\(picBaseUrl)\(urlString)"
}
let url = URL(string: urlString)
guard let imageURL = url else {
print("Invalid URL")
return
}
let resource:QSResource = QSResource(url: imageURL)
self.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}

func qs_setAvatarWithURLString(urlString:String){
self.image = UIImage(named: "default_avatar_light")
let imageUrlString = "\(picBaseUrl)\(urlString)"
let url:URL? = URL(string: imageUrlString)
guard let imageURL = url else {
print("Invalid URL")
return
}
let resource:QSResource = QSResource(url: imageURL)
self.kf.setImage(with: resource, placeholder: UIImage(named: "default_avatar_light"), options: nil, progressBlock: nil, completionHandler: nil)
}
}
29 changes: 29 additions & 0 deletions zhuishushenqi/Main/Category/UILabel+zhuishu.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// UILabel+zhuishu.swift
// zhuishushenqi
//
// Created by caonongyun on 2017/3/16.
// Copyright © 2017年 QS. All rights reserved.
//

import Foundation
import UIKit

extension UILabel{
func qs_setCreateTime(createTime:String,append:String){
if createTime.lengthOfBytes(using: String.Encoding.utf8) > 18{
let year = createTime.subStr(to: 4)
let month = createTime.sub(start: 5, end: 7)
let day = createTime.sub(start: 8, length: 2)
let hour = createTime.sub(start: 11, length: 2)
let mimute = createTime.sub(start: 14, length: 2)
let second = createTime.sub(start: 17, length: 2)
let beginDate = NSDate.getWithYear(year, month: month, day: day, hour: hour, mimute: mimute, second: second)
let endDate = Date()
let formatter = DateIntervalFormatter()
let out = formatter.timeInfo(from: beginDate!, to: endDate)
self.text = "\(out)\(append)"
print(out)
}
}
}
34 changes: 3 additions & 31 deletions zhuishushenqi/Main/Views/BookCommentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,9 @@ class BookCommentCell: UITableViewCell {

@discardableResult
func modelSetAction(model:BookComment?)->CGFloat{

let created = model?.created ?? "2014-02-23T16:48:18.179Z"
if created.lengthOfBytes(using: String.Encoding.utf8) > 18{

let year = created.subStr(to: 4)
let month = created.sub(start: 5, end: 7)
let day = created.sub(start: 8, length: 2)
let hour = created.sub(start: 11, length: 2)
let mimute = created.sub(start: 14, length: 2)
let second = created.sub(start: 17, length: 2)
let beginDate = NSDate.getWithYear(year, month: month, day: day, hour: hour, mimute: mimute, second: second)
let endDate = Date()
let formatter = DateIntervalFormatter()
let out = formatter.timeInfo(from: beginDate!, to: endDate)
self.createTime.text = "\(out)"
print(out)
}

self.createTime.qs_setCreateTime(createTime: created,append: "")
readerName.text = "\(model?.author.nickname ?? "") lv.\(model?.author.lv ?? 0)"
// createTime.text = ""
title.text = "\(model?.title ?? "")"
var height = heightOfString(title.text ?? "", font: UIFont.systemFont(ofSize: 13), width: self.bounds.width - 30)
titleHeight.constant = height
Expand All @@ -66,27 +49,16 @@ class BookCommentCell: UITableViewCell {
toolBar(height:totalHeight)
makeStarView()
self.totalCellHeight = totalHeight + 80


if model?.book.cover == "" {
return totalHeight + 80
}
let cover = ("\(model?.book.cover ?? "qqqqqqqq")" as NSString).substring(from: 7)

let coverUrl = URL(string: cover)
if let coverURL = coverUrl {
let resource:QSResource = QSResource(url: coverURL)
self.bookCover.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.bookCover.qs_setBookCoverWithURLString(urlString: cover)
if self.model?.author.avatar == "" {
return totalHeight + 80
}
let urlString = "\(picBaseUrl)\(self.model?.author.avatar ?? "qqqqqqqq")"
let url = URL(string: urlString)
if let urlstring = url {
let resource:QSResource = QSResource(url: urlstring)
self.readerIcon.kf.setImage(with: resource, placeholder: UIImage(named: "default_avatar_light"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.readerIcon.qs_setAvatarWithURLString(urlString: urlString)
setNeedsDisplay()
return totalHeight + 80
}
Expand Down
28 changes: 2 additions & 26 deletions zhuishushenqi/Main/Views/BookDetailHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class BookDetailHeader: UIView {
var model:BookDetail?{
didSet{
name.text = model?.title

let mArr:[BookDetail]? = BookShelfInfo.books.bookShelf as? [BookDetail]
for item in mArr ?? [] {
if item._id == model?._id {
Expand All @@ -35,31 +34,8 @@ class BookDetailHeader: UIView {
words.text = "\(Int(model?.wordCount ?? "0")!/10000)万字"

let created = model?.updated ?? "2014-02-23T16:48:18.179Z"
if created.lengthOfBytes(using: String.Encoding.utf8) > 18{

let year = created.subStr(to: 4)
let month = created.sub(start: 5, end: 7)
let day = created.sub(start: 8, length: 2)
let hour = created.sub(start: 11, length: 2)
let mimute = created.sub(start: 14, length: 2)
let second = created.sub(start: 17, length: 2)
let beginDate = NSDate.getWithYear(year, month: month, day: day, hour: hour, mimute: mimute, second: second)
let endDate = Date()
let formatter = DateIntervalFormatter()
let out = formatter.timeInfo(from: beginDate!, to: endDate)
self.new.text = "\(out)"
print(out)
}

if self.model?.cover == "" {
return;
}
let urlString = "\(picBaseUrl)\(self.model?.cover ?? "qqqqqqqq")"
let url = URL(string: urlString)
if let urlstring = url {
let resource:QSResource = QSResource(url: urlstring)
self.icon.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.new.qs_setCreateTime(createTime: created,append: "")
self.icon.qs_setBookCoverWithURLString(urlString: self.model?.cover ?? "qqqqqqqq")
}
}

Expand Down
24 changes: 2 additions & 22 deletions zhuishushenqi/Main/Views/HotCommentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,16 @@ class HotCommentCell: UITableViewCell {

var model:QSHotComment?{
didSet{
let imageUrlString = "\(picBaseUrl)\(model?.author.avatar ?? "")"
let url:URL? = URL(string: imageUrlString)
if let imageUrl = url {
let resource:QSResource = QSResource(url: imageUrl)
self.iconView?.kf.setImage(with: resource, placeholder: UIImage(named: "default_avatar_light"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.iconView.qs_setAvatarWithURLString(urlString: model?.author.avatar ?? "")
self.userNameLabel.text = "\(model?.author.nickname ?? "")"
self.titleLabel.text = "\(model?.title ?? "")"
self.contentLabel.text = "\(model?.content ?? "")"
self.userfulBtn.setTitle("\(model?.likeCount ?? 0)", for: .normal)
let width = (1 + 10*(model?.rating ?? 60) + ((model?.rating ?? 60) - 1)*2)
self.lightView?.frame = CGRect(x: 65 , y: 53, width: width, height: 10)
self.publishTimeLabel.text = ""

let created = model?.created ?? "2014-02-23T16:48:18.179Z"
if created.lengthOfBytes(using: String.Encoding.utf8) > 18{

let year = created.subStr(to: 4)
let month = created.sub(start: 5, end: 7)
let day = created.sub(start: 8, length: 2)
let hour = created.sub(start: 11, length: 2)
let mimute = created.sub(start: 14, length: 2)
let second = created.sub(start: 17, length: 2)
let beginDate = NSDate.getWithYear(year, month: month, day: day, hour: hour, mimute: mimute, second: second)
let endDate = Date()
let formatter = DateIntervalFormatter()
let out = formatter.timeInfo(from: beginDate!, to: endDate)
self.publishTimeLabel.text = "\(out)"
print(out)
}
self.publishTimeLabel.qs_setCreateTime(createTime: created,append:"")
}
}

Expand Down
8 changes: 1 addition & 7 deletions zhuishushenqi/Main/Views/RankingViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class RankingViewCell: UITableViewCell {
return
}
let imageUrlString = "\(picBaseUrl)\(model?.cover ?? "")"
let url:URL? = URL(string: imageUrlString)
if let imageUrl = url {
self.accessoryImageView.isHidden = true
let resource:QSResource = QSResource(url: imageUrl)
self.imageView?.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.imageView?.qs_setBookCoverWithURLString(urlString: imageUrlString)
}
}

Expand Down Expand Up @@ -61,7 +56,6 @@ class RankingViewCell: UITableViewCell {
public lazy var accessoryImageView:UIButton = {
let imageView = UIButton()
imageView.frame = CGRect(x: self.bounds.width - 29, y: self.bounds.height/2 - 3.5, width: 14, height: 7)
// imageView.image = UIImage(named: "ranking_arrow_down")
imageView.setImage(UIImage(named: "IQButtonBarArrowDown"), for: .normal)
imageView.setImage(UIImage(named: "IQButtonBarArrowUp"), for: .selected)
imageView.isSelected = false
Expand Down
26 changes: 2 additions & 24 deletions zhuishushenqi/Main/Views/SwipableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,9 @@ class SwipableCell: UITableViewCell,UIScrollViewDelegate {
title!.text = model?.title

let created = model?.updated ?? "2014-02-23T16:48:18.179Z"
if created.lengthOfBytes(using: String.Encoding.utf8) > 18{

let year = created.subStr(to: 4)
let month = created.sub(start: 5, end: 7)
let day = created.sub(start: 8, length: 2)
let hour = created.sub(start: 11, length: 2)
let mimute = created.sub(start: 14, length: 2)
let second = created.sub(start: 17, length: 2)
let beginDate = NSDate.getWithYear(year, month: month, day: day, hour: hour, mimute: mimute, second: second)
let endDate = Date()
let formatter = DateIntervalFormatter()
let out = formatter.timeInfo(from: beginDate!, to: endDate)
self.detailTitle?.text = "\(out)前更新:\(model?.updateInfo?.lastChapter ?? "")"
print(out)
}

if self.model?.cover == "" {
return;
}
self.detailTitle?.qs_setCreateTime(createTime: created, append: "前更新:\(model?.updateInfo?.lastChapter ?? "")")
let urlString = "\(self.model?.cover.subStr(from: 7) ?? "")"
let url = URL(string: urlString)
if let urlstring = url {
let resource:QSResource = QSResource(url: urlstring)
self.imgView?.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.imgView?.qs_setBookCoverWithURLString(urlString: urlString)
}
}

Expand Down
10 changes: 1 addition & 9 deletions zhuishushenqi/Main/Views/ThemeTopicCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ class ThemeTopicCell: UITableViewCell {
let width = widthOfString(self.reading.text ?? "", font: UIFont.systemFont(ofSize: 11), height: 21)
self.persueWidth.constant = width + 5

self.icon.image = UIImage(named: "default_book_cover")
if self.model?.cover == "" {
return;
}
let urlString = "\(picBaseUrl)\(self.model?.cover ?? "qqqqqqqq")"
let url = URL(string: urlString)
if let urlstring = url {
let resource:QSResource = QSResource(url: urlstring)
self.icon.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.icon.qs_setBookCoverWithURLString(urlString: urlString)
}
}

Expand Down
9 changes: 1 addition & 8 deletions zhuishushenqi/Main/Views/TopDetailCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ class TopDetailCell: UITableViewCell {
return;
}
var urlString = "\(((self.model?.cover ?? "qqqqqqqq") as NSString).substring(from: 7))"
if urlString.contains("http") == false {
urlString = "\(picBaseUrl)\(self.model?.cover ?? "qqqqqqqq")"
}
let url = URL(string: urlString)
if let urlstring = url {
let resource:QSResource = QSResource(url: urlstring)
self.icon.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.icon.qs_setBookCoverWithURLString(urlString: urlString)
}
}

Expand Down
6 changes: 1 addition & 5 deletions zhuishushenqi/Main/Views/TopicDetailCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ class TopicDetailCell: UITableViewCell {
return;
}
let urlString = "\(picBaseUrl)\(self.model?.book.cover ?? "qqqqqqqq")"
let url = URL(string: urlString)
if let urlstring = url {
let resource:QSResource = QSResource(url: urlstring)
self.icon.kf.setImage(with: resource, placeholder: UIImage(named: "default_book_cover"), options: nil, progressBlock: nil, completionHandler: nil)
}
self.icon.qs_setBookCoverWithURLString(urlString: urlString)
}
}
override func awakeFromNib() {
Expand Down
Loading

0 comments on commit bc33226

Please sign in to comment.