private async void ResendMessageIfNeeded() { DateTime nowLocal = TimeZoneInfo.ConvertTimeFromUtc(SystemTime.Now(), TimeZoneInfo.Local); DateTime todayUtc = SystemTime.Now().Date; DateTime lastReceivedMessageDateTimeUtc = MessageUtils.GetDateTimeFromSecureStorageForKey(SecureStorageKeys.LAST_SENT_NOTIFICATION_UTC_KEY, nameof(ResendMessageIfNeeded)); DateTime lastReceivedMessageDateTimeLocal = lastReceivedMessageDateTimeUtc.ToLocalTime(); if (lastReceivedMessageDateTimeUtc < todayUtc && nowLocal.Date.Subtract(lastReceivedMessageDateTimeLocal.Date).TotalHours >= Conf.HOURS_UNTIL_RESEND_MESSAGES) { if (nowLocal.Hour >= Conf.HOUR_WHEN_MESSAGE_SHOULD_BE_RESEND) { List <MessageSQLiteModel> unreadMessages = await MessageUtils.GetAllUnreadMessages(); List <MessageSQLiteModel> unreadMessagesNotOlderThanMsgRetentionTime = unreadMessages.FindAll(message => { double totalMinutes = SystemTime.Now().Subtract(message.TimeStamp).TotalMinutes; return(totalMinutes < Conf.MAX_MESSAGE_RETENTION_TIME_IN_MINUTES); }) .ToList(); if (unreadMessagesNotOlderThanMsgRetentionTime.Count > 0) { NotificationsHelper.CreateNotification(NotificationsEnum.NewMessageReceived, 0); MessageUtils.SaveDateTimeToSecureStorageForKey( SecureStorageKeys.LAST_SENT_NOTIFICATION_UTC_KEY, SystemTime.Now(), nameof(ResendMessageIfNeeded)); } } } }
private async void Init() { MessagesViewModel.SubscribeMessages(this, ClearAndAddNewMessages); _messagesList = FindViewById <ListView>(Resource.Id.messages_list); _noItemsTextView = FindViewById <TextView>(Resource.Id.no_items_description); _lastUpdatedTextView = FindViewById <TextView>(Resource.Id.last_updated); _messagesList.Divider = null; _messagesList.DividerHeight = 0; TextView title = FindViewById <TextView>(Resource.Id.messages_page_title); title.Text = MessagesViewModel.MESSAGES_HEADER; title.SetAccessibilityDelegate(AccessibilityUtils.GetHeadingAccessibilityDelegate()); string headerText = MessagesViewModel.MESSAGES_NO_ITEMS_TITLE; int unreadMessages = (await MessageUtils.GetAllUnreadMessages()).Count; int messages = (await MessageUtils.GetMessages()).Count; if (unreadMessages > 0) { headerText = MessagesViewModel.MESSAGES_NEW_MESSAGES_HEADER; } else if (messages > 0) { headerText = MessagesViewModel.MESSAGES_NO_NEW_MESSAGES_HEADER; } TextView subheader = FindViewById <TextView>(Resource.Id.messages_page_sub_header); subheader.Text = headerText; subheader.SetAccessibilityDelegate(AccessibilityUtils.GetHeadingAccessibilityDelegate()); string lastUpdatedString = MessagesViewModel.LastUpdateString; if (lastUpdatedString == "") { _lastUpdatedTextView.Visibility = ViewStates.Gone; } else { _lastUpdatedTextView.Visibility = ViewStates.Visible; _lastUpdatedTextView.Text = MessagesViewModel.LastUpdateString; } _noItemsTextView.Text = MessagesViewModel.MESSAGES_NO_ITEMS_DESCRIPTION; _closeButton = FindViewById <ImageView>(Resource.Id.arrow_back); _closeButton.Click += new StressUtils.SingleClick(OnCloseBtnClicked).Run; _closeButton.ContentDescription = MessagesViewModel.MESSAGES_ACCESSIBILITY_CLOSE_BUTTON; _adapterMessages = new MessagesAdapter(this, new MessageItemViewModel[0]); _messagesList.Adapter = _adapterMessages; _messagesList.OnItemClickListener = new ItemClickListener(_adapterMessages); ShowList(false); }
public async void GetMarkAllAsReadShouldMarkAllMessagesAsRead() { MessageUtils.MarkAllAsRead(); List <MessageSQLiteModel> messagesAfterMark = await MessageUtils.GetAllUnreadMessages(); messagesAfterMark.Should().HaveCount(0); messagesAfterMark.All(message => message.IsRead).Should().BeTrue(); }
public async void GetAllUnreadShouldReturnTwoRecords() { var models = MessageUtils.ToMessageItemViewModelList(await MessageUtils.GetMessages()); MessageUtils.MarkAsRead(models[1], true); var messagesAfterMark = await MessageUtils.GetAllUnreadMessages(); messagesAfterMark.Should().HaveCount(2); messagesAfterMark.All(message => message.IsRead == false).Should().BeTrue(); }
async Task NewMessagesFetched() { List <MessageItemViewModel> orderedMessages = MessageUtils.ToMessageItemViewModelList((await MessageUtils.GetMessages()) .OrderByDescending(message => message.TimeStamp) .ToList()); if (orderedMessages.Any()) { _latestMessageDateTime = orderedMessages[0].TimeStamp; } List <MessageSQLiteModel> unreadMessagesResult = await MessageUtils.GetAllUnreadMessages(); ShowNewMessageIcon = unreadMessagesResult.Any(); NewMessagesIconVisibilityChanged?.Invoke(this, null); }
private async void SetStyling() { StyleUtil.InitLabelWithSpacing(Label, StyleUtil.FontType.FontBold, MESSAGES_HEADER, 0.8, 22, 34); StyleUtil.InitLabelWithSpacing(LabelLastUpdate, StyleUtil.FontType.FontRegular, LastUpdateString, 1.14, 15, 17, UITextAlignment.Left); int unreadMessages = (await MessageUtils.GetAllUnreadMessages()).Count; int messages = (await MessageUtils.GetMessages()).Count; string headerText = MESSAGES_NO_ITEMS_TITLE; if (unreadMessages > 0) { headerText = MESSAGES_NEW_MESSAGES_HEADER; } else if (messages > 0) { headerText = MESSAGES_NO_NEW_MESSAGES_HEADER; } StyleUtil.InitLabelWithSpacing(NoItemsLabel1, StyleUtil.FontType.FontBold, headerText, 1, 32, 34); StyleUtil.InitLabelWithSpacing(NoItemsLabel2, StyleUtil.FontType.FontRegular, MESSAGES_NO_ITEMS_DESCRIPTION, 1.25, 18, 20, UITextAlignment.Left); BackButton.AccessibilityLabel = SettingsViewModel.SETTINGS_CHILD_PAGE_ACCESSIBILITY_BACK_BUTTON; }