< Summary

Class:PlaceAndEventsCardsReloader
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/EventsSubSection/EventsSubSectionMenu/PlaceAndEventsCardsReloader.cs
Covered lines:26
Uncovered lines:8
Coverable lines:34
Total lines:85
Line coverage:76.4% (26 of 34)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:7
Method coverage:71.4% (5 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlaceAndEventsCardsReloader(...)0%110100%
Initialize()0%2100%
Dispose()0%220100%
OnExploreV2Open(...)0%220100%
CanReload()0%3.073080%
RequestAll()0%220100%
OnAnimationTransitionFinished(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/EventsSubSection/EventsSubSectionMenu/PlaceAndEventsCardsReloader.cs

#LineLine coverage
 1using DCL;
 2using System;
 3using UnityEngine;
 4
 5public class PlaceAndEventsCardsReloader : IDisposable
 6{
 7    private readonly IPlacesAndEventsSubSectionComponentView view;
 8    private readonly IPlacesAndEventsAPIRequester requester;
 9    private readonly DataStore_ExploreV2 exploreV2Menu;
 10
 5111    internal bool firstLoading = true;
 12    internal bool reloadSubSection;
 13    private bool isWaitingAnimTransition;
 14
 15    internal float lastTimeAPIChecked;
 16
 5117    public PlaceAndEventsCardsReloader(IPlacesAndEventsSubSectionComponentView view, IPlacesAndEventsAPIRequester reques
 18    {
 5119        this.view = view;
 5120        this.exploreV2Menu = exploreV2Menu;
 5121        this.requester = requester;
 5122    }
 23
 24    public void Initialize()
 25    {
 026        exploreV2Menu.isOpen.OnChange += OnExploreV2Open;
 027    }
 28
 29    public void Dispose()
 30    {
 5131        exploreV2Menu.isOpen.OnChange -= OnExploreV2Open;
 32
 5133        if (isWaitingAnimTransition)
 134            exploreV2Menu.isInShowAnimationTransiton.OnChange -= OnAnimationTransitionFinished;
 5135    }
 36
 37    internal void OnExploreV2Open(bool current, bool _)
 38    {
 639        if (!current)
 340            reloadSubSection = true;
 641    }
 42
 43    public bool CanReload()
 44    {
 645        if (!firstLoading)
 046            return reloadSubSection && !IsInCooldown();
 47
 648        reloadSubSection = true;
 649        lastTimeAPIChecked = Time.realtimeSinceStartup - PlacesAndEventsSectionComponentController.MIN_TIME_TO_CHECK_API
 50
 651        return true;
 52
 053        bool IsInCooldown() => lastTimeAPIChecked < Time.realtimeSinceStartup - PlacesAndEventsSectionComponentControlle
 54    }
 55
 56    public void RequestAll()
 57    {
 658        view.RestartScrollViewPosition();
 659        view.SetAllAsLoading();
 60
 661        reloadSubSection = false;
 662        lastTimeAPIChecked = Time.realtimeSinceStartup;
 63
 664        if (!exploreV2Menu.isInShowAnimationTransiton.Get())
 565            requester.RequestAllFromAPI();
 66        else
 67        {
 168            exploreV2Menu.isInShowAnimationTransiton.OnChange += OnAnimationTransitionFinished;
 169            isWaitingAnimTransition = true;
 70        }
 171    }
 72
 73    private void OnAnimationTransitionFinished(bool _, bool __)
 74    {
 075        exploreV2Menu.isInShowAnimationTransiton.OnChange -= OnAnimationTransitionFinished;
 076        isWaitingAnimTransition = false;
 77
 078        requester.RequestAllFromAPI();
 079    }
 80}
 81
 82public interface IPlacesAndEventsAPIRequester
 83{
 84    void RequestAllFromAPI();
 85}