-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCommunityCardView.cs
More file actions
295 lines (250 loc) · 15.7 KB
/
Copy pathCommunityCardView.cs
File metadata and controls
295 lines (250 loc) · 15.7 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
using Cysharp.Threading.Tasks;
using DCL.Communities.CommunitiesCard.Events;
using DCL.Communities.CommunitiesCard.Members;
using DCL.Communities.CommunitiesCard.Photos;
using DCL.Communities.CommunitiesCard.Places;
using DCL.Diagnostics;
using DCL.UI;
using DCL.UI.GenericContextMenu;
using DCL.UI.GenericContextMenu.Controls.Configs;
using DCL.UI.GenericContextMenuParameter;
using DCL.UI.Profiles.Helpers;
using DCL.Utilities.Extensions;
using MVC;
using System;
using System.Threading;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Utility;
using Utility.Types;
namespace DCL.Communities.CommunitiesCard
{
public class CommunityCardView : ViewBase, IView
{
private const string COMMUNITY_MEMBERS_NUMBER_FORMAT = "<b>{0}</b> Members";
private const string LEAVE_COMMUNITY_TEXT_FORMAT = "Are you sure you want to leave '{0}'?";
private const string LEAVE_COMMUNITY_CONFIRM_TEXT = "YES";
private const string LEAVE_COMMUNITY_CANCEL_TEXT = "NO";
private const string DELETE_COMMUNITY_TEXT_FORMAT = "Are you sure you want to delete [{0}] Community?";
private const string DELETE_COMMUNITY_CONFIRM_TEXT = "CONTINUE";
private const string DELETE_COMMUNITY_CANCEL_TEXT = "CANCEL";
public enum Sections
{
PHOTOS,
MEMBERS,
PLACES,
}
[Serializable]
public struct CameraReelGalleryConfig
{
public PhotosView PhotosView;
public int GridLayoutFixedColumnCount;
public int ThumbnailHeight;
public int ThumbnailWidth;
}
public event Action<Sections>? SectionChanged;
public event Action? OpenWizardRequested;
public event Action? OpenChatRequested;
public event Action? JoinCommunity;
public event Action? LeaveCommunityRequested;
public event Action? DeleteCommunityRequested;
[field: Header("References")]
[field: SerializeField] private Button closeButton { get; set; }
[field: SerializeField] private Button backgroundCloseButton { get; set; }
[field: SerializeField] private GameObject loadingObject { get; set; }
[field: SerializeField] private Image backgroundImage { get; set; }
[field: SerializeField] public Color BackgroundColor { get; private set; }
[field: SerializeField] private ConfirmationDialogView confirmationDialogView { get; set; }
[field: SerializeField] internal WarningNotificationView warningNotificationView { get; set; }
[field: SerializeField] internal WarningNotificationView successNotificationView { get; set; }
[field: SerializeField] private Sprite defaultCommunityImage { get; set; }
[field: SerializeField] private Sprite deleteCommunityImage { get; set; }
[field: SerializeField] private CommunityCardContextMenuConfiguration contextMenuSettings { get; set; }
[field: Header("Community interactions")]
[field: SerializeField] private Button openChatButton { get; set; }
[field: SerializeField] private Button openWizardButton { get; set; }
[field: SerializeField] private Button openContextMenuButton { get; set; }
[field: SerializeField] private Button joinedButton { get; set; }
[field: SerializeField] private Button joinButton { get; set; }
[field: Header("Community data references")]
[field: SerializeField] private TMP_Text communityName { get; set; }
[field: SerializeField] private TMP_Text communityMembersNumber { get; set; }
[field: SerializeField] private TMP_Text communityDescription { get; set; }
[field: SerializeField] public ImageView CommunityThumbnail { get; private set; }
[field: Header("-- Sections")]
[field: Header("Buttons")]
[field: SerializeField] private Button photosButton { get; set; }
[field: SerializeField] private Button membersButton { get; set; }
[field: SerializeField] private Button placesButton { get; set; }
[field: SerializeField] private Button placesWithSignButton { get; set; }
[field: SerializeField] private Button placesShortcutButton { get; set; }
[field: SerializeField] private Button membersTextButton { get; set; }
[field: Header("Selections")]
[field: SerializeField] private GameObject photosSectionSelection { get; set; }
[field: SerializeField] private GameObject membersSectionSelection { get; set; }
[field: SerializeField] private GameObject placesSectionSelection { get; set; }
[field: SerializeField] private GameObject placesWithSignSectionSelection { get; set; }
[field: Header("Sections views")]
[field: SerializeField] public CameraReelGalleryConfig CameraReelGalleryConfigs { get; private set; }
[field: SerializeField] public MembersListView MembersListView { get; private set; }
[field: SerializeField] public PlacesSectionView PlacesSectionView { get; private set; }
[field: SerializeField] public EventListView EventListView { get; private set; }
private readonly UniTask[] closingTasks = new UniTask[3];
private CancellationTokenSource confirmationDialogCts = new ();
private GenericContextMenu contextMenu;
private GenericContextMenuElement leaveCommunityContextMenuElement;
private GenericContextMenuElement deleteCommunityContextMenuElement;
private CancellationToken cancellationToken;
private void Awake()
{
openWizardButton.onClick.AddListener(() => OpenWizardRequested?.Invoke());
openChatButton.onClick.AddListener(() => OpenChatRequested?.Invoke());
openContextMenuButton.onClick.AddListener(OpenContextMenu);
joinButton.onClick.AddListener(() => JoinCommunity?.Invoke());
joinedButton.onClick.AddListener(ShowLeaveConfirmationDialog);
photosButton.onClick.AddListener(() => ToggleSection(Sections.PHOTOS));
membersButton.onClick.AddListener(() => ToggleSection(Sections.MEMBERS));
membersTextButton.onClick.AddListener(() => ToggleSection(Sections.MEMBERS));
placesButton.onClick.AddListener(() => ToggleSection(Sections.PLACES));
placesWithSignButton.onClick.AddListener(() => ToggleSection(Sections.PLACES));
placesShortcutButton.onClick.AddListener(() => OpenWizardRequested?.Invoke());
contextMenu = new GenericContextMenu(contextMenuSettings.ContextMenuWidth,
offsetFromTarget: contextMenuSettings.OffsetFromTarget,
verticalLayoutPadding: contextMenuSettings.VerticalPadding,
elementsSpacing: contextMenuSettings.ElementsSpacing,
anchorPoint: ContextMenuOpenDirection.BOTTOM_LEFT)
.AddControl(leaveCommunityContextMenuElement = new GenericContextMenuElement(
new ButtonContextMenuControlSettings(contextMenuSettings.LeaveCommunityText, contextMenuSettings.LeaveCommunitySprite, ShowLeaveConfirmationDialog)))
.AddControl(deleteCommunityContextMenuElement = new GenericContextMenuElement(
new ButtonContextMenuControlSettings(contextMenuSettings.DeleteCommunityText, contextMenuSettings.DeleteCommunitySprite, OnDeleteCommunityRequested,
textColor: contextMenuSettings.DeleteCommunityTextColor, iconColor: contextMenuSettings.DeleteCommunityTextColor)));
}
public void SetConfirmationDialogDependencies(ProfileRepositoryWrapper profileRepositoryWrapper)
{
confirmationDialogView.SetProfileRepository(profileRepositoryWrapper);
}
private void OnDeleteCommunityRequested()
{
confirmationDialogCts = confirmationDialogCts.SafeRestart();
ShowDeleteConfirmationDialogAsync(confirmationDialogCts.Token).Forget();
return;
async UniTask ShowDeleteConfirmationDialogAsync(CancellationToken ct)
{
Result<ConfirmationDialogView.ConfirmationResult> dialogResult = await confirmationDialogView.ShowConfirmationDialogAsync(
new ConfirmationDialogView.DialogData(string.Format(DELETE_COMMUNITY_TEXT_FORMAT, communityName.text),
DELETE_COMMUNITY_CANCEL_TEXT,
DELETE_COMMUNITY_CONFIRM_TEXT,
deleteCommunityImage,
false, false),
ct)
.SuppressToResultAsync(ReportCategory.COMMUNITIES);
if (!dialogResult.Success || dialogResult.Value == ConfirmationDialogView.ConfirmationResult.CANCEL) return;
DeleteCommunityRequested?.Invoke();
}
}
public void SetPanelCancellationToken(CancellationToken cancellationToken)
{
this.cancellationToken = cancellationToken;
}
private void OpenContextMenu()
{
openContextMenuButton.interactable = false;
ViewDependencies.ContextMenuOpener.OpenContextMenu(new GenericContextMenuParameter(contextMenu, openContextMenuButton.transform.position,
actionOnHide: () => openContextMenuButton.interactable = true), cancellationToken);
}
private void OnDisable()
{
confirmationDialogCts.SafeCancelAndDispose();
}
private void ShowLeaveConfirmationDialog()
{
confirmationDialogCts = confirmationDialogCts.SafeRestart();
ShowLeaveConfirmationDialogAsync(confirmationDialogCts.Token).Forget();
return;
async UniTask ShowLeaveConfirmationDialogAsync(CancellationToken ct)
{
Result<ConfirmationDialogView.ConfirmationResult> dialogResult = await confirmationDialogView.ShowConfirmationDialogAsync(
new ConfirmationDialogView.DialogData(string.Format(LEAVE_COMMUNITY_TEXT_FORMAT, communityName.text),
LEAVE_COMMUNITY_CANCEL_TEXT,
LEAVE_COMMUNITY_CONFIRM_TEXT,
CommunityThumbnail.ImageSprite,
true, true),
ct)
.SuppressToResultAsync(ReportCategory.COMMUNITIES);
if (!dialogResult.Success || dialogResult.Value == ConfirmationDialogView.ConfirmationResult.CANCEL) return;
LeaveCommunityRequested?.Invoke();
}
}
public UniTask[] GetClosingTasks(UniTask controllerTask, CancellationToken ct)
{
closingTasks[0] = closeButton.OnClickAsync(ct);
closingTasks[1] = backgroundCloseButton.OnClickAsync(ct);
closingTasks[2] = controllerTask;
return closingTasks;
}
public void SetCardBackgroundColor(Color color, int shaderProperty)
{
Color.RGBToHSV(color, out float h, out float s, out float v);
backgroundImage.material.SetColor(shaderProperty, Color.HSVToRGB(h, s, Mathf.Clamp01(v - 0.3f)));
}
public void ResetToggle(bool invokeEvent) =>
ToggleSection(Sections.MEMBERS, invokeEvent);
public void SetLoadingState(bool isLoading)
{
communityName.enabled = !isLoading;
communityMembersNumber.enabled = !isLoading;
communityDescription.enabled = !isLoading;
EventListView.SetLoadingStateActive(isLoading);
loadingObject.SetActive(isLoading);
}
private void ToggleSection(Sections section, bool invokeEvent = true)
{
photosSectionSelection.SetActive(section == Sections.PHOTOS);
membersSectionSelection.SetActive(section == Sections.MEMBERS);
placesSectionSelection.SetActive(section == Sections.PLACES);
placesWithSignSectionSelection.SetActive(section == Sections.PLACES);
CameraReelGalleryConfigs.PhotosView.SetActive(section == Sections.PHOTOS);
MembersListView.SetActive(section == Sections.MEMBERS);
PlacesSectionView.SetActive(section == Sections.PLACES);
if (invokeEvent)
SectionChanged?.Invoke(section);
}
public void ConfigureInteractionButtons(CommunityMemberRole role)
{
openChatButton.gameObject.SetActive(role is CommunityMemberRole.owner or CommunityMemberRole.moderator or CommunityMemberRole.member);
openWizardButton.gameObject.SetActive(role is CommunityMemberRole.owner or CommunityMemberRole.moderator);
openContextMenuButton.gameObject.SetActive(role is CommunityMemberRole.owner or CommunityMemberRole.moderator);
joinedButton.gameObject.SetActive(role is CommunityMemberRole.member);
joinButton.gameObject.SetActive(role == CommunityMemberRole.none);
}
public void SetDefaults(ImageController imageController)
{
imageController.SetImage(defaultCommunityImage);
communityName.text = string.Empty;
communityMembersNumber.text = string.Empty;
communityDescription.text = string.Empty;
openChatButton.gameObject.SetActive(false);
openWizardButton.gameObject.SetActive(false);
openContextMenuButton.gameObject.SetActive(false);
joinedButton.gameObject.SetActive(false);
joinButton.gameObject.SetActive(false);
placesWithSignButton.gameObject.SetActive(false);
placesButton.gameObject.SetActive(true);
}
public void ConfigureCommunity(GetCommunityResponse.CommunityData communityData,
ImageController imageController)
{
communityName.text = communityData.name;
communityMembersNumber.text = string.Format(COMMUNITY_MEMBERS_NUMBER_FORMAT, CommunitiesUtility.NumberToCompactString(communityData.membersCount));
communityDescription.text = communityData.description;
if (communityData.thumbnails != null)
imageController.RequestImage(communityData.thumbnails.Value.raw);
deleteCommunityContextMenuElement.Enabled = communityData.role == CommunityMemberRole.owner;
leaveCommunityContextMenuElement.Enabled = communityData.role == CommunityMemberRole.moderator;
ConfigureInteractionButtons(communityData.role);
placesWithSignButton.gameObject.SetActive(communityData.role is CommunityMemberRole.owner or CommunityMemberRole.moderator);
placesButton.gameObject.SetActive(!placesWithSignButton.gameObject.activeSelf);
}
}
}