Skip to content

Commit

Permalink
Add features
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Nov 4, 2023
1 parent 0b4eb5b commit a223b64
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 230 deletions.
1 change: 1 addition & 0 deletions AniStream/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace AniStream;
Theme = "@style/Maui.SplashTheme",
MainLauncher = true,
SupportsPictureInPicture = true,
ClearTaskOnLaunch = true,
ConfigurationChanges = ConfigChanges.ScreenSize
| ConfigChanges.Orientation
| ConfigChanges.UiMode
Expand Down
8 changes: 8 additions & 0 deletions AniStream/Resources/Styles/Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@
<Setter Property="VerticalOptions" Value="Center" />
</Style>

<Style x:Key="Entry.Border" TargetType="Border">
<Setter Property="StrokeThickness" Value="2" />
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="Stroke" Value="{StaticResource Secondary}" />
<Setter Property="StrokeShape" Value="RoundRectangle 8" />
<Setter Property="VerticalOptions" Value="Center" />
</Style>

<Style x:Key="EntrySearchBorderStyle" TargetType="Border">
<Setter Property="Padding" Value="20,0" />
<Setter Property="Margin" Value="12,0" />
Expand Down
7 changes: 6 additions & 1 deletion AniStream/Utils/ProviderResolver.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using Juro.Core.Providers;
using System.Collections.Generic;
using Juro.Core.Providers;
using Juro.Providers.Anime;
using Juro.Providers.Anime.Indonesian;

namespace AniStream.Utils;

internal static class ProviderResolver
{
public static IAnimeProvider GetAnimeProvider() => new Gogoanime();

public static List<IAnimeProvider> GetAnimeProviders() =>
new() { new Gogoanime(), new AnimePahe(), new Aniwave(), new Kaido(), new OtakuDesu() };
}
63 changes: 54 additions & 9 deletions AniStream/ViewModels/EpisodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public partial class EpisodeViewModel : CollectionViewModel<Episode>, IQueryAttr
private readonly PlayerSettings _playerSettings = new();
private readonly SettingsService _settingsService = new();

private readonly IAnimeProvider _provider = ProviderResolver.GetAnimeProvider();
private IAnimeProvider _provider = ProviderResolver.GetAnimeProvider();
private readonly List<IAnimeProvider> _providers = ProviderResolver.GetAnimeProviders();

public ObservableRangeCollection<string> ProviderNames { get; set; } = new();

[ObservableProperty]
private Media? _entity;
Expand All @@ -52,6 +55,12 @@ public partial class EpisodeViewModel : CollectionViewModel<Episode>, IQueryAttr
[ObservableProperty]
private GridLayoutMode _gridLayoutMode;

[ObservableProperty]
private bool _isDubSelected;

[ObservableProperty]
private int _providerIndex;

private bool IsSavingFavorite { get; set; }

public EpisodeViewModel(AniClient aniClient)
Expand All @@ -60,12 +69,45 @@ public EpisodeViewModel(AniClient aniClient)

SelectedViewModelIndex = 1;

ProviderNames.AddRange(_providers.ConvertAll(x => x.Name));
ProviderIndex = 0;

//Load();

_playerSettings.Load();
_settingsService.Load();

GridLayoutMode = _settingsService.EpisodesGridLayoutMode;

PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(IsDubSelected))
IsDubSelectedChanged();
};
}

private async void IsDubSelectedChanged()
{
Entities.Clear();
await LoadCore();
}

[RelayCommand]
private async Task ProviderChanged(int index)
{
// Todo
ProviderIndex = 0;
await App.AlertService.ShowAlertAsync(
"Coming soon",
"This feature will be available in the coming releases."
);
//

return;

Entities.Clear();
_provider = _providers[index];
await LoadCore();
}

protected override async Task LoadCore()
Expand All @@ -86,6 +128,7 @@ protected override async Task LoadCore()
Anime = await TryFindBestAnime();
if (Anime is null)
{
await Toast.Make("Nothing found").Show();
await ShowProviderSearch();
return;
}
Expand Down Expand Up @@ -198,13 +241,17 @@ private void RefreshEpisodesProgress()
{
try
{
var result = await _provider.SearchAsync(Entity.Title.RomajiTitle);
var dubText = IsDubSelected ? " (dub)" : "";

SearchingText = $"Searching : {Entity.Title?.PreferredTitle}" + dubText;

var result = await _provider.SearchAsync(Entity.Title.RomajiTitle + dubText);

if (result.Count == 0)
result = await _provider.SearchAsync(Entity.Title.NativeTitle);
result = await _provider.SearchAsync(Entity.Title.NativeTitle + dubText);

if (result.Count == 0)
result = await _provider.SearchAsync(Entity.Title.EnglishTitle);
result = await _provider.SearchAsync(Entity.Title.EnglishTitle + dubText);

return result.FirstOrDefault();
}
Expand Down Expand Up @@ -263,11 +310,11 @@ async Task ShowSheet(Episode episode)
if (Anime is null)
return;

//var test1 = new EpisodeSelectionSheet2();
//var test1 = new VideoSourceSheet2();
//Shell.Current.ShowBottomSheet(test1, false);
//return;

var sheet = new EpisodeSelectionSheet();
var sheet = new VideoSourceSheet();
sheet.BindingContext = new VideoSourceViewModel(sheet, Anime, episode, Entity);

await sheet.ShowAsync();
Expand Down Expand Up @@ -324,7 +371,7 @@ private async Task RefreshIsFavorite()
{
var media = await _anilistClient.GetMediaAsync(Entity.Id);
Entity.IsFavorite = media.IsFavorite;
IsFavorite = media.IsFavorite;
//IsFavorite = media.IsFavorite;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -376,8 +423,6 @@ public void ApplyQueryAttributes(IDictionary<string, object> query)

OnPropertyChanged(nameof(Entity));

SearchingText = $"Searching : {Entity.Title?.PreferredTitle}";

RefreshIsFavorite();
}
}
Loading

0 comments on commit a223b64

Please sign in to comment.