| | 1 | | using DCL; |
| | 2 | | using DCL.NotificationModel; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class NotificationsController : MonoBehaviour |
| | 6 | | { |
| 45 | 7 | | public static NotificationsController i { get; private set; } |
| | 8 | | public static bool disableWelcomeNotification = false; |
| | 9 | |
|
| 23 | 10 | | public bool allowNotifications { get; set; } |
| | 11 | |
|
| 46 | 12 | | void Awake() { i = this; } |
| | 13 | |
|
| | 14 | | private INotificationHUDController controller; |
| | 15 | | private DataStore_Notifications notificationsDataStore; |
| | 16 | |
|
| | 17 | | // TODO: refactor into a bridge->service architecture so this dependencies are properly injected |
| | 18 | | public void Initialize( |
| | 19 | | INotificationHUDController controller, |
| | 20 | | DataStore_Notifications notificationsDataStore) |
| | 21 | | { |
| 0 | 22 | | this.controller = controller; |
| 0 | 23 | | this.notificationsDataStore = notificationsDataStore; |
| 0 | 24 | | allowNotifications = true; |
| | 25 | |
|
| 0 | 26 | | this.notificationsDataStore.DefaultErrorNotification.OnChange += ShowDefaultErrorNotification; |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | public void Dispose() |
| | 30 | | { |
| 0 | 31 | | notificationsDataStore.DefaultErrorNotification.OnChange -= ShowDefaultErrorNotification; |
| 0 | 32 | | controller.Dispose(); |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | public void ShowNotificationFromJson(string notificationJson) |
| | 36 | | { |
| 0 | 37 | | if (!allowNotifications) |
| 0 | 38 | | return; |
| | 39 | |
|
| 0 | 40 | | Model model = JsonUtility.FromJson<Model>(notificationJson); |
| 0 | 41 | | ShowNotification(model); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public void ShowNotification(Model notification) |
| | 45 | | { |
| 0 | 46 | | if (!allowNotifications) |
| 0 | 47 | | return; |
| | 48 | |
|
| 0 | 49 | | controller?.ShowNotification(notification); |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | public void ShowNotification(INotification notification) |
| | 53 | | { |
| 0 | 54 | | if (!allowNotifications) |
| 0 | 55 | | return; |
| | 56 | |
|
| 0 | 57 | | controller?.ShowNotification(notification); |
| 0 | 58 | | } |
| | 59 | |
|
| 0 | 60 | | public void DismissAllNotifications(string groupID) { controller?.DismissAllNotifications(groupID); } |
| | 61 | |
|
| | 62 | | public void ShowWelcomeNotification() |
| | 63 | | { |
| 0 | 64 | | if (!allowNotifications || disableWelcomeNotification) |
| 0 | 65 | | return; |
| | 66 | |
|
| | 67 | | //TODO(Brian): This should be triggered entirely by kernel |
| 0 | 68 | | controller?.ShowWelcomeNotification(); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | private void ShowDefaultErrorNotification(string errorText, string _) |
| | 72 | | { |
| 0 | 73 | | ShowNotification(new Model |
| | 74 | | { |
| | 75 | | message = errorText, |
| | 76 | | type = Type.ERROR, |
| | 77 | | timer = 5f, |
| | 78 | | destroyOnFinish = true |
| | 79 | | }); |
| 0 | 80 | | } |
| | 81 | | } |