| | 1 | | using System; |
| | 2 | |
|
| | 3 | | namespace DCL.ConfirmationPopup |
| | 4 | | { |
| | 5 | | public class ConfirmationPopupHUDController : IDisposable |
| | 6 | | { |
| | 7 | | private readonly IConfirmationPopupHUDView view; |
| | 8 | | private readonly DataStore_Notifications dataStore; |
| | 9 | |
|
| | 10 | | private Action externalConfirmationAction; |
| | 11 | | private Action externalCancelAction; |
| | 12 | |
|
| 4 | 13 | | public ConfirmationPopupHUDController(IConfirmationPopupHUDView view, |
| | 14 | | DataStore_Notifications dataStore) |
| | 15 | | { |
| 4 | 16 | | this.view = view; |
| 4 | 17 | | this.dataStore = dataStore; |
| | 18 | |
|
| 4 | 19 | | this.view.OnConfirm += OnConfirmFromView; |
| 4 | 20 | | this.view.OnCancel += OnCancelFromView; |
| | 21 | |
|
| 4 | 22 | | this.dataStore.GenericConfirmation.OnChange += ShowOrHide; |
| | 23 | |
|
| 4 | 24 | | view.Hide(true); |
| 4 | 25 | | } |
| | 26 | |
|
| | 27 | | public void Dispose() |
| | 28 | | { |
| 4 | 29 | | dataStore.GenericConfirmation.OnChange -= ShowOrHide; |
| 4 | 30 | | view.OnConfirm -= OnConfirmFromView; |
| 4 | 31 | | view.OnCancel -= OnCancelFromView; |
| 4 | 32 | | view.Dispose(); |
| 4 | 33 | | externalCancelAction = null; |
| 4 | 34 | | externalConfirmationAction = null; |
| 4 | 35 | | } |
| | 36 | |
|
| | 37 | | private void OnCancelFromView() |
| | 38 | | { |
| 1 | 39 | | externalCancelAction?.Invoke(); |
| 1 | 40 | | Hide(); |
| 1 | 41 | | } |
| | 42 | |
|
| | 43 | | private void OnConfirmFromView() |
| | 44 | | { |
| 1 | 45 | | externalConfirmationAction?.Invoke(); |
| 1 | 46 | | Hide(); |
| 1 | 47 | | } |
| | 48 | |
|
| | 49 | | private void ShowOrHide(GenericConfirmationNotificationData current, GenericConfirmationNotificationData previou |
| | 50 | | { |
| 4 | 51 | | if (current == null) |
| 1 | 52 | | Hide(); |
| | 53 | | else |
| 3 | 54 | | Show(current); |
| 3 | 55 | | } |
| | 56 | |
|
| | 57 | | private void Hide() |
| | 58 | | { |
| 3 | 59 | | externalCancelAction = null; |
| 3 | 60 | | externalConfirmationAction = null; |
| 3 | 61 | | view.Hide(); |
| 3 | 62 | | } |
| | 63 | |
|
| | 64 | | private void Show(GenericConfirmationNotificationData data) |
| | 65 | | { |
| 3 | 66 | | externalCancelAction = data.CancelAction; |
| 3 | 67 | | externalConfirmationAction = data.ConfirmAction; |
| 3 | 68 | | view.SetModel(new ConfirmationPopupHUDViewModel(data.Title, data.Body, data.CancelButton, data.ConfirmButton |
| 3 | 69 | | view.Show(); |
| 3 | 70 | | } |
| | 71 | | } |
| | 72 | | } |