Skip to content

Commit

Permalink
Merge pull request #52 from susemi99/develop
Browse files Browse the repository at this point in the history
v3.7
  • Loading branch information
Changhoon, Jin authored Dec 21, 2019
2 parents 0947a66 + 097f1e6 commit 78cf152
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 336 deletions.
12 changes: 5 additions & 7 deletions GPXTracker/GPXTracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
7D3E0769207A08B500EF3F00 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7D3E0767207A08B500EF3F00 /* Main.storyboard */; };
7D3E076B207A08B600EF3F00 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D3E076A207A08B600EF3F00 /* Assets.xcassets */; };
7D3E076E207A08B600EF3F00 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7D3E076C207A08B600EF3F00 /* LaunchScreen.storyboard */; };
7D3E0779207A096A00EF3F00 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D3E0778207A096A00EF3F00 /* CoreLocation.framework */; };
7D51CAD02081F5B4007465BE /* FileController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D51CACF2081F5B4007465BE /* FileController.swift */; };
7D51CAD32081F73D007465BE /* GTFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D51CAD22081F73D007465BE /* GTFile.swift */; };
7DA532F9208B4AA4000CF90A /* TCXParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA532F8208B4AA4000CF90A /* TCXParser.swift */; };
Expand Down Expand Up @@ -65,7 +64,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
7D3E0779207A096A00EF3F00 /* CoreLocation.framework in Frameworks */,
7DC69015207A16D800447E9B /* PKHUD.framework in Frameworks */,
7DC69016207A16D800447E9B /* Kanna.framework in Frameworks */,
7D14ADB62082328D007C17DA /* Zip.framework in Frameworks */,
Expand Down Expand Up @@ -235,7 +233,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/usr/local/bin/carthage copy-frameworks";
shellScript = "/usr/local/bin/carthage copy-frameworks\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -405,7 +403,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.6;
CURRENT_PROJECT_VERSION = 3.7;
DEVELOPMENT_TEAM = 37DX6YRT9T;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -417,7 +415,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.6;
MARKETING_VERSION = 3.7;
PRODUCT_BUNDLE_IDENTIFIER = net.chocobi.GPXiPhone;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -430,7 +428,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.6;
CURRENT_PROJECT_VERSION = 3.7;
DEVELOPMENT_TEAM = 37DX6YRT9T;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -442,7 +440,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.6;
MARKETING_VERSION = 3.7;
PRODUCT_BUNDLE_IDENTIFIER = net.chocobi.GPXiPhone;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
7 changes: 2 additions & 5 deletions GPXTracker/GPXTracker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand Down Expand Up @@ -33,11 +31,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
NotificationCenter.default.post(name: Notification.Name(rawValue: SELECTED_FILE),
object: nil,
userInfo: [SELECTED_FILE_PATH : GTFile(file: url)])
userInfo: [SELECTED_FILE_PATH: GTFile(file: url)])
return true
}
}

64 changes: 33 additions & 31 deletions GPXTracker/GPXTracker/FileController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,69 @@ class FileController {
let sourceFolder = path + "/samples"
let files = try! FileManager.default.contentsOfDirectory(atPath: sourceFolder)
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

do {
for file in files {
try FileManager.default.copyItem(atPath: "\(sourceFolder)/\(file)", toPath: "\(documentDirectory.path)/\(file)")
}
} catch let error{
} catch {
print(error.localizedDescription)
}
}

static func files() -> [GTFile] {
var result: [GTFile] = []
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
result.append(contentsOf: addFilesInDirectory(path: documentDirectory))

// received from iCloud Drive
let temporaryDirectory = NSURL.fileURL(withPath: NSTemporaryDirectory(), isDirectory: true)
result.append(contentsOf: addFilesInDirectory(path: temporaryDirectory))
return result.sorted {$0.name.lowercased() < $1.name.lowercased()}

return result.sorted { $0.name.lowercased() < $1.name.lowercased() }
}


/// 폴더 안의 파일 목록 가져오기
/// - Parameter path: folder path
static func addFilesInDirectory(path: URL) -> [GTFile] {
var result: [GTFile] = []

if path.absoluteString.contains(UNZIP_FOLER_NAME) {
return result
}

do {
let contentsOfDirectory = try FileManager.default.contentsOfDirectory(at: path,
includingPropertiesForKeys: nil,
options: FileManager.DirectoryEnumerationOptions())

var isDirectory: ObjCBool = false
for content in contentsOfDirectory {
if FileManager.default.fileExists(atPath: content.path, isDirectory:&isDirectory) {
if isDirectory.boolValue {
result += addFilesInDirectory(path: content)
}
else {
result.append(GTFile(file: content))
}
}
}
} catch let error {
let contentsOfDirectory = try FileManager.default.contentsOfDirectory(at: path, includingPropertiesForKeys: nil)

// 폴더 안의 파일 가져오기
_ = contentsOfDirectory
.filter { $0.hasDirectoryPath }
.map { result += addFilesInDirectory(path: $0) }

// 파싱 가능한 파일이면 목록에 표시하기
_ = contentsOfDirectory
.filter { !$0.hasDirectoryPath }
.filter { ["kml", "kmz", "gpx", "tcx"].contains($0.pathExtension) }
.map { GTFile(file: $0) }
.map { result.append($0) }
} catch {
print(error.localizedDescription)
}

return result
}


/// 파일 삭제
/// - Parameter file: GTFile
static func delete(file: GTFile) {
do {
try FileManager.default.removeItem(at: file.path)

if !file.unzippedFolderPath.isEmpty {
try FileManager.default.removeItem(atPath: file.unzippedFolderPath)
}
} catch let error {
} catch {
print(error.localizedDescription)
}
}
Expand Down
46 changes: 24 additions & 22 deletions GPXTracker/GPXTracker/FileListViewController.swift
Original file line number Diff line number Diff line change
@@ -1,82 +1,84 @@
import UIKit
import PKHUD
import UIKit

class FileListViewController: UITableViewController {
var items: [GTFile] = []

override func viewDidLoad() {
super.viewDidLoad()
if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad{

if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad {
navigationItem.leftBarButtonItems = []
}

if !UserDefaults.standard.bool(forKey: IS_FIRST_RUN) {
FileController.copyBundleToFolder()
UserDefaults.standard.set(true, forKey: IS_FIRST_RUN)
}

reload()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

// MARK: - User Action

@IBAction func cancelButtonClicked(_ sender: AnyObject) {
close()
}

func close() {
dismiss(animated: true, completion: nil)
}

@IBAction func reloadButtonClicked(_ sender: Any) {
reload()
}

func reload() {
self.items.removeAll()
items.removeAll()

HUD.show(.progress)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.items = FileController.files()
self.tableView.reloadData()
HUD.hide()
}
}

// MARK: - UITableView

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let file = items[indexPath.row]
cell.textLabel?.text = file.fullName
return cell
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let row = indexPath.row
FileController.delete(file: self.items[row])
self.items.remove(at: row)
FileController.delete(file: items[row])
items.remove(at: row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
NotificationCenter.default.post(name: Notification.Name(rawValue: SELECTED_FILE),
object: nil,
userInfo: [SELECTED_FILE_PATH : self.items[indexPath.row]])
userInfo: [SELECTED_FILE_PATH: self.items[indexPath.row]])
close()
}
}
Loading

0 comments on commit 78cf152

Please sign in to comment.