<commit_before>#import "Common.h"
#import "DownloaderParentVC.h"
#import "DiskFreeSpace.h"
#import "MWMAlertViewController.h"
#import "UIColor+MapsMeColor.h"

#include "platform/platform.hpp"

@implementation DownloaderParentVC

- (void)viewDidLoad
{
  [super viewDidLoad];
  [self.view addSubview:self.tableView];
  self.tableView.backgroundColor = [UIColor pressBackground];
  self.tableView.separatorColor = [UIColor blackDividers];
}

- (UITableView *)tableView
{
  if (!_tableView) {
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  }
  return _tableView;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  if (buttonIndex != alertView.cancelButtonIndex)
  {
    if (self.selectedInActionSheetOptions == MapOptions::Map)
      [self performAction:DownloaderActionDownloadMap withSizeCheck:NO];
    else if (self.selectedInActionSheetOptions == MapOptions::CarRouting)
      [self performAction:DownloaderActionDownloadCarRouting withSizeCheck:NO];
    else if (self.selectedInActionSheetOptions == MapOptions::MapWithCarRouting)
      [self performAction:DownloaderActionDownloadAll withSizeCheck:NO];
  }
}

- (void)download
{
  if (self.selectedInActionSheetOptions == MapOptions::Map)
    [self performAction:DownloaderActionDownloadMap withSizeCheck:NO];
  else if (self.selectedInActionSheetOptions == MapOptions::CarRouting)
    [self performAction:DownloaderActionDownloadCarRouting withSizeCheck:NO];
  else if (self.selectedInActionSheetOptions == MapOptions::MapWithCarRouting)
    [self performAction:DownloaderActionDownloadAll withSizeCheck:NO];
}

#pragma mark - Virtual methods

- (void)performAction:(DownloaderAction)action withSizeCheck:(BOOL)check {}
- (NSString *)parentTitle { return nil; }
- (NSString *)selectedMapName { return nil; }
- (uint64_t)selectedMapSizeWithOptions:(MapOptions)options { return 0; }
- (TStatus)selectedMapStatus { return TStatus::EUnknown; }
- (MapOptions)selectedMapOptions { return MapOptions::Map; }

#pragma mark - Virtual table view methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return nil; }

#pragma mark - Public methods for successors

- (BOOL)canDownloadSelectedMap
{
  uint64_t const size = [self selectedMapSizeWithOptions:self.selectedInActionSheetOptions];
  NSString * name = [self selectedMapName];

  Platform::EConnectionType const connection = Platform::ConnectionStatus();
  MWMAlertViewController * alert = [[MWMAlertViewController alloc] initWithViewController:self];
  if (connection != Platform::EConnectionType::CONNECTION_NONE)
  {
    if (connection == Platform::EConnectionType::CONNECTION_WWAN && size > 50 * MB)
      [alert presentnoWiFiAlertWithName:name downloadBlock:^{[self download];}];
    else
      return YES;
  }
  else
  {
    [alert presentNoConnectionAlert];
  }
  return NO;
}

- (UIActionSheet *)actionSheetToPerformActionOnSelectedMap
{
  TStatus const status = [self selectedMapStatus];
  MapOptions const options = [self selectedMapOptions];
  [self.actionSheetActions removeAllObjects];
  UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:self.actionSheetTitle delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
    [self addButtonWithTitle:L(@"zoom_to_country") action:DownloaderActionZoomToCountry toActionSheet:actionSheet];

  if (status == TStatus::ENotDownloaded || status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed)
  {
    NSString * fullSize = formattedSize([self selectedMapSizeWithOptions:MapOptions::MapWithCarRouting]);
    NSString * onlyMapSize = formattedSize([self selectedMapSizeWithOptions:MapOptions::Map]);
    [self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_download_map"), fullSize] action:DownloaderActionDownloadAll toActionSheet:actionSheet];
    [self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_download_map_no_routing"), onlyMapSize] action:DownloaderActionDownloadMap toActionSheet:actionSheet];
  }

  if (status == TStatus::EOnDiskOutOfDate && options == MapOptions::MapWithCarRouting)
  {
    NSString * size = formattedSize([self selectedMapSizeWithOptions:MapOptions::MapWithCarRouting]);
    [self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_update_map_and_routing"), size] action:DownloaderActionDownloadAll toActionSheet:actionSheet];
  }

  if (status == TStatus::EOnDisk && options == MapOptions::Map)
  {
    NSString * size = formattedSize([self selectedMapSizeWithOptions:MapOptions::CarRouting]);
    NSString * title = [NSString stringWithFormat:@"%@, %@", L(@"downloader_download_routing"), size];
    [self addButtonWithTitle:title action:DownloaderActionDownloadCarRouting toActionSheet:actionSheet];
  }

  if (status == TStatus::EOnDiskOutOfDate && options == MapOptions::Map)
  {
    NSString * size = formattedSize([self selectedMapSizeWithOptions:MapOptions::Map]);
    NSString * title = [NSString stringWithFormat:@"%@, %@", L(@"downloader_update_map"), size];
    [self addButtonWithTitle:title action:DownloaderActionDownloadMap toActionSheet:actionSheet];
    size = formattedSize([self selectedMapSizeWithOptions:MapOptions::MapWithCarRouting]);
    title = [NSString stringWithFormat:@"%@, %@", L(@"downloader_update_map_and_routing"), size];
    [self addButtonWithTitle:title action:DownloaderActionDownloadAll toActionSheet:actionSheet];
  }

  if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
  {
    if (options == MapOptions::MapWithCarRouting)
      [self addButtonWithTitle:L(@"downloader_delete_routing") action:DownloaderActionDeleteCarRouting toActionSheet:actionSheet];

    [self addButtonWithTitle:L(@"downloader_delete_map") action:DownloaderActionDeleteMap toActionSheet:actionSheet];
    actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
  }

  if (status == TStatus::EDownloading || status == TStatus::EInQueue)
  {
    [self addButtonWithTitle:L(@"cancel_download") action:DownloaderActionCancelDownloading toActionSheet:actionSheet];
    actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
  }

  if (!IPAD)
  {
    [actionSheet addButtonWithTitle:L(@"cancel")];
    actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;
  }<commit_msg>[old-map-downloader][ios] Removed routing button from downloader.<commit_after>#import "Common.h"
#import "DownloaderParentVC.h"
#import "DiskFreeSpace.h"
#import "MWMAlertViewController.h"
#import "UIColor+MapsMeColor.h"

#include "platform/platform.hpp"

@implementation DownloaderParentVC

- (void)viewDidLoad
{
  [super viewDidLoad];
  [self.view addSubview:self.tableView];
  self.tableView.backgroundColor = [UIColor pressBackground];
  self.tableView.separatorColor = [UIColor blackDividers];
}

- (UITableView *)tableView
{
  if (!_tableView) {
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  }
  return _tableView;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  if (buttonIndex != alertView.cancelButtonIndex)
  {
    if (self.selectedInActionSheetOptions == MapOptions::Map)
      [self performAction:DownloaderActionDownloadMap withSizeCheck:NO];
    else if (self.selectedInActionSheetOptions == MapOptions::CarRouting)
      [self performAction:DownloaderActionDownloadCarRouting withSizeCheck:NO];
    else if (self.selectedInActionSheetOptions == MapOptions::MapWithCarRouting)
      [self performAction:DownloaderActionDownloadAll withSizeCheck:NO];
  }
}

- (void)download
{
  if (self.selectedInActionSheetOptions == MapOptions::Map)
    [self performAction:DownloaderActionDownloadMap withSizeCheck:NO];
  else if (self.selectedInActionSheetOptions == MapOptions::CarRouting)
    [self performAction:DownloaderActionDownloadCarRouting withSizeCheck:NO];
  else if (self.selectedInActionSheetOptions == MapOptions::MapWithCarRouting)
    [self performAction:DownloaderActionDownloadAll withSizeCheck:NO];
}

#pragma mark - Virtual methods

- (void)performAction:(DownloaderAction)action withSizeCheck:(BOOL)check {}
- (NSString *)parentTitle { return nil; }
- (NSString *)selectedMapName { return nil; }
- (uint64_t)selectedMapSizeWithOptions:(MapOptions)options { return 0; }
- (TStatus)selectedMapStatus { return TStatus::EUnknown; }
- (MapOptions)selectedMapOptions { return MapOptions::Map; }

#pragma mark - Virtual table view methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return nil; }

#pragma mark - Public methods for successors

- (BOOL)canDownloadSelectedMap
{
  uint64_t const size = [self selectedMapSizeWithOptions:self.selectedInActionSheetOptions];
  NSString * name = [self selectedMapName];

  Platform::EConnectionType const connection = Platform::ConnectionStatus();
  MWMAlertViewController * alert = [[MWMAlertViewController alloc] initWithViewController:self];
  if (connection != Platform::EConnectionType::CONNECTION_NONE)
  {
    if (connection == Platform::EConnectionType::CONNECTION_WWAN && size > 50 * MB)
      [alert presentnoWiFiAlertWithName:name downloadBlock:^{[self download];}];
    else
      return YES;
  }
  else
  {
    [alert presentNoConnectionAlert];
  }
  return NO;
}

- (UIActionSheet *)actionSheetToPerformActionOnSelectedMap
{
  [self.actionSheetActions removeAllObjects];
  UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:self.actionSheetTitle delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  NSString * fullSize = formattedSize([self selectedMapSizeWithOptions:MapOptions::MapWithCarRouting]);
  switch ([self selectedMapStatus])
  {
    case TStatus::EOnDisk:
      [self addButtonWithTitle:L(@"zoom_to_country") action:DownloaderActionZoomToCountry toActionSheet:actionSheet];
      [self addButtonWithTitle:L(@"downloader_delete_map") action:DownloaderActionDeleteMap toActionSheet:actionSheet];
      actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
      break;
    case TStatus::EOnDiskOutOfDate:
      [self addButtonWithTitle:L(@"zoom_to_country") action:DownloaderActionZoomToCountry toActionSheet:actionSheet];
      [self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_update_map"), fullSize] action:DownloaderActionDownloadAll toActionSheet:actionSheet];
      [self addButtonWithTitle:L(@"downloader_delete_map") action:DownloaderActionDeleteMap toActionSheet:actionSheet];
      actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
      break;
    case TStatus::ENotDownloaded:
    case TStatus::EDownloadFailed:
    case TStatus::EOutOfMemFailed:
      [self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_download_map"), fullSize] action:DownloaderActionDownloadAll toActionSheet:actionSheet];
      break;
    case TStatus::EDownloading:
    case TStatus::EInQueue:
      [self addButtonWithTitle:L(@"cancel_download") action:DownloaderActionCancelDownloading toActionSheet:actionSheet];
      actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
      break;
    case TStatus::EUnknown:
      NSAssert(NO, @"Invalid status");
      break;
  }

  if (!IPAD)
  {
    [actionSheet addButtonWithTitle:L(@"cancel")];
    actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;
  }
{'fraction_non_alphanumeric': 0.10803324099722991, 'fraction_numerical': 0.0018738797458041389, 'mean_word_length': 6.729848866498741, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 91, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3290086', 'n_tokens_mistral': 3658, 'n_tokens_neox': 3509, 'n_words': 622}