< Summary

Class:DCLFeatures.CameraReel.ScreenshotViewer.ScreenshotViewerController
Assembly:CameraReel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/ScreenshotViewer/Scripts/ScreenshotViewerController.cs
Covered lines:0
Uncovered lines:95
Coverable lines:95
Total lines:207
Line coverage:0% (0 of 95)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:13
Method coverage:0% (0 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ScreenshotViewerController(...)0%2100%
Dispose()0%2100%
Show(...)0%6200%
UpdatePictureOwnerInfo()0%20400%
ShowPrevScreenshot()0%2100%
ShowNextScreenshot()0%2100%
<DeleteScreenshot()0%20400%
DeleteScreenshot()0%6200%
DownloadScreenshot()0%2100%
CopyScreenshotLink()0%12300%
ShareOnTwitter()0%12300%
JumpInScene()0%12300%
OpenPictureOwnerProfile()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/ScreenshotViewer/Scripts/ScreenshotViewerController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Browser;
 4using DCL.Tasks;
 5using DCLFeatures.CameraReel.Section;
 6using DCLServices.CameraReelService;
 7using DCLServices.EnvironmentProvider;
 8using System;
 9using System.Threading;
 10using UnityEngine;
 11
 12namespace 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
 035        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        {
 047            this.view = view;
 048            this.model = model;
 049            this.dataStore = dataStore;
 050            this.storageService = storageService;
 051            this.userProfileBridge = userProfileBridge;
 052            this.clipboard = clipboard;
 053            this.browserBridge = browserBridge;
 054            this.analytics = analytics;
 055            this.environmentProviderService = environmentProviderService;
 056            this.actionsPanelView = actionsPanelView;
 057            this.infoSidePanelView = infoSidePanelView;
 58
 059            view.CloseButtonClicked += view.Hide;
 060            view.PrevScreenshotClicked += ShowPrevScreenshot;
 061            view.NextScreenshotClicked += ShowNextScreenshot;
 62
 063            actionsPanelView.DownloadClicked += DownloadScreenshot;
 064            actionsPanelView.DeleteClicked += DeleteScreenshot;
 065            actionsPanelView.LinkClicked += CopyScreenshotLink;
 066            actionsPanelView.TwitterClicked += ShareOnTwitter;
 067            actionsPanelView.InfoClicked += view.ToggleInfoSidePanel;
 68
 069            infoSidePanelView.SidePanelButtonClicked += view.ToggleInfoSidePanel;
 070            infoSidePanelView.SceneButtonClicked += JumpInScene;
 071            infoSidePanelView.OnOpenPictureOwnerProfile += OpenPictureOwnerProfile;
 072        }
 73
 74        public void Dispose()
 75        {
 076            view.CloseButtonClicked -= view.Hide;
 077            view.PrevScreenshotClicked -= ShowPrevScreenshot;
 078            view.NextScreenshotClicked -= ShowNextScreenshot;
 79
 080            actionsPanelView.DownloadClicked -= DownloadScreenshot;
 081            actionsPanelView.DeleteClicked -= DeleteScreenshot;
 082            actionsPanelView.LinkClicked -= CopyScreenshotLink;
 083            actionsPanelView.TwitterClicked -= ShareOnTwitter;
 084            actionsPanelView.InfoClicked -= view.ToggleInfoSidePanel;
 85
 086            infoSidePanelView.SidePanelButtonClicked -= view.ToggleInfoSidePanel;
 087            infoSidePanelView.SceneButtonClicked -= JumpInScene;
 088            infoSidePanelView.OnOpenPictureOwnerProfile -= OpenPictureOwnerProfile;
 89
 090            view.Dispose();
 091        }
 92
 93        public void Show(CameraReelResponse reel)
 94        {
 095            if (reel == null) return;
 96
 097            currentScreenshot = reel;
 98
 099            view.SetScreenshotImage(reel.url);
 0100            infoSidePanelView.SetSceneInfoText(reel.metadata.scene);
 0101            infoSidePanelView.SetDateText(reel.metadata.GetLocalizedDateTime());
 0102            infoSidePanelView.ShowVisiblePersons(reel.metadata.visiblePeople);
 0103            pictureOwnerCancellationToken = pictureOwnerCancellationToken.SafeRestart();
 0104            UpdatePictureOwnerInfo(reel, pictureOwnerCancellationToken.Token).Forget();
 105
 0106            view.Show();
 0107        }
 108
 109        private async UniTaskVoid UpdatePictureOwnerInfo(CameraReelResponse reel, CancellationToken cancellationToken)
 110        {
 0111            UserProfile profile = userProfileBridge.Get(reel.metadata.userAddress)
 112                                                      ?? await userProfileBridge.RequestFullUserProfileAsync(reel.metada
 113
 0114            infoSidePanelView.SetPictureOwner(reel.metadata.userName, profile.face256SnapshotURL);
 0115        }
 116
 117        private void ShowPrevScreenshot() =>
 0118            Show(model.GetPreviousScreenshot(currentScreenshot));
 119
 120        private void ShowNextScreenshot() =>
 0121            Show(model.GetNextScreenshot(currentScreenshot));
 122
 123        private void DeleteScreenshot()
 124        {
 125            async UniTaskVoid DeleteScreenshotAsync(CameraReelResponse screenshot, CancellationToken cancellationToken)
 126            {
 127                try
 128                {
 0129                    CameraReelStorageStatus storage = await storageService.DeleteScreenshot(screenshot.id, cancellationT
 0130                    model.RemoveScreenshot(screenshot);
 0131                    model.SetStorageStatus(storage.CurrentScreenshots, storage.MaxScreenshots);
 0132                    analytics.DeletePhoto();
 0133                }
 0134                catch (OperationCanceledException) { }
 135                catch (Exception e)
 136                {
 0137                    dataStore.notifications.DefaultErrorNotification.Set(DELETE_ERROR_MESSAGE, true);
 0138                    Debug.LogException(e);
 0139                }
 140                finally
 141                {
 0142                    view.Hide();
 143                }
 0144            }
 145
 0146            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",
 0151                () => {},
 152                () =>
 153                {
 0154                    deleteScreenshotCancellationToken = deleteScreenshotCancellationToken.SafeRestart();
 0155                    DeleteScreenshotAsync(currentScreenshot, deleteScreenshotCancellationToken.Token).Forget();
 0156                }), true);
 0157        }
 158
 159        private void DownloadScreenshot()
 160        {
 0161            browserBridge.OpenUrl(currentScreenshot.url);
 0162            analytics.DownloadPhoto("Explorer");
 0163        }
 164
 165        private void CopyScreenshotLink()
 166        {
 0167            var url = $"https://reels.decentraland.{(environmentProviderService.IsProd() ? "org" : "zone")}/{currentScre
 168
 0169            clipboard.WriteText(url);
 0170            browserBridge.OpenUrl(url);
 0171            analytics.Share("Explorer", "Copy");
 0172        }
 173
 174        private void ShareOnTwitter()
 175        {
 0176            var description = "Check out what I'm doing in Decentraland right now and join me!".Replace(" ", "%20");
 0177            var url = $"https://reels.decentraland.{(environmentProviderService.IsProd() ? "org" : "zone")}/{currentScre
 0178            var twitterUrl = $"https://twitter.com/intent/tweet?text={description}&hashtags=DCLCamera&url={url}";
 179
 0180            clipboard.WriteText(twitterUrl);
 0181            browserBridge.OpenUrl(twitterUrl);
 0182            analytics.Share("Explorer", "Twitter");
 0183        }
 184
 185        private void JumpInScene()
 186        {
 0187            if (!int.TryParse(currentScreenshot.metadata.scene.location.x, out int x)
 188                || !int.TryParse(currentScreenshot.metadata.scene.location.y, out int y))
 0189                return;
 190
 191            void TrackToAnalyticsThenCloseView()
 192            {
 0193                analytics.JumpIn("Explorer");
 0194                view.Hide();
 0195                dataStore.exploreV2.isOpen.Set(false);
 0196            }
 197
 0198            dataStore.HUDs.gotoPanelVisible.Set(true, true);
 0199            dataStore.HUDs.gotoPanelCoordinates.Set((new ParcelCoordinates(x, y), currentScreenshot.metadata.realm, Trac
 0200        }
 201
 202        private void OpenPictureOwnerProfile()
 203        {
 0204            dataStore.HUDs.currentPlayerId.Set((currentScreenshot.metadata.userAddress, SCREEN_SOURCE));
 0205        }
 206    }
 207}