Skip to content

Commit

Permalink
save reading progress
Browse files Browse the repository at this point in the history
  • Loading branch information
caonongyun authored and caonongyun committed Apr 25, 2017
1 parent e142d1c commit 876a9ee
Show file tree
Hide file tree
Showing 264 changed files with 9,213 additions and 521 deletions.
446 changes: 420 additions & 26 deletions zhuishushenqi.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions zhuishushenqi/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// AppDelegate.swift
// zhuishushenqi
//
// Created by Nory Chao on 16/9/16.
// Created by Nory Cao on 16/9/16.
// Copyright © 2016年 QS. All rights reserved.
//

Expand All @@ -27,11 +27,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window?.rootViewController = sideNavVC
window?.makeKeyAndVisible()
UIApplication.shared.setStatusBarHidden(false, with: .fade)
#if DEBUG
// #if DEBUG
let fpsLabel = V2FPSLabel(frame: CGRect(x:15, y:ScreenHeight-40, width:55,height: 20));
self.window?.addSubview(fpsLabel);
#else
#endif
// #else
// #endif

configureDataBase()
// [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Controllers/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BaseViewController.swift
// zhuishushenqi
//
// Created by Nory Chao on 16/9/20.
// Created by Nory Cao on 16/9/20.
// Copyright © 2016年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Controllers/SideViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SideViewController.swift
// zhuishushenqi
//
// Created by Nory Chao on 16/9/30.
// Created by Nory Cao on 16/9/30.
// Copyright © 2016年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/CommunityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CommunityView.swift
// zhuishushenqi
//
// Created by Nory Chao on 16/10/22.
// Created by Nory Cao on 16/10/22.
// Copyright © 2016年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/DarkStarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// DarkStarView.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/9.
// Created by Nory Cao on 2017/3/9.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/DarkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// DarkView.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/9.
// Created by Nory Cao on 2017/3/9.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/EmptyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// EmptyView.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/17.
// Created by Nory Cao on 2017/3/17.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/LightStarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// LightStarView.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/9.
// Created by Nory Cao on 2017/3/9.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/LightView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// LightView.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/9.
// Created by Nory Cao on 2017/3/9.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/QSLoadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// QSLoadingView.swift
// zhuishushenqi
//
// Created by caonongyun on 2017/4/13.
// Created by Nory Cao on 2017/4/13.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/RateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RateView.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/14.
// Created by Nory Cao on 2017/3/14.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Base/Views/XYCActionSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// XYCActionSheet.swift
// zhuishushenqi
//
// Created by Nory Chao on 16/10/6.
// Created by Nory Cao on 16/10/6.
// Copyright © 2016年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Client/QSNetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// QSNetworkManager.swift
// zhuishushenqi
//
// Created by caonongyun on 2017/3/20.
// Created by Nory Cao on 2017/3/20.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
156 changes: 126 additions & 30 deletions zhuishushenqi/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Config.swift
// zhuishushenqi
//
// Created by Nory Chao on 16/9/17.
// Created by Nory Cao on 16/9/17.
// Copyright © 2016年 QS. All rights reserved.
//

Expand Down Expand Up @@ -202,6 +202,7 @@ func isExistShelf(bookDetail:BookDetail?)->Bool{
enum BookShelfUpdateType {
case add
case delete
case update
}

@discardableResult
Expand All @@ -217,51 +218,146 @@ func isExistBookShelf(bookDetail:BookDetail?)->Bool{
}

func updateReadingInfo(bookDetail:BookDetail?){
var mArr:[BookDetail] = BookShelfInfo.books.bookShelf
var index = 0
for item in mArr {
let model = item
if item._id == (bookDetail?._id ?? "") {
model.chapter = bookDetail?.chapter ?? 0
model.page = bookDetail?.page ?? 0
model.sourceIndex = bookDetail?.sourceIndex ?? 0
model.chapters = bookDetail?.chapters
model.resources = bookDetail?.resources
mArr[index] = model
BookShelfInfo.books.bookShelf = mArr
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "BookShelfRefresh")))
DispatchQueue.global().async {
var mArr:[BookDetail] = BookShelfInfo.books.bookShelf
var index = 0
for item in mArr {
let model = item
if item._id == (bookDetail?._id ?? "") {
model.chapter = bookDetail?.chapter ?? 0
model.page = bookDetail?.page ?? 0
model.sourceIndex = bookDetail?.sourceIndex ?? 0
model.chapters = bookDetail?.chapters
model.resources = bookDetail?.resources
mArr[index] = model
BookShelfInfo.books.bookShelf = mArr
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "BookShelfRefresh")))
}
index += 1
}
index += 1
}
}

@discardableResult
func updateBookShelf(bookDetail:BookDetail?,type:BookShelfUpdateType)->Bool{
var mArr:[BookDetail] = BookShelfInfo.books.bookShelf
var exist = false
func bookShelfRefresh(model:BookDetail,arr:[BookDetail])->[BookDetail]{
var models = arr
var index = 0
for item in mArr {
if item._id == (bookDetail?._id ?? "") {
exist = true
for item in arr {
if item._id == model._id {
models.remove(at: index)
}
index += 1
}
if !exist {
return models
}

//发通知删除时需要重新请求数据,反应慢,书架删除时应该直接删除而不重新请求
@discardableResult
func updateBookShelf(bookDetail:BookDetail?,type:BookShelfUpdateType,refresh:Bool){
DispatchQueue.global().async {

var mArr:[BookDetail] = BookShelfInfo.books.bookShelf
var index = 0
var existIndex = -1
for item in mArr {
if item._id == (bookDetail?._id ?? "") {
existIndex = index
}
index += 1
}
if let model = bookDetail{
if type == .add {
mArr.append(model)
BookShelfInfo.books.bookShelf = mArr
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "BookShelfRefresh")))
if existIndex == -1 {
mArr.append(model)
BookShelfInfo.books.bookShelf = mArr
if refresh {
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "BookShelfRefresh")))
}
}
}else if type == .delete {
mArr.remove(at: index - 1)
BookShelfInfo.books.bookShelf = mArr
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "BookShelfRefresh")))
if existIndex != -1 {
mArr.remove(at: existIndex)
BookShelfInfo.books.bookShelf = mArr
if refresh {
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "BookShelfRefresh")))
}
}
}else if type == .update {
if existIndex != -1 {
mArr[existIndex] = model
BookShelfInfo.books.bookShelf = mArr
if refresh {
NotificationCenter.default.post(Notification(name: Notification.Name(rawValue: "BookShelfRefresh")))
}
}
}
}
}
return exist
}

func getAttributes(with lineSpave:CGFloat,font:UIFont)->NSDictionary{
let paraStyle = NSMutableParagraphStyle()
paraStyle.lineBreakMode = .byCharWrapping
paraStyle.alignment = .left
paraStyle.lineSpacing = lineSpave
paraStyle.hyphenationFactor = 1.0
paraStyle.firstLineHeadIndent = 0.0
paraStyle.paragraphSpacingBefore = 0.0
paraStyle.headIndent = 0
paraStyle.tailIndent = 0
let dict = [NSFontAttributeName:font,NSKernAttributeName:1.5,NSParagraphStyleAttributeName:paraStyle] as [String : Any]
return dict as NSDictionary
}

func attributeText(with lineSpace:CGFloat,text:String,font:UIFont)->NSAttributedString{
let paraStyle = NSMutableParagraphStyle()
paraStyle.lineBreakMode = .byCharWrapping
paraStyle.alignment = .left
paraStyle.hyphenationFactor = 1.0
paraStyle.firstLineHeadIndent = 0.0
paraStyle.paragraphSpacingBefore = 0.0
paraStyle.headIndent = 0
paraStyle.tailIndent = 0
let dict = [NSFontAttributeName:font,NSKernAttributeName:1.5,NSParagraphStyleAttributeName:paraStyle] as [String : Any]
let attributeStr = NSAttributedString(string: text, attributes: dict)
return attributeStr
}

//-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
// NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
// paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
// paraStyle.alignment = NSTextAlignmentLeft;
// paraStyle.lineSpacing = UILABEL_LINE_SPACE; //设置行间距
// paraStyle.hyphenationFactor = 1.0;
// paraStyle.firstLineHeadIndent = 0.0;
// paraStyle.paragraphSpacingBefore = 0.0;
// paraStyle.headIndent = 0;
// paraStyle.tailIndent = 0;
// //设置字间距 NSKernAttributeName:@1.5f
// NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
// };
//
// NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
// label.attributedText = attributeStr;
//}
//
////计算UILabel的高度(带有行间距的情况)
//-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {
// NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
// paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
// paraStyle.alignment = NSTextAlignmentLeft;
// paraStyle.lineSpacing = UILABEL_LINE_SPACE;
// paraStyle.hyphenationFactor = 1.0;
// paraStyle.firstLineHeadIndent = 0.0;
// paraStyle.paragraphSpacingBefore = 0.0;
// paraStyle.headIndent = 0;
// paraStyle.tailIndent = 0;
// NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
// };
//
// CGSize size = [str boundingRectWithSize:CGSizeMake(width, HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
// return size.height;
//}



func QSLog<T>(_ message:T,fileName:String = #file,lineName:Int = #line,funcName:String = #function){
Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Extension/Date+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Date+Extension.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/15.
// Created by Nory Cao on 2017/3/15.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// DateIntervalFormatter+formatter.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/15.
// Created by Nory Cao on 2017/3/15.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Extension/NSDate+Date.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// NSDate+Date.h
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/14.
// Created by Nory Cao on 2017/3/14.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Extension/NSDate+Date.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// NSDate+Date.m
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/14.
// Created by Nory Cao on 2017/3/14.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion zhuishushenqi/Extension/String+crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// String+crypto.swift
// zhuishushenqi
//
// Created by Nory Chao on 2017/3/6.
// Created by Nory Cao on 2017/3/6.
// Copyright © 2017年 QS. All rights reserved.
//

Expand Down
Loading

0 comments on commit 876a9ee

Please sign in to comment.