Skip to content

Commit

Permalink
#134 - feeds iOS | patch issue that causes a crash on iOS when loadin…
Browse files Browse the repository at this point in the history
…g a feed
  • Loading branch information
bricefriha committed Jun 18, 2024
1 parent f50b0d3 commit 57d456f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
31 changes: 15 additions & 16 deletions AresNews/AresNews/ViewModels/FeedsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public bool IsRefreshing
OnPropertyChanged(nameof(IsRefreshing));
}
}
private ObservableCollection<Article> _articles;
private ObservableRangeCollection<Article> _articles;

public ObservableCollection<Article> Articles
public ObservableRangeCollection<Article> Articles
{
get { return _articles; }
set
Expand Down Expand Up @@ -233,9 +233,9 @@ public FeedsViewModel(FeedsPage page)
CurrentPage = page;

// Instantiate definitions
FeedTabs = new ObservableCollection<TabButton>();
FeedTabs = new ObservableRangeCollection<TabButton>();
Feeds = new ObservableCollection<Feed>(App.SqLiteConn.GetAllWithChildren<Feed>());
_articles = new ObservableCollection<Article>();
_articles = new ObservableRangeCollection<Article>();

// Organise feeds into tabs
CopyFeedsToTabs();
Expand Down Expand Up @@ -460,14 +460,16 @@ private async Task AggregateFeed(Feed feed, bool firstLoad = true)
{


articles = await App.WService.Get<List<Article>>(controller:"feeds", action: needUpdate ? "update" : null, parameters: needUpdate ? new string[] { timeUpdate } : null, jsonBody: $"{{\"search\": \"{feed.Keywords}\"}}", unSuccessCallback: async (err) =>
articles = await App.WService.Get<List<Article>>(controller:"feeds",
action: needUpdate ? "update" : null,
parameters: needUpdate ?
new string[] { timeUpdate } : null,
jsonBody: $"{{\"search\": \"{feed.Keywords}\"}}", unSuccessCallback: async (err) =>
{
#if DEBUG
throw new Exception(await err.Content.ReadAsStringAsync());
#endif
});
//if (!needUpdate)
// Articles?.Clear();

}
// Offline search
Expand All @@ -491,11 +493,8 @@ private async Task AggregateFeed(Feed feed, bool firstLoad = true)
UnnoticedArticles = new ObservableCollection<Article>( articles);
}
else
{
// Update list of articles
InsertArticles(articles);

}
SelectedFeed.IsLoaded = true;

IsRefreshing = false;
Expand All @@ -507,12 +506,12 @@ private async Task AggregateFeed(Feed feed, bool firstLoad = true)
/// <param name="articles">articles to add</param>
private void InsertArticles(IEnumerable<Article> articles)
{
Articles?.Clear();
for (int i = 0; i < articles.Count(); i++)
{
if (i != -1)
Articles.Add(articles.ElementAt(i));
}
ObservableRangeCollection<Article> articlesOld = new (_articles);
Articles = new ObservableRangeCollection<Article>();

Articles.AddRange(articles);
if (articlesOld.Any())
Articles.AddRange(articlesOld);
}

// See detail of the article
Expand Down
6 changes: 0 additions & 6 deletions AresNews/AresNews/Views/Portals/DiscordAuthPortal.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
using AresNews.Models.Http.Responses;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

Expand Down

0 comments on commit 57d456f

Please sign in to comment.