[ios] implement the DocumentPicker to import files into the app

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-06-06 19:56:04 +04:00 committed by Alexander Borsuk
parent 577c6cc37f
commit 787fe7a3f9
10 changed files with 43 additions and 8 deletions

View file

@ -20,7 +20,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YDi-5J-vFD">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic24PxAddCopy" translatesAutoresizingMaskIntoConstraints="NO" id="paw-km-zXg">
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic24PxAddCopy" translatesAutoresizingMaskIntoConstraints="NO" id="paw-km-zXg">
<rect key="frame" x="16" y="10" width="24" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="S7u-WM-dEL"/>

View file

@ -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")!
}
}
}

View file

@ -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()

View file

@ -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()
}

View file

@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "ic24PxImport.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

View file

@ -0,0 +1,3 @@
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
<path d="M4 16v2.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V16M12 3v13m-4-4 4 4 4-4" fill="none" stroke="#000" stroke-width="2" stroke-linejoin="round" paint-order="fill markers stroke" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 289 B

View file

@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "ic_share.svg",
"filename" : "ic24PxShare.svg",
"idiom" : "universal"
}
],

View file

@ -0,0 +1,4 @@
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
<path d="M7.5 7h-2A1.5 1.5 0 0 0 4 8.5v8A1.5 1.5 0 0 0 5.5 18h9a1.5 1.5 0 0 0 1.5-1.5v-8A1.5 1.5 0 0 0 14.5 7h-2" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8 19v1.5A1.5 1.5 0 0 0 9.5 22h9a1.5 1.5 0 0 0 1.5-1.5v-8a1.5 1.5 0 0 0-1.5-1.5H17M10 13V1M7 4l3-3 3 3" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 486 B

View file

@ -1,5 +0,0 @@
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M9 8H6.5A1.5 1.5 135 0 0 5 9.5v8A1.5 1.5 45 0 0 6.5 19h9a1.5 1.5 135 0 0 1.5-1.5v-8A1.5 1.5 45 0 0 15.5 8H13" fill="none" stroke="#000" stroke-width="2" stroke-linejoin="round" paint-order="fill markers stroke"/>
<path d="M8 19v1.5A1.5 1.5 45 0 0 9.5 22h9a1.5 1.5 135 0 0 1.5-1.5v-8a1.5 1.5 45 0 0-1.5-1.5H17" fill="none" stroke="#000" stroke-width="2" stroke-linejoin="round" paint-order="fill markers stroke"/>
<path d="M11 13V2M8 5l3-3 3 2.907" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" paint-order="fill markers stroke"/>
</svg>

Before

Width:  |  Height:  |  Size: 680 B

View file

@ -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