< Summary

Class:NotificationHUDController
Assembly:NotificationHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationHUDController.cs
Covered lines:23
Uncovered lines:11
Coverable lines:34
Total lines:81
Line coverage:67.6% (23 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
NotificationHUDController()0%110100%
NotificationHUDController(...)0%110100%
ShowNotification(...)0%110100%
ShowNotification(...)0%2.032080%
DismissAllNotifications(...)0%16.765022.22%
OnNotificationDismissed(...)0%110100%
SetActive(...)0%110100%
Dispose()0%220100%
SetVisibility(...)0%110100%
ShowWelcomeNotification()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationHUDController.cs

#LineLine coverage
 1using System.Collections.Generic;
 2
 3public class NotificationHUDController : IHUD, INotificationHUDController
 4{
 5    [System.Serializable]
 6    public class Model
 7    {
 168        public List<INotification> notifications = new List<INotification>();
 9    }
 10
 011    public NotificationHUDView view { get; private set; }
 012    public Model model { get; private set; }
 13
 3214    public NotificationHUDController() : this(new Model()) { }
 15
 1616    public NotificationHUDController(Model model)
 17    {
 1618        this.model = model;
 1619        view = NotificationHUDView.Create();
 1620        view.OnNotificationDismissedEvent += OnNotificationDismissed;
 1621    }
 22
 23    public void ShowNotification(INotification notification)
 24    {
 225        model.notifications.Add(notification);
 226        view.ShowNotification(notification, notification.model);
 227    }
 28
 29    public void ShowNotification(DCL.NotificationModel.Model model)
 30    {
 431        if (!string.IsNullOrEmpty(model.groupID))
 32        {
 33            //NOTE(Brian): If more notifications of the same group are visible, hide them.
 34            //             This works when having notifications in different contexts (i.e. FriendsHUD vs global notific
 035            DismissAllNotifications(model.groupID);
 36        }
 37
 438        var notification = view.ShowNotification(model);
 439        this.model.notifications.Add(notification);
 440    }
 41
 42    public void DismissAllNotifications(string groupID)
 43    {
 144        if (this.model.notifications.Count > 0)
 45        {
 46            //NOTE(Brian): Copy list to avoid modify while iterating error
 047            var notiList = new List<INotification>(this.model.notifications);
 048            int notiCount = notiList.Count;
 49
 050            for (int i = 0; i < notiCount; i++)
 51            {
 052                if (!string.IsNullOrEmpty(groupID) && groupID != notiList[i].model.groupID)
 53                    continue;
 54
 055                notiList[i].Dismiss(instant: true);
 56            }
 57        }
 158    }
 59
 260    private void OnNotificationDismissed(INotification notification) { model.notifications.Remove(notification); }
 61
 262    public void SetActive(bool active) { view.SetActive(active); }
 63
 64    public void Dispose()
 65    {
 1666        if (view != null)
 67        {
 1668            UnityEngine.Object.Destroy(view.gameObject);
 69        }
 70
 1671        view.OnNotificationDismissedEvent -= OnNotificationDismissed;
 1672    }
 73
 274    public void SetVisibility(bool visible) { SetActive(visible); }
 75
 76    public void ShowWelcomeNotification()
 77    {
 078        var model = WelcomeNotification.Get();
 079        ShowNotification(model);
 080    }
 81}