| | 1 | | using DCL.Helpers; |
| | 2 | | using DCLServices.CameraReelService; |
| | 3 | | using System; |
| | 4 | | using UIComponents.ContextMenu; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCLFeatures.CameraReel.Gallery |
| | 9 | | { |
| | 10 | | [RequireComponent(typeof(RectTransform))] |
| | 11 | | public class ThumbnailContextMenuView : ContextMenuComponentView, IThumbnailContextMenuView |
| | 12 | | { |
| 0 | 13 | | public static readonly BaseList<ThumbnailContextMenuView> Instances = new (); |
| | 14 | |
|
| | 15 | | [SerializeField] private Button downloadButton; |
| | 16 | | [SerializeField] private Button deleteButton; |
| | 17 | | [SerializeField] private Button copyLinkButton; |
| | 18 | | [SerializeField] private Button shareToTwitterButton; |
| | 19 | | [SerializeField] private bool selfDestroy; |
| | 20 | |
|
| | 21 | | public event Action OnDownloadRequested; |
| | 22 | | public event Action OnDeletePictureRequested; |
| | 23 | | public event Action OnCopyPictureLinkRequested; |
| | 24 | | public event Action OnShareToTwitterRequested; |
| | 25 | | public event Action<CameraReelResponse> OnSetup; |
| | 26 | |
|
| | 27 | | public override void Awake() |
| | 28 | | { |
| 0 | 29 | | base.Awake(); |
| | 30 | |
|
| 0 | 31 | | HidingHierarchyTransforms = new[] |
| | 32 | | { |
| | 33 | | transform, |
| | 34 | | downloadButton.transform, |
| | 35 | | deleteButton.transform, |
| | 36 | | copyLinkButton.transform, |
| | 37 | | shareToTwitterButton.transform, |
| | 38 | | }; |
| | 39 | |
|
| 0 | 40 | | downloadButton.onClick.AddListener(() => |
| | 41 | | { |
| 0 | 42 | | OnDownloadRequested?.Invoke(); |
| 0 | 43 | | Hide(); |
| 0 | 44 | | }); |
| | 45 | |
|
| 0 | 46 | | deleteButton.onClick.AddListener(() => |
| | 47 | | { |
| 0 | 48 | | OnDeletePictureRequested?.Invoke(); |
| 0 | 49 | | Hide(); |
| 0 | 50 | | }); |
| | 51 | |
|
| 0 | 52 | | copyLinkButton.onClick.AddListener(() => |
| | 53 | | { |
| 0 | 54 | | OnCopyPictureLinkRequested?.Invoke(); |
| 0 | 55 | | Hide(); |
| 0 | 56 | | }); |
| | 57 | |
|
| 0 | 58 | | shareToTwitterButton.onClick.AddListener(() => |
| | 59 | | { |
| 0 | 60 | | OnShareToTwitterRequested?.Invoke(); |
| 0 | 61 | | Hide(); |
| 0 | 62 | | }); |
| | 63 | |
|
| 0 | 64 | | Instances.Add(this); |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | private void OnDestroy() |
| | 68 | | { |
| 0 | 69 | | Instances.Remove(this); |
| 0 | 70 | | } |
| | 71 | |
|
| 0 | 72 | | public override void RefreshControl() { } |
| | 73 | |
|
| | 74 | | public void Show(CameraReelResponse picture) |
| | 75 | | { |
| 0 | 76 | | gameObject.SetActive(true); |
| 0 | 77 | | ClampPositionToScreenBorders(transform.position); |
| 0 | 78 | | OnSetup?.Invoke(picture); |
| 0 | 79 | | } |
| | 80 | |
|
| | 81 | | public override void Hide(bool instant = false) |
| | 82 | | { |
| 0 | 83 | | base.Hide(instant); |
| | 84 | |
|
| 0 | 85 | | gameObject.SetActive(false); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | public override void Dispose() |
| | 89 | | { |
| 0 | 90 | | if (selfDestroy) |
| 0 | 91 | | Utils.SafeDestroy(gameObject); |
| 0 | 92 | | } |
| | 93 | | } |
| | 94 | | } |