<commit_before>#import "Common.h"
#import "LocalNotificationManager.h"
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMStorage.h"
#import "Statistics.h"
#import "TimeUtils.h"

#import "3party/Alohalytics/src/alohalytics_objc.h"

#include "Framework.h"

#include "platform/platform.hpp"
#include "storage/country_info_getter.hpp"
#include "storage/storage_defines.hpp"
#include "storage/storage_helpers.hpp"

namespace
{
NSString * const kDownloadMapActionKey = @"DownloadMapActionKey";
NSString * const kDownloadMapActionName = @"DownloadMapActionName";
NSString * const kDownloadMapCountryId = @"DownloadMapCountryId";

NSString * const kFlagsKey = @"DownloadMapNotificationFlags";

NSTimeInterval constexpr kRepeatedNotificationIntervalInSeconds = 3 * 30 * 24 * 60 * 60; // three months
} // namespace

using namespace storage;

@interface LocalNotificationManager () <CLLocationManagerDelegate, UIAlertViewDelegate>

@property (nonatomic) CLLocationManager * locationManager;
@property (copy, nonatomic) CompletionHandler downloadMapCompletionHandler;
@property (weak, nonatomic) NSTimer * timer;

@end

@implementation LocalNotificationManager

+ (instancetype)sharedManager
{
  static LocalNotificationManager * manager = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^
  {
    manager = [[self alloc] init];
  });
  return manager;
}

- (void)dealloc
{
  _locationManager.delegate = nil;
}

- (void)processNotification:(UILocalNotification *)notification onLaunch:(BOOL)onLaunch
{
  NSDictionary * userInfo = [notification userInfo];
  if ([userInfo[kDownloadMapActionKey] isEqualToString:kDownloadMapActionName])
  {
    [[Statistics instance] logEvent:@"'Download Map' Notification Clicked"];
    MapViewController * mapViewController = [MapsAppDelegate theApp].mapViewController;
    [mapViewController.navigationController popToRootViewControllerAnimated:NO];

    NSString * notificationCountryId = userInfo[kDownloadMapCountryId];
    TCountryId const countryId = notificationCountryId.UTF8String;
    [MWMStorage downloadNode:countryId alertController:mapViewController.alertController onSuccess:^
    {
      auto & f = GetFramework();
      double const defaultZoom = 10;
      f.ShowRect(f.GetCountryBounds(countryId), defaultZoom);
    }];
  }
}

#pragma mark - Location Notifications

- (void)showDownloadMapNotificationIfNeeded:(CompletionHandler)completionHandler
{
  NSTimeInterval const completionTimeIndent = 2.0;
  NSTimeInterval const backgroundTimeRemaining =
      UIApplication.sharedApplication.backgroundTimeRemaining - completionTimeIndent;
  if ([CLLocationManager locationServicesEnabled] && backgroundTimeRemaining > 0.0)
  {
    self.downloadMapCompletionHandler = completionHandler;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:backgroundTimeRemaining
                                                  target:self
                                                selector:@selector(timerSelector:)
                                                userInfo:nil
                                                 repeats:NO];
    [self.locationManager startUpdatingLocation];
  }
  else
  {<commit_msg>[new downloader] iOS build fix after changes connected with ShowNode.<commit_after>#import "Common.h"
#import "LocalNotificationManager.h"
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMStorage.h"
#import "Statistics.h"
#import "TimeUtils.h"

#import "3party/Alohalytics/src/alohalytics_objc.h"

#include "Framework.h"

#include "platform/platform.hpp"
#include "storage/country_info_getter.hpp"
#include "storage/storage_defines.hpp"
#include "storage/storage_helpers.hpp"

namespace
{
NSString * const kDownloadMapActionKey = @"DownloadMapActionKey";
NSString * const kDownloadMapActionName = @"DownloadMapActionName";
NSString * const kDownloadMapCountryId = @"DownloadMapCountryId";

NSString * const kFlagsKey = @"DownloadMapNotificationFlags";

NSTimeInterval constexpr kRepeatedNotificationIntervalInSeconds = 3 * 30 * 24 * 60 * 60; // three months
} // namespace

using namespace storage;

@interface LocalNotificationManager () <CLLocationManagerDelegate, UIAlertViewDelegate>

@property (nonatomic) CLLocationManager * locationManager;
@property (copy, nonatomic) CompletionHandler downloadMapCompletionHandler;
@property (weak, nonatomic) NSTimer * timer;

@end

@implementation LocalNotificationManager

+ (instancetype)sharedManager
{
  static LocalNotificationManager * manager = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^
  {
    manager = [[self alloc] init];
  });
  return manager;
}

- (void)dealloc
{
  _locationManager.delegate = nil;
}

- (void)processNotification:(UILocalNotification *)notification onLaunch:(BOOL)onLaunch
{
  NSDictionary * userInfo = [notification userInfo];
  if ([userInfo[kDownloadMapActionKey] isEqualToString:kDownloadMapActionName])
  {
    [[Statistics instance] logEvent:@"'Download Map' Notification Clicked"];
    MapViewController * mapViewController = [MapsAppDelegate theApp].mapViewController;
    [mapViewController.navigationController popToRootViewControllerAnimated:NO];

    NSString * notificationCountryId = userInfo[kDownloadMapCountryId];
    TCountryId const countryId = notificationCountryId.UTF8String;
    [MWMStorage downloadNode:countryId alertController:mapViewController.alertController onSuccess:^
    {
      auto & f = GetFramework();
      double const defaultZoom = 10;
      f.ShowRect(CalcLimitRect(countryId, f.Storage(), f.CountryInfoGetter()));
    }];
  }
}

#pragma mark - Location Notifications

- (void)showDownloadMapNotificationIfNeeded:(CompletionHandler)completionHandler
{
  NSTimeInterval const completionTimeIndent = 2.0;
  NSTimeInterval const backgroundTimeRemaining =
      UIApplication.sharedApplication.backgroundTimeRemaining - completionTimeIndent;
  if ([CLLocationManager locationServicesEnabled] && backgroundTimeRemaining > 0.0)
  {
    self.downloadMapCompletionHandler = completionHandler;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:backgroundTimeRemaining
                                                  target:self
                                                selector:@selector(timerSelector:)
                                                userInfo:nil
                                                 repeats:NO];
    [self.locationManager startUpdatingLocation];
  }
  else
  {
{'fraction_non_alphanumeric': 0.09019668100799016, 'fraction_numerical': 0.005224339274738783, 'mean_word_length': 4.392709196354598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 47, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5758027', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1701, 'n_words': 352}