[ios] Conversion kml after async load

This commit is contained in:
VladiMihaylenko 2018-04-12 16:19:32 +03:00 committed by Roman Kuznetsov
parent b469e43088
commit c59c2ab7e9
3 changed files with 12 additions and 20 deletions

View file

@ -42,15 +42,7 @@ final class BMCViewController: MWMViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let count = viewModel.filesCountForConversion
if count > 0 {
MWMAlertViewController.activeAlert().presentConvertBookmarksAlert(withCount: count)
{ [weak viewModel] in
MWMAlertViewController.activeAlert().presentSpinnerAlert(withTitle: L("converting"),
cancel: nil)
viewModel?.convertAllKML()
}
}
viewModel.convertAllKMLIfNeeded()
}
private func updateCategoryName(category: BMCCategory?) {
@ -77,7 +69,6 @@ final class BMCViewController: MWMViewController {
private func shareCategory(category: BMCCategory, anchor: UIView) {
let shareOnSuccess = { [viewModel] (url: URL) in
typealias AVC = MWMActivityViewController
let fileName = (url.lastPathComponent as NSString).deletingPathExtension
let message = L("share_bookmarks_email_body")
let shareController = AVC.share(for: url, message: message) { [viewModel] _, _, _, _ in
viewModel?.finishShareCategory()

View file

@ -23,12 +23,6 @@ final class BMCDefaultViewModel: NSObject {
var minCategoryNameLength: UInt = Const.minCategoryNameLength
var maxCategoryNameLength: UInt = Const.maxCategoryNameLength
var filesCountForConversion: UInt {
get {
return BM.filesCountForConversion()
}
}
override init() {
super.init()
BM.add(self)
@ -203,14 +197,22 @@ extension BMCDefaultViewModel: BMCViewModel {
pendingPermission(isPending: false)
}
func convertAllKML() {
BM.convertAll()
func convertAllKMLIfNeeded() {
let count = BM.filesCountForConversion()
if count > 0 {
MWMAlertViewController.activeAlert().presentConvertBookmarksAlert(withCount: count) {
MWMAlertViewController.activeAlert().presentSpinnerAlert(withTitle: L("converting"),
cancel: nil)
BM.convertAll()
}
}
}
}
extension BMCDefaultViewModel: MWMBookmarksObserver {
func onBookmarksLoadFinished() {
loadData()
convertAllKMLIfNeeded()
}
func onBookmarkDeleted(_: MWMMarkID) {

View file

@ -41,6 +41,5 @@ protocol BMCViewModel: AnyObject {
func pendingPermission(isPending: Bool)
func grant(permission: BMCPermission?)
var filesCountForConversion: UInt { get }
func convertAllKML();
func convertAllKMLIfNeeded();
}