Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 add database 2 fix crash 3 add back button #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

Pods
Podfile.lock
.DS_Store
Pods/

## Build generated
build/
DerivedData/
Expand Down
21 changes: 21 additions & 0 deletions CCSQLiteData/CCSQLiteData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// CCSQLiteData.h
// CCSQLiteDemo
//
// Created by dengyouhua on 22/01/2018.
// Copyright © 2018 CC | [email protected]. All rights reserved.
// https://github.com/ccworld1000/CCSQLite
//

#import <Foundation/Foundation.h>

@interface CCSQLiteData : NSObject

+ (void) writeDataList;
+ (NSArray *) readDataList;

// for res
+ (NSArray *) readDefaultDataList;

@end

61 changes: 61 additions & 0 deletions CCSQLiteData/CCSQLiteData.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// CCSQLiteData.m
// CCSQLiteDemo
//
// Created by dengyouhua on 22/01/2018.
// Copyright © 2018 CC | [email protected]. All rights reserved.
// https://github.com/ccworld1000/CCSQLite
//

#import "CCSQLiteData.h"
#import "CCSQLite/CCSQLite.h" // if error try #import "CCSQLite/CCSQLite.h" or #import "CCSQLite.h"

#define CCSQLiteDataDB @"CCSQLiteData.sqlite"

@implementation CCSQLiteData

+ (void) writeDataList {
NSLog(@"writeDataList");

NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:CCSQLiteDataDB];

CCKeyValue *kv = [CCKeyValue defaultKeyValueWithPath:path];
kv.valueType = CCKeyValueTypeJson;

NSData * data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"list" ofType:@"json"]];
[kv setObject:data key:CCKeyValueDataKey];
}

+ (NSArray *) readDataListAtPath : (NSString *) path {
NSArray *list = nil;

if (!path) {
return list;
}

CCKeyValue *kv = [CCKeyValue defaultKeyValueWithPath:path];
kv.valueType = CCKeyValueTypeJson;

id CCJSON = [kv objectForKey:CCKeyValueDataKey];

if ([CCJSON isKindOfClass:[NSArray class]]) {
list = CCJSON;
}

return list;
}

+ (NSArray *) readDataList {
NSLog(@"readDataList");

NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:CCSQLiteDataDB];
return [self readDataListAtPath:path];
}

+ (NSArray *) readDefaultDataList {
NSLog(@"readDefaultDataList");
NSString *path = [[NSBundle mainBundle] pathForResource:@"CCSQLiteData" ofType:@"sqlite"];
return [self readDataListAtPath:path];
}

@end
Binary file added CCSQLiteData/CCSQLiteData.sqlite
Binary file not shown.
5 changes: 5 additions & 0 deletions CCSQLiteData/OKKLineSwift-iOS-Demo-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "CCSQLiteData.h"
106 changes: 62 additions & 44 deletions OKKLineSwift-iOS-Demo/OKKLineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,81 @@
//

import UIKit
import SnapKit

class OKKLineViewController: UIViewController {


// fix iphoneX by CC on 25/01/2018.
let iphonexOffset : CGFloat = 30;
var klineView: OKKLineView!

// fix data use database by CC on 22/01/2018.
func sqliteHandle() {
print(sqliteHandle)

if let list = CCSQLiteData.readDefaultDataList() {
let datas = list as! [[Double]]

print(datas.count)
var dataArray = [OKKLineModel]()
for data in datas {
let model = OKKLineModel(date: data[0], open: data[1], close: data[4], high: data[2], low: data[3], volume: data[5])
dataArray.append(model)
}

self.klineView.drawKLineView(klineModels: dataArray)
}
}

var backButton: UIButton!;
func loadingUI() {
print(loadingUI)

backButton = UIButton(type: .custom)
backButton.setTitle("Back", for: .normal)
backButton.titleLabel?.font = UIFont.systemFont(size: 12)
backButton.backgroundColor = UIColor.blue
backButton.addTarget(self, action:#selector(backHandle(button:)) , for: .touchUpInside)

view.addSubview(backButton)

backButton.snp.makeConstraints { (make) in
make.top.equalToSuperview()
if #available(iOS 11, *) {
make.left.equalTo(iphonexOffset)
} else {
make.left.equalToSuperview()
}

make.size.equalTo(CGSize(width: 50, height: 20))
}
}

@objc func backHandle(button: UIButton) {
print("backHandle")
dismiss(animated: true, completion: nil)
}

override func viewDidLoad() {
super.viewDidLoad()

self.view.backgroundColor = OKConfiguration.sharedConfiguration.main.backgroundColor
klineView = OKKLineView()
klineView.doubleTapHandle = { () -> Void in
self.dismiss(animated: true, completion: nil)
}
view.addSubview(self.klineView)

klineView.snp.makeConstraints { (make) in
make.edges.equalTo(OKEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
make.edges.equalTo(view).inset(UIEdgeInsetsMake(0, iphonexOffset, 0, iphonexOffset))
}
// let timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(fetchData), userInfo: nil, repeats: true)

fetchData()

// timer.fire()

//let unitValue = (limitValue.maxValue - limitValue.minValue) / Double(drawHeight)
//let drawValue = Double(drawMaxY - drawY) * unitValue + limitValue.minValue
//let drawY: CGFloat = abs(self.drawMaxY - CGFloat((drawValue - limitValue.minValue) / unitValue))

loadingUI()
klineView.backgroundColor = UIColor.red

// fix data use database by CC on 22/01/2018.
sqliteHandle()
klineView.backgroundColor = UIColor.red
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -46,37 +96,5 @@ class OKKLineViewController: UIViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscape
}

@objc
func fetchData() {
let param = ["type" : "5min",
"symbol" : "okcoincnbtccny",
"size" : "300"]
Just.post("https://www.btc123.com/kline/klineapi", params: param, asyncCompletionHandler: { (result) -> Void in

print(result)
DispatchQueue.main.async(execute: {

if result.ok {
let resultData = result.json as! [String : Any]
let datas = resultData["datas"] as! [[Double]]

var dataArray = [OKKLineModel]()
for data in datas {

let model = OKKLineModel(date: data[0], open: data[1], close: data[4], high: data[2], low: data[3], volume: data[5])
dataArray.append(model)
}

// for model in OKConfiguration.shared.klineModels {
// print(model.propertyDescription())
// }
self.klineView.drawKLineView(klineModels: dataArray)
}


})

})
}

}
22 changes: 0 additions & 22 deletions OKKLineSwift-iOS-DemoTests/Info.plist

This file was deleted.

36 changes: 0 additions & 36 deletions OKKLineSwift-iOS-DemoTests/OKKLineSwift_iOS_DemoTests.swift

This file was deleted.

26 changes: 0 additions & 26 deletions OKKLineSwift-macOS-Demo/AppDelegate.swift

This file was deleted.

This file was deleted.

Loading