use models from api by nuget package

This commit is contained in:
Tobias Wohlleben 2024-09-12 11:54:39 +02:00
parent 46c1af77c0
commit 836fcb3f4d
10 changed files with 27 additions and 98 deletions

View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="itob86.rblnews" android:versionCode="1">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:label="RBLNews"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
</manifest> </manifest>

View File

@ -32,7 +32,7 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">32.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">31.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
@ -42,6 +42,10 @@
<AndroidPackageFormat>apk</AndroidPackageFormat> <AndroidPackageFormat>apk</AndroidPackageFormat>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<!-- App Icon --> <!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

View File

@ -14,7 +14,7 @@
<div class="top-row ps-3 navbar navbar-dark"> <div class="top-row ps-3 navbar navbar-dark">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<Icon Name="IconName.InfoCircle" class="me-2"></Icon>Letztes Update @this.FeedDataService.Feeds?.LastUpdateDisplay <Icon Name="IconName.InfoCircle" class="me-2"></Icon>Letztes Update @this.FeedDataService.Feeds?.LastUpdate.ToString("dd.MM.yyyy HH:mm")
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,14 +1,14 @@
@page "/" @page "/"
@using RBLFeederCommon.Enums
@using RBLFeederCommon.Models.RssFeed @using RBLFeederCommon.Models.RssFeed
@using RBLNews.Shared.Enums
@using RBLNews.Shared.Services @using RBLNews.Shared.Services
@inject IFeedDataService feedDataService @inject IFeedDataService feedDataService
@if (this.FeedDataService.Feeds == null) @if (FeedDataService.Feeds == null)
{ {
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
Lade Feeds ... Lade Feeds ...<br/>
<Spinner Type="SpinnerType.Grow" Color="SpinnerColor.Primary" Size="SpinnerSize.Large" /> <Spinner Type="SpinnerType.Grow" Color="SpinnerColor.Primary" Size="SpinnerSize.Large" />
</div> </div>
} }
@ -19,7 +19,7 @@ else
<div class="container"> <div class="container">
@foreach (FeedGroupVM feedGrp in this.FeedDataService.Feeds.FeedGroups) @foreach (FeedGroupVM feedGrp in this.FeedDataService.Feeds.FeedGroups)
{ {
<h4><Icon Name="IconName.Calendar2Event" /> @feedGrp.PublishDateDisplay</h4> <h4><Icon Name="IconName.Calendar2Event" /> @feedGrp.PublishDate.ToString("dd.MM.yyyy")</h4>
@foreach (FeedVM feed in feedGrp.Feeds) @foreach (FeedVM feed in feedGrp.Feeds)
{ {
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-4"> <div class="col-xs-12 col-sm-12 col-md-8 col-lg-4">
@ -48,14 +48,14 @@ else
</div> </div>
} }
@code { @code {
HttpClient httpClient = new HttpClient();
[Inject] [Inject]
private IFeedDataService FeedDataService { get; set; } private IFeedDataService FeedDataService { get; set; }
protected async override Task OnInitializedAsync() protected async override Task OnInitializedAsync()
{ {
this.FeedDataService.LoadFeeds(); await FeedDataService.LoadFeeds();
StateHasChanged();
} }
private string GetRssSourceName(RssFeedSources source) private string GetRssSourceName(RssFeedSources source)

View File

@ -1,13 +0,0 @@
namespace RBLNews.Shared.Enums
{
public enum RssFeedSources
{
Lvz,
Kicker,
Bild,
Transfermarkt,
NitterRbLive,
NitterFabrizioRomano,
RbLive
}
}

View File

@ -1,14 +0,0 @@
using Newtonsoft.Json;
namespace RBLFeederCommon.Models.RssFeed;
public class FeedGroupVM
{
public string PublishDateDisplay { get => PublishDate.ToString("dd.MM.yyyy"); }
[JsonProperty("pubDate")]
public DateTime PublishDate { get; set; }
[JsonProperty("news")]
public IList<FeedVM> Feeds { get; set; }
}

View File

@ -1,27 +0,0 @@
using Newtonsoft.Json;
namespace RBLFeederCommon.Models.RssFeed;
public class FeedVM
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("imgUrl")]
public string ImgUrl { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("pubDate")]
public DateTime? PubDate { get; set; }
[JsonProperty("link")]
public string Link { get; set; }
[JsonProperty("source")]
public int Source { get; set; }
}

View File

@ -1,19 +0,0 @@
using Newtonsoft.Json;
namespace RBLFeederCommon.Models.RssFeed;
public class RssVM
{
public string LastUpdateDisplay { get => this.LastUpdate.ToLocalTime().ToString("dd.MM.yyyy HH:mm"); }
[JsonProperty("lastUpdate")]
public DateTime LastUpdate { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("feedGroups")]
public IList<FeedGroupVM> FeedGroups { get; set; } = new List<FeedGroupVM>();
}

View File

@ -12,10 +12,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AntDesign" Version="0.20.3" />
<PackageReference Include="Blazor.Bootstrap" Version="3.0.0" /> <PackageReference Include="Blazor.Bootstrap" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.8" /> <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RBLFeederCommon" Version="1.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,30 +1,25 @@
using RBLFeederCommon.Models.RssFeed; 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Text; using RBLFeederCommon.Models.RssFeed;
using System.Threading.Tasks;
namespace RBLNews.Shared.Services namespace RBLNews.Shared.Services
{ {
public interface IFeedDataService public interface IFeedDataService
{ {
public RssVM? Feeds { get; } public RssVM Feeds { get; }
Task LoadFeeds(); Task LoadFeeds();
} }
public class FeedDataService : IFeedDataService public class FeedDataService : IFeedDataService
{ {
private static HttpClient httpClient = new HttpClient(); private static readonly HttpClient httpClient = new();
private RssVM? feeds; public RssVM Feeds { get; private set; }
public RssVM? Feeds { get => this.feeds; }
public async Task LoadFeeds() public async Task LoadFeeds()
{ {
feeds = await httpClient.GetFromJsonAsync<RssVM>("https://rblnews.de/api/feeds"); Feeds = await httpClient.GetFromJsonAsync<RssVM>("https://rblnews.de/api/feeds") ?? new RssVM();
} }
} }
} }