-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCameraReelController.cs
More file actions
141 lines (117 loc) · 5.4 KB
/
Copy pathCameraReelController.cs
File metadata and controls
141 lines (117 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Cysharp.Threading.Tasks;
using DCL.Input;
using DCL.InWorldCamera.CameraReelStorageService;
using DCL.InWorldCamera.CameraReelStorageService.Schemas;
using DCL.InWorldCamera.PhotoDetail;
using DCL.UI;
using DCL.Web3.Identities;
using DG.Tweening;
using MVC;
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using Utility;
namespace DCL.InWorldCamera.CameraReelGallery
{
public class CameraReelController : ISection, IDisposable
{
public event Action Activated;
public readonly CameraReelGalleryController CameraReelGalleryController;
private readonly CameraReelView view;
private readonly RectTransform rectTransform;
private readonly ICameraReelStorageService cameraReelStorageService;
private readonly IWeb3IdentityCache web3IdentityCache;
private readonly IMVCManager mvcManager;
private readonly ICursor cursor;
private readonly GalleryEventBus galleryEventBus;
private CancellationTokenSource showCancellationTokenSource;
public CameraReelController(
CameraReelView view,
CameraReelGalleryController cameraReelGalleryController,
ICameraReelStorageService cameraReelStorageService,
IWeb3IdentityCache web3IdentityCache,
IMVCManager mvcManager,
ICursor cursor,
GalleryEventBus galleryEventBus,
string storageProgressBarLabelText)
{
this.view = view;
this.cameraReelStorageService = cameraReelStorageService;
this.web3IdentityCache = web3IdentityCache;
this.CameraReelGalleryController = cameraReelGalleryController;
this.mvcManager = mvcManager;
this.cursor = cursor;
this.galleryEventBus = galleryEventBus;
rectTransform = view.transform.parent.GetComponent<RectTransform>();
this.view.MouseEnter += StorageFullIconEnter;
this.view.MouseExit += StorageFullIconExit;
this.CameraReelGalleryController.ThumbnailClicked += ThumbnailClicked;
this.CameraReelGalleryController.StorageUpdated += SetStorageStatus;
this.view.goToCameraButton.onClick.AddListener(OnGoToCameraButtonClicked);
view.storageProgressBar.SetLabelString(storageProgressBarLabelText);
}
private void OnGoToCameraButtonClicked()
{
//TODO (Lorenzo): Close gallery and open camera
}
private void ThumbnailClicked(List<CameraReelResponseCompact> reels, int index,
Action<CameraReelResponseCompact> reelDeleteIntention, Action<CameraReelResponseCompact> reelListRefreshIntention) =>
mvcManager.ShowAsync(PhotoDetailController.IssueCommand(new PhotoDetailParameter(reels, index,
false, PhotoDetailParameter.CallerContext.CameraReel, reelDeleteIntention,
reelListRefreshIntention, galleryEventBus)));
private void StorageFullIconEnter() =>
view.storageFullToast.DOFade(1f, view.storageFullToastFadeTime);
private void StorageFullIconExit() =>
view.storageFullToast.DOFade(0f, view.storageFullToastFadeTime);
private async UniTask ShowAsync(CancellationToken ct)
{
view.CameraReelGalleryView.gameObject.SetActive(false);
CameraReelStorageStatus storageStatus = await cameraReelStorageService.GetUserGalleryStorageInfoAsync(web3IdentityCache.Identity.Address, ct);
SetStorageStatus(storageStatus);
await CameraReelGalleryController.ShowWalletGalleryAsync(web3IdentityCache.Identity.Address, ct, storageStatus);
}
private void SetStorageStatus(CameraReelStorageStatus storageStatus)
{
view.storageProgressBar.SetPercentageValue((storageStatus.ScreenshotsAmount * 1.0f / storageStatus.MaxScreenshots) * 100, 0 , storageStatus.MaxScreenshots);
view.storageFullIcon.SetActive(!storageStatus.HasFreeSpace);
if (storageStatus.ScreenshotsAmount == 0)
view.emptyState.SetActive(true);
view.CameraReelGalleryView.gameObject.SetActive(storageStatus.ScreenshotsAmount > 0);
}
public void Activate()
{
showCancellationTokenSource = showCancellationTokenSource.SafeRestart();
view.gameObject.SetActive(true);
cursor.Unlock();
ShowAsync(showCancellationTokenSource.Token).SuppressCancellationThrow().Forget();
Activated?.Invoke();
}
public void Deactivate()
{
view.gameObject.SetActive(false);
showCancellationTokenSource.SafeCancelAndDispose();
}
public void Animate(int triggerId)
{
view.panelAnimator.SetTrigger(triggerId);
view.headerAnimator.SetTrigger(triggerId);
}
public void ResetAnimator()
{
view.panelAnimator.Rebind();
view.headerAnimator.Rebind();
view.panelAnimator.Update(0);
view.headerAnimator.Update(0);
}
public RectTransform GetRectTransform() =>
rectTransform;
public void Dispose()
{
view.MouseEnter -= StorageFullIconEnter;
view.MouseExit -= StorageFullIconExit;
CameraReelGalleryController.Dispose();
view.goToCameraButton.onClick.RemoveAllListeners();
}
}
}