[ios] implement 'share all bookmarks' button

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-02-29 16:29:19 +04:00 committed by Roman Tsisyk
parent 2308e08aa6
commit 1a0896a1c1
6 changed files with 69 additions and 14 deletions

View file

@ -84,6 +84,7 @@ NS_SWIFT_NAME(BookmarksManager)
- (MWMTrackIDCollection)trackIdsForCategory:(MWMMarkGroupID)categoryId;
- (void)shareCategory:(MWMMarkGroupID)groupId;
- (void)shareAllCategories;
- (NSURL *)shareCategoryURL;
- (void)finishShareCategory;

View file

@ -572,9 +572,23 @@ static BookmarkManager::SortingType convertSortingTypeToCore(MWMBookmarksSorting
{
self.bm.PrepareFileForSharing({groupId}, [self](auto sharingResult)
{
MWMBookmarksShareStatus status;
switch (sharingResult.m_code)
{
[self handleSharingResult:sharingResult];
});
}
- (void)shareAllCategories
{
self.bm.PrepareAllFilesForSharing([self](auto sharingResult)
{
[self handleSharingResult:sharingResult];
});
}
- (void)handleSharingResult:(BookmarkManager::SharingResult)sharingResult
{
MWMBookmarksShareStatus status;
switch (sharingResult.m_code)
{
case BookmarkManager::SharingResult::Code::Success:
{
self.shareCategoryURL = [NSURL fileURLWithPath:@(sharingResult.m_sharingPath.c_str()) isDirectory:NO];
@ -591,13 +605,12 @@ static BookmarkManager::SortingType convertSortingTypeToCore(MWMBookmarksSorting
case BookmarkManager::SharingResult::Code::FileError:
status = MWMBookmarksShareStatusFileError;
break;
}
}
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
if ([observer respondsToSelector:@selector(onBookmarksCategoryFilePrepared:)])
[observer onBookmarksCategoryFilePrepared:status];
}];
});
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
if ([observer respondsToSelector:@selector(onBookmarksCategoryFilePrepared:)])
[observer onBookmarksCategoryFilePrepared:status];
}];
}
- (NSURL *)shareCategoryURL

View file

@ -5,8 +5,8 @@ final class BMCActionsCell: MWMTableViewCell {
private var model: BMCAction! {
didSet {
actionImage.image = #imageLiteral(resourceName: "ic24PxAddCopy")
actionTitle.text = L("bookmarks_create_new_group")
actionImage.image = model.image
actionTitle.text = model.title
}
}

View file

@ -8,6 +8,27 @@ protocol BMCModel {}
enum BMCAction: BMCModel {
case create
case exportAll
}
extension BMCAction {
var title: String {
switch self {
case .create:
return L("bookmarks_create_new_group")
case .exportAll:
return L("bookmarks_export")
}
}
var image: UIImage {
switch self {
case .create:
return UIImage(named: "ic24PxAddCopy")!
case .exportAll:
return UIImage(named: "ic24PxShare")!
}
}
}
enum BMCNotification: BMCModel {

View file

@ -77,8 +77,7 @@ final class BMCViewController: MWMViewController {
viewModel.shareCategoryFile(at: index) {
switch $0 {
case let .success(url):
let shareController = ActivityViewController.share(for: url,
message: L("share_bookmarks_email_body"))
let shareController = ActivityViewController.share(for: url, message: L("share_bookmarks_email_body"))
{ [weak self] _, _, _, _ in
self?.viewModel?.finishShareCategory()
}
@ -89,6 +88,21 @@ final class BMCViewController: MWMViewController {
}
}
private func shareAllCategories() {
viewModel.shareAllCategories {
switch $0 {
case let .success(url):
let shareController = ActivityViewController.share(for: url, message: L("share_bookmarks_email_body"))
{ [weak self] _, _, _, _ in
self?.viewModel?.finishShareCategory()
}
shareController?.present(inParentViewController: self, anchorView: nil)
case let .error(title, text):
MWMAlertViewController.activeAlert().presentInfoAlert(title, text: text)
}
}
}
private func openCategorySettings(category: BookmarkGroup) {
let settingsController = CategorySettingsViewController(bookmarkGroup: BookmarksManager.shared().category(withId: category.categoryId))
settingsController.delegate = self
@ -255,6 +269,7 @@ extension BMCViewController: UITableViewDelegate {
case .actions:
switch viewModel.action(at: indexPath.row) {
case .create: createNewCategory()
case .exportAll: shareAllCategories()
}
default:
assertionFailure()

View file

@ -40,7 +40,7 @@ final class BMCDefaultViewModel: NSObject {
}
private func setActions() {
actions = [.create]
actions = [.create, .exportAll]
}
private func setNotifications() {
@ -143,6 +143,11 @@ extension BMCDefaultViewModel {
manager.shareCategory(category.categoryId)
}
func shareAllCategories(handler: @escaping OnPreparedToShareHandler) {
onPreparedToShareCategory = handler
manager.shareAllCategories()
}
func finishShareCategory() {
manager.finishShareCategory()
onPreparedToShareCategory = nil