Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit dc6c03d

Browse files
committed
RepositoryExplore now has a loading screen
1 parent 93ab92b commit dc6c03d

3 files changed

Lines changed: 48 additions & 19 deletions

File tree

CodeHub.Core/ViewModels/Repositories/RepositoriesExploreViewModel.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,45 @@ public string SearchText
2929
set { _searchText = value; RaisePropertyChanged(() => SearchText); }
3030
}
3131

32+
private bool _isSearching;
33+
public bool IsSearching
34+
{
35+
get { return _isSearching; }
36+
private set
37+
{
38+
_isSearching = value;
39+
RaisePropertyChanged(() => IsSearching);
40+
}
41+
}
42+
3243
public ICommand GoToRepositoryCommand
3344
{
3445
get { return new MvxCommand<RepositorySearchModel.RepositoryModel>(x => ShowViewModel<RepositoryViewModel>(new RepositoryViewModel.NavObject { Username = x.Owner.Login, Repository = x.Name })); }
3546
}
3647

3748
public ICommand SearchCommand
3849
{
39-
get { return new MvxCommand(Search, () => !string.IsNullOrEmpty(SearchText)); }
50+
get { return new MvxCommand(() => Search(), () => !string.IsNullOrEmpty(SearchText)); }
4051
}
4152

42-
private async void Search()
53+
private async Task Search()
4354
{
4455
try
4556
{
46-
await Task.Run(() =>
47-
{
48-
var request = this.GetApplication().Client.Repositories.SearchRepositories(new [] { SearchText }, new string[] { });
49-
request.UseCache = false;
50-
var response = this.GetApplication().Client.Execute(request);
51-
Repositories.Items.Reset(response.Data.Items);
52-
});
57+
IsSearching = true;
58+
59+
var request = this.GetApplication().Client.Repositories.SearchRepositories(new [] { SearchText }, new string[] { });
60+
request.UseCache = false;
61+
var response = await this.GetApplication().Client.ExecuteAsync(request);
62+
Repositories.Items.Reset(response.Data.Items);
5363
}
5464
catch (Exception e)
5565
{
5666
ReportError(e);
67+
}
68+
finally
69+
{
70+
IsSearching = false;
5771
}
5872
}
5973
}

CodeHub.iOS/AppDelegate.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
using CodeFramework.iOS;
88
using System.Collections.Generic;
9-
using System; using Cirrious.CrossCore;
9+
using System;
10+
using Cirrious.CrossCore;
1011
using Cirrious.MvvmCross.Touch.Platform;
1112
using Cirrious.MvvmCross.ViewModels;
1213
using MonoTouch.Foundation;
@@ -118,9 +119,12 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
118119
}
119120
}
120121

121-
122-
const UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
123-
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
122+
// Notifications don't work on teh simulator so don't bother
123+
if (MonoTouch.ObjCRuntime.Runtime.Arch != MonoTouch.ObjCRuntime.Arch.SIMULATOR)
124+
{
125+
const UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
126+
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
127+
}
124128

125129
return true;
126130
}
@@ -144,7 +148,7 @@ private void HandleNotification(NSDictionary data)
144148
}
145149
catch (Exception e)
146150
{
147-
Console.WriteLine("Handle Notifications issue: " + e.ToString());
151+
Console.WriteLine("Handle Notifications issue: " + e);
148152
}
149153
}
150154

CodeHub.iOS/Views/Repositories/RepositoriesExploreView.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
using System;
2-
using System.Drawing;
32
using CodeFramework.iOS.Elements;
43
using CodeFramework.ViewControllers;
54
using CodeHub.Core.ViewModels;
65
using MonoTouch.UIKit;
76
using Cirrious.MvvmCross.Binding.BindingContext;
7+
using CodeFramework.iOS.Utils;
88

99
namespace CodeHub.iOS.Views.Repositories
10-
{
11-
public sealed class RepositoriesExploreView : ViewModelCollectionDrivenViewController
12-
{
10+
{
11+
public class RepositoriesExploreView : ViewModelCollectionDrivenViewController
12+
{
13+
private Hud _hud;
14+
1315
public RepositoriesExploreView()
1416
{
1517
AutoHideSearch = false;
@@ -19,8 +21,9 @@ public RepositoriesExploreView()
1921
}
2022

2123
public override void ViewDidLoad()
22-
{
24+
{
2325
base.ViewDidLoad();
26+
_hud = new Hud(View);
2427
var vm = (RepositoriesExploreViewModel)ViewModel;
2528
var search = (UISearchBar)TableView.TableHeaderView;
2629

@@ -34,6 +37,14 @@ public override void ViewDidLoad()
3437
vm.SearchCommand.Execute(null);
3538
};
3639

40+
vm.Bind(x => x.IsSearching, x =>
41+
{
42+
if (x)
43+
_hud.Show("Searching...");
44+
else
45+
_hud.Hide();
46+
});
47+
3748
BindCollection(vm.Repositories, repo =>
3849
{
3950
var description = vm.ShowRepositoryDescription ? repo.Description : string.Empty;

0 commit comments

Comments
 (0)