<commit_before>#import "SearchVC.h"
#import "CompassView.h"
#import "LocationManager.h"
#import "SearchBannerChecker.h"
#import "SearchCell.h"

#include "../../geometry/angles.hpp"
#include "../../geometry/distance_on_sphere.hpp"
#include "../../platform/settings.hpp"
#include "../../platform/platform.hpp"
#include "../../indexer/mercator.hpp"
#include "../../map/framework.hpp"
#include "../../map/measurement_utils.hpp"
#include "../../search/result.hpp"


/// When to display compass instead of country flags
#define MIN_COMPASS_DISTANCE 25000.0

SearchVC * g_searchVC = nil;
volatile int g_queryId = 0;

@interface ResultsWrapper : NSObject
{
  vector<search::Result> m_results;
  NSString * m_searchString;
  int m_queryId;
}
// Stores search string which corresponds to these results.
@property(nonatomic,retain) NSString * m_searchString;
// Used to double-checking and discarding old results in GUI thread
@property(nonatomic,assign) int m_queryId;
- (id)initWithResults:(search::Results const &) res andQueryId:(int)qId;
- (vector<search::Result> const &)get;
@end

@implementation ResultsWrapper

@synthesize m_searchString;
@synthesize m_queryId;

- (id)initWithResults:(search::Results const &)res andQueryId:(int)qId
{
  if ((self = [super init]))
  {
    m_results.assign(res.Begin(), res.End());
    m_queryId = qId;
  }
  return self;
}

- (vector<search::Result> const &)get
{
  return m_results;
}
@end

// Last search results are stored betweel SearchVC sessions
// to appear instantly for the user, they also store last search text query
ResultsWrapper * g_lastSearchResults = nil;

static void OnSearchResultCallback(search::Results const & res, int queryId)
{
  int currQueryId = g_queryId;
  if (g_searchVC && queryId == currQueryId)
  {
    ResultsWrapper * w = [[ResultsWrapper alloc] initWithResults:res andQueryId:currQueryId];
    [g_searchVC performSelectorOnMainThread:@selector(addResult:)
                                 withObject:w
                              waitUntilDone:NO];
    [w release];
  }
}

/////////////////////////////////////////////////////////////////////

@interface CustomView : UIView
@end
@implementation CustomView
- (void)layoutSubviews
{
  UINavigationBar * navBar = (UINavigationBar *)[self.subviews objectAtIndex:0];
  [navBar sizeToFit];
  [navBar.topItem.titleView sizeToFit];

  UIView * table = [self.subviews objectAtIndex:1];
  CGRect rTable;
  rTable.origin = CGPointMake(navBar.frame.origin.x, navBar.frame.origin.y + navBar.frame.size.height);
  rTable.size = self.bounds.size;
  rTable.size.height -= navBar.bounds.size.height;
  table.frame = rTable;
}
@end

////////////////////////////////////////////////////////////////////

@implementation SearchVC


+ (BOOL)isLocationValid:(CLLocation *)l
{
  if (l == nil) return false;
  
  // do not use too old locations
  static NSTimeInterval const SECONDS_TO_EXPIRE = 300.0;
  
  // timeIntervalSinceNow returns negative value - because of "since now"
  return [l.timestamp timeIntervalSinceNow] > (-SECONDS_TO_EXPIRE);
}

- (id)initWithFramework:(Framework *)framework andLocationManager:(LocationManager *)lm
{<commit_msg>[ios] Fixed black background for Done button in search view<commit_after>#import "SearchVC.h"
#import "CompassView.h"
#import "LocationManager.h"
#import "SearchBannerChecker.h"
#import "SearchCell.h"

#include "../../geometry/angles.hpp"
#include "../../geometry/distance_on_sphere.hpp"
#include "../../platform/settings.hpp"
#include "../../platform/platform.hpp"
#include "../../indexer/mercator.hpp"
#include "../../map/framework.hpp"
#include "../../map/measurement_utils.hpp"
#include "../../search/result.hpp"


/// When to display compass instead of country flags
#define MIN_COMPASS_DISTANCE 25000.0

SearchVC * g_searchVC = nil;
volatile int g_queryId = 0;

@interface ResultsWrapper : NSObject
{
  vector<search::Result> m_results;
  NSString * m_searchString;
  int m_queryId;
}
// Stores search string which corresponds to these results.
@property(nonatomic,retain) NSString * m_searchString;
// Used to double-checking and discarding old results in GUI thread
@property(nonatomic,assign) int m_queryId;
- (id)initWithResults:(search::Results const &) res andQueryId:(int)qId;
- (vector<search::Result> const &)get;
@end

@implementation ResultsWrapper

@synthesize m_searchString;
@synthesize m_queryId;

- (id)initWithResults:(search::Results const &)res andQueryId:(int)qId
{
  if ((self = [super init]))
  {
    m_results.assign(res.Begin(), res.End());
    m_queryId = qId;
  }
  return self;
}

- (vector<search::Result> const &)get
{
  return m_results;
}
@end

// Last search results are stored betweel SearchVC sessions
// to appear instantly for the user, they also store last search text query
ResultsWrapper * g_lastSearchResults = nil;

static void OnSearchResultCallback(search::Results const & res, int queryId)
{
  int currQueryId = g_queryId;
  if (g_searchVC && queryId == currQueryId)
  {
    ResultsWrapper * w = [[ResultsWrapper alloc] initWithResults:res andQueryId:currQueryId];
    [g_searchVC performSelectorOnMainThread:@selector(addResult:)
                                 withObject:w
                              waitUntilDone:NO];
    [w release];
  }
}

/////////////////////////////////////////////////////////////////////

@interface CustomView : UIView
@end
@implementation CustomView
- (void)layoutSubviews
{
  UINavigationBar * navBar = (UINavigationBar *)[self.subviews objectAtIndex:0];
  [navBar sizeToFit];
  [navBar setNeedsDisplay];

  UIView * table = [self.subviews objectAtIndex:1];
  CGRect rTable;
  rTable.origin = CGPointMake(navBar.frame.origin.x, navBar.frame.origin.y + navBar.frame.size.height);
  rTable.size = self.bounds.size;
  rTable.size.height -= navBar.bounds.size.height;
  table.frame = rTable;
}
@end

////////////////////////////////////////////////////////////////////

@implementation SearchVC


+ (BOOL)isLocationValid:(CLLocation *)l
{
  if (l == nil) return false;
  
  // do not use too old locations
  static NSTimeInterval const SECONDS_TO_EXPIRE = 300.0;
  
  // timeIntervalSinceNow returns negative value - because of "since now"
  return [l.timestamp timeIntervalSinceNow] > (-SECONDS_TO_EXPIRE);
}

- (id)initWithFramework:(Framework *)framework andLocationManager:(LocationManager *)lm
{
{'fraction_non_alphanumeric': 0.16592920353982302, 'fraction_numerical': 0.0041087231352718075, 'mean_word_length': 3.4073816155988856, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5426336', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1935, 'n_words': 469}