< 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:27
Uncovered lines:8
Coverable lines:35
Total lines:86
Line coverage:77.1% (27 of 35)
Covered branches:0
Total branches:0

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.043083.33%
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
 6511    internal bool firstLoading = true;
 12    internal bool reloadSubSection;
 13    private bool isWaitingAnimTransition;
 14
 15    internal float lastTimeAPIChecked;
 16
 6517    public PlaceAndEventsCardsReloader(IPlacesAndEventsSubSectionComponentView view, IPlacesAndEventsAPIRequester reques
 18    {
 6519        this.view = view;
 6520        this.exploreV2Menu = exploreV2Menu;
 6521        this.requester = requester;
 6522    }
 23
 24    public void Initialize()
 25    {
 026        exploreV2Menu.isOpen.OnChange += OnExploreV2Open;
 027    }
 28
 29    public void Dispose()
 30    {
 6531        exploreV2Menu.isOpen.OnChange -= OnExploreV2Open;
 32
 6533        if (isWaitingAnimTransition)
 134            exploreV2Menu.isInShowAnimationTransiton.OnChange -= OnAnimationTransitionFinished;
 6535    }
 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        firstLoading = false;
 649        reloadSubSection = true;
 650        lastTimeAPIChecked = Time.realtimeSinceStartup - PlacesAndEventsSectionComponentController.MIN_TIME_TO_CHECK_API
 51
 652        return true;
 53
 054        bool IsInCooldown() => lastTimeAPIChecked < Time.realtimeSinceStartup - PlacesAndEventsSectionComponentControlle
 55    }
 56
 57    public void RequestAll()
 58    {
 659        view.RestartScrollViewPosition();
 660        view.SetAllAsLoading();
 61
 662        reloadSubSection = false;
 663        lastTimeAPIChecked = Time.realtimeSinceStartup;
 64
 665        if (!exploreV2Menu.isInShowAnimationTransiton.Get())
 566            requester.RequestAllFromAPI();
 67        else
 68        {
 169            exploreV2Menu.isInShowAnimationTransiton.OnChange += OnAnimationTransitionFinished;
 170            isWaitingAnimTransition = true;
 71        }
 172    }
 73
 74    private void OnAnimationTransitionFinished(bool _, bool __)
 75    {
 076        exploreV2Menu.isInShowAnimationTransiton.OnChange -= OnAnimationTransitionFinished;
 077        isWaitingAnimTransition = false;
 78
 079        requester.RequestAllFromAPI();
 080    }
 81}
 82
 83public interface IPlacesAndEventsAPIRequester
 84{
 85    void RequestAllFromAPI();
 86}