Skip to content

Commit

Permalink
fixing some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Noc2 committed Apr 10, 2018
1 parent 333efc2 commit a76f5b5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
13 changes: 11 additions & 2 deletions Chiota/Chiota.Android/Services/NotificationsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ private async Task<bool> LookForNewNotifications()
var contactApprovedList = await user.TangleMessenger.GetJsonMessageAsync<SentDataWrapper<Contact>>(user.ApprovedAddress);

// currently no messages for contact request due to perfomance issues
// show only one new message
var contactNotificationId = 0;
foreach (var contact in contactApprovedList.Where(c => !c.Data.Rejected))
{
var encryptedMessages = await user.TangleMessenger.GetMessagesAsync(contact.Data.ChatAdress);

foreach (var unused in encryptedMessages.Where(c => !c.Stored))
// don't send a reminder for every new message
if (encryptedMessages.Any(c => !c.Stored))
{
var intent = Application.Context.PackageManager.GetLaunchIntentForPackage(Application.Context.PackageName);
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);
var builder = new NotificationCompat.Builder(Application.Context)
.SetAutoCancel(true) // Dismiss from the notif. area when clicked
.SetContentIntent(pendingIntent)
.SetContentTitle(contact.Data.Name) // Set its title
.SetContentText("New Message from " + contact.Data.Name)
.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
.SetSmallIcon(Resource.Drawable.reminder);
var notification = builder.Build();
var notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
notificationManager?.Notify(0, notification);
notificationManager?.Notify(contactNotificationId, notification);
}

contactNotificationId++;
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions Chiota/Chiota/IOTAServices/RepositoryFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Chiota.IOTAServices
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using RestSharp;

Expand Down Expand Up @@ -51,8 +53,15 @@ private static bool NoteIsHealthy(IIotaNodeRepository node)
{
try
{
var nodeInfo = node.GetNodeInfo();
return nodeInfo.LatestMilestoneIndex == nodeInfo.LatestSolidSubtangleMilestoneIndex;
// Timeout after 5 seconds
var task = Task.Run(() => node.GetNodeInfo());
if (task.Wait(TimeSpan.FromSeconds(5)))
{
var nodeInfo = task.Result;
return nodeInfo.LatestMilestoneIndex == nodeInfo.LatestSolidSubtangleMilestoneIndex;
}

return false;
}
catch
{
Expand Down
3 changes: 1 addition & 2 deletions Chiota/Chiota/ViewModels/ChatViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public ChatViewModel(ListView messagesListView, Contact contact, User user)
this.user = user;
this.contact = contact;
this.messagesListView = messagesListView;
this.PageIsShown = true;
this.OutGoingText = null;

// reset hash short storage, because it's different for every chat
Expand Down Expand Up @@ -81,7 +80,7 @@ public ObservableCollection<MessageViewModel> Messages

public async void OnAppearing()
{
// cancel if there is no interent
this.PageIsShown = true;
this.contact.PublicNtruKey = await this.GetContactPublicKey();
if (this.contact.PublicNtruKey == null)
{
Expand Down
7 changes: 3 additions & 4 deletions Chiota/Chiota/Views/ChatPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ChatPage : ContentPage
{
private ChatViewModel vm;
private readonly ChatViewModel vm;

public ChatPage(Contact contact, User user)
{
Expand All @@ -34,15 +34,14 @@ public ChatPage(Contact contact, User user)

protected override void OnAppearing()
{
this.vm.OnAppearing();
this.vm?.OnAppearing();
base.OnAppearing();
}

protected override void OnDisappearing()
{
this.vm.PageIsShown = false;
this.vm = null;
this.Navigation.PopAsync();
base.OnDisappearing();
}

private void OnTextChanged(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Chiota/Chiota/Views/ContactPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ContentPage.Resources>

<AbsoluteLayout BackgroundColor="#f5f5f5" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout BackgroundColor="#f5f5f5">
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<SearchBar Placeholder="Search..."
PlaceholderColor="Gray"
TextChanged="Handler_TextChanged"/>
Expand Down

0 comments on commit a76f5b5

Please sign in to comment.