| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Browser; |
| | 4 | | using DCL.Tasks; |
| | 5 | | using DCLFeatures.CameraReel.Section; |
| | 6 | | using DCLServices.CameraReelService; |
| | 7 | | using DCLServices.EnvironmentProvider; |
| | 8 | | using System; |
| | 9 | | using System.Threading; |
| | 10 | | using UnityEngine; |
| | 11 | |
|
| | 12 | | namespace DCLFeatures.CameraReel.ScreenshotViewer |
| | 13 | | { |
| | 14 | | public class ScreenshotViewerController : IDisposable |
| | 15 | | { |
| | 16 | | private const string SCREEN_SOURCE = "ReelPictureDetail"; |
| | 17 | | private const string DELETE_ERROR_MESSAGE = "There was an unexpected error when deleting the picture. Try again |
| | 18 | |
|
| | 19 | | private readonly IScreenshotViewerView view; |
| | 20 | | private readonly CameraReelModel model; |
| | 21 | | private readonly DataStore dataStore; |
| | 22 | | private readonly ICameraReelStorageService storageService; |
| | 23 | | private readonly IUserProfileBridge userProfileBridge; |
| | 24 | | private readonly IClipboard clipboard; |
| | 25 | | private readonly IBrowserBridge browserBridge; |
| | 26 | | private readonly ICameraReelAnalyticsService analytics; |
| | 27 | | private readonly IEnvironmentProviderService environmentProviderService; |
| | 28 | | private readonly IScreenshotViewerActionsPanelView actionsPanelView; |
| | 29 | | private readonly IScreenshotViewerInfoSidePanelView infoSidePanelView; |
| | 30 | |
|
| | 31 | | private CancellationTokenSource deleteScreenshotCancellationToken; |
| | 32 | | private CancellationTokenSource pictureOwnerCancellationToken; |
| | 33 | | private CameraReelResponse currentScreenshot; |
| | 34 | |
|
| 0 | 35 | | public ScreenshotViewerController(IScreenshotViewerView view, |
| | 36 | | CameraReelModel model, |
| | 37 | | DataStore dataStore, |
| | 38 | | ICameraReelStorageService storageService, |
| | 39 | | IUserProfileBridge userProfileBridge, |
| | 40 | | IClipboard clipboard, |
| | 41 | | IBrowserBridge browserBridge, |
| | 42 | | ICameraReelAnalyticsService analytics, |
| | 43 | | IEnvironmentProviderService environmentProviderService, |
| | 44 | | IScreenshotViewerActionsPanelView actionsPanelView, |
| | 45 | | IScreenshotViewerInfoSidePanelView infoSidePanelView) |
| | 46 | | { |
| 0 | 47 | | this.view = view; |
| 0 | 48 | | this.model = model; |
| 0 | 49 | | this.dataStore = dataStore; |
| 0 | 50 | | this.storageService = storageService; |
| 0 | 51 | | this.userProfileBridge = userProfileBridge; |
| 0 | 52 | | this.clipboard = clipboard; |
| 0 | 53 | | this.browserBridge = browserBridge; |
| 0 | 54 | | this.analytics = analytics; |
| 0 | 55 | | this.environmentProviderService = environmentProviderService; |
| 0 | 56 | | this.actionsPanelView = actionsPanelView; |
| 0 | 57 | | this.infoSidePanelView = infoSidePanelView; |
| | 58 | |
|
| 0 | 59 | | view.CloseButtonClicked += view.Hide; |
| 0 | 60 | | view.PrevScreenshotClicked += ShowPrevScreenshot; |
| 0 | 61 | | view.NextScreenshotClicked += ShowNextScreenshot; |
| | 62 | |
|
| 0 | 63 | | actionsPanelView.DownloadClicked += DownloadScreenshot; |
| 0 | 64 | | actionsPanelView.DeleteClicked += DeleteScreenshot; |
| 0 | 65 | | actionsPanelView.LinkClicked += CopyScreenshotLink; |
| 0 | 66 | | actionsPanelView.TwitterClicked += ShareOnTwitter; |
| 0 | 67 | | actionsPanelView.InfoClicked += view.ToggleInfoSidePanel; |
| | 68 | |
|
| 0 | 69 | | infoSidePanelView.SidePanelButtonClicked += view.ToggleInfoSidePanel; |
| 0 | 70 | | infoSidePanelView.SceneButtonClicked += JumpInScene; |
| 0 | 71 | | infoSidePanelView.OnOpenPictureOwnerProfile += OpenPictureOwnerProfile; |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | public void Dispose() |
| | 75 | | { |
| 0 | 76 | | view.CloseButtonClicked -= view.Hide; |
| 0 | 77 | | view.PrevScreenshotClicked -= ShowPrevScreenshot; |
| 0 | 78 | | view.NextScreenshotClicked -= ShowNextScreenshot; |
| | 79 | |
|
| 0 | 80 | | actionsPanelView.DownloadClicked -= DownloadScreenshot; |
| 0 | 81 | | actionsPanelView.DeleteClicked -= DeleteScreenshot; |
| 0 | 82 | | actionsPanelView.LinkClicked -= CopyScreenshotLink; |
| 0 | 83 | | actionsPanelView.TwitterClicked -= ShareOnTwitter; |
| 0 | 84 | | actionsPanelView.InfoClicked -= view.ToggleInfoSidePanel; |
| | 85 | |
|
| 0 | 86 | | infoSidePanelView.SidePanelButtonClicked -= view.ToggleInfoSidePanel; |
| 0 | 87 | | infoSidePanelView.SceneButtonClicked -= JumpInScene; |
| 0 | 88 | | infoSidePanelView.OnOpenPictureOwnerProfile -= OpenPictureOwnerProfile; |
| | 89 | |
|
| 0 | 90 | | view.Dispose(); |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | public void Show(CameraReelResponse reel) |
| | 94 | | { |
| 0 | 95 | | if (reel == null) return; |
| | 96 | |
|
| 0 | 97 | | currentScreenshot = reel; |
| | 98 | |
|
| 0 | 99 | | view.SetScreenshotImage(reel.url); |
| 0 | 100 | | infoSidePanelView.SetSceneInfoText(reel.metadata.scene); |
| 0 | 101 | | infoSidePanelView.SetDateText(reel.metadata.GetLocalizedDateTime()); |
| 0 | 102 | | infoSidePanelView.ShowVisiblePersons(reel.metadata.visiblePeople); |
| 0 | 103 | | pictureOwnerCancellationToken = pictureOwnerCancellationToken.SafeRestart(); |
| 0 | 104 | | UpdatePictureOwnerInfo(reel, pictureOwnerCancellationToken.Token).Forget(); |
| | 105 | |
|
| 0 | 106 | | view.Show(); |
| 0 | 107 | | } |
| | 108 | |
|
| | 109 | | private async UniTaskVoid UpdatePictureOwnerInfo(CameraReelResponse reel, CancellationToken cancellationToken) |
| | 110 | | { |
| 0 | 111 | | UserProfile profile = userProfileBridge.Get(reel.metadata.userAddress) |
| | 112 | | ?? await userProfileBridge.RequestFullUserProfileAsync(reel.metada |
| | 113 | |
|
| 0 | 114 | | infoSidePanelView.SetPictureOwner(reel.metadata.userName, profile.face256SnapshotURL); |
| 0 | 115 | | } |
| | 116 | |
|
| | 117 | | private void ShowPrevScreenshot() => |
| 0 | 118 | | Show(model.GetPreviousScreenshot(currentScreenshot)); |
| | 119 | |
|
| | 120 | | private void ShowNextScreenshot() => |
| 0 | 121 | | Show(model.GetNextScreenshot(currentScreenshot)); |
| | 122 | |
|
| | 123 | | private void DeleteScreenshot() |
| | 124 | | { |
| | 125 | | async UniTaskVoid DeleteScreenshotAsync(CameraReelResponse screenshot, CancellationToken cancellationToken) |
| | 126 | | { |
| | 127 | | try |
| | 128 | | { |
| 0 | 129 | | CameraReelStorageStatus storage = await storageService.DeleteScreenshot(screenshot.id, cancellationT |
| 0 | 130 | | model.RemoveScreenshot(screenshot); |
| 0 | 131 | | model.SetStorageStatus(storage.CurrentScreenshots, storage.MaxScreenshots); |
| 0 | 132 | | analytics.DeletePhoto(); |
| 0 | 133 | | } |
| 0 | 134 | | catch (OperationCanceledException) { } |
| | 135 | | catch (Exception e) |
| | 136 | | { |
| 0 | 137 | | dataStore.notifications.DefaultErrorNotification.Set(DELETE_ERROR_MESSAGE, true); |
| 0 | 138 | | Debug.LogException(e); |
| 0 | 139 | | } |
| | 140 | | finally |
| | 141 | | { |
| 0 | 142 | | view.Hide(); |
| | 143 | | } |
| 0 | 144 | | } |
| | 145 | |
|
| 0 | 146 | | dataStore.notifications.GenericConfirmation.Set(new GenericConfirmationNotificationData( |
| | 147 | | "Are you sure you want to delete this photo?", |
| | 148 | | "This photo will be removed and you will no longer be able to access it.", |
| | 149 | | "NO", |
| | 150 | | "YES", |
| 0 | 151 | | () => {}, |
| | 152 | | () => |
| | 153 | | { |
| 0 | 154 | | deleteScreenshotCancellationToken = deleteScreenshotCancellationToken.SafeRestart(); |
| 0 | 155 | | DeleteScreenshotAsync(currentScreenshot, deleteScreenshotCancellationToken.Token).Forget(); |
| 0 | 156 | | }), true); |
| 0 | 157 | | } |
| | 158 | |
|
| | 159 | | private void DownloadScreenshot() |
| | 160 | | { |
| 0 | 161 | | browserBridge.OpenUrl(currentScreenshot.url); |
| 0 | 162 | | analytics.DownloadPhoto("Explorer"); |
| 0 | 163 | | } |
| | 164 | |
|
| | 165 | | private void CopyScreenshotLink() |
| | 166 | | { |
| 0 | 167 | | var url = $"https://reels.decentraland.{(environmentProviderService.IsProd() ? "org" : "zone")}/{currentScre |
| | 168 | |
|
| 0 | 169 | | clipboard.WriteText(url); |
| 0 | 170 | | browserBridge.OpenUrl(url); |
| 0 | 171 | | analytics.Share("Explorer", "Copy"); |
| 0 | 172 | | } |
| | 173 | |
|
| | 174 | | private void ShareOnTwitter() |
| | 175 | | { |
| 0 | 176 | | var description = "Check out what I'm doing in Decentraland right now and join me!".Replace(" ", "%20"); |
| 0 | 177 | | var url = $"https://reels.decentraland.{(environmentProviderService.IsProd() ? "org" : "zone")}/{currentScre |
| 0 | 178 | | var twitterUrl = $"https://twitter.com/intent/tweet?text={description}&hashtags=DCLCamera&url={url}"; |
| | 179 | |
|
| 0 | 180 | | clipboard.WriteText(twitterUrl); |
| 0 | 181 | | browserBridge.OpenUrl(twitterUrl); |
| 0 | 182 | | analytics.Share("Explorer", "Twitter"); |
| 0 | 183 | | } |
| | 184 | |
|
| | 185 | | private void JumpInScene() |
| | 186 | | { |
| 0 | 187 | | if (!int.TryParse(currentScreenshot.metadata.scene.location.x, out int x) |
| | 188 | | || !int.TryParse(currentScreenshot.metadata.scene.location.y, out int y)) |
| 0 | 189 | | return; |
| | 190 | |
|
| | 191 | | void TrackToAnalyticsThenCloseView() |
| | 192 | | { |
| 0 | 193 | | analytics.JumpIn("Explorer"); |
| 0 | 194 | | view.Hide(); |
| 0 | 195 | | dataStore.exploreV2.isOpen.Set(false); |
| 0 | 196 | | } |
| | 197 | |
|
| 0 | 198 | | dataStore.HUDs.gotoPanelVisible.Set(true, true); |
| 0 | 199 | | dataStore.HUDs.gotoPanelCoordinates.Set((new ParcelCoordinates(x, y), currentScreenshot.metadata.realm, Trac |
| 0 | 200 | | } |
| | 201 | |
|
| | 202 | | private void OpenPictureOwnerProfile() |
| | 203 | | { |
| 0 | 204 | | dataStore.HUDs.currentPlayerId.Set((currentScreenshot.metadata.userAddress, SCREEN_SOURCE)); |
| 0 | 205 | | } |
| | 206 | | } |
| | 207 | | } |