Welcome to mirror list, hosted at ThFree Co, Russian Federation.

viewport_search_callback.cpp « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 988a68116f8baee1b658cc1c84535a47ae96d10f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "search/viewport_search_callback.hpp"

#include "search/result.hpp"

#include "base/assert.hpp"

namespace search
{
ViewportSearchCallback::ViewportSearchCallback(Delegate & delegate, TOnResults onResults)
  : m_delegate(delegate)
  , m_onResults(move(onResults))
  , m_hotelsModeSet(false)
  , m_firstCall(true)
  , m_lastResultsSize(0)
{
}

void ViewportSearchCallback::operator()(Results const & results)
{
  ASSERT_LESS_OR_EQUAL(m_lastResultsSize, results.GetCount(), ());
  m_hotelsClassif.Add(results.begin() + m_lastResultsSize, results.end());
  m_lastResultsSize = results.GetCount();

  if (!m_hotelsModeSet && m_hotelsClassif.IsHotelResults())
  {
    m_delegate.SetHotelDisplacementMode();
    m_hotelsModeSet = true;
  }

  if (!results.IsEndMarker())
  {
    auto & delegate = m_delegate;
    bool const firstCall = m_firstCall;

    m_delegate.RunUITask([&delegate, firstCall, results]() {
      if (!delegate.IsViewportSearchActive())
        return;

      if (firstCall)
        delegate.ClearViewportSearchResults();

      delegate.ShowViewportSearchResults(results);
    });
  }

  if (m_onResults)
    m_onResults(results);

  m_firstCall = false;
}
}  // namespace search