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

Commit 13f6474

Browse files
committed
Push notifications alert will appear after you login
1 parent 51e71fd commit 13f6474

17 files changed

+388
-1
lines changed

CodeHub.Core/CodeHub.Core.iOS.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
<Compile Include="Messages\GistAddMessage.cs" />
132132
<Compile Include="ViewModels\Repositories\RepositoriesTrendingViewModel.cs" />
133133
<Compile Include="Utils\MarkdownHtmlGenerator.cs" />
134+
<Compile Include="ViewModels\App\SidebarOrderViewModel.cs" />
135+
<Compile Include="Factories\IFeatureFactory.cs" />
134136
</ItemGroup>
135137
<ItemGroup />
136138
<ItemGroup>
@@ -168,4 +170,7 @@
168170
<Content Include="Markdown\marked.js" />
169171
<Content Include="Markdown\markdown.html" />
170172
</ItemGroup>
173+
<ItemGroup>
174+
<Folder Include="Factories\" />
175+
</ItemGroup>
171176
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace CodeHub.Core.Factories
5+
{
6+
public interface IFeatureFactory
7+
{
8+
Task PromptPushNotificationFeature();
9+
}
10+
}
11+

CodeHub.Core/ViewModels/Accounts/LoginViewModel.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Windows.Input;
66
using Cirrious.MvvmCross.ViewModels;
77
using System.Threading.Tasks;
8+
using CodeHub.Core.Factories;
9+
using Cirrious.CrossCore;
810

911
namespace CodeHub.Core.ViewModels.Accounts
1012
{
@@ -114,6 +116,23 @@ public async Task Login(string code)
114116
IsLoggingIn = true;
115117
var account = AttemptedAccount;
116118
var data = await _loginService.LoginWithToken(ClientId, ClientSecret, code, RedirectUri, WebDomain, apiUrl, account);
119+
120+
try
121+
{
122+
if (!IsEnterprise)
123+
{
124+
var features = Mvx.Resolve<IFeaturesService>();
125+
if (!features.IsPushNotificationsActivated)
126+
{
127+
await Mvx.Resolve<IFeatureFactory>().PromptPushNotificationFeature();
128+
}
129+
}
130+
}
131+
catch
132+
{
133+
// Don't do anything...
134+
}
135+
117136
this.GetApplication().ActivateUser(data.Account, data.Client);
118137
}
119138
catch (Exception e)

CodeHub.Core/ViewModels/App/SettingsViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public ICommand GoToDefaultStartupViewCommand
3030
get { return new MvxCommand(() => ShowViewModel<DefaultStartupViewModel>()); }
3131
}
3232

33+
public ICommand GoToSidebarOrderCommand
34+
{
35+
get { return new MvxCommand(() => ShowViewModel<SidebarOrderViewModel>()); }
36+
}
37+
3338
public ICommand DeleteAllCacheCommand
3439
{
3540
get { return new MvxCommand(DeleteCache); }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using CodeFramework.Core.ViewModels;
3+
using System.Collections.Generic;
4+
5+
namespace CodeHub.Core.ViewModels.App
6+
{
7+
public class SidebarOrderViewModel : BaseViewModel
8+
{
9+
public List<string> Items
10+
{
11+
get;
12+
private set;
13+
}
14+
15+
public SidebarOrderViewModel()
16+
{
17+
Items = new List<string>();
18+
Items.Add("Favorite Repositories");
19+
Items.Add("News");
20+
Items.Add("Issues");
21+
Items.Add("Notifications");
22+
}
23+
24+
}
25+
}
26+

CodeHub.iOS/AppDelegate.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public class AppDelegate : MvxApplicationDelegate
3737
private UIWindow window;
3838
public string DeviceToken;
3939

40+
public new UIWindow Window
41+
{
42+
get { return this.window; }
43+
}
44+
4045
/// <summary>
4146
/// This is the main entry point of the application.
4247
/// </summary>

CodeHub.iOS/CodeHub.iOS.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@
215215
<Compile Include="Views\Repositories\RepositoriesTrendingView.cs" />
216216
<None Include="RELEASE-NOTES.txt" />
217217
<Compile Include="ViewControllers\MarkdownComposerViewController.cs" />
218+
<Compile Include="Views\App\SidebarOrderView.cs" />
219+
<Compile Include="Views\App\EnablePushNotificationsViewController.cs" />
220+
<Compile Include="Views\App\EnablePushNotificationsViewController.designer.cs">
221+
<DependentUpon>EnablePushNotificationsViewController.cs</DependentUpon>
222+
</Compile>
223+
<InterfaceDefinition Include="Views\App\EnablePushNotificationsViewController.xib" />
224+
<Compile Include="Factory\FeatureFactory.cs" />
218225
</ItemGroup>
219226
<ItemGroup>
220227
<ProjectReference Include="..\lib\CodeFramework\CodeFramework.Core\CodeFramework.Core.iOS.csproj">
@@ -278,6 +285,9 @@
278285
<HintPath>..\lib\CodeFramework\lib\iOS\MTiRate.dll</HintPath>
279286
</Reference>
280287
<Reference Include="System.Net.Http" />
288+
<Reference Include="OHAttributedLabel">
289+
<HintPath>..\lib\CodeFramework\lib\iOS\OHAttributedLabel.dll</HintPath>
290+
</Reference>
281291
</ItemGroup>
282292
<ItemGroup>
283293
<Content Include="Images\anonymous%402x.png" />
@@ -435,5 +445,6 @@
435445
<ItemGroup>
436446
<Folder Include="ViewControllers\" />
437447
<Folder Include="Images\MarkdownComposer\" />
448+
<Folder Include="Factory\" />
438449
</ItemGroup>
439450
</Project>

CodeHub.iOS/CodeHub.iOS.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserVoice", "..\lib\CodeFra
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeHub.Core.iOS", "..\CodeHub.Core\CodeHub.Core.iOS.csproj", "{B7970173-9022-466B-B57A-7AB1E1F3145F}"
2323
EndProject
24+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{796438D1-990E-430C-9FF0-494285D4411E}"
25+
ProjectSection(SolutionItems) = preProject
26+
CodeHub.iOS.sln = CodeHub.iOS.sln
27+
EndProjectSection
28+
EndProject
2429
Global
2530
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2631
AdHoc|Any CPU = AdHoc|Any CPU
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using CodeHub.Core.Factories;
3+
using CodeHub.iOS.Views.App;
4+
using System.Threading.Tasks;
5+
using MonoTouch.UIKit;
6+
7+
namespace CodeHub.iOS.Factory
8+
{
9+
public class FeatureFactory : IFeatureFactory
10+
{
11+
public Task PromptPushNotificationFeature()
12+
{
13+
var tcs = new TaskCompletionSource<object>();
14+
var ctrl = new EnablePushNotificationsViewController();
15+
ctrl.Dismissed += (sender, e) => tcs.SetResult(null);
16+
(UIApplication.SharedApplication.Delegate as AppDelegate).Window.RootViewController.PresentViewController(ctrl, true, null);
17+
return tcs.Task;
18+
}
19+
}
20+
}
21+

CodeHub.iOS/Setup.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ protected override IMvxApplication CreateApp()
9797
.AsInterfaces()
9898
.RegisterAsLazySingleton();
9999

100+
this.CreatableTypes()
101+
.EndingWith("Factory")
102+
.AsInterfaces()
103+
.RegisterAsDynamic();
104+
105+
this.CreatableTypes(typeof(Core.App).Assembly)
106+
.EndingWith("Factory")
107+
.AsInterfaces()
108+
.RegisterAsDynamic();
109+
100110
return new Core.App();
101111
}
102112
}

0 commit comments

Comments
 (0)