From ee77f38ccd88eebcab81236c6121fc03798e313e Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Thu, 23 Jan 2020 20:35:18 +0300 Subject: [PATCH] [tips] review fixes --- .../maplayer/MapLayerCompositeController.java | 26 +++++++++---------- map/tips_api.cpp | 26 +++++++------------ map/tips_api_delegate.cpp | 2 +- map/tips_api_delegate.hpp | 2 +- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java b/android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java index a7b00e21ed..c60e1ed991 100644 --- a/android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java +++ b/android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java @@ -2,6 +2,7 @@ package com.mapswithme.maps.maplayer; import android.app.Activity; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import android.view.View; @@ -56,7 +57,7 @@ public class MapLayerCompositeController implements MapLayerController isoLinesView.setOnClickListener(dialogClickListener); ControllerAndMode subwayEntry = new ControllerAndMode(Mode.SUBWAY, Tutorial.SUBWAY, subwayMapLayerController); - ControllerAndMode trafficEntry = new ControllerAndMode(Mode.TRAFFIC, Tutorial.STUB, + ControllerAndMode trafficEntry = new ControllerAndMode(Mode.TRAFFIC, null, trafficButtonController); ControllerAndMode isoLineEntry = new ControllerAndMode(Mode.ISOLINES, Tutorial.ISOLINES, isoLinesController); @@ -66,17 +67,14 @@ public class MapLayerCompositeController implements MapLayerController // entries.add(isoLineEntry); entries.add(trafficEntry); - if (tutorial != Tutorial.STUB) + Collections.sort(entries, (lhs, rhs) -> { - Collections.sort(entries, (lhs, rhs) -> - { - if (lhs.getTutorial().equals(tutorial)) - return 1; - if (rhs.getTutorial().equals(tutorial)) - return -1; - return 0; - }); - } + if (lhs.getTutorial() == tutorial) + return -1; + if (rhs.getTutorial() == tutorial) + return 1; + return 0; + }); return Collections.unmodifiableList(entries); } @@ -252,12 +250,12 @@ public class MapLayerCompositeController implements MapLayerController { @NonNull private final Mode mMode; - @NonNull + @Nullable private final Tutorial mTutorial; @NonNull private final MapLayerController mController; - ControllerAndMode(@NonNull Mode mode, @NonNull Tutorial tutorial, + ControllerAndMode(@NonNull Mode mode, @Nullable Tutorial tutorial, @NonNull MapLayerController controller) { mMode = mode; @@ -292,7 +290,7 @@ public class MapLayerCompositeController implements MapLayerController return mMode; } - @NonNull + @Nullable Tutorial getTutorial() { return mTutorial; diff --git a/map/tips_api.cpp b/map/tips_api.cpp index 04b899223d..92cf28c94f 100644 --- a/map/tips_api.cpp +++ b/map/tips_api.cpp @@ -8,6 +8,7 @@ #include "base/timer.hpp" #include +#include #include using namespace eye; @@ -27,7 +28,7 @@ size_t constexpr kActionClicksCountToDisable = 1; // If a user clicks 3 times on the button GOT IT the appropriate screen will never be shown again. size_t constexpr kGotitClicksCountToDisable = 3; -auto constexpr kIsolinesExceptedMwms = +std::unordered_set const kIsolinesExceptedMwms = { "Argentina_Buenos Aires_Buenos Aires", "Australia_Melbourne", @@ -110,7 +111,7 @@ std::optional GetTipImpl(TipsApi::Duration showAnyTipPeriod, } // Iterates reversed because we need to show newest tip first. - for (auto c = candidates.crbegin(); c != candidates.rend(); ++c) + for (auto c = candidates.crbegin(); c != candidates.crend(); ++c) { if (c->second && conditions[ToIndex(c->first)](*info)) return c->first; @@ -199,12 +200,10 @@ TipsApi::TipsApi(std::unique_ptr delegate) { for (auto const & layer : info.m_layers) { - if (layer.m_type == Layer::Type::PublicTransport) + if (layer.m_type == Layer::Type::PublicTransport && + layer.m_lastTimeUsed.time_since_epoch().count() != 0) { - if (layer.m_lastTimeUsed.time_since_epoch().count() != 0) - { - return false; - } + return false; } } @@ -219,23 +218,18 @@ TipsApi::TipsApi(std::unique_ptr delegate) { for (auto const & layer : info.m_layers) { - if (layer.m_type == Layer::Type::Isolines) + if (layer.m_type == Layer::Type::Isolines && + layer.m_lastTimeUsed.time_since_epoch().count() != 0) { - if (layer.m_lastTimeUsed.time_since_epoch().count() != 0) - { - return false; - } + return false; } } auto const pos = m_delegate->GetViewportCenter(); auto const countryId = m_delegate->GetCountryId(pos); - for (auto const & exceptedMwmId : kIsolinesExceptedMwms) - { - if (exceptedMwmId == countryId) + if (kIsolinesExceptedMwms.find(countryId) != kIsolinesExceptedMwms.end()) return false; - } return m_delegate->GetCountryVersion(countryId) > 191124; }, diff --git a/map/tips_api_delegate.cpp b/map/tips_api_delegate.cpp index aa2d5c6fb3..d0236c6285 100644 --- a/map/tips_api_delegate.cpp +++ b/map/tips_api_delegate.cpp @@ -1,6 +1,6 @@ #include "map/tips_api_delegate.hpp" -TipsApiDelegate::TipsApiDelegate(Framework & framework) +TipsApiDelegate::TipsApiDelegate(Framework const & framework) : m_framework(framework) { } diff --git a/map/tips_api_delegate.hpp b/map/tips_api_delegate.hpp index 1a7a21163d..a66b77ea93 100644 --- a/map/tips_api_delegate.hpp +++ b/map/tips_api_delegate.hpp @@ -7,7 +7,7 @@ class TipsApiDelegate : public TipsApi::Delegate { public: - TipsApiDelegate(Framework & framework); + explicit TipsApiDelegate(Framework const & framework); boost::optional GetCurrentPosition() const override; bool IsCountryLoaded(m2::PointD const & pt) const override;