From 787fe7a3f99f6e18f1ccf0804c4c95e040c70f21 Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Thu, 6 Jun 2024 19:56:04 +0400 Subject: [PATCH] [ios] implement the DocumentPicker to import files into the app Signed-off-by: Kiryl Kaveryn --- .../Categories/Actions/BMCActionsCell.xib | 2 +- iphone/Maps/Bookmarks/Categories/BMCModels.swift | 5 +++++ .../Categories/BMCView/BMCViewController.swift | 7 +++++++ .../BMCViewModel/BMCDefaultViewModel.swift | 6 ++++++ .../Sharing/ic24PxImport.imageset/Contents.json | 15 +++++++++++++++ .../ic24PxImport.imageset/ic24PxImport.svg | 3 +++ .../Sharing/ic24PxShare.imageset/Contents.json | 2 +- .../Sharing/ic24PxShare.imageset/ic24PxShare.svg | 4 ++++ .../Sharing/ic24PxShare.imageset/ic_share.svg | 5 ----- iphone/Maps/UI/DocumentPicker/FileType.swift | 2 +- 10 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/Contents.json create mode 100644 iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/ic24PxImport.svg create mode 100644 iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic24PxShare.svg delete mode 100644 iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic_share.svg diff --git a/iphone/Maps/Bookmarks/Categories/Actions/BMCActionsCell.xib b/iphone/Maps/Bookmarks/Categories/Actions/BMCActionsCell.xib index 528edcbf40..c0c1d5ac0f 100644 --- a/iphone/Maps/Bookmarks/Categories/Actions/BMCActionsCell.xib +++ b/iphone/Maps/Bookmarks/Categories/Actions/BMCActionsCell.xib @@ -20,7 +20,7 @@ - + diff --git a/iphone/Maps/Bookmarks/Categories/BMCModels.swift b/iphone/Maps/Bookmarks/Categories/BMCModels.swift index a3a7aa4099..c7d4c934e8 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCModels.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCModels.swift @@ -9,6 +9,7 @@ protocol BMCModel {} enum BMCAction: BMCModel { case create case exportAll + case `import` } extension BMCAction { @@ -18,6 +19,8 @@ extension BMCAction { return L("bookmarks_create_new_group") case .exportAll: return L("bookmarks_export") + case .import: + return L("bookmarks_import") } } @@ -27,6 +30,8 @@ extension BMCAction { return UIImage(named: "ic24PxAddCopy")! case .exportAll: return UIImage(named: "ic24PxShare")! + case .import: + return UIImage(named: "ic24PxImport")! } } } diff --git a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift index 51fbd45775..4489d6991f 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift @@ -99,6 +99,12 @@ final class BMCViewController: MWMViewController { } } + private func showImportDialog() { + DocumentPicker.shared.present(from: self) { [viewModel] urls in + viewModel?.importCategories(from: urls) + } + } + private func openCategorySettings(category: BookmarkGroup) { let settingsController = CategorySettingsViewController(bookmarkGroup: BookmarksManager.shared().category(withId: category.categoryId)) settingsController.delegate = self @@ -268,6 +274,7 @@ extension BMCViewController: UITableViewDelegate { switch viewModel.action(at: indexPath.row) { case .create: createNewCategory() case .exportAll: shareAllCategories(anchor: tableView.cellForRow(at: indexPath)) + case .import: showImportDialog() } default: assertionFailure() diff --git a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift index 69195c361b..8097d8cf8a 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift @@ -33,6 +33,7 @@ final class BMCDefaultViewModel: NSObject { private func setActions() { actions = [.create] + actions.append(.import) if !manager.areAllCategoriesEmpty() { actions.append(.exportAll) } @@ -141,6 +142,11 @@ extension BMCDefaultViewModel { manager.shareAllCategories(completion: handler) } + func importCategories(from urls: [URL]) { + // TODO: Refactor this call when the multiple files parsing support will be added to the bookmark_manager. + urls.forEach(manager.loadBookmarkFile(_:)) + } + func finishShareCategory() { manager.finishShareCategory() } diff --git a/iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/Contents.json b/iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/Contents.json new file mode 100644 index 0000000000..c6a82a5a29 --- /dev/null +++ b/iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "ic24PxImport.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/ic24PxImport.svg b/iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/ic24PxImport.svg new file mode 100644 index 0000000000..1688ee9ba1 --- /dev/null +++ b/iphone/Maps/Images.xcassets/Sharing/ic24PxImport.imageset/ic24PxImport.svg @@ -0,0 +1,3 @@ + + + diff --git a/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/Contents.json b/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/Contents.json index 0d40dda86c..6031d7afdf 100644 --- a/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/Contents.json +++ b/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "ic_share.svg", + "filename" : "ic24PxShare.svg", "idiom" : "universal" } ], diff --git a/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic24PxShare.svg b/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic24PxShare.svg new file mode 100644 index 0000000000..832959976c --- /dev/null +++ b/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic24PxShare.svg @@ -0,0 +1,4 @@ + + + + diff --git a/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic_share.svg b/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic_share.svg deleted file mode 100644 index 57c45054b6..0000000000 --- a/iphone/Maps/Images.xcassets/Sharing/ic24PxShare.imageset/ic_share.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/iphone/Maps/UI/DocumentPicker/FileType.swift b/iphone/Maps/UI/DocumentPicker/FileType.swift index 12932b19e0..a7968c1d24 100644 --- a/iphone/Maps/UI/DocumentPicker/FileType.swift +++ b/iphone/Maps/UI/DocumentPicker/FileType.swift @@ -1,6 +1,6 @@ import UniformTypeIdentifiers -// TODO: Remove this type-wrapper and use custom UTTypeIdentifier that is registered into the Info.plist after updating to the iOS >= 14.0. +// TODO: (KK) Remove this type-wrapper and use custom UTTypeIdentifier that is registered into the Info.plist after updating to the iOS >= 14.0. struct FileType { let fileExtension: String let typeIdentifier: String