Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes on previous changes #121

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions AresNews/AresNews/ViewModels/NewsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public Command CloseSearch
{
return new Command(() =>
{
CurrentApp.ShowLoadingIndicator();
IsSearching = false;

if (string.IsNullOrEmpty(_searchText) || !IsSearchProcessed) return;

CurrentApp.ShowLoadingIndicator();

// Scroll up before fetching the items
CurrentPage.ScrollFeed();
Expand All @@ -183,7 +183,6 @@ public Command CloseSearch
SearchText = string.Empty;

IsSearchProcessed = false;
CurrentApp.RemoveLoadingIndicator();

});
}
Expand Down Expand Up @@ -291,6 +290,7 @@ public bool IsRefreshing
}

public bool IsFirstLoad { get; private set; } = true;
public bool IsSearchLoading { get; private set; }

public NewsViewModel(NewsPage currentPage)
{
Expand Down Expand Up @@ -401,23 +401,31 @@ public NewsViewModel(NewsPage currentPage)

if (IsSearchOpen)
{
if (string.IsNullOrEmpty(SearchText))
return;
// Fetch the article
_ = FetchArticles();
_ = FetchArticles(true);
return;
}
// Fetch the article
_ = FetchArticles();
});
LoadSearch = new Command(async () =>
{
if (IsSearchLoading)
return;
CurrentApp.ShowLoadingIndicator();
IsSearchProcessed = true;
IsSearchLoading = true;

await FetchArticles().ContinueWith((res) =>
CurrentApp.RemoveLoadingIndicator());
{
CurrentApp.RemoveLoadingIndicator();
IsSearchLoading = false;
});
});
// Set command to share an article
_shareArticle = new Command(async (id) =>
_shareArticle = new Command((id) =>
{
// Get selected article
var article = _articles.FirstOrDefault(art => art.Id == id.ToString());
Expand Down Expand Up @@ -455,28 +463,21 @@ public async Task FetchArticles(bool isFullRefresh = false)
var articles = new ObservableRangeCollection<Article>();
if (isFullRefresh)
{

CurrentApp.ShowLoadingIndicator();
// the articles of the last 2 months
articles = new (await CurrentApp.DataFetcher.GetMainFeedUpdate().ConfigureAwait(false));

var oldFeed = new Collection<Article>(_articles.Where(ats => ats.FullPublishDate > DateTime.Now.AddMonths(-2)).ToList());

_isLaunching = false;
List<Article> filteredArticles = articles.Where(article => article.Blocked == null || article.Blocked == false).ToList();

// Reload the feed
Articles.Clear();
Articles = new ObservableRangeCollection<Article>(articles.Where(article => article.Blocked == null || article.Blocked == false));


// Register date of the refresh
IsRefreshing = false;
IsSearchOpen = false;
_prevSearch = string.Empty;

if (Device.RuntimePlatform == Device.iOS)
CurrentApp.RemoveLoadingIndicator();

// Check if we have new articles before refreshing the DB
if (oldFeed.Count != articles.Count)
_ = RefreshDB();
CurrentApp.RemoveLoadingIndicator();
return;
}

Expand Down Expand Up @@ -768,7 +769,7 @@ public void Resume()
{
CurrentApp.ShowLoadingIndicator();
_ = FetchArticles(_articles?.Count <= 0).ContinueWith(res =>
CurrentApp.RemoveLoadingIndicator());
CurrentApp.RemoveLoadingIndicator());

IsFirstLoad = false;

Expand Down
2 changes: 1 addition & 1 deletion AresNews/AresNews/Views/FeedsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace AresNews.Views
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class FeedsPage : ContentPage
{
private const int rButtonYStart = -22;
private const int rButtonYStart = -43;
private const uint _modalHeightStart = 0;
private readonly uint _modalWidthStart = 50;
private readonly FeedsViewModel _vm;
Expand Down