Skip to content

Commit

Permalink
fix f9427c5 deletes; y-axis label vertical; choice graph label work; f…
Browse files Browse the repository at this point in the history
…9427c5 remnants:multithreaded db access; main thread issues loading csv files
  • Loading branch information
rob-miller committed Dec 10, 2023
1 parent 9fc06b5 commit 8d74799
Show file tree
Hide file tree
Showing 15 changed files with 967 additions and 609 deletions.
172 changes: 98 additions & 74 deletions Classes/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public class RootViewController: UIViewController, UITableViewDelegate, UITableV
let docsDir = rTracker_resource.ioFilePath(nil, access: true)
let localFileManager = FileManager.default
var newRtcsvTracker = false

//let files = try localFileManager.contentsOfDirectory(atPath: docsDir)
let directoryURL = URL(fileURLWithPath: docsDir)
let enumerator = localFileManager.enumerator(at: directoryURL, includingPropertiesForKeys: [.isDirectoryKey], options: [])
Expand All @@ -205,83 +205,98 @@ public class RootViewController: UIViewController, UITableViewDelegate, UITableV
while let url = enumerator?.nextObject() as? URL {
files.append(url.lastPathComponent)
}
for fileName in files {
let fullPath = URL(fileURLWithPath: docsDir).appendingPathComponent(fileName)
var to: trackerObj? = nil
let fname = URL(fileURLWithPath: fileName).lastPathComponent
var tname: String? = nil
var validMatch = false
var loadObj: String?

switch fullPath.pathExtension {
case "csv":
loadObj = "_in.csv"
if fileName.hasSuffix("_in.csv") {
validMatch = true
}
case "rtcsv":
loadObj = "_in.rtcsv"
if fileName.hasSuffix(loadObj!) {
validMatch = true
} else {
loadObj = ".rtcsv" // accept _in above, already know it has .rtcsv extension
validMatch = true
}
default:
continue
}

if validMatch {
tname = String(fileName.dropLast(loadObj!.count)) // String(fileName.prefix(fileName.count - (loadObj!.count + 1))) // Removing suffix
DBGLog("\(loadObj!) load input: \(fname) as \(tname!)")
jumpMaxPriv()
tlist.loadTopLayoutTable()
let tid = tlist.getTIDfromName(tname)
if tid != 0 {
to = trackerObj(tid)
DBGLog("found existing tracker tid \(tid) with matching name")
} else if fullPath.pathExtension == "rtcsv" {
to = trackerObj()
to?.trackerName = tname
to?.toid = tlist.getUnique()
to?.saveConfig()
tlist.add(toTopLayoutTable: to!)
newRtcsvTracker = true
DBGLog("created new tracker for rtcsv, id= \(to!.toid)")
}
restorePriv()
tlist.loadTopLayoutTable()
if let to = to {
safeDispatchSync { [self] in
rTracker_resource.startActivityIndicator(view, navItem: nil, disable: false, str: "loading \(tname ?? "")...")

safeDispatchSync { [self] in
jumpMaxPriv()
tlist.loadTopLayoutTable() // runs on main queue
DispatchQueue.global(qos: .userInitiated).async { [self] in // all this in background queue

for fileName in files {
let fullPath = URL(fileURLWithPath: docsDir).appendingPathComponent(fileName)
var to: trackerObj? = nil
let fname = URL(fileURLWithPath: fileName).lastPathComponent
var tname: String? = nil
var validMatch = false
var loadObj: String?

switch fullPath.pathExtension {
case "csv":
loadObj = "_in.csv"
if fileName.hasSuffix("_in.csv") {
validMatch = true
}
case "rtcsv":
loadObj = "_in.rtcsv"
if fileName.hasSuffix(loadObj!) {
validMatch = true
} else {
loadObj = ".rtcsv" // accept _in above, already know it has .rtcsv extension
validMatch = true
}
default:
continue
}

do {
let csvString = try String(contentsOfFile: fullPath.path, encoding: .utf8)
safeDispatchSync { [self] in
UIApplication.shared.isIdleTimerDisabled = true
//jumpMaxPriv() just needed to get in tracker list above
doCSVLoad(csvString, to: to, fname: fname)
//restorePriv()

if validMatch {
tname = String(fileName.dropLast(loadObj!.count))
let tid = tlist.getTIDfromName(tname)
if tid != 0 {
to = trackerObj(tid)
DBGLog("found existing tracker tid \(tid) with matching name")
} else if fullPath.pathExtension == "rtcsv" {
to = trackerObj()
to?.trackerName = tname
to?.toid = tlist.getUnique()
to?.saveConfig()
tlist.add(toTopLayoutTable: to!)
newRtcsvTracker = true
DBGLog("created new tracker for rtcsv, id= \(to!.toid)")
}

if let to = to {
safeDispatchSync { [self] in
rTracker_resource.startActivityIndicator(self.view, navItem: nil, disable: false, str: "loading \(tname ?? "")...")
UIApplication.shared.isIdleTimerDisabled = true
//print("activity indicator \(tname ?? "tname nil")")
}
do {
try localFileManager.removeItem(at: fullPath)

let csvString = try String(contentsOfFile: fullPath.path, encoding: .utf8)
//jumpMaxPriv() just needed to get in tracker list above
self.doCSVLoad(csvString, to: to, fname: fname)
//print("back from csv load \(tname ?? "tname nil")")
//restorePriv()
do {
try localFileManager.removeItem(at: fullPath)
} catch {
DBGWarn("Error deleting file \(fname): \(error)")
}
DispatchQueue.main.async { [self] in
UIApplication.shared.isIdleTimerDisabled = false
// Stop activity indicator and any other UI updates
rTracker_resource.finishActivityIndicator(view, navItem: nil, disable: false)
//print("stop activity indicator \(tname ?? "tname nil")")
}
} catch {
DBGWarn("Error deleting file \(fname): \(error)")
DispatchQueue.main.async {
UIApplication.shared.isIdleTimerDisabled = false
DBGWarn("Error processing file \(fname): \(error)")
rTracker_resource.finishActivityIndicator(self.view, navItem: nil, disable: false)
//print("error stop activity indicator \(tname ?? "tname nil")")
}
}
UIApplication.shared.isIdleTimerDisabled = false
}
} catch {
DBGWarn("Error reading or deleting file \(fname): \(error)")
}

safeDispatchSync { [self] in
rTracker_resource.finishActivityIndicator(view, navItem: nil, disable: false)
}
}
}
}


// still on background queue
restorePriv()
tlist.loadTopLayoutTable() // runs on main queue
safeDispatchSync {
refreshToolBar(true)
}

} // end of background queue
} // end of main queue

if newRtcsvTracker {
refreshViewPart2()
Expand Down Expand Up @@ -1545,6 +1560,10 @@ public class RootViewController: UIViewController, UITableViewDelegate, UITableV
if PVNOSHOW != privacyObj.showing {
return
}
if privacyObj.jmpriv {
return
}

var ctlc: configTlistController?
ctlc = configTlistController(nibName: "configTlistController", bundle: nil)
ctlc?.tlist = tlist
Expand Down Expand Up @@ -1751,10 +1770,15 @@ public class RootViewController: UIViewController, UITableViewDelegate, UITableV
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


if _privacyObj != nil && PVNOSHOW != privacyObj.showing {
return
if _privacyObj != nil {
if PVNOSHOW != privacyObj.showing {
return
}
if privacyObj.jmpriv {
return
}
}

//NSUInteger row = [indexPath row];
//DBGLog(@"selected row %d : %@", row, [self.tlist.topLayoutNames objectAtIndex:row]);

Expand Down
2 changes: 1 addition & 1 deletion Classes/gfx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import UIKit
*/


let GFXHDEBUG = 0
// let GFXHDEBUG = 1 // control in project - targets rTracker - swift compiler custom flags - active compilation conditions

func CGPush(_ c: CGContext) {
c.saveGState()
Expand Down
8 changes: 4 additions & 4 deletions Classes/gtXAxV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class gtXAxV: UIView {
MoveTo(context!, scaleOriginX, 0.0)
AddLineTo(context!, scaleWidthX, 0.0)
//Stroke

context!.strokePath()
drawXAxis(context)
}

Expand All @@ -84,13 +84,12 @@ class gtXAxV: UIView {
var nextXd = -2 * DOFFST

for i in 1...Int(XTICKS) {
var x = d(i) * step
var x = CGFloat(d(i) * step)
var y: CGFloat = 0.0 // self.bounds.size.height - BORDER;
MoveTo(context!, x, y)
y += TICKLEN
//if (i>0) // from when 1st tick at origin
AddLineTo(context!, x, y)

y += 1.0 // skip space to time label
let y2 = y + 4.0 // hack to lengthen ticks where date label can be drawn
let x2 = x
Expand Down Expand Up @@ -151,6 +150,7 @@ class gtXAxV: UIView {
}
}

context!.strokePath()
//Stroke
}

Expand Down
Loading

0 comments on commit 8d74799

Please sign in to comment.