Skip to content

Commit

Permalink
Fixed AnimeListView null Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicPredator committed Jul 25, 2023
1 parent 1aa44bc commit 9ec7f35
Show file tree
Hide file tree
Showing 12 changed files with 2,520 additions and 95 deletions.
8 changes: 5 additions & 3 deletions src/AniMoe.App/AniMoe.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Page Remove="Constants\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Assets\emptyList.json" />
<None Remove="Assets\like-filled.svg" />
<None Remove="Assets\Window-Icon.ico" />
<None Remove="Controls\CharacterListView.xaml" />
Expand Down Expand Up @@ -71,6 +72,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.5.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230602002" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down Expand Up @@ -139,6 +141,9 @@
<Content Remove="Assets\profile.jpg" />
</ItemGroup>
<ItemGroup>
<Content Update="Assets\emptyList.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\like-filled.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -162,9 +167,6 @@
<Page Update="Controls\CharacterViewControls\AnimeListControl.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<None Update="Extensions\empty-list.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Page Update="Views\CharacterView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
2 changes: 1 addition & 1 deletion src/AniMoe.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public partial class App : Application
public App()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Debug()
.WriteTo.Debug()
.CreateLogger();
Log.Information("Logging Services Started");
Expand Down
1 change: 1 addition & 0 deletions src/AniMoe.App/Assets/emptyList.json

Large diffs are not rendered by default.

2,322 changes: 2,322 additions & 0 deletions src/AniMoe.App/Extensions/EmptyList.cs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/AniMoe.App/Extensions/empty-list.json

This file was deleted.

102 changes: 63 additions & 39 deletions src/AniMoe.App/ViewModels/AnimeListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@

namespace AniMoe.App.ViewModels
{
public class AnimeListViewModel : ObservableObject
public partial class AnimeListViewModel : ObservableObject
{
private AnimeListModel model;
private MasterViewModel StatusModel;
private bool loaded = false;
private bool isLoading = true;
private IEnumerable<string> statusLists;
private bool isEmpty = false;
private ObservableCollection<string> statusLists;
private ObservableCollection<Entry> currentListView;
private string selectedStatus;
private MediaListFliterView filterDialog;
private bool emptyCollection = false;
private Brush buttonColor = (Brush)App.Current.Resources["CardBackgroundFillColorDefaultBrush"];

[ObservableProperty]
private bool loadStatusBar;

public AnimeListModel Model
{
get => model;
Expand All @@ -52,6 +56,12 @@ public bool IsLoading
set => SetProperty(ref isLoading, value);
}

public bool IsEmpty
{
get => isEmpty;
set => SetProperty(ref isEmpty, value);
}

public Brush ButtonColor
{
get => buttonColor;
Expand All @@ -67,7 +77,7 @@ public bool EmptyCollection
public IAsyncRelayCommand LoadView { get; }
public IAsyncRelayCommand ReloadCollection { get; }

public IEnumerable<string> StatusLists
public ObservableCollection<string> StatusLists
{
get => statusLists;
set => SetProperty(ref statusLists, value);
Expand All @@ -88,7 +98,7 @@ public ObservableCollection<Entry> CurrentListView
public void StatusChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox box = sender as ComboBox;
if( CurrentListView != null && Model != null )
if( CurrentListView != null && Model != null && StatusLists != null)
{
Loaded = false;
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
Expand All @@ -99,33 +109,29 @@ public void StatusChanged(object sender, SelectionChangedEventArgs e)
}
}

private void CheckEmptyList()
{
EmptyCollection = CurrentListView.Count < 0;
}

public void SearchTextChanged(object sender, TextChangedEventArgs e)
{
TextBox box = sender as TextBox;
if( box.Text != "" )
{
Loaded = false;
ApplyFilters(filterDialog.Model);
CurrentListView = new ObservableCollection<Entry>(Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries.Where(
y => y.Media.Title.UserPreferred.ToLower().Contains(box.Text)
));
Loaded = true;
CheckEmptyList();
}
else
if (CurrentListView.Count > 0 )
{
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries;
ApplyFilters(filterDialog.Model);
CheckEmptyList();
TextBox box = sender as TextBox;
if( box.Text != "" )
{
Loaded = false;
ApplyFilters(filterDialog.Model);
CurrentListView = new ObservableCollection<Entry>(Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries.Where(
y => y.Media.Title.UserPreferred.ToLower().Contains(box.Text)
));
Loaded = true;
}
else
{
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries;
ApplyFilters(filterDialog.Model);
}
}
}

Expand All @@ -142,24 +148,39 @@ public AnimeListViewModel(MasterViewModel masterViewModel)

public async Task InitView(bool isReload = false)
{
Loaded = false;
IsLoading = !Loaded;
if( SelectedStatus == null )
if( !isReload )
{
Loaded = false;
IsLoading = !Loaded;
LoadStatusBar = false;
}
if( StatusLists == null )
{
StatusLists = StatusModel.mediaListStatusModel.Data.AnimeStatusList.Lists.Select(x => x.Name);
StatusLists = new(
StatusModel.mediaListStatusModel.Data.AnimeStatusList
.Lists.Select(x => x.Name).ToList()
);
}
if ( Model == null || isReload)
{
Model = await Initialize.FetchData();
}
CurrentListView = new();
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
LoadStatusBar = true;
if( Model.Data.MediaListCollection.Lists.Count > 0 )
{
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries;
ApplyFilters(filterDialog.Model);
).FirstOrDefault().Entries;
ApplyFilters(filterDialog.Model);
IsEmpty = false;
}
else
{
CurrentListView = null;
IsEmpty = true;
}
Loaded = true;
IsLoading = !Loaded;
CheckEmptyList();
}

public async void FilterButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
Expand All @@ -170,16 +191,19 @@ public async void FilterButton_Click(object sender, Microsoft.UI.Xaml.RoutedEven
if( result == ContentDialogResult.Primary)
{
ApplyFilters(filterDialog.Model);
CheckEmptyList();
} else if ( result == ContentDialogResult.Secondary )
{
ApplyFilters(filterDialog.Model);
CheckEmptyList();
}
}

private async Task reloadCollection()
{
Loaded = false;
IsLoading = !Loaded;
LoadStatusBar = false;
StatusLists = null;
await StatusModel.LoadFromApi();
await InitView(true);
}

Expand Down
84 changes: 57 additions & 27 deletions src/AniMoe.App/ViewModels/MangaListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@
using AniMoe.App.Models;
using Microsoft.UI.Xaml.Media;
using Windows.UI;
using Microsoft.Extensions.DependencyInjection;

namespace AniMoe.App.ViewModels
{
public class MangaListViewModel : ObservableRecipient
public partial class MangaListViewModel : ObservableObject
{
private MangaListModel model;
private MasterViewModel StatusModel;
private bool loaded = false;
private bool isLoading = true;
private IEnumerable<string> statusLists;
private bool isEmpty = false;
private ObservableCollection<string> statusLists;
private ObservableCollection<Entry> currentListView;
private string selectedStatus;
private MediaListFliterView filterDialog;
private Brush buttonColor = (Brush)App.Current.Resources["CardBackgroundFillColorDefaultBrush"];

[ObservableProperty]
private bool loadStatusBar;

public MangaListModel Model
{
get => model;
Expand All @@ -47,6 +50,12 @@ public bool IsLoading
set => SetProperty(ref isLoading, value);
}

public bool IsEmpty
{
get => isEmpty;
set => SetProperty(ref isEmpty, value);
}

public Brush ButtonColor
{
get => buttonColor;
Expand All @@ -57,7 +66,7 @@ public Brush ButtonColor
public IRelayCommand SaveImage { get; }
public IAsyncRelayCommand ReloadCollection { get; }

public IEnumerable<string> StatusLists
public ObservableCollection<string> StatusLists
{
get => statusLists;
set => SetProperty(ref statusLists, value);
Expand All @@ -77,7 +86,7 @@ public ObservableCollection<Entry> CurrentListView

public void StatusChanged(object sender, SelectionChangedEventArgs e)
{
if( CurrentListView != null && Model != null )
if( CurrentListView != null && Model != null && SelectedStatus != null )
{
Loaded = false;
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
Expand All @@ -90,24 +99,27 @@ public void StatusChanged(object sender, SelectionChangedEventArgs e)

public void SearchTextChanged(object sender, TextChangedEventArgs e)
{
TextBox box = sender as TextBox;
if( box.Text != "" )
if (CurrentListView != null )
{
Loaded = false;
ApplyFilters(filterDialog.Model);
CurrentListView = new ObservableCollection<Entry>(Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries.Where(
y => y.Media.Title.UserPreferred.ToLower().Contains(box.Text)
));
Loaded = true;
}
else
{
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries;
ApplyFilters(filterDialog.Model);
TextBox box = sender as TextBox;
if( box.Text != "" )
{
Loaded = false;
ApplyFilters(filterDialog.Model);
CurrentListView = new ObservableCollection<Entry>(Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries.Where(
y => y.Media.Title.UserPreferred.ToLower().Contains(box.Text)
));
Loaded = true;
}
else
{
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).First().Entries;
ApplyFilters(filterDialog.Model);
}
}
}

Expand All @@ -124,23 +136,35 @@ public MangaListViewModel(MasterViewModel masterViewModel)

public async Task InitView(bool isReload = false)
{
Loaded = false;
IsLoading = !Loaded;
if( !isReload )
{
Loaded = false;
IsLoading = !Loaded;
LoadStatusBar = false;
}
if( StatusLists == null )
{
StatusLists = StatusModel.mediaListStatusModel.Data.MangaStatusList.Lists.Select(x => x.Name);
StatusLists = new(
StatusModel.mediaListStatusModel.Data.MangaStatusList
.Lists.Select(x => x.Name).ToList()
);
}
if( Model == null || isReload )
{
Model = await Initialize.FetchData();
}
CurrentListView = new();
if (Model.Data.MediaListCollection.Lists.Count > 0 )
LoadStatusBar = true;
if( Model.Data.MediaListCollection.Lists.Count > 0 )
{
CurrentListView = Model.Data.MediaListCollection.Lists.Where(
x => x.Name == SelectedStatus
).FirstOrDefault().Entries;
ApplyFilters(filterDialog.Model);
IsEmpty = false;
} else
{
CurrentListView = null;
IsEmpty = true;
}
Loaded = true;
IsLoading = !Loaded;
Expand All @@ -163,6 +187,12 @@ public async void FilterButton_Click(object sender, Microsoft.UI.Xaml.RoutedEven

private async Task reloadCollection()
{
Loaded = false;
IsLoading = !Loaded;
LoadStatusBar = false;
IsEmpty = false;
StatusLists = null;
await StatusModel.LoadFromApi();
await InitView(true);
}

Expand Down
Loading

0 comments on commit 9ec7f35

Please sign in to comment.