refresh on open app
This commit is contained in:
parent
51212f9354
commit
b8eb4725a4
@ -1,12 +1,33 @@
|
||||
namespace RBLNews.Maui
|
||||
using RBLNews.Shared.Services;
|
||||
|
||||
namespace RBLNews.Maui
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
public App()
|
||||
private readonly AppLifecycleService _appLifecycleService;
|
||||
|
||||
public App(AppLifecycleService appLifecycleService)
|
||||
{
|
||||
_appLifecycleService = appLifecycleService;
|
||||
InitializeComponent();
|
||||
|
||||
MainPage = new MainPage();
|
||||
}
|
||||
|
||||
protected override Window CreateWindow(IActivationState activationState)
|
||||
{
|
||||
Window window = base.CreateWindow(activationState);
|
||||
window.Activated += (sender, eventArgs) =>
|
||||
{
|
||||
_appLifecycleService.Activated();
|
||||
|
||||
};
|
||||
window.Resumed += (sender, eventArgs) =>
|
||||
{
|
||||
_appLifecycleService.Resumed();
|
||||
// take actions here...
|
||||
};
|
||||
return window;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,11 +5,11 @@
|
||||
xmlns:shared="clr-namespace:RBLNews.Shared;assembly=RBLNews.Shared"
|
||||
x:Class="RBLNews.Maui.MainPage"
|
||||
BackgroundColor="{DynamicResource PageBackgroundColor}">
|
||||
|
||||
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
|
||||
<BlazorWebView.RootComponents>
|
||||
<RootComponent Selector="#app" ComponentType="{x:Type shared:Components.Routes}" />
|
||||
</BlazorWebView.RootComponents>
|
||||
</BlazorWebView>
|
||||
|
||||
<RefreshView x:Name="RefreshView" Refreshing="RefreshView_Refreshing">
|
||||
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
|
||||
<BlazorWebView.RootComponents>
|
||||
<RootComponent Selector="#app" ComponentType="{x:Type shared:Components.Routes}" />
|
||||
</BlazorWebView.RootComponents>
|
||||
</BlazorWebView>
|
||||
</RefreshView>
|
||||
</ContentPage>
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
namespace RBLNews.Maui
|
||||
using RBLNews.Shared.Components.Pages;
|
||||
|
||||
namespace RBLNews.Maui
|
||||
{
|
||||
public partial class MainPage : ContentPage
|
||||
{
|
||||
@ -6,5 +8,15 @@
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
void RefreshView_Refreshing(object sender, EventArgs e)
|
||||
{
|
||||
if (RefreshablePageBase.Current?.NavigationManager != null)
|
||||
{
|
||||
var navigationManager = RefreshablePageBase.Current.NavigationManager;
|
||||
navigationManager.NavigateTo(navigationManager.Uri, true, true);
|
||||
RefreshView.IsRefreshing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ namespace RBLNews.Maui
|
||||
builder.Services.AddBlazorBootstrap();
|
||||
|
||||
builder.Services.AddSingleton<IFeedDataService, FeedDataService>();
|
||||
builder.Services.AddSingleton<AppLifecycleService>();
|
||||
|
||||
#if DEBUG
|
||||
builder.Services.AddBlazorWebViewDeveloperTools();
|
||||
|
||||
@ -84,4 +84,6 @@
|
||||
<Folder Include="IaC\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionRBLNewsMauiHideInfoBar="True" /></VisualStudio></ProjectExtensions>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
@page "/"
|
||||
@inherits RefreshablePageBase
|
||||
@page "/"
|
||||
@using RBLFeederCommon.Enums
|
||||
@using RBLFeederCommon.Models.RssFeed
|
||||
@using RBLNews.Shared.Services
|
||||
|
||||
@inject IFeedDataService feedDataService
|
||||
@inject AppLifecycleService appLifecycleService
|
||||
|
||||
@if (FeedDataService.Feeds == null)
|
||||
{
|
||||
<div class="d-flex justify-content-center">
|
||||
Lade Feeds ...<br/>
|
||||
Lade Feeds ...<br/><br/>
|
||||
<Spinner Type="SpinnerType.Grow" Color="SpinnerColor.Primary" Size="SpinnerSize.Large" />
|
||||
</div>
|
||||
}
|
||||
@ -19,7 +21,7 @@ else
|
||||
<div class="container">
|
||||
@foreach (FeedGroupVM feedGrp in this.FeedDataService.Feeds.FeedGroups)
|
||||
{
|
||||
<h4><Icon Name="IconName.Calendar2Event" /> @feedGrp.PublishDate.ToString("dd.MM.yyyy")</h4>
|
||||
<h4><Icon Name="IconName.Calendar2Event" /> @feedGrp.PublishDate.ToLocalTime().ToString("dd.MM.yyyy")</h4>
|
||||
@foreach (FeedVM feed in feedGrp.Feeds)
|
||||
{
|
||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-4">
|
||||
@ -30,7 +32,7 @@ else
|
||||
</CardBody>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item">
|
||||
@GetRssSourceName((RssFeedSources)@feed.Source) | @feed.PubDate
|
||||
@GetRssSourceName((RssFeedSources)@feed.Source) | @feed.PubDate?.ToLocalTime()
|
||||
</li>
|
||||
</ul>
|
||||
<CardFooter>
|
||||
@ -48,13 +50,24 @@ else
|
||||
</div>
|
||||
}
|
||||
@code {
|
||||
|
||||
|
||||
[Inject]
|
||||
private IFeedDataService FeedDataService { get; set; }
|
||||
|
||||
protected async override Task OnInitializedAsync()
|
||||
[Inject]
|
||||
private AppLifecycleService AppLifecycleService { get; set; }
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
AppLifecycleService.OnActivated = LoadFeeds;
|
||||
|
||||
LoadFeeds();
|
||||
}
|
||||
|
||||
private async void LoadFeeds()
|
||||
{
|
||||
await FeedDataService.LoadFeeds();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private string GetRssSourceName(RssFeedSources source)
|
||||
|
||||
18
RBLNews.Shared/Components/Pages/RefreshablePageBase.cs
Normal file
18
RBLNews.Shared/Components/Pages/RefreshablePageBase.cs
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace RBLNews.Shared.Components.Pages
|
||||
{
|
||||
public abstract class RefreshablePageBase : ComponentBase
|
||||
{
|
||||
public static RefreshablePageBase Current;
|
||||
|
||||
[Inject]
|
||||
public NavigationManager NavigationManager { get; set; }
|
||||
|
||||
protected RefreshablePageBase()
|
||||
{
|
||||
Current = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
RBLNews.Shared/Services/AppLifecycleService.cs
Normal file
17
RBLNews.Shared/Services/AppLifecycleService.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace RBLNews.Shared.Services
|
||||
{
|
||||
public class AppLifecycleService
|
||||
{
|
||||
internal Action OnResumed;
|
||||
internal Action OnActivated;
|
||||
|
||||
public void Resumed()
|
||||
{
|
||||
OnResumed?.Invoke();
|
||||
}
|
||||
public void Activated()
|
||||
{
|
||||
OnActivated?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,9 +5,9 @@ VisualStudioVersion = 17.11.35222.181
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RBLNews.Maui", "RBLNews.Maui\RBLNews.Maui.csproj", "{671920E6-6BE5-4F41-8F85-EB029567866E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RBLNews.Web", "RBLNews.Web\RBLNews.Web.csproj", "{0409A1B9-73D9-477E-91C9-80AE3C25C4E9}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RBLNews.Web", "RBLNews.Web\RBLNews.Web.csproj", "{0409A1B9-73D9-477E-91C9-80AE3C25C4E9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RBLNews.Shared", "RBLNews.Shared\RBLNews.Shared.csproj", "{1A0120DC-700A-4C8E-BC3A-ECFFBE973563}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RBLNews.Shared", "RBLNews.Shared\RBLNews.Shared.csproj", "{1A0120DC-700A-4C8E-BC3A-ECFFBE973563}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
Loading…
Reference in New Issue
Block a user