Skip to content

Commit af17fbc

Browse files
Separate login page and get token asynchronously.
1 parent be4afc1 commit af17fbc

File tree

14 files changed

+226
-79
lines changed

14 files changed

+226
-79
lines changed

sample/Sample/Constants.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ namespace Sample
99
{
1010
public static class Constants
1111
{
12-
public const string ApiUrl = "https://notifo.easierlife.com";
12+
// public const string ApiUrl = "https://notifo.easierlife.com";
1313

14-
public const string UserApiKey = "y2giqssxfvun1mnkrweql9pt5hay1xzuv6dmasba9jax";
14+
// public const string UserApiKey = "y2giqssxfvun1mnkrweql9pt5hay1xzuv6dmasba9jax";
15+
16+
public const string ApiUrl = "https://notifo-dev.easierlife.com";
17+
18+
public const string UserApiKey = "1zkry2syrttdxjqbs1zoj7dg9o45cixfuxhblhh49lcx";
1519
}
1620
}

sample/Sample/NotifoStartup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public void ConfigureService(INotifoMobilePush notifo)
1717
{
1818
notifo
1919
.SetBaseUrl(Constants.ApiUrl)
20-
.SetApiKey(Constants.UserApiKey)
21-
.UseFirebasePluginEventsProvider()
22-
.Register();
20+
.UseFirebasePluginEventsProvider();
2321

2422
notifo.OnNotificationOpened += Current_OnNotificationOpened;
2523
}

sample/Sample/Sample.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@
3636
<ItemGroup>
3737
<ProjectReference Include="..\..\sdk\Notifo.SDK.FirebasePlugin\Notifo.SDK.FirebasePlugin.csproj" />
3838
</ItemGroup>
39+
40+
<ItemGroup>
41+
<EmbeddedResource Update="Views\EventsPage.xaml">
42+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
43+
</EmbeddedResource>
44+
<EmbeddedResource Update="Views\LoginPage.xaml">
45+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
46+
</EmbeddedResource>
47+
</ItemGroup>
3948
</Project>

sample/Sample/ViewModels/MainPageViewModel.cs renamed to sample/Sample/ViewModels/EventsPageViewModel.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616

1717
namespace Sample.ViewModels
1818
{
19-
public class MainPageViewModel : BindableBase, IPageLifecycleAware
19+
public class EventsPageViewModel : BindableBase, IPageLifecycleAware
2020
{
21-
public ObservableRangeCollection<UserNotificationDto> Notifications { get; private set; } = new ObservableRangeCollection<UserNotificationDto>() { };
22-
21+
private readonly INotifoMobilePush notifoService;
22+
private readonly IDeviceService deviceService;
2323
private bool isRefreshing;
24+
25+
public ObservableRangeCollection<UserNotificationDto> Notifications { get; } = new ObservableRangeCollection<UserNotificationDto>();
26+
2427
public bool IsRefreshing
2528
{
26-
get { return isRefreshing; }
27-
set { SetProperty(ref isRefreshing, value); }
29+
get => isRefreshing;
30+
set => SetProperty(ref isRefreshing, value);
2831
}
2932

30-
public DelegateCommand RefreshCommand { get; set; }
33+
public DelegateCommand RefreshCommand { get; }
3134

32-
private readonly INotifoMobilePush notifoService;
33-
private readonly IDeviceService deviceService;
34-
35-
public MainPageViewModel(INotifoMobilePush notifoService, IDeviceService deviceService)
35+
public EventsPageViewModel(INotifoMobilePush notifoService, IDeviceService deviceService)
3636
{
3737
this.notifoService = notifoService;
3838
this.deviceService = deviceService;
@@ -43,7 +43,6 @@ public MainPageViewModel(INotifoMobilePush notifoService, IDeviceService deviceS
4343
public void OnAppearing()
4444
{
4545
notifoService.OnNotificationReceived += Current_OnNotificationReceived;
46-
4746
RefreshEventsAsync();
4847
}
4948

@@ -69,6 +68,7 @@ private void RefreshEventsAsync()
6968
try
7069
{
7170
var notifications = await notifoService.Notifications.GetMyNotificationsAsync();
71+
7272
Notifications.ReplaceRange(notifications.Items);
7373
}
7474
catch (Exception ex)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using Notifo.SDK;
9+
using Prism.Commands;
10+
using Prism.Mvvm;
11+
12+
namespace Sample.ViewModels
13+
{
14+
public class LoginPageViewModel : BindableBase
15+
{
16+
private readonly INotifoMobilePush notifoService;
17+
private string apiKey = Constants.UserApiKey;
18+
19+
public string ApiKey
20+
{
21+
get => apiKey;
22+
set => SetProperty(ref apiKey, value);
23+
}
24+
25+
public DelegateCommand LoginCommand { get; }
26+
27+
public LoginPageViewModel(INotifoMobilePush notifoService)
28+
{
29+
this.notifoService = notifoService;
30+
31+
LoginCommand = new DelegateCommand(Login, () => !string.IsNullOrWhiteSpace(ApiKey)).ObservesProperty(() => ApiKey);
32+
}
33+
34+
private void Login()
35+
{
36+
notifoService.SetApiKey(ApiKey);
37+
notifoService.Register();
38+
}
39+
}
40+
}

sample/Sample/Views/EventsPage.xaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage
3+
x:Class="Sample.Views.EventsPage"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:prism="http://prismlibrary.com"
7+
prism:ViewModelLocator.AutowireViewModel="True"
8+
BackgroundColor="White"
9+
Title="Events">
10+
11+
<ContentPage.Content>
12+
<StackLayout>
13+
<RefreshView Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
14+
<CollectionView Margin="0,8,0,0" HorizontalOptions="FillAndExpand" ItemsSource="{Binding Notifications}" VerticalOptions="FillAndExpand">
15+
<CollectionView.ItemTemplate>
16+
<DataTemplate>
17+
<StackLayout>
18+
<Label
19+
Margin="8,0"
20+
FontAttributes="Bold"
21+
FontSize="18"
22+
Text="{Binding Subject}"
23+
TextColor="Black" />
24+
25+
<Label
26+
Margin="8,0"
27+
FontAttributes="None"
28+
FontSize="14"
29+
Text="{Binding Body}"
30+
TextColor="Black" />
31+
32+
<Label
33+
Margin="8,0"
34+
FontAttributes="None"
35+
FontSize="14"
36+
HorizontalTextAlignment="End"
37+
Text="{Binding Created, StringFormat='{0:dd MMM, HH:mm}'}"
38+
TextColor="Gray" />
39+
40+
<BoxView BackgroundColor="LightGray" HeightRequest="1" />
41+
</StackLayout>
42+
</DataTemplate>
43+
</CollectionView.ItemTemplate>
44+
<CollectionView.EmptyView>
45+
<StackLayout>
46+
<Label
47+
Margin="0,20,0,0"
48+
FontAttributes="None"
49+
FontSize="20"
50+
HorizontalOptions="Center"
51+
Text="Loading events..."
52+
TextColor="Gray"
53+
VerticalOptions="Center" />
54+
</StackLayout>
55+
</CollectionView.EmptyView>
56+
</CollectionView>
57+
</RefreshView>
58+
</StackLayout>
59+
</ContentPage.Content>
60+
</ContentPage>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using Xamarin.Forms;
9+
using Xamarin.Forms.Xaml;
10+
11+
namespace Sample.Views
12+
{
13+
[XamlCompilation(XamlCompilationOptions.Compile)]
14+
public partial class EventsPage : ContentPage
15+
{
16+
public EventsPage()
17+
{
18+
InitializeComponent();
19+
}
20+
}
21+
}

sample/Sample/Views/LoginPage.xaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage
3+
x:Class="Sample.Views.LoginPage"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:prism="http://prismlibrary.com"
7+
prism:ViewModelLocator.AutowireViewModel="True"
8+
Title="Login">
9+
10+
<ContentPage.Content>
11+
<StackLayout Spacing="20" Padding="20">
12+
<Label
13+
FontAttributes="None"
14+
FontSize="Title"
15+
Text="Login"
16+
HorizontalOptions="CenterAndExpand" />
17+
18+
<Label
19+
FontAttributes="None"
20+
FontSize="Default"
21+
Text="Enter API Key"
22+
HorizontalOptions="CenterAndExpand" />
23+
24+
<Entry Text="{Binding ApiKey, Mode=TwoWay}" />
25+
26+
<Button Command="{Binding LoginCommand}" Text="Login" />
27+
</StackLayout>
28+
</ContentPage.Content>
29+
</ContentPage>

sample/Sample/Views/LoginPage.xaml.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using Xamarin.Forms;
9+
using Xamarin.Forms.Xaml;
10+
11+
namespace Sample.Views
12+
{
13+
[XamlCompilation(XamlCompilationOptions.Compile)]
14+
public partial class LoginPage : ContentPage
15+
{
16+
public LoginPage()
17+
{
18+
InitializeComponent();
19+
}
20+
}
21+
}

sample/Sample/Views/MainPage.xaml

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,12 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<ContentPage
2+
<TabbedPage
33
x:Class="Sample.Views.MainPage"
44
xmlns="http://xamarin.com/schemas/2014/forms"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
66
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
7-
xmlns:prism="http://prismlibrary.com"
8-
ios:Page.UseSafeArea="true"
9-
prism:ViewModelLocator.AutowireViewModel="True"
7+
xmlns:local="clr-namespace:Sample.Views"
108
BackgroundColor="White">
119

12-
<StackLayout>
13-
<RefreshView
14-
x:Name="RefreshView"
15-
Command="{Binding RefreshCommand}"
16-
IsRefreshing="{Binding IsRefreshing}">
17-
<CollectionView
18-
Margin="0,8,0,0"
19-
HorizontalOptions="FillAndExpand"
20-
ItemsSource="{Binding Notifications}"
21-
VerticalOptions="FillAndExpand">
22-
<CollectionView.ItemTemplate>
23-
<DataTemplate>
24-
<StackLayout>
25-
<Label
26-
Margin="8,0"
27-
FontAttributes="Bold"
28-
FontSize="18"
29-
Text="{Binding Subject}"
30-
TextColor="Black" />
31-
<Label
32-
Margin="8,0"
33-
FontSize="14"
34-
Text="{Binding Body}"
35-
TextColor="Black" />
36-
<Label
37-
Margin="8,0"
38-
FontSize="14"
39-
HorizontalTextAlignment="End"
40-
Text="{Binding Created, StringFormat='{0:dd MMM, HH:mm}'}"
41-
TextColor="Gray" />
42-
<BoxView BackgroundColor="LightGray" HeightRequest="1" />
43-
</StackLayout>
44-
</DataTemplate>
45-
</CollectionView.ItemTemplate>
46-
<CollectionView.EmptyView>
47-
<StackLayout>
48-
<Label
49-
Margin="0,20,0,0"
50-
FontSize="20"
51-
HorizontalOptions="Center"
52-
Text="Loading events..."
53-
TextColor="Gray"
54-
VerticalOptions="Center" />
55-
</StackLayout>
56-
</CollectionView.EmptyView>
57-
</CollectionView>
58-
</RefreshView>
59-
</StackLayout>
60-
</ContentPage>
10+
<local:LoginPage />
11+
<local:EventsPage />
12+
</TabbedPage>

0 commit comments

Comments
 (0)