Merge branch 'develop' into feature/molecular
# Conflicts: # JSONCreator_iOS/JSONCreator/AppDelegate.swift # JSONCreator_iOS/JSONCreator/DetailViewController.swift # JSONCreator_iOS/JSONCreator/MasterViewController.swift
This commit is contained in:
commit
e1c4fdda63
@ -13,16 +13,10 @@ import MVMCoreUI
|
|||||||
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
|
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
|
||||||
|
|
||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
var mvcNav: UINavigationController?
|
||||||
func itera(_ path: String) {
|
var dvcNav: UINavigationController?
|
||||||
|
var mvc: UIViewController?
|
||||||
let fileManager = FileManager.default
|
var dvc: UIViewController?
|
||||||
let enumerator = fileManager.enumerator(atPath: path)!
|
|
||||||
for element in enumerator {
|
|
||||||
//do something
|
|
||||||
print(element)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||||
// Setup our core object with the default implementation
|
// Setup our core object with the default implementation
|
||||||
@ -31,15 +25,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
|||||||
}
|
}
|
||||||
|
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
itera(Bundle.main.resourcePath! + "/JSON")
|
|
||||||
|
|
||||||
// Override point for customization after application launch.
|
// Override point for customization after application launch.
|
||||||
let splitViewController = window!.rootViewController as! UISplitViewController
|
let splitViewController = window!.rootViewController as! UISplitViewController
|
||||||
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count - 1] as! UINavigationController
|
mvcNav = splitViewController.viewControllers[0] as? UINavigationController
|
||||||
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
|
mvcNav?.delegate = self
|
||||||
|
mvc = mvcNav?.topViewController
|
||||||
|
dvcNav = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as? UINavigationController
|
||||||
|
dvc = dvcNav?.topViewController
|
||||||
|
dvc?.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
|
||||||
|
dvc?.navigationItem.leftItemsSupplementBackButton = true
|
||||||
splitViewController.delegate = self
|
splitViewController.delegate = self
|
||||||
splitViewController.preferredDisplayMode = .allVisible
|
splitViewController.preferredDisplayMode = .allVisible
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(forName: UIViewController.showDetailTargetDidChangeNotification, object: splitViewController, queue: nil) { [weak self] (notification) in
|
||||||
|
if let strongSelf = self, let svc = notification.object as? UISplitViewController {
|
||||||
|
if svc.isCollapsed {
|
||||||
|
strongSelf.mvc?.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Editor", style: .plain, target: self, action: #selector(self?.showEditor))
|
||||||
|
} else {
|
||||||
|
strongSelf.mvcNav?.setViewControllers([strongSelf.mvc!], animated: false)
|
||||||
|
strongSelf.mvc?.navigationItem.rightBarButtonItem = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,11 +76,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
|||||||
// MARK: - Split view
|
// MARK: - Split view
|
||||||
|
|
||||||
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
|
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
|
||||||
|
//guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
|
||||||
|
//guard let _ = secondaryAsNavController.topViewController as? DetailViewController else { return false }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
guard let secondaryAsNavController = secondaryViewController as? UINavigationController,
|
@objc func showEditor() {
|
||||||
let _ = secondaryAsNavController.topViewController as? DetailViewController
|
mvcNav?.pushViewController(dvc!, animated: true)
|
||||||
else { return false }
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension AppDelegate: UINavigationControllerDelegate {
|
||||||
|
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
||||||
|
if mvc == viewController {
|
||||||
|
dvcNav?.setViewControllers([dvc!], animated: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,11 @@ class DetailViewController: UIViewController {
|
|||||||
textView.textDropDelegate = self
|
textView.textDropDelegate = self
|
||||||
|
|
||||||
view.addSubview(textView)
|
view.addSubview(textView)
|
||||||
textView.font = UIFont.systemFont(ofSize: 30)
|
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||||
|
textView.font = UIFont.systemFont(ofSize: 40)
|
||||||
|
} else {
|
||||||
|
textView.font = UIFont.systemFont(ofSize: 14)
|
||||||
|
}
|
||||||
textView.translatesAutoresizingMaskIntoConstraints = false
|
textView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
textView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
textView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
||||||
textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
|
textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
|
||||||
|
|||||||
@ -43,6 +43,7 @@
|
|||||||
<string>UIInterfaceOrientationPortrait</string>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||||
<array>
|
<array>
|
||||||
|
|||||||
@ -23,6 +23,7 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
let folderPath = Bundle.main.resourcePath! + "/JSON"
|
let folderPath = Bundle.main.resourcePath! + "/JSON"
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Life Cycle
|
// MARK: - Life Cycle
|
||||||
@ -30,6 +31,36 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
|
|||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
=======
|
||||||
|
var sectionsMap: [AnyHashable: Any] = [:]
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
// Do any additional setup after loading the view.
|
||||||
|
|
||||||
|
// setup the data
|
||||||
|
sectionsMap = [:]
|
||||||
|
let sections = try! FileManager.default.contentsOfDirectory(atPath: folderPath)
|
||||||
|
for section in sections {
|
||||||
|
let paths = try! FileManager.default.subpathsOfDirectory(atPath: "\(folderPath)/\(section)")
|
||||||
|
var array: [String] = []
|
||||||
|
for path in paths {
|
||||||
|
if path.hasSuffix(".json") {
|
||||||
|
array.append(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sectionsMap[section] = array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getData(for indexPath: IndexPath) -> String? {
|
||||||
|
let sectionName = self.tableView(tableView, titleForHeaderInSection: indexPath.section)
|
||||||
|
let array = sectionsMap[sectionName!]! as! Array<Any>
|
||||||
|
let subPath = (array[indexPath.row] as! String)
|
||||||
|
let path = "\(folderPath)/\(sectionName!)/\(subPath)"
|
||||||
|
return try! String.init(contentsOfFile: path)
|
||||||
|
}
|
||||||
|
>>>>>>> develop
|
||||||
|
|
||||||
tableView.delegate = self
|
tableView.delegate = self
|
||||||
tableView.dataSource = self
|
tableView.dataSource = self
|
||||||
@ -43,6 +74,7 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
|
|||||||
// MARK: - Table View
|
// MARK: - Table View
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
return try? FileManager.default.contentsOfDirectory(atPath: folderPath)[section]
|
return try? FileManager.default.contentsOfDirectory(atPath: folderPath)[section]
|
||||||
}
|
}
|
||||||
@ -54,10 +86,25 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
|
|||||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
||||||
return try! FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[section]).count
|
return try! FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[section]).count
|
||||||
|
=======
|
||||||
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
|
return (((sectionsMap as NSDictionary).allKeys[section]) as! String)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
return sectionsMap.count
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
let sectionName = self.tableView(tableView, titleForHeaderInSection: section)
|
||||||
|
let array = sectionsMap.arrayForKey(sectionName!)
|
||||||
|
return array.count
|
||||||
|
>>>>>>> develop
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
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 name = try? FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath.section])[indexPath.row]
|
||||||
@ -78,6 +125,14 @@ 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)
|
||||||
|
=======
|
||||||
|
override 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)
|
||||||
|
>>>>>>> develop
|
||||||
|
|
||||||
return button
|
return button
|
||||||
}
|
}
|
||||||
@ -87,6 +142,7 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -117,6 +173,26 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
=======
|
||||||
|
override 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()
|
||||||
|
}
|
||||||
|
>>>>>>> develop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,10 +203,15 @@ 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)
|
||||||
|
<<<<<<< HEAD
|
||||||
let sectionName = try! FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath!.section]
|
let sectionName = try! FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath!.section]
|
||||||
let path = try! folderPath + "/" + sectionName + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + sectionName)[indexPath!.row]
|
let path = try! folderPath + "/" + sectionName + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + sectionName)[indexPath!.row]
|
||||||
let content = try! String(contentsOfFile: path)
|
let content = try! String(contentsOfFile: path)
|
||||||
let provider = NSItemProvider(object: content as NSString)
|
let provider = NSItemProvider(object: content as NSString)
|
||||||
|
=======
|
||||||
|
let content = getData(for: indexPath!)
|
||||||
|
let provider = NSItemProvider(object: content! as NSString)
|
||||||
|
>>>>>>> develop
|
||||||
let item = UIDragItem(itemProvider: provider)
|
let item = UIDragItem(itemProvider: provider)
|
||||||
|
|
||||||
return [item]
|
return [item]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user