Fixed merge conflicts.

This commit is contained in:
Kevin G Christiano 2019-08-15 09:54:19 -04:00
parent 3fedfb3afe
commit 03fceaab5a

View File

@ -23,7 +23,7 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
//-------------------------------------------------- //--------------------------------------------------
let folderPath = Bundle.main.resourcePath! + "/JSON" let folderPath = Bundle.main.resourcePath! + "/JSON"
var sectionsMap: [AnyHashable: Any] = [:]
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Life Cycle // MARK: - Life Cycle
@ -32,12 +32,6 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
var sectionsMap: [AnyHashable: Any] = [:]
func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// setup the data // setup the data
sectionsMap = [:] sectionsMap = [:]
let sections = try! FileManager.default.contentsOfDirectory(atPath: folderPath) let sections = try! FileManager.default.contentsOfDirectory(atPath: folderPath)
@ -61,10 +55,12 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
} }
func getData(for indexPath: IndexPath) -> String? { func getData(for indexPath: IndexPath) -> String? {
let sectionName = self.tableView(tableView, titleForHeaderInSection: indexPath.section) let sectionName = self.tableView(tableView, titleForHeaderInSection: indexPath.section)
let array = sectionsMap[sectionName!]! as! Array<Any> let array = sectionsMap[sectionName!]! as! Array<Any>
let subPath = (array[indexPath.row] as! String) let subPath = (array[indexPath.row] as! String)
let path = "\(folderPath)/\(sectionName!)/\(subPath)" let path = "\(folderPath)/\(sectionName!)/\(subPath)"
return try! String.init(contentsOfFile: path) return try! String.init(contentsOfFile: path)
} }
@ -72,19 +68,6 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
// MARK: - Table View // MARK: - Table View
//-------------------------------------------------- //--------------------------------------------------
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return try? FileManager.default.contentsOfDirectory(atPath: folderPath)[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return try! FileManager.default.contentsOfDirectory(atPath: folderPath).count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return try! FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[section]).count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return (((sectionsMap as NSDictionary).allKeys[section]) as! String) return (((sectionsMap as NSDictionary).allKeys[section]) as! String)
} }
@ -101,20 +84,25 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
} }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let name = try? FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath.section])[indexPath.row] let sectionName = self.tableView(tableView, titleForHeaderInSection: indexPath.section)
cell.textLabel?.text = name let array = sectionsMap[sectionName!]! as! Array<Any>
cell.textLabel?.text = (array[indexPath.row] as! String)
if cell.interactions.first == nil { if cell.interactions.first == nil {
let dragInteraction = UIDragInteraction(delegate: self) let dragInteraction = UIDragInteraction(delegate: self)
cell.addInteraction(dragInteraction) cell.addInteraction(dragInteraction)
} }
return cell return cell
} }
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let button = UIButton(frame: .zero) let button = UIButton(frame: .zero)
@ -122,22 +110,30 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
button.backgroundColor = .red button.backgroundColor = .red
button.tag = section // why not... ``\__(~_~)__/`` button.tag = section // why not... ``\__(~_~)__/``
button.addTarget(self, action: #selector(requestJSON), for: .touchUpInside) button.addTarget(self, action: #selector(requestJSON), for: .touchUpInside)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let sectionName = self.tableView(tableView, titleForHeaderInSection: indexPath.section)
let array = sectionsMap[sectionName!]! as! Array<Any>
cell.textLabel?.text = (array[indexPath.row] as! String)
return button return button
} }
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Return false if you do not want the specified item to be editable.
return true UIPasteboard.general.string = getData(for: indexPath)
let label = UILabel(frame: .zero)
label.clipsToBounds = true
label.backgroundColor = .gray
label.text = " Copied "
label.font = UIFont.systemFont(ofSize: 40)
label.translatesAutoresizingMaskIntoConstraints = false
label.layer.cornerRadius = 5
view.superview!.addSubview(label)
label.centerXAnchor.constraint(equalTo: view.superview!.centerXAnchor).isActive = true
label.centerYAnchor.constraint(equalTo: view.superview!.centerYAnchor).isActive = true
UIView.animate(withDuration: 2, animations: {
label.alpha = 0
}) { completed in
label.removeFromSuperview()
}
} }
//-------------------------------------------------- //--------------------------------------------------
@ -170,32 +166,9 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
} }
}) })
}) })
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
UIPasteboard.general.string = getData(for: indexPath)
let label = UILabel(frame: .zero)
label.clipsToBounds = true
label.backgroundColor = .gray
label.text = " Copied "
label.font = UIFont.systemFont(ofSize: 40)
label.translatesAutoresizingMaskIntoConstraints = false
label.layer.cornerRadius = 5
view.superview!.addSubview(label)
label.centerXAnchor.constraint(equalTo: view.superview!.centerXAnchor).isActive = true
label.centerYAnchor.constraint(equalTo: view.superview!.centerYAnchor).isActive = true
UIView.animate(withDuration: 2, animations: {
label.alpha = 0
}) { completed in
label.removeFromSuperview()
}
} }
} }
}
}
// MARK:- Drag Interaction Delegate // MARK:- Drag Interaction Delegate
extension MasterViewController: UIDragInteractionDelegate { extension MasterViewController: UIDragInteractionDelegate {
@ -204,17 +177,9 @@ extension MasterViewController: UIDragInteractionDelegate {
let location = session.location(in: tableView) let location = session.location(in: tableView)
let indexPath = tableView.indexPathForRow(at: location) let indexPath = tableView.indexPathForRow(at: location)
let sectionName = try! FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath!.section]
let path = try! folderPath + "/" + sectionName + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + sectionName)[indexPath!.row]
let content = try! String(contentsOfFile: path)
let provider = NSItemProvider(object: content as NSString)
let content = getData(for: indexPath!) let content = getData(for: indexPath!)
let provider = NSItemProvider(object: content! as NSString) let provider = NSItemProvider(object: content! as NSString)
let item = UIDragItem(itemProvider: provider) let item = UIDragItem(itemProvider: provider)
return [item] return [item]
} }
} }