-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCameraReelGalleryController.cs
More file actions
658 lines (548 loc) · 27 KB
/
Copy pathCameraReelGalleryController.cs
File metadata and controls
658 lines (548 loc) · 27 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
using Cysharp.Threading.Tasks;
using DCL.Browser;
using DCL.Clipboard;
using DCL.Diagnostics;
using DCL.InWorldCamera.CameraReelGallery.Components;
using DCL.InWorldCamera.CameraReelStorageService;
using DCL.InWorldCamera.CameraReelStorageService.Schemas;
using DCL.InWorldCamera.CameraReelToast;
using DCL.InWorldCamera.ReelActions;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Optimization.Pools;
using DCL.UI.Utilities;
using DG.Tweening;
using MVC;
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Pool;
using UnityEngine.UI;
using Utility;
namespace DCL.InWorldCamera.CameraReelGallery
{
public class CameraReelGalleryController : IDisposable
{
private enum ScrollDirection
{
UP,
DOWN
}
private struct ReelToDeleteInfo
{
public readonly string Id;
public readonly string Datetime;
public ReelToDeleteInfo(string id, string datetime)
{
Id = id;
Datetime = datetime;
}
}
public delegate void ThumbnailClick(
List<CameraReelResponseCompact> reels,
int index,
Action<CameraReelResponseCompact> reelDeleteIntention,
Action<CameraReelResponseCompact> reelListRefreshIntention);
public event ThumbnailClick? ThumbnailClicked;
public event Action<CameraReelStorageStatus>? StorageUpdated;
public event Action ScreenshotDeleted;
public event Action ScreenshotShared;
public event Action ScreenshotDownloaded;
public event Action<int> MaxThumbnailsUpdated;
private const int THUMBNAIL_POOL_DEFAULT_CAPACITY = 100;
private const int THUMBNAIL_POOL_MAX_SIZE = 10000;
private const int GRID_POOL_DEFAULT_CAPACITY = 10;
private const int GRID_POOL_MAX_SIZE = 500;
private const int ANIMATION_DELAY = 300;
private static readonly ListObjectPool<CameraReelResponseCompact> CAMERA_REEL_RESPONSES_POOL = new ();
private readonly CameraReelGalleryView view;
private readonly ICameraReelStorageService cameraReelStorageService;
private readonly IDecentralandUrlsSource? decentralandUrlsSource;
private readonly ISystemClipboard? systemClipboard;
private readonly IWebBrowser? webBrowser;
private readonly GalleryEventBus galleryEventBus;
private readonly ReelGalleryPoolManager reelGalleryPoolManager;
private readonly Dictionary<DateTime, MonthGridController> monthViews = new ();
private readonly Dictionary<CameraReelResponseCompact, Texture> reelThumbnailCache = new ();
private readonly CameraReelOptionButtonController? optionButtonController;
private readonly Rect elementMaskRect;
private readonly ReelGalleryStringMessages? reelGalleryStringMessages;
private readonly ReelGalleryConfigParams reelGalleryConfigParams;
private readonly bool useSignedRequest;
private bool isLoading;
private bool isDragging;
private float previousY = 1f;
private CancellationTokenSource loadNextPageCts = new ();
private CancellationTokenSource setPublicCts = new ();
private CancellationTokenSource deleteScreenshotCts = new ();
private CancellationTokenSource downloadScreenshotCts = new ();
private ReelThumbnailController[] thumbnailImages;
private int beginVisible;
private int endVisible;
private int currentSize;
private CameraReelResponseCompact reelToDelete;
private PagedCameraReelManager pagedCameraReelManager;
public CameraReelGalleryController(CameraReelGalleryView view,
ICameraReelStorageService cameraReelStorageService,
ICameraReelScreenshotsStorage cameraReelScreenshotsStorage,
ReelGalleryConfigParams reelGalleryConfigParams,
bool useSignedRequest,
CameraReelOptionButtonView? optionButtonView = null,
IWebBrowser? webBrowser = null,
IDecentralandUrlsSource? decentralandUrlsSource = null,
ISystemClipboard? systemClipboard = null,
ReelGalleryStringMessages? reelGalleryStringMessages = null,
IMVCManager? mvcManager = null,
GalleryEventBus galleryEventBus = null)
{
this.view = view;
this.cameraReelStorageService = cameraReelStorageService;
this.reelGalleryConfigParams = reelGalleryConfigParams;
this.reelGalleryStringMessages = reelGalleryStringMessages;
this.view.Disable += OnDisable;
this.view.scrollRectDragHandler.BeginDrag += ScrollBeginDrag;
this.view.scrollRectDragHandler.EndDrag += ScrollEndDrag;
this.view.scrollBarDragHandler.BeginDrag += ScrollBeginDrag;
this.view.scrollBarDragHandler.EndDrag += ScrollEndDrag;
this.elementMaskRect = this.view.elementMask.GetWorldRect();
this.useSignedRequest = useSignedRequest;
this.decentralandUrlsSource = decentralandUrlsSource;
this.systemClipboard = systemClipboard;
this.webBrowser = webBrowser;
this.galleryEventBus = galleryEventBus;
this.view.scrollRect.SetScrollSensitivityBasedOnPlatform();
if (optionButtonView is not null)
this.optionButtonController = new CameraReelOptionButtonController(optionButtonView, mvcManager!);
reelGalleryPoolManager = new ReelGalleryPoolManager(view.thumbnailViewPrefab, view.monthGridPrefab, view.unusedThumbnailViewObject,
view.unusedGridViewObject, cameraReelScreenshotsStorage,
reelGalleryConfigParams,
THUMBNAIL_POOL_DEFAULT_CAPACITY, THUMBNAIL_POOL_MAX_SIZE, GRID_POOL_DEFAULT_CAPACITY, GRID_POOL_MAX_SIZE);
view.cancelDeleteIntentButton?.onClick.AddListener(() => OnDeletionModalCancelClick());
view.cancelDeleteIntentBackgroundButton?.onClick.AddListener(() => OnDeletionModalCancelClick(false));
view.deleteReelButton?.onClick.AddListener(DeleteScreenshot);
if (this.optionButtonController != null)
{
this.optionButtonController.SetPublicRequested += SetReelPublic;
this.optionButtonController.ShareToXRequested += ShareToX;
this.optionButtonController.CopyPictureLinkRequested += CopyPictureLink;
this.optionButtonController.DownloadRequested += DownloadReelLocally;
this.optionButtonController.DeletePictureRequested += DeleteReel;
}
}
private void DeleteReel(CameraReelResponseCompact response)
{
ShowDeleteModal();
reelToDelete = response;
}
private void DownloadReelLocally(CameraReelResponseCompact response)
{
async UniTaskVoid DownloadAndOpenAsync(CancellationToken ct)
{
try
{
await ReelCommonActions.DownloadReelToFileAsync(response.url, ct);
ScreenshotDownloaded?.Invoke();
view.cameraReelToastMessage?.ShowToastMessage(CameraReelToastMessageType.DOWNLOAD,
reelGalleryStringMessages?.PhotoSuccessfullyDownloadedMessage);
}
catch (Exception e)
{
ReportHub.LogException(e, new ReportData(ReportCategory.CAMERA_REEL));
view.cameraReelToastMessage?.ShowToastMessage(CameraReelToastMessageType.FAILURE);
}
}
downloadScreenshotCts = downloadScreenshotCts.SafeRestart();
DownloadAndOpenAsync(downloadScreenshotCts.Token).Forget();
}
private void CopyPictureLink(CameraReelResponseCompact response)
{
ReelCommonActions.CopyReelLink(response.id, decentralandUrlsSource!, systemClipboard!);
view.cameraReelToastMessage?.ShowToastMessage(CameraReelToastMessageType.SUCCESS, reelGalleryStringMessages?.LinkCopiedMessage);
}
private void ShareToX(CameraReelResponseCompact response)
{
ReelCommonActions.ShareReelToX(reelGalleryStringMessages?.ShareToXMessage, response.id, decentralandUrlsSource!, systemClipboard!, webBrowser!);
ScreenshotShared?.Invoke();
}
private void SetReelPublic(CameraReelResponseCompact response, bool isPublic)
{
async UniTaskVoid SetPublicFlagAsync(CancellationToken ct)
{
try
{
await cameraReelStorageService.UpdateScreenshotVisibilityAsync(response.id, isPublic, ct);
response.isPublic = isPublic;
view.cameraReelToastMessage?.ShowToastMessage(CameraReelToastMessageType.SUCCESS, reelGalleryStringMessages?.PhotoSuccessfullyUpdatedMessage);
}
catch (UnityWebRequestException e)
{
ReportHub.LogException(e, new ReportData(ReportCategory.CAMERA_REEL));
view.cameraReelToastMessage?.ShowToastMessage(CameraReelToastMessageType.FAILURE);
}
}
SetPublicFlagAsync(setPublicCts.Token).Forget();
}
private void ShowDeleteModal()
{
view.deleteReelModal.gameObject.SetActive(true);
view.deleteReelModal.DOFade(1f, view.deleteModalAnimationDuration);
}
private void HideDeleteModal(InputAction.CallbackContext callbackContext = default)
{
view.deleteReelModal.DOFade(0f, view.deleteModalAnimationDuration).OnComplete(() => view.deleteReelModal.gameObject.SetActive(false));
}
private void OnDeletionModalCancelClick(bool waitForAnimation = true)
{
async UniTaskVoid AnimateAndAwaitAsync()
{
await UniTask.Delay(ANIMATION_DELAY);
HideDeleteModal();
}
if (waitForAnimation)
AnimateAndAwaitAsync().Forget();
else
HideDeleteModal();
}
private void DeleteScreenshot()
{
async UniTaskVoid AnimateAndAwaitAsync()
{
await UniTask.Delay(ANIMATION_DELAY);
if (reelToDelete is not null)
DeleteScreenshotsAsync(new ReelToDeleteInfo(reelToDelete.id, reelToDelete.dateTime), deleteScreenshotCts.Token).Forget();
reelToDelete = null;
HideDeleteModal();
}
AnimateAndAwaitAsync().Forget();
}
private async UniTask DeleteScreenshotsAsync(ReelToDeleteInfo reelToDeleteInfo, CancellationToken ct = default)
{
try
{
CameraReelStorageStatus response = await cameraReelStorageService.DeleteScreenshotAsync(reelToDeleteInfo.Id, ct);
RemoveThumbnailFromList(reelToDeleteInfo.Id, reelToDeleteInfo.Datetime);
ScreenshotDeleted?.Invoke();
StorageUpdated?.Invoke(response);
view.cameraReelToastMessage?.ShowToastMessage(CameraReelToastMessageType.SUCCESS, reelGalleryStringMessages?.PhotoSuccessfullyDeletedMessage);
}
catch (UnityWebRequestException e)
{
ReportHub.LogException(e, new ReportData(ReportCategory.CAMERA_REEL));
view.cameraReelToastMessage?.ShowToastMessage(CameraReelToastMessageType.FAILURE);
}
}
private void HideReelFromList(CameraReelResponseCompact reelToHide)
{
if (reelToHide != null)
RemoveThumbnailFromList(reelToHide.id, reelToHide.dateTime);
}
private void RemoveThumbnailFromList(string reelId, string dateTime)
{
int indexToRemove = -1;
for (int i = 0; i < currentSize; i++)
{
if (indexToRemove >= 0)
{
thumbnailImages[i - 1] = thumbnailImages[i];
}
else if (thumbnailImages[i].CameraReelResponse.id == reelId)
{
indexToRemove = i;
}
}
thumbnailImages[currentSize - 1] = null;
currentSize--;
ResetThumbnailsVisibility();
MonthGridController monthGridView = GetMonthGrid(ReelUtility.GetMonthDateTimeFromString(dateTime));
monthGridView.RemoveThumbnail(reelId);
if (monthGridView.GridIsEmpty())
{
monthViews.Remove(monthGridView.DateTimeBucket);
ReleaseGridView(monthGridView);
}
pagedCameraReelManager.RemoveReelId(reelId);
if(currentSize <= 0)
view.emptyState.SetActive(true);
}
private void OnReelPublicStateChange(string reelId, bool isPublic)
{
foreach (var thumbnail in pagedCameraReelManager.AllOrderedResponses)
{
if(thumbnail.id != reelId) continue;
thumbnail.isPublic = isPublic;
return;
}
}
private void PrepareShowGallery(CancellationToken ct)
{
view.loadingSpinner.SetActive(true);
view.emptyState.SetActive(false);
loadNextPageCts = loadNextPageCts.SafeRestartLinked(ct);
setPublicCts = setPublicCts.SafeRestart();
deleteScreenshotCts = deleteScreenshotCts.SafeRestart();
view.scrollRect.verticalNormalizedPosition = 1f;
previousY = 1f;
}
private void FinishShowGallery()
{
view.scrollRect.onValueChanged.AddListener(OnScrollRectValueChanged);
view.loadingSpinner.SetActive(false);
galleryEventBus.ReelPublicStateChangeEvent += OnReelPublicStateChange;
}
public async UniTask ShowWalletGalleryAsync(string walletAddress, CancellationToken ct, CameraReelStorageStatus? storageStatus = null)
{
PrepareShowGallery(ct);
storageStatus ??= await cameraReelStorageService.UnsignedGetUserGalleryStorageInfoAsync(walletAddress, ct);
if (storageStatus.Value.ScreenshotsAmount == 0)
{
view.emptyState.SetActive(true);
FinishShowGallery();
return;
}
pagedCameraReelManager = new PagedCameraReelManager(cameraReelStorageService, new PagedCameraReelManagerParameters(walletAddress, useSignedRequest), storageStatus.Value.ScreenshotsAmount, view.PaginationLimit);
thumbnailImages = new ReelThumbnailController[storageStatus.Value.MaxScreenshots];
await LoadMorePageAsync(ct);
FinishShowGallery();
}
public async UniTask ShowPlaceGalleryAsync(string placeId, CancellationToken ct)
{
PrepareShowGallery(ct);
CameraReelStorageStatus storageStatus = await cameraReelStorageService.GetPlaceGalleryStorageInfoAsync(placeId, ct);
pagedCameraReelManager = new PagedCameraReelManager(cameraReelStorageService, new PagedCameraReelManagerParameters(placeId), storageStatus.ScreenshotsAmount, view.PaginationLimit);
thumbnailImages = new ReelThumbnailController[storageStatus.MaxScreenshots];
await LoadMorePageAsync(ct);
FinishShowGallery();
}
public async UniTask ShowPlacesGalleryAsync(string[] placeIds, CancellationToken ct)
{
PrepareShowGallery(ct);
CameraReelStorageStatus storageStatus = await cameraReelStorageService.GetPlacesGalleryStorageInfoAsync(placeIds, ct);
if (storageStatus.MaxScreenshots == 0)
{
view.emptyState.SetActive(true);
FinishShowGallery();
return;
}
pagedCameraReelManager = new PagedCameraReelManager(cameraReelStorageService, new PagedCameraReelManagerParameters(placeIds), storageStatus.MaxScreenshots, view.PaginationLimit);
thumbnailImages = new ReelThumbnailController[storageStatus.MaxScreenshots];
await LoadMorePageAsync(ct);
FinishShowGallery();
}
private MonthGridController GetMonthGrid(DateTime dateTime)
{
MonthGridController monthGridView = null;
if (!reelGalleryConfigParams.GroupByMonth && monthViews.Count == 1)
foreach (MonthGridController controller in monthViews.Values)
monthGridView = controller;
else if (monthViews.TryGetValue(dateTime, out MonthGridController monthView))
monthGridView = monthView;
else
{
monthGridView = reelGalleryPoolManager.GetGridElement(view.scrollContentRect);
monthViews.Add(dateTime, monthGridView);
}
return monthGridView;
}
private async UniTask LoadMorePageAsync(CancellationToken ct)
{
isLoading = true;
Dictionary<DateTime, List<CameraReelResponseCompact>> result = await pagedCameraReelManager.FetchNextPageAsync(CAMERA_REEL_RESPONSES_POOL, ct);
foreach (var bucket in result)
{
MonthGridController monthGridView = GetMonthGrid(bucket.Key);
IReadOnlyList<ReelThumbnailController> thumbnailViews = monthGridView.Setup(bucket.Key, bucket.Value, optionButtonController,
(cameraReelResponse, sprite) => reelThumbnailCache.Add(cameraReelResponse, sprite),
cameraReelResponse =>
ThumbnailClicked?.Invoke(pagedCameraReelManager.AllOrderedResponses, pagedCameraReelManager.AllOrderedResponses.IndexOf(cameraReelResponse),
reelToDelete =>
{
this.reelToDelete = reelToDelete;
DeleteScreenshot();
},
HideReelFromList)
);
for (int i = 0; i < thumbnailViews.Count; i++)
thumbnailImages[currentSize + i] = thumbnailViews[i];
currentSize += thumbnailViews.Count;
CAMERA_REEL_RESPONSES_POOL.Release(bucket.Value);
}
MaxThumbnailsUpdated?.Invoke(currentSize);
DictionaryPool<DateTime, List<CameraReelResponseCompact>>.Release(result);
endVisible = currentSize - 1;
//ScrollRect gets updated in LateUpdate, therefore waiting for PostLateUpdate ensures that the layout has been correctly updated
await UniTask.Yield(PlayerLoopTiming.PostLateUpdate, ct);
HandleElementsVisibility(ScrollDirection.UP);
previousY = view.scrollRect.verticalNormalizedPosition;
isLoading = false;
}
private void ScrollBeginDrag() => isDragging = true;
private void ScrollEndDrag()
{
isDragging = false;
CheckNeedsToLoadMore();
}
private void OnScrollRectValueChanged(Vector2 value)
{
//Exclude visibility computation when scrolling over the top or bottom of the scroll rect due to elasticity
if (view.scrollRect is { verticalNormalizedPosition: >= 1f, velocity: { y: > 0f } } or { verticalNormalizedPosition: <= 0f, velocity: { y: < 0f } })
return;
HandleElementsVisibility(value.y > previousY ? ScrollDirection.UP : ScrollDirection.DOWN);
CheckNeedsToLoadMore();
previousY = value.y;
if (endVisible < beginVisible)
ResetThumbnailsVisibility();
}
private void ResetThumbnailsVisibility()
{
beginVisible = -1;
for (int i = 0; i < currentSize; i++)
if (ViewIntersectsImage(thumbnailImages[i].view.thumbnailImage))
{
if (beginVisible < 0)
beginVisible = i;
EnableThumbnailImage(thumbnailImages[i]);
endVisible = i;
} else
DisableThumbnailImage(thumbnailImages[i]);
//If no image is visible (achieved while scrolling against the scroll limit), set beginVisible to 0
if (beginVisible < 0)
beginVisible = 0;
}
private void CheckNeedsToLoadMore()
{
if (currentSize - endVisible < view.loadMoreCounterThreshold && !pagedCameraReelManager.AllImagesLoaded && !isLoading && !isDragging)
LoadMorePageAsync(loadNextPageCts.Token).Forget();
}
private void DisableThumbnailImage(ReelThumbnailController thumbnailController)
{
thumbnailController.view.thumbnailImage.texture = null;
thumbnailController.view.thumbnailImage.enabled = false;
}
private void EnableThumbnailImage(ReelThumbnailController thumbnailController)
{
if (reelThumbnailCache.TryGetValue(thumbnailController.CameraReelResponse, out Texture sprite))
thumbnailController.view.thumbnailImage.texture = sprite;
thumbnailController.view.thumbnailImage.enabled = true;
}
private void HandleElementsVisibility(ScrollDirection scrollDirection)
{
if (currentSize == 0) return;
if (scrollDirection == ScrollDirection.UP)
{
while (beginVisible >= 0 && ViewIntersectsImage(thumbnailImages[beginVisible].view.thumbnailImage))
beginVisible--;
beginVisible++;
beginVisible = Mathf.Clamp(beginVisible, 0, currentSize - 1);
while (endVisible >= 0 && !ViewIntersectsImage(thumbnailImages[endVisible].view.thumbnailImage))
endVisible--;
endVisible = Mathf.Clamp(endVisible, 0, currentSize - 1);
}
else
{
while (endVisible < currentSize && ViewIntersectsImage(thumbnailImages[endVisible].view.thumbnailImage))
endVisible++;
endVisible--;
endVisible = Mathf.Clamp(endVisible, 0, currentSize - 1);
while (beginVisible < currentSize && !ViewIntersectsImage(thumbnailImages[beginVisible].view.thumbnailImage))
beginVisible++;
beginVisible = Mathf.Clamp(beginVisible, 0, currentSize - 1);
}
for (int i = 0; i < beginVisible; i++)
if (thumbnailImages[i].view.thumbnailImage.enabled)
DisableThumbnailImage(thumbnailImages[i]);
for (int i = beginVisible; i <= endVisible; i++)
if (!thumbnailImages[i].view.thumbnailImage.enabled)
EnableThumbnailImage(thumbnailImages[i]);
for (int i = endVisible + 1; i < currentSize; i++)
if (thumbnailImages[i].view.thumbnailImage.enabled)
DisableThumbnailImage(thumbnailImages[i]);
}
private bool ViewIntersectsImage(RawImage image)
{
var img = image.rectTransform.GetWorldRect();
return img.yMax >= elementMaskRect.yMin && img.yMin < elementMaskRect.yMax;
}
private void ReleaseGridView(MonthGridController monthGridView)
{
monthGridView.Release();
reelGalleryPoolManager.ReleaseGridElement(monthGridView);
}
private void ReleaseGridViews()
{
foreach (MonthGridController monthGridView in monthViews.Values)
ReleaseGridView(monthGridView);
}
private void OnDisable()
{
ReleaseGridViews();
monthViews.Clear();
foreach (KeyValuePair<CameraReelResponseCompact, Texture> row in reelThumbnailCache)
GameObject.Destroy(row.Value);
reelThumbnailCache.Clear();
beginVisible = 0;
endVisible = 0;
currentSize = 0;
thumbnailImages = null;
view.scrollRect.onValueChanged.RemoveListener(OnScrollRectValueChanged);
loadNextPageCts.SafeCancelAndDispose();
setPublicCts.SafeCancelAndDispose();
deleteScreenshotCts.SafeCancelAndDispose();
HideDeleteModal();
optionButtonController?.HideControl();
galleryEventBus.ReelPublicStateChangeEvent -= OnReelPublicStateChange;
}
public void Dispose()
{
OnDisable();
view.Disable -= OnDisable;
ThumbnailClicked = null;
StorageUpdated = null;
ScreenshotDeleted = null;
view.cancelDeleteIntentButton?.onClick.RemoveAllListeners();
view.cancelDeleteIntentBackgroundButton?.onClick.RemoveAllListeners();
downloadScreenshotCts.SafeCancelAndDispose();
optionButtonController?.Dispose();
if (this.optionButtonController != null)
{
this.optionButtonController.SetPublicRequested -= SetReelPublic;
this.optionButtonController.ShareToXRequested -= ShareToX;
this.optionButtonController.CopyPictureLinkRequested -= CopyPictureLink;
this.optionButtonController.DownloadRequested -= DownloadReelLocally;
this.optionButtonController.DeletePictureRequested -= DeleteReel;
}
}
}
public struct ReelGalleryStringMessages
{
public readonly string? ShareToXMessage;
public readonly string? PhotoSuccessfullyDeletedMessage;
public readonly string? PhotoSuccessfullyUpdatedMessage;
public readonly string? PhotoSuccessfullyDownloadedMessage;
public readonly string? LinkCopiedMessage;
public ReelGalleryStringMessages(string? shareToXMessage, string? photoSuccessfullyDeletedMessage, string? photoSuccessfullyUpdatedMessage, string? photoSuccessfullyDownloadedMessage, string? linkCopiedMessage)
{
ShareToXMessage = shareToXMessage;
PhotoSuccessfullyDeletedMessage = photoSuccessfullyDeletedMessage;
PhotoSuccessfullyUpdatedMessage = photoSuccessfullyUpdatedMessage;
PhotoSuccessfullyDownloadedMessage = photoSuccessfullyDownloadedMessage;
LinkCopiedMessage = linkCopiedMessage;
}
}
public struct ReelGalleryConfigParams
{
public readonly int GridLayoutFixedColumnCount;
public readonly int ThumbnailHeight;
public readonly int ThumbnailWidth;
public readonly bool GridShowMonth;
public readonly bool GroupByMonth;
public ReelGalleryConfigParams(int gridLayoutFixedColumnCount, int thumbnailHeight, int thumbnailWidth, bool gridShowMonth, bool groupByMonth)
{
GridLayoutFixedColumnCount = gridLayoutFixedColumnCount;
ThumbnailHeight = thumbnailHeight;
ThumbnailWidth = thumbnailWidth;
GridShowMonth = gridShowMonth;
GroupByMonth = groupByMonth;
}
}
}