filter function

This commit is contained in:
iTob 2024-09-19 15:14:28 +02:00
parent d1a22778b2
commit 2314cb91d2
7 changed files with 245 additions and 145 deletions

View File

@ -1,11 +1,39 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
namespace RBLNews.Maui
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
public override bool DispatchTouchEvent(MotionEvent? e)
{
if (e!.Action == MotionEventActions.Down)
{
var focusedElement = CurrentFocus;
if (focusedElement is EditText editText)
{
var editTextLocation = new int[2];
editText.GetLocationOnScreen(editTextLocation);
var clearTextButtonWidth = 100;
var editTextRect = new Rect(editTextLocation[0], editTextLocation[1], editText.Width + clearTextButtonWidth, editText.Height);
var touchPosX = (int)e.RawX;
var touchPosY = (int)e.RawY;
if (!editTextRect.Contains(touchPosX, touchPosY))
{
editText.ClearFocus();
var inputService = GetSystemService(Context.InputMethodService) as InputMethodManager;
inputService?.HideSoftInputFromWindow(editText.WindowToken, 0);
}
}
}
return base.DispatchTouchEvent(e);
}
}
}

View File

@ -10,9 +10,9 @@
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet" />
<link href="_content/RBLNews.Shared/blazor.bootstrap.css" rel="stylesheet" />
<!--<link rel="stylesheet" href="_content/RBLNews.Shared/css/bootstrap/bootstrap.min.css" />-->
<!--<link rel="stylesheet" href="_content/RBLNews.Shared/css/bootstrap/bootstrap.min.css" />-->
<!-- <link rel="stylesheet" href="_content/Blazor.Bootstrap/Blazor.Bootstrap.bundle.scp.css" />-->
<link rel="stylesheet" href="_content/RBLNews.Shared/css/app.css" />
<link rel="stylesheet" href="RBLNews.Maui.styles.css" />
<link rel="icon" type="image/ico" href="favicon.ico" />
</head>

View File

@ -1,12 +1,13 @@
@using RBLFeederCommon.Enums
@if (ShowCount)
{
<Button Color="ButtonColor.Info" Size="ButtonSize.Small" Clicked="@OnClicked()" Outline>@Text <small>@Count</small></Button>
}
else
{
<Button Size="ButtonSize.Small">@Text</Button>
}
<Button Size="ButtonSize.Small" Type="ButtonType.Button" @onclick="OnClicked" Color="ButtonColor.Primary" Outline="@outline" Position="Position.Relative">
@Text
<Badge Color="BadgeColor.Info"
Position="Position.Absolute"
Placement="BadgePlacement.TopRight"
IndicatorType="BadgeIndicatorType.RoundedPill"
VisuallyHiddenText="Anz. News">@Count</Badge>
</Button>
@code {
@ -14,7 +15,7 @@ else
public RssFeedSources Source { get; set; }
[Parameter]
public string Text { get; set; }
public string Text { get; set; } = "";
[Parameter]
public bool ShowCount { get; set; }
@ -25,14 +26,15 @@ else
[Parameter]
public EventCallback<RssFeedSources> OnClickedCallback { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
}
bool outline = true;
private async Task OnClicked()
Task OnClicked()
{
await OnClickedCallback.InvokeAsync(Source);
outline = !outline;
OnClickedCallback.InvokeAsync(Source);
return Task.CompletedTask;
}
}

View File

@ -13,7 +13,7 @@
}
else
{
<text>Letztes Update @FeedDataService.Feeds?.LastUpdate.ToString("dd.MM.yyyy HH:mm")</text>
<text>Letzter Check: @FeedDataService.Feeds?.LastUpdate.ToString("dd.MM.yyyy HH:mm")</text>
}
</div>
</div>

View File

@ -10,125 +10,155 @@
@if (FeedGroups == null)
{
<div class="d-flex justify-content-center">
Lade Feeds ...<br /><br />
<Spinner Type="SpinnerType.Grow" Color="SpinnerColor.Primary" Size="SpinnerSize.Large" />
</div>
<div class="d-flex justify-content-center">
<Spinner Type="SpinnerType.Grow" Color="SpinnerColor.Primary" Size="SpinnerSize.Large"/>
</div>
}
else
{
<br />
<div id="feeds-page" class="row">
<div class="container">
<div class="FilterButtons">
@foreach (IGrouping<int, int> sGrouping in SourceGroupings)
{
@* <BadgeWithCounter ShowCount="true" Source="(RssFeedSources)sGrouping.Key" OnClickedCallback="OnClicked" Text="@GetRssSourceName((RssFeedSources)sGrouping.Key)" Count="@sGrouping.Count()"></BadgeWithCounter> *@
}
</div>
@foreach (FeedGroupVM feedGrp in FeedGroups)
{
<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">
<Card>
<CardBody>
<CardTitle>@feed.Title</CardTitle>
<CardText>@feed.Description</CardText>
</CardBody>
<ul class="list-group list-group-flush">
<li class="list-group-item">
@GetRssSourceName((RssFeedSources)@feed.Source) | @feed.PubDate?.ToLocalTime()
</li>
</ul>
<CardFooter>
<div class="row">
<Button Color="ButtonColor.Primary" Class="btn-sm align-self-end ml-auto" To="@feed.Link" Type="ButtonType.Link"><Icon Name="IconName.Link" /> Öffnen</Button>
</div>
</CardFooter>
</Card>
<br />
</div>
<div id="feeds-page">
<div class="container-fluid">
<section id="filter">
@foreach (IGrouping<int, int> sGrouping in SourceGroupings)
{
<BadgeWithCounter
ShowCount="true"
Source="(RssFeedSources)sGrouping.Key"
OnClickedCallback="OnClicked"
Text="@GetRssSourceName((RssFeedSources)sGrouping.Key)"
Count="@sGrouping.Count()">
</BadgeWithCounter>
}
</section>
<section id="feeds-list">
@foreach (FeedGroupVM feedGrp in FeedGroups)
{
<h1>
<Icon Name="IconName.Calendar2Event"/> @feedGrp.PublishDate.ToLocalTime().ToString("dd.MM.yyyy")
</h1>
@foreach (FeedVM feed in feedGrp.Feeds)
{
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-4">
<Card>
<CardBody>
<CardTitle>@feed.Title</CardTitle>
<CardText>@feed.Description</CardText>
<div class="row">
<Button Outline="true" Color="ButtonColor.Primary" Class="btn-sm align-self-end ml-auto" To="@feed.Link" Type="ButtonType.Link"><Icon Name="IconName.Link"/> Öffnen</Button>
</div>
</CardBody>
@* <ul class="list-group list-group-flush"> *@
@* <li class="list-group-item"> *@
@* <div class="row"> *@
@* <Button Outline="true" Color="ButtonColor.Primary" Class="btn-sm align-self-end ml-auto" To="@feed.Link" Type="ButtonType.Link"><Icon Name="IconName.Link"/> Öffnen</Button> *@
@* </div> *@
@* </li> *@
@* </ul> *@
<CardFooter>
}
}
</div>
</div>
@GetRssSourceName((RssFeedSources)@feed.Source) | @feed.PubDate?.ToLocalTime()
</CardFooter>
</Card>
<br/>
</div>
}
}
</section>
</div>
</div>
}
@code {
[Inject]
private IFeedDataService FeedDataService { get; set; }
[Inject] private IFeedDataService FeedDataService { get; set; }
[Inject]
private AppLifecycleService AppLifecycleService { get; set; }
[Inject] private AppLifecycleService AppLifecycleService { get; set; }
private List<FeedGroupVM>? FeedGroups { get; set; }
private List<FeedGroupVM>? FeedGroups { get; set; }
private IEnumerable<IGrouping<int, int>> SourceGroupings { get; set; } = new List<IGrouping<int, int>>();
private IEnumerable<IGrouping<int, int>> SourceGroupings { get; set; } = new List<IGrouping<int, int>>();
protected override void OnInitialized()
{
AppLifecycleService.OnActivated = LoadFeeds;
private List<RssFeedSources> activeFilters = new List<RssFeedSources>();
LoadFeeds();
}
private async void LoadFeeds()
{
// Copy feed list to keep original list
await FeedDataService.LoadFeeds();
FeedGroups = [..FeedDataService.Feeds.FeedGroups];
protected override void OnInitialized()
{
AppLifecycleService.OnActivated = LoadFeeds;
List<FeedGroupVM> listTmp = [.. FeedDataService.Feeds.FeedGroups];
LoadFeeds();
}
SourceGroupings = listTmp.SelectMany(fg => fg.Feeds.Select(f => f.Source)).GroupBy(sources => sources);
StateHasChanged();
}
private async void LoadFeeds()
{
// Copy feed list to keep original list
await FeedDataService.LoadFeeds();
FeedGroups = [.. FeedDataService.Feeds.FeedGroups];
private string GetRssSourceName(RssFeedSources source)
{
switch (source)
{
case RssFeedSources.RbLive:
case RssFeedSources.NitterRbLive:
return "RBLive!";
case RssFeedSources.NitterFabrizioRomano:
return "Fabrizio Romano";
case RssFeedSources.Lvz:
return "LVZ";
case RssFeedSources.Kicker:
return "Kicker";
case RssFeedSources.Bild:
return "BILD";
case RssFeedSources.Transfermarkt:
return "Transfermarkt";
default:
return "?";
}
}
List<FeedGroupVM> listTmp = [.. FeedDataService.Feeds.FeedGroups];
private void OnClicked(RssFeedSources source)
{
FeedGroups = new List<FeedGroupVM>();
foreach (FeedGroupVM fg in FeedDataService.Feeds.FeedGroups)
{
List<FeedVM> feeds = fg.Feeds.Where(f => (RssFeedSources)f.Source == source).ToList();
if (feeds.Any())
{
FeedGroups.Add(new FeedGroupVM
{
Feeds = feeds,
PublishDate = fg.PublishDate
});
SourceGroupings = listTmp.SelectMany(fg => fg.Feeds.Select(f => f.Source)).GroupBy(sources => sources);
}
}
StateHasChanged();
}
StateHasChanged();
}
}
private string GetRssSourceName(RssFeedSources source)
{
switch (source)
{
case RssFeedSources.RbLive:
case RssFeedSources.NitterRbLive:
return "RBLive!";
case RssFeedSources.NitterFabrizioRomano:
return "Fabrizio Romano";
case RssFeedSources.Lvz:
return "LVZ";
case RssFeedSources.Kicker:
return "Kicker";
case RssFeedSources.Bild:
return "BILD";
case RssFeedSources.Transfermarkt:
return "Transfermarkt";
default:
return "?";
}
}
private void OnClicked(RssFeedSources source)
{
if (activeFilters.Contains(source))
activeFilters.Remove(source);
else
{
activeFilters.Add(source);
}
if (!activeFilters.Any())
{
FeedGroups = [.. FeedDataService.Feeds.FeedGroups];
return;
}
FeedGroups = new List<FeedGroupVM>();
foreach (FeedGroupVM fg in FeedDataService.Feeds.FeedGroups)
{
List<FeedVM> feeds = fg.Feeds.Where(f => activeFilters.Contains((RssFeedSources)f.Source)).ToList();
if (feeds.Any())
{
FeedGroups.Add(
new FeedGroupVM
{
Feeds = feeds,
PublishDate = fg.PublishDate
});
}
}
StateHasChanged();
}
}

View File

@ -1,5 +1,6 @@
/**
rot: #DD0741
schrift: #4b4b4b
*/
@font-face {
@ -9,11 +10,27 @@ rot: #DD0741
src: url('../fonts/NanumMyeongjo-Regular.ttf');
}
h1, h2, h3, h4, h5, h6, h7 {
color: rgb(221, 7, 65) !important;
#feeds-page {
color: #4b4b4b;
}
.card {
color: #4b4b4b;
font-size: 1em;
}
.card .card-title {
color: #DD0741;
font-size: 1em;
text-transform: uppercase;
}
.card .card-footer {
color: #4b4b4b;
background-color: #fff;
font-size: 0.8em;
}
nav .container-fluid {
padding-right: 0px !important;
padding-left: 0px !important;
@ -22,14 +39,55 @@ nav .container-fluid {
nav .top-row {
height: 1.8rem;
background-color: rgb(221, 7, 65);
color: #eee !important;
color: #eee;
}
nav .top-row h1, h2, h3, h4, h5 {
color: #eee !important;
}
/*nav .top-row h1, h2, h3, h4, h5 {*/
/* color: #eee;*/
/*}*/
#filter button {
margin-top: 13px;
margin-bottom: 13px;
margin-right: 16px;
}
/*#feeds-page #feeds-list h1, h2, h3, h4, h5 {*/
/* color: rgb(221, 7, 65);*/
/* text-transform: uppercase;*/
/*}*/
.btn-primary {
color: #fff;
background-color: #f75581;
border-color: #DD0741;
}
.btn-primary:hover {
color: #fff;
background-color: #DD0741;
border-color: #DD0741;
}
.btn-outline-primary {
color: #DD0741;
background-color: #fff;
border-color: #DD0741;
}
.btn-outline-primary:hover {
color: #fff;
background-color: #DD0741;
border-color: #DD0741;
}
.text-bg-info {
color: #DD0741 !important;
background-color: #fff !important;
border-top: 1px solid #DD0741 !important;
border-right: 1px solid #DD0741 !important;
}
.navbar-toggler {
appearance: none;
cursor: pointer;
@ -131,9 +189,6 @@ nav .top-row {
.list-group-item {
font-size: 0.8rem !important;
}
.loading {
position: absolute;
@ -146,13 +201,6 @@ nav .top-row {
border-color: rgb(221, 7, 65);
}
.btn-primary {
background-color: #fff !important;
color: rgb(221, 7, 65) !important;
border: 1px solid rgb(221, 7, 65) !important;
}
.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}
@ -214,14 +262,6 @@ nav .top-row {
}
}
.FilterButtons {
margin: 10px;
}
#feeds-page h4, h5 {
color: rgb(221, 7, 65) !important;
text-transform: uppercase;
}
/*html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;

View File

@ -7,11 +7,11 @@
<base href="/" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet" />
<link href="_content/RBLNews.Shared/blazor.bootstrap.css" rel="stylesheet" />
@* <link href="_content/RBLNews.Shared/blazor.bootstrap.css" rel="stylesheet" /> *@
@* <link rel="stylesheet" href="_content/RBLNews.Shared/css/bootstrap/bootstrap.min.css" /> *@
@* <link rel="stylesheet" href="RBLNews.Web.styles.css" /> *@
<link rel="stylesheet" href="_content/RBLNews.Shared/css/app.css" />
<link rel="stylesheet" href="RBLNews.Web.styles.css" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>