forked from organicmaps/organicmaps
[ios][ugc] checking ugc save result + ugc toasts
This commit is contained in:
parent
5908287adc
commit
0e0cab56c7
4 changed files with 78 additions and 43 deletions
|
@ -197,7 +197,8 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d
|
|||
|
||||
// UGC
|
||||
- (ftraits::UGCRatingCategories)ugcRatingCategories;
|
||||
- (void)setUGCUpdateFrom:(MWMUGCReviewModel *)reviewModel;
|
||||
- (void)setUGCUpdateFrom:(MWMUGCReviewModel *)reviewModel
|
||||
resultHandler:(void (^)(BOOL))resultHandler;
|
||||
|
||||
// Route points
|
||||
- (RouteMarkType)routeMarkType;
|
||||
|
|
|
@ -641,7 +641,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
|
||||
- (ftraits::UGCRatingCategories)ugcRatingCategories { return m_info.GetRatingCategories(); }
|
||||
|
||||
- (void)setUGCUpdateFrom:(MWMUGCReviewModel *)reviewModel
|
||||
- (void)setUGCUpdateFrom:(MWMUGCReviewModel *)reviewModel resultHandler:(void (^)(BOOL))resultHandler
|
||||
{
|
||||
using namespace ugc;
|
||||
auto appInfo = AppInfo.sharedInfo;
|
||||
|
@ -658,9 +658,16 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
r.emplace_back(star.title.UTF8String, star.value);
|
||||
|
||||
UGCUpdate update{r, t, std::chrono::system_clock::now()};
|
||||
auto & f = GetFramework();
|
||||
f.GetUGCApi()->SetUGCUpdate(m_info.GetID(), update);
|
||||
f.UpdatePlacePageInfoForCurrentSelection();
|
||||
|
||||
GetFramework().GetUGCApi()->SetUGCUpdate(m_info.GetID(), update,
|
||||
[resultHandler](Storage::SettingResult const result)
|
||||
{
|
||||
if (result != Storage::SettingResult::Success)
|
||||
return resultHandler(NO);
|
||||
|
||||
resultHandler(YES);
|
||||
GetFramework().UpdatePlacePageInfoForCurrentSelection();
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Bookmark
|
||||
|
|
|
@ -81,7 +81,7 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type, place_page:
|
|||
|
||||
@interface MWMPlacePageManager ()<MWMFrameworkStorageObserver, MWMPlacePageLayoutDelegate,
|
||||
MWMPlacePageLayoutDataSource, MWMLocationObserver,
|
||||
MWMBookmarksObserver>
|
||||
MWMBookmarksObserver, MWMUGCAddReviewControllerDelegate>
|
||||
|
||||
@property(nonatomic) MWMPlacePageLayout * layout;
|
||||
@property(nonatomic) MWMPlacePageData * data;
|
||||
|
@ -602,19 +602,7 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type, place_page:
|
|||
}];
|
||||
auto ugcReviewModel =
|
||||
[[MWMUGCReviewModel alloc] initWithReviewValue:value ratings:ratings title:title text:@""];
|
||||
auto ugcVC = [MWMUGCAddReviewController instanceWithModel:ugcReviewModel
|
||||
onSave:^(MWMUGCReviewModel * model) {
|
||||
auto data = self.data;
|
||||
if (!data)
|
||||
{
|
||||
NSAssert(false, @"");
|
||||
return;
|
||||
}
|
||||
RegisterEventIfPossible(
|
||||
eye::MapObject::Event::Type::UgcSaved,
|
||||
data.getRawData);
|
||||
[data setUGCUpdateFrom:model];
|
||||
}];
|
||||
auto ugcVC = [MWMUGCAddReviewController instanceWithModel:ugcReviewModel delegate: self];
|
||||
[[MapViewController sharedController].navigationController pushViewController:ugcVC animated:YES];
|
||||
}
|
||||
|
||||
|
@ -698,4 +686,27 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type, place_page:
|
|||
|
||||
- (MapViewController *)ownerViewController { return [MapViewController sharedController]; }
|
||||
|
||||
- (void)saveUgcWithModel:(MWMUGCReviewModel *)model resultHandler:(void (^)(BOOL))resultHandler
|
||||
{
|
||||
auto data = self.data;
|
||||
if (!data)
|
||||
{
|
||||
NSAssert(false, @"");
|
||||
resultHandler(NO);
|
||||
return;
|
||||
}
|
||||
|
||||
__weak auto weakData = data;
|
||||
[data setUGCUpdateFrom:model resultHandler:^(BOOL result)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
auto data = weakData;
|
||||
if (data)
|
||||
RegisterEventIfPossible(eye::MapObject::Event::Type::UgcSaved, data.getRawData);
|
||||
}
|
||||
resultHandler(result);
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
@objc(MWMUGCAddReviewControllerDelegate)
|
||||
protocol UGCAddReviewControllerDelegate {
|
||||
typealias onSaveHandler = (Bool) -> Void
|
||||
func saveUgc(model: UGCAddReviewController.Model, resultHandler: @escaping onSaveHandler)
|
||||
}
|
||||
|
||||
@objc(MWMUGCAddReviewController)
|
||||
final class UGCAddReviewController: MWMTableViewController {
|
||||
typealias Model = UGCReviewModel
|
||||
|
@ -10,10 +16,10 @@ final class UGCAddReviewController: MWMTableViewController {
|
|||
case text
|
||||
}
|
||||
|
||||
@objc static func instance(model: Model, onSave: @escaping (Model) -> Void) -> UGCAddReviewController {
|
||||
@objc static func instance(model: Model, delegate: UGCAddReviewControllerDelegate) -> UGCAddReviewController {
|
||||
let vc = UGCAddReviewController(nibName: toString(self), bundle: nil)
|
||||
vc.model = model
|
||||
vc.onSave = onSave
|
||||
vc.delegate = delegate
|
||||
return vc
|
||||
}
|
||||
|
||||
|
@ -26,8 +32,8 @@ final class UGCAddReviewController: MWMTableViewController {
|
|||
}
|
||||
}
|
||||
|
||||
private var onSave: ((Model) -> Void)!
|
||||
private var sections: [Sections] = []
|
||||
private var delegate: UGCAddReviewControllerDelegate?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
@ -60,31 +66,41 @@ final class UGCAddReviewController: MWMTableViewController {
|
|||
assertionFailure()
|
||||
return
|
||||
}
|
||||
Statistics.logEvent(kStatUGCReviewSuccess)
|
||||
|
||||
reviewPosted = true
|
||||
model.text = text
|
||||
onSave(model)
|
||||
guard let nc = navigationController else { return }
|
||||
let onSuccess = { Toast.toast(withText: L("ugc_thanks_message_auth")).show() }
|
||||
let onError = { Toast.toast(withText: L("ugc_thanks_message_not_auth")).show() }
|
||||
let onComplete = { () -> Void in nc.popToRootViewController(animated: true) }
|
||||
|
||||
if MWMAuthorizationViewModel.isAuthenticated() || MWMPlatform.networkConnectionType() == .none {
|
||||
if MWMAuthorizationViewModel.isAuthenticated() {
|
||||
onSuccess()
|
||||
} else {
|
||||
onError()
|
||||
delegate!.saveUgc(model: model, resultHandler: { (saveResult) in
|
||||
guard let nc = self.navigationController else { return }
|
||||
|
||||
if !saveResult {
|
||||
nc.popViewController(animated: true)
|
||||
return
|
||||
}
|
||||
nc.popViewController(animated: true)
|
||||
} else {
|
||||
Statistics.logEvent(kStatUGCReviewAuthShown, withParameters: [kStatFrom: kStatAfterSave])
|
||||
let authVC = AuthorizationViewController(barButtonItem: navigationItem.rightBarButtonItem!,
|
||||
sourceComponent: .UGC,
|
||||
successHandler: {_ in onSuccess()},
|
||||
errorHandler: {_ in onError()},
|
||||
completionHandler: {_ in onComplete()})
|
||||
present(authVC, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
Statistics.logEvent(kStatUGCReviewSuccess)
|
||||
|
||||
let onSuccess = { Toast.toast(withText: L("ugc_thanks_message_auth")).show() }
|
||||
let onError = { Toast.toast(withText: L("ugc_thanks_message_not_auth")).show() }
|
||||
let onComplete = { () -> Void in nc.popToRootViewController(animated: true) }
|
||||
|
||||
if MWMAuthorizationViewModel.isAuthenticated() || MWMPlatform.networkConnectionType() == .none {
|
||||
if MWMAuthorizationViewModel.isAuthenticated() {
|
||||
onSuccess()
|
||||
} else {
|
||||
onError()
|
||||
}
|
||||
nc.popViewController(animated: true)
|
||||
} else {
|
||||
Statistics.logEvent(kStatUGCReviewAuthShown, withParameters: [kStatFrom: kStatAfterSave])
|
||||
let authVC = AuthorizationViewController(barButtonItem: self.navigationItem.rightBarButtonItem!,
|
||||
sourceComponent: .UGC,
|
||||
successHandler: {_ in onSuccess()},
|
||||
errorHandler: {_ in onError()},
|
||||
completionHandler: {_ in onComplete()})
|
||||
self.present(authVC, animated: true, completion: nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override func numberOfSections(in _: UITableView) -> Int {
|
||||
|
|
Loading…
Add table
Reference in a new issue