| | 1 | | using DCL.Browser; |
| | 2 | | using DCL.SettingsCommon; |
| | 3 | | using System; |
| | 4 | |
|
| | 5 | | namespace DCL.MyAccount |
| | 6 | | { |
| | 7 | | public class MyAccountCardController |
| | 8 | | { |
| | 9 | | private const string OPEN_PASSPORT_SOURCE = "ProfileHUD"; |
| | 10 | | private const string URL_TERMS_OF_USE = "https://decentraland.org/terms"; |
| | 11 | | private const string URL_PRIVACY_POLICY = "https://decentraland.org/privacy"; |
| | 12 | |
|
| | 13 | | private readonly IMyAccountCardComponentView view; |
| | 14 | | private readonly DataStore dataStore; |
| | 15 | | private readonly IUserProfileBridge userProfileBridge; |
| | 16 | | private readonly Settings settings; |
| | 17 | | private readonly IBrowserBridge browserBridge; |
| | 18 | |
|
| 11 | 19 | | public MyAccountCardController( |
| | 20 | | IMyAccountCardComponentView view, |
| | 21 | | DataStore dataStore, |
| | 22 | | IUserProfileBridge userProfileBridge, |
| | 23 | | Settings settings, |
| | 24 | | IBrowserBridge browserBridge) |
| | 25 | | { |
| 11 | 26 | | this.view = view; |
| 11 | 27 | | this.dataStore = dataStore; |
| 11 | 28 | | this.userProfileBridge = userProfileBridge; |
| 11 | 29 | | this.settings = settings; |
| 11 | 30 | | this.browserBridge = browserBridge; |
| | 31 | |
|
| 11 | 32 | | view.OnPreviewProfileClicked += OnPreviewProfileClicked; |
| 11 | 33 | | view.OnAccountSettingsClicked += OnAccountSettingsClicked; |
| 11 | 34 | | view.OnSignOutClicked += OnSignOutClicked; |
| 11 | 35 | | view.OnTermsOfServiceClicked += OnTermsOfServiceClicked; |
| 11 | 36 | | view.OnPrivacyPolicyClicked += OnPrivacyPolicyClicked; |
| | 37 | |
|
| 11 | 38 | | userProfileBridge.GetOwn().OnUpdate += OnOwnUserProfileUpdate; |
| 11 | 39 | | bool isProfileInitialized = !string.IsNullOrEmpty(userProfileBridge.GetOwn().userId); |
| 11 | 40 | | if (isProfileInitialized) |
| 5 | 41 | | OnOwnUserProfileUpdate(userProfileBridge.GetOwn()); |
| 11 | 42 | | } |
| | 43 | |
|
| | 44 | | public void Dispose() |
| | 45 | | { |
| 11 | 46 | | view.OnPreviewProfileClicked -= OnPreviewProfileClicked; |
| 11 | 47 | | view.OnAccountSettingsClicked -= OnAccountSettingsClicked; |
| 11 | 48 | | view.OnSignOutClicked -= OnSignOutClicked; |
| 11 | 49 | | view.OnTermsOfServiceClicked -= OnTermsOfServiceClicked; |
| 11 | 50 | | view.OnPrivacyPolicyClicked -= OnPrivacyPolicyClicked; |
| 11 | 51 | | userProfileBridge.GetOwn().OnUpdate -= OnOwnUserProfileUpdate; |
| 11 | 52 | | } |
| | 53 | |
|
| | 54 | | private void OnOwnUserProfileUpdate(UserProfile userProfile) |
| | 55 | | { |
| 5 | 56 | | if (userProfile == null) |
| 0 | 57 | | return; |
| | 58 | |
|
| 5 | 59 | | view.SetSignOutButtonActive(!userProfile.isGuest); |
| 5 | 60 | | } |
| | 61 | |
|
| | 62 | | private void OnPreviewProfileClicked() |
| | 63 | | { |
| 1 | 64 | | dataStore.HUDs.currentPlayerId.Set((userProfileBridge.GetOwn().userId, OPEN_PASSPORT_SOURCE)); |
| 1 | 65 | | dataStore.exploreV2.profileCardIsOpen.Set(false); |
| 1 | 66 | | view.Hide(); |
| 1 | 67 | | } |
| | 68 | |
|
| | 69 | | private void OnAccountSettingsClicked() => |
| 1 | 70 | | dataStore.myAccount.myAccountSectionOpenFromProfileHUD.Set(true, true); |
| | 71 | |
|
| | 72 | | private void OnSignOutClicked() |
| | 73 | | { |
| 1 | 74 | | settings?.SaveSettings(); |
| 1 | 75 | | userProfileBridge.LogOut(); |
| 1 | 76 | | } |
| | 77 | |
|
| | 78 | | private void OnTermsOfServiceClicked() => |
| 1 | 79 | | browserBridge.OpenUrl(URL_TERMS_OF_USE); |
| | 80 | |
|
| | 81 | | private void OnPrivacyPolicyClicked() => |
| 1 | 82 | | browserBridge.OpenUrl(URL_PRIVACY_POLICY); |
| | 83 | | } |
| | 84 | | } |