protected void UpdateUserData() { if (!NetworkService.IsNetworkAvailable() || !Convert.ToBoolean(SdkService.MegaSdk.isLoggedIn())) { if (String.IsNullOrWhiteSpace(AccountDetails.UserName)) { Deployment.Current.Dispatcher.BeginInvoke(() => AccountDetails.Firstname = UiResources.MyAccount); } if (AccountDetails.AvatarColor == null || AccountDetails.AvatarColor.ToString().Equals("#00000000")) { AccountDetails.AvatarColor = (Color)Application.Current.Resources["MegaRedColor"]; } } else { bool accountChange = false; String currentEmail = SdkService.MegaSdk.getMyEmail(); if (currentEmail != null && currentEmail.Length != 0) { if (String.IsNullOrEmpty(AccountDetails.UserEmail)) { accountChange = true; } else if (!AccountDetails.UserEmail.Equals(SdkService.MegaSdk.getMyEmail())) { accountChange = true; } } if (accountChange) { AccountDetails.UserEmail = SdkService.MegaSdk.getMyEmail(); AccountService.AccountDetails.IsDataLoaded = false; } if (accountChange || AccountDetails.AvatarColor == null || AccountDetails.AvatarColor.ToString().Equals("#00000000") || AccountDetails.AvatarColor.Equals((Color)Application.Current.Resources["MegaRedColor"])) { AccountDetails.AvatarColor = UiService.GetColorFromHex(SdkService.MegaSdk.getUserAvatarColor(SdkService.MegaSdk.getMyUser())); } if (accountChange && (!String.IsNullOrEmpty(AccountDetails.AvatarPath) && AccountDetails.AvatarUri == null)) { SdkService.MegaSdk.getOwnUserAvatar(AccountDetails.AvatarPath, new GetUserAvatarRequestListener()); } if (accountChange || (String.IsNullOrEmpty(AccountDetails.Firstname) || AccountDetails.Firstname.Equals(UiResources.MyAccount))) { SdkService.MegaSdk.getOwnUserAttribute((int)MUserAttrType.USER_ATTR_FIRSTNAME, new GetUserDataRequestListener()); } if (accountChange || (String.IsNullOrEmpty(AccountDetails.Lastname))) { SdkService.MegaSdk.getOwnUserAttribute((int)MUserAttrType.USER_ATTR_LASTNAME, new GetUserDataRequestListener()); } } }
/// <summary> /// Check the password typed by the user /// </summary> private void CheckPassword(object obj) { if (string.IsNullOrWhiteSpace(this.passwordBox.Password)) { return; } this.passwordChecked = SdkService.MegaSdk.checkPassword(this.passwordBox.Password); if (!this.passwordChecked) { this.errorMessage.Text = AppMessages.AM_TestPasswordWarning; this.failedAttempts++; if (this.failedAttempts < MaxAttempts) { return; } // I user has exceeded the number of attempts, close // this dialog and show the "Change password" dialog this.CloseDialog(); DialogService.ShowChangePasswordDialog(); return; } this.dismissButton.Visibility = Visibility.Collapsed; this.errorMessage.Foreground = new SolidColorBrush(UiService.GetColorFromHex("#00C0A5")); this.errorMessage.Text = AppMessages.AM_TestPasswordSuccess; this.testPasswordButton.Command = this.CloseCommand; this.testPasswordButton.Content = this.atLogout ? UiResources.UI_Logout : UiResources.UI_Close; }
public ContactViewModel(MUser contact, ContactsListViewModel contactList) : base(SdkService.MegaSdk) { this.MegaUser = contact; this.ContactList = contactList; this.Handle = contact.getHandle(); this.Email = contact.getEmail(); this.Timestamp = contact.getTimestamp(); this.Visibility = contact.getVisibility(); this.AvatarColor = UiService.GetColorFromHex(this.MegaSdk.getUserAvatarColor(contact)); this.SharedItems = new ContactSharedItemsViewModel(contact); this.RemoveContactCommand = new RelayCommand(RemoveContact); this.ViewProfileCommand = new RelayCommand(ViewProfile); }
/// <summary> /// Check the password typed by the user /// </summary> private void CheckPassword() { if (string.IsNullOrWhiteSpace(this.Password)) { return; } this.ControlState = false; this.SecondaryButtonState = false; this.passwordChecked = SdkService.MegaSdk.checkPassword(this.Password); if (!this.passwordChecked) { this.ControlState = true; this.WarningColor = (SolidColorBrush)Application.Current.Resources["MegaRedColorBrush"]; this.WarningText = ResourceService.AppMessages.GetString("AM_TestPasswordWarning"); this.failedAttempts++; if (this.failedAttempts < MaxAttempts) { return; } // I user has exceeded the number of attempts, close // this dialog and show the "Change password" dialog this.OnHideDialog(); DialogService.ShowChangePasswordDialog(); return; } if (!this.AtLogout) { this.DialogStyle = (Style)Application.Current.Resources["MegaContentDialogStyle"]; } this.CloseButtonVisibility = Visibility.Collapsed; this.WarningColor = new SolidColorBrush(UiService.GetColorFromHex("#00C0A5")); this.WarningText = ResourceService.AppMessages.GetString("AM_TestPasswordSuccess"); this.SecondaryButtonCommand = this.CloseCommand; this.SecondaryButtonState = true; this.SecondaryButtonText = this.AtLogout ? ResourceService.UiResources.GetString("UI_Logout") : ResourceService.UiResources.GetString("UI_Close"); }
public ContactRequestViewModel(MContactRequest contactRequest, ContactRequestsListViewModel contactRequestsList) { MegaContactRequest = contactRequest; Handle = contactRequest.getHandle(); SourceEmail = contactRequest.getSourceEmail(); SourceMessage = contactRequest.getSourceMessage(); TargetEmail = contactRequest.getTargetEmail(); CreationTime = contactRequest.getCreationTime(); ModificationTime = contactRequest.getModificationTime(); Status = contactRequest.getStatus(); IsOutgoing = contactRequest.isOutgoing(); AvatarColor = UiService.GetColorFromHex( SdkService.MegaSdk.getUserHandleAvatarColor(Handle.ToString())); this.ContactRequestsList = contactRequestsList; this.AcceptContactRequestCommand = new RelayCommand(AcceptContact); this.IgnoreContactRequestCommand = new RelayCommand(IgnoreContact); this.DeclineContactRequestCommand = new RelayCommand(DeclineContact); this.RemindContactRequestCommand = new RelayCommand(RemindContact); this.CancelContactRequestCommand = new RelayCommand(CancelContact); }
public ContactViewModel(MUser contact, ContactsListViewModel contactList) : base(SdkService.MegaSdk) { this.MegaUser = contact; this.ContactList = contactList; if (contact != null) { this.Handle = contact.getHandle(); this.Email = contact.getEmail(); this.Timestamp = contact.getTimestamp(); this.Visibility = contact.getVisibility(); } else { LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "'MUser' of contact is NULL"); } this.AvatarColor = UiService.GetColorFromHex(this.MegaSdk.getUserAvatarColor(contact)); this.SharedItems = new ContactSharedItemsViewModel(contact); this.RemoveContactCommand = new RelayCommand(RemoveContact); this.ViewProfileCommand = new RelayCommand(ViewProfile); }
public void onUsersUpdate(MegaSDK api, MUserList users) { if (users == null || users.size() < 1) { return; } for (int i = 0; i < users.size(); i++) { MUser user = users.get(i); if (user == null) { continue; } // If the change is on the current user if (user.getHandle().Equals(api.getMyUser().getHandle()) && !Convert.ToBoolean(user.isOwnChange())) { if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_AVATAR) && !String.IsNullOrWhiteSpace(AccountService.AccountDetails.AvatarPath)) { api.getUserAvatar(user, AccountService.AccountDetails.AvatarPath, new GetUserAvatarRequestListener()); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_EMAIL)) { Deployment.Current.Dispatcher.BeginInvoke(() => AccountService.AccountDetails.UserEmail = user.getEmail()); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_FIRSTNAME)) { api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_FIRSTNAME, new GetUserDataRequestListener()); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_LASTNAME)) { api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_LASTNAME, new GetUserDataRequestListener()); } } else // If the change is on a contact { // If there are any ContactsViewModel active foreach (var contactViewModel in Contacts) { Contact existingContact = contactViewModel.MegaContactsList.FirstOrDefault( contact => contact.Handle.Equals(user.getHandle())); // If the contact exists in the contact list if (existingContact != null) { // If the contact is no longer a contact (REMOVE CONTACT SCENARIO) if (!existingContact.Visibility.Equals(user.getVisibility()) && !(user.getVisibility().Equals(MUserVisibility.VISIBILITY_VISIBLE))) { Deployment.Current.Dispatcher.BeginInvoke(() => contactViewModel.MegaContactsList.Remove(existingContact)); } // If the contact has been changed (UPDATE CONTACT SCENARIO) and is not an own change else if (!Convert.ToBoolean(user.isOwnChange())) { if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_AVATAR) && !String.IsNullOrWhiteSpace(existingContact.AvatarPath)) { api.getUserAvatar(user, existingContact.AvatarPath, new GetContactAvatarRequestListener(existingContact)); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_EMAIL)) { Deployment.Current.Dispatcher.BeginInvoke(() => existingContact.Email = user.getEmail()); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_FIRSTNAME)) { api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_FIRSTNAME, new GetContactDataRequestListener(existingContact)); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_LASTNAME)) { api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_LASTNAME, new GetContactDataRequestListener(existingContact)); } } } // If is a new contact (ADD CONTACT SCENARIO - REQUEST ACCEPTED) else if (user.getVisibility().Equals(MUserVisibility.VISIBILITY_VISIBLE)) { var _megaContact = new Contact() { Handle = user.getHandle(), Email = user.getEmail(), Timestamp = user.getTimestamp(), Visibility = user.getVisibility(), AvatarColor = UiService.GetColorFromHex(SdkService.MegaSdk.getUserAvatarColor(user)) }; Deployment.Current.Dispatcher.BeginInvoke(() => contactViewModel.MegaContactsList.Add(_megaContact)); api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_FIRSTNAME, new GetContactDataRequestListener(_megaContact)); api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_LASTNAME, new GetContactDataRequestListener(_megaContact)); api.getUserAvatar(user, _megaContact.AvatarPath, new GetContactAvatarRequestListener(_megaContact)); } } // If there are any ContactDetailsViewModel active foreach (var contactDetailsViewModel in ContactsDetails) { // If the selected contact has been changed (UPDATE CONTACT SCENARIO) if (contactDetailsViewModel.SelectedContact.Handle.Equals(user.getHandle())) { if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_AVATAR) && !String.IsNullOrWhiteSpace(contactDetailsViewModel.SelectedContact.AvatarPath)) { api.getUserAvatar(user, contactDetailsViewModel.SelectedContact.AvatarPath, new GetContactAvatarRequestListener(contactDetailsViewModel.SelectedContact)); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_EMAIL)) { Deployment.Current.Dispatcher.BeginInvoke(() => contactDetailsViewModel.SelectedContact.Email = user.getEmail()); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_FIRSTNAME)) { api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_FIRSTNAME, new GetContactDataRequestListener(contactDetailsViewModel.SelectedContact)); } if (user.hasChanged((int)MUserChangeType.CHANGE_TYPE_LASTNAME)) { api.getUserAttribute(user, (int)MUserAttrType.USER_ATTR_LASTNAME, new GetContactDataRequestListener(contactDetailsViewModel.SelectedContact)); } } } } } }
public void GetMegaContacts() { // User must be online to perform this operation if (!IsUserOnline()) { return; } // First cancel any other loading task that is busy CancelLoad(); // Create the option to cancel CreateLoadCancelOption(); SetEmptyContentTemplate(true); OnUiThread(() => MegaContactsList.Clear()); MUserList contactsList = this.MegaSdk.getContacts(); Task.Factory.StartNew(() => { try { Deployment.Current.Dispatcher.BeginInvoke(() => { for (int i = 0; i < contactsList.size(); i++) { // If the task has been cancelled, stop processing if (LoadingCancelToken.IsCancellationRequested) { LoadingCancelToken.ThrowIfCancellationRequested(); } // To avoid null values if (contactsList.get(i) == null) { continue; } if ((contactsList.get(i).getVisibility() == MUserVisibility.VISIBILITY_VISIBLE)) { var _megaContact = new Contact() { Handle = contactsList.get(i).getHandle(), Email = contactsList.get(i).getEmail(), Timestamp = contactsList.get(i).getTimestamp(), Visibility = contactsList.get(i).getVisibility(), AvatarColor = UiService.GetColorFromHex(SdkService.MegaSdk.getUserAvatarColor(contactsList.get(i))) }; MegaContactsList.Add(_megaContact); MegaSdk.getUserAttribute(contactsList.get(i), (int)MUserAttrType.USER_ATTR_FIRSTNAME, new GetContactDataRequestListener(_megaContact)); MegaSdk.getUserAttribute(contactsList.get(i), (int)MUserAttrType.USER_ATTR_LASTNAME, new GetContactDataRequestListener(_megaContact)); MegaSdk.getUserAvatar(contactsList.get(i), _megaContact.AvatarPath, new GetContactAvatarRequestListener(_megaContact)); } } SetEmptyContentTemplate(false); }); } catch (OperationCanceledException) { // Do nothing. Just exit this background process because a cancellation exception has been thrown } }, LoadingCancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Current); }
/// <summary> /// Gets the contact avatar color /// </summary> public void GetContactAvatarColor() { var avatarColor = UiService.GetColorFromHex(this.MegaSdk.getUserAvatarColor(this.MegaUser)); UiService.OnUiThread(() => this.AvatarColor = avatarColor); }