-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBlockedScreenController.cs
More file actions
96 lines (77 loc) · 3.2 KB
/
Copy pathBlockedScreenController.cs
File metadata and controls
96 lines (77 loc) · 3.2 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
using Cysharp.Threading.Tasks;
using DCL.Browser;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Utility;
using MVC;
using System;
using System.Globalization;
using System.Text;
using System.Threading;
namespace DCL.ApplicationGuards
{
public class BlockedScreenController : ControllerBase<BlockedScreenView, BlockedScreenParameters>
{
private const string DEFAULT_INFO_TEXT = "Contact Support for more information.";
private readonly UnityAppWebBrowser webBrowser;
private readonly StringBuilder infoTextBuilder = new ();
public override CanvasOrdering.SortingLayer Layer => CanvasOrdering.SortingLayer.OVERLAY;
public BlockedScreenController(ViewFactoryMethod viewFactory, UnityAppWebBrowser webBrowser) : base(viewFactory)
{
this.webBrowser = webBrowser;
}
protected override void OnViewInstantiated()
{
if (viewInstance != null)
{
viewInstance.CloseButton.onClick.AddListener(ExitUtils.Exit);
viewInstance.SupportButton.onClick.AddListener(OnSupportClicked);
}
}
protected override void OnBeforeViewShow()
{
infoTextBuilder.Clear();
if (inputData.BannedUserData != null && !string.IsNullOrEmpty(inputData.BannedUserData.expiresAt))
{
infoTextBuilder.Append("Ban period: ");
infoTextBuilder.Append(FormatRemainingBanTime(inputData.BannedUserData.expiresAt));
infoTextBuilder.Append(".");
infoTextBuilder.AppendLine();
infoTextBuilder.Append("Reason: ");
infoTextBuilder.Append(inputData.BannedUserData.reason);
infoTextBuilder.Append(".");
infoTextBuilder.AppendLine();
}
infoTextBuilder.Append(DEFAULT_INFO_TEXT);
viewInstance!.InfoText.text = infoTextBuilder.ToString();
}
public override void Dispose()
{
infoTextBuilder.Clear();
if (viewInstance == null)
return;
viewInstance.CloseButton.onClick.RemoveListener(ExitUtils.Exit);
viewInstance.SupportButton.onClick.RemoveListener(OnSupportClicked);
}
private void OnSupportClicked()
{
webBrowser.OpenUrlMainThreadOnly(DecentralandUrl.Help);
}
private static string FormatRemainingBanTime(string expiresAt)
{
if (!DateTime.TryParse(expiresAt, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTime expirationUtc))
return expiresAt;
TimeSpan remaining = expirationUtc - DateTime.UtcNow;
if (remaining.TotalSeconds <= 0)
return "expired";
var hours = (int)Math.Ceiling(remaining.TotalHours);
if (hours >= 24)
{
var days = (int)Math.Ceiling(remaining.TotalDays);
return days == 1 ? "1 day" : $"{days} days";
}
return hours <= 1 ? "1h" : $"{hours}h";
}
protected override UniTask WaitForCloseIntentAsync(CancellationToken ct) =>
UniTask.Never(ct);
}
}