public LastSeenViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { EventAggregator.Subscribe(this); _rules = StateService.PrivacyRules; StateService.PrivacyRules = null; MainRules = new List <TLPrivacyRuleBase> { new TLPrivacyValueAllowAll { Label = AppResources.Everybody.ToLowerInvariant() }, new TLPrivacyValueAllowContacts { Label = AppResources.MyContacts.ToLowerInvariant() }, new TLPrivacyValueDisallowAll { Label = AppResources.Nobody.ToLowerInvariant() } }; _selectedMainRule = GetSelectedMainRule(MainRules, _rules, MainRules[0], MainRules[2]); _selectedAllowUsers = GetSelectedRule <TLPrivacyValueAllowUsers>(_rules) ?? new TLPrivacyValueAllowUsers { Users = new TLVector <TLInt>() }; _selectedDisallowUsers = GetSelectedRule <TLPrivacyValueDisallowUsers>(_rules) ?? new TLPrivacyValueDisallowUsers { Users = new TLVector <TLInt>() }; SwitchUsersVisibility(true); PropertyChanged += OnPropertyChanged; }
public CameraViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _settings = StateService.GetCameraSettings(); MainRules = new List <TLPrivacyRuleBase> { new TLPrivacyValueAllowAll { Label = AppResources.InAppCamera }, new TLPrivacyValueAllowContacts { Label = AppResources.ExternalCamera } }; _selectedMainRule = _settings.External ? MainRules[1] : MainRules[0]; _selectedMainRule.IsChecked = true; PropertyChanged += OnPropertyChanged; }
private void UpdateLastSeenString(TLPrivacyRules rules) { _privacyRules = rules; TLPrivacyRuleBase mainRule = null; var mainRuleString = string.Empty; var minusCount = 0; var plusCount = 0; foreach (var rule in rules.Rules) { if (rule is TLPrivacyValueAllowAll) { mainRule = rule; mainRuleString = AppResources.Everybody; } if (rule is TLPrivacyValueAllowContacts) { mainRule = rule; mainRuleString = AppResources.MyContacts; } if (rule is TLPrivacyValueDisallowAll) { mainRule = rule; mainRuleString = AppResources.Nobody; } if (rule is TLPrivacyValueDisallowUsers) { minusCount += ((TLPrivacyValueDisallowUsers)rule).Users.Count; } if (rule is TLPrivacyValueAllowUsers) { plusCount += ((TLPrivacyValueAllowUsers)rule).Users.Count; } } if (mainRule == null) { mainRule = new TLPrivacyValueDisallowAll(); mainRuleString = AppResources.Nobody; } var countStrings = new List <string>(); if (minusCount > 0) { countStrings.Add("-" + minusCount); } if (plusCount > 0) { countStrings.Add("+" + plusCount); } if (countStrings.Count > 0) { mainRuleString += string.Format(" ({0})", string.Join(", ", countStrings)); } LastSeenSubtitle = mainRuleString.ToLowerInvariant(); }
private TLPrivacyRuleBase GetSelectedMainRule(List <TLPrivacyRuleBase> mainRules, TLPrivacyRules rules, TLPrivacyRuleBase defaultRule, TLPrivacyRuleBase noRules) { if (rules == null) { } else { foreach (var rule in rules.Rules) { var mainRule = mainRules.FirstOrDefault(x => x.GetType() == rule.GetType()); if (mainRule != null) { return(mainRule); } } return(noRules); } return(defaultRule); }
private string GetPrivacyString(TLPrivacyRules rules, out TLPrivacyRules currentRules) { currentRules = rules; TLPrivacyRuleBase mainRule = null; var mainRuleString = string.Empty; var minusCount = 0; var plusCount = 0; foreach (var rule in rules.Rules) { if (rule is TLPrivacyValueAllowAll) { mainRule = rule; mainRuleString = AppResources.Everybody; } if (rule is TLPrivacyValueAllowContacts) { mainRule = rule; mainRuleString = AppResources.MyContacts; } if (rule is TLPrivacyValueDisallowAll) { mainRule = rule; mainRuleString = AppResources.Nobody; } if (rule is TLPrivacyValueDisallowUsers) { minusCount += ((TLPrivacyValueDisallowUsers)rule).Users.Count; } if (rule is TLPrivacyValueAllowUsers) { plusCount += ((TLPrivacyValueAllowUsers)rule).Users.Count; } } if (mainRule == null) { mainRule = new TLPrivacyValueDisallowAll(); mainRuleString = AppResources.Nobody; } var countStrings = new List <string>(); if (minusCount > 0) { countStrings.Add("-" + minusCount); } if (plusCount > 0) { countStrings.Add("+" + plusCount); } if (countStrings.Count > 0) { mainRuleString += string.Format(" ({0})", string.Join(", ", countStrings)); } return(mainRuleString); }