Skip to content

Commit

Permalink
added bible downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Dec 8, 2023
1 parent e42a6de commit 53c52df
Show file tree
Hide file tree
Showing 47 changed files with 2,811 additions and 167,151 deletions.
3 changes: 3 additions & 0 deletions Bible.App/Abstractions/IUiDataService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Bible.App.Models;
using Bible.Reader.Models;

namespace Bible.App.Abstractions
{
public interface IUiDataService
{
Task<BibleUiModel> LoadFileAsync(string fileName);
Task<BibleUiModel?> GetBibleAsync(string identifier, CancellationToken cancellationToken = default);
IAsyncEnumerable<WebBibleInfoModel> AsyncGetBibleInfo(CancellationToken cancellationToken = default);
}
}
5 changes: 3 additions & 2 deletions Bible.App/App.xaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Application
x:Class="BibleApp.App"
x:Class="Bible.App.App"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BibleApp">
xmlns:local="clr-namespace:Bible.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
<ResourceDictionary Source="Resources/Styles/Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
28 changes: 1 addition & 27 deletions Bible.App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
using Bible.App.Abstractions;
using Bible.App.ViewModels;
using Bible.Core.Abstractions;
using Bible.Core.Models;
using Bible.Reader.Services;
using CommunityToolkit.Mvvm.DependencyInjection;

namespace BibleApp
namespace Bible.App
{
public sealed partial class App : Application
{
private bool _initialized;

public App()
{
InitializeComponent();

// Register services
if (!_initialized)
{
_initialized = true;
Ioc.Default.ConfigureServices(
new ServiceCollection()
//Services
//.AddSingleton<IDataService<BibleModel>, BibleReader>()
.AddSingleton<IUiDataService, BibleUiData>()
#if DEBUG
//.AddSingleton<IUiDataService, TestUiData>()
#endif
//ViewModels
.AddTransient<MainPageViewModel>()
.BuildServiceProvider());
}

MainPage = new AppShell();
}
}
Expand Down
4 changes: 2 additions & 2 deletions Bible.App/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="BibleApp.AppShell"
x:Class="Bible.App.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Bible.App.Pages"
Title="BibleApp"
Title="Bible App"
Shell.FlyoutBehavior="Disabled">

<ShellContent
Expand Down
11 changes: 1 addition & 10 deletions Bible.App/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
using Bible.App.Pages;

namespace BibleApp
namespace Bible.App
{
public sealed partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
Register<MainPage>();
}

void Register<T>() where T : class
{
var type = typeof(T);
Routing.RegisterRoute(type.Name, type);
}
}
}
2 changes: 1 addition & 1 deletion Bible.App/Bible.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>BibleApp</RootNamespace>
<RootNamespace>Bible.App</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
58 changes: 54 additions & 4 deletions Bible.App/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using CommunityToolkit.Maui;
using Bible.App.Abstractions;
using Bible.App.Pages;
using Bible.App.ViewModels;
using Bible.Reader.Services;
using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.ComponentModel;

namespace BibleApp
namespace Bible.App
{
public static class MauiProgram
{
Expand All @@ -15,13 +21,57 @@ public static MauiApp CreateMauiApp()
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("MaterialIcons-Regular.ttf", "Material");
fonts.AddFont("MaterialIconsOutlined-Regular.ttf", "MaterialOutlined");
});

builder.Services.Register();

return builder.Build();
}

public static T? GetService<T>() =>
Ioc.Default.GetService<T>();

public static T GetRequiredService<T>() where T : notnull =>
Ioc.Default.GetRequiredService<T>();

static IServiceProvider Register(this IServiceCollection services)
{
#if DEBUG
builder.Logging.AddDebug();
services.AddLogging(o => o.AddDebug());
#endif
// Services
services.AddSingleton<WebZefaniaService>();
services.AddSingleton<IUiDataService, BibleUiDataService>();
//services.AddSingleton<IDataService<BibleModel>, BibleReader>()

return builder.Build();
// Views and ViewModels
services.Register<MainPage, MainPageViewModel>();

var provider = services.BuildServiceProvider();
Ioc.Default.ConfigureServices(provider);

return provider;
}

static void Register<TView>(this IServiceCollection services)
where TView : class, IView
{
// View
services.AddSingleton<TView>();
// Route
var type = typeof(TView);
Routing.RegisterRoute(type.Name, type);
}

static void Register<TView, TViewModel>(this IServiceCollection services)
where TView : class, IView
where TViewModel : class, INotifyPropertyChanged
{
// ViewModel
services.AddTransient<TViewModel>();
services.Register<TView>();
}
}
}
11 changes: 11 additions & 0 deletions Bible.App/Models/About.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Bible.App.Models;

public sealed class About
{
public string Title => AppInfo.Name;
public string Version => AppInfo.VersionString;
public string MoreInfoUrl => "https://aka.ms/maui";
public string Message => "This app is written in XAML and C# with .NET MAUI.";

public override string ToString() => $"{Title} v{Version}";
}
18 changes: 18 additions & 0 deletions Bible.App/Models/LanguageUiModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Bible.App.Models
{
public sealed partial class LanguageUiModel : List<TranslationUiModel>
{
/// <summary>
/// ISO 3 language code
/// </summary>
public string Language { get; set; }

public LanguageUiModel(string language, List<TranslationUiModel>? translations = null) : base(translations ?? new())
{
Language = language;
}

public override string ToString() =>
$"[{Language}] ({this.Count} translations)";
}
}
18 changes: 18 additions & 0 deletions Bible.App/Models/TranslationUiModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Bible.App.Models
{
public sealed partial class TranslationUiModel
{
public string Identifier { get; }

public string Name { get; }

public TranslationUiModel(string identifier, string name)
{
Identifier = identifier;
Name = name;
}

public override string ToString() =>
$"[{Identifier}] {Name}";
}
}
13 changes: 6 additions & 7 deletions Bible.App/Pages/BasePage.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using System.ComponentModel;

namespace Bible.App.Pages
{
public abstract class BasePage<TViewModel> : BasePage where TViewModel : ObservableObject
public abstract class BasePage<TViewModel> : BasePage where TViewModel : class, INotifyPropertyChanged
{
public TViewModel ViewModel { get; }
public TViewModel ViewModel { get; private set; }

protected BasePage(TViewModel? viewModel = null) : base()
{
ViewModel = viewModel ?? Ioc.Default.GetRequiredService<TViewModel>();
ViewModel = viewModel ?? MauiProgram.GetRequiredService<TViewModel>();
BindingContext = ViewModel;
}
}
Expand All @@ -18,8 +17,8 @@ public abstract class BasePage : ContentPage
{
protected BasePage()
{
if (string.IsNullOrWhiteSpace(Title))
Title = GetType().Name;
//if (string.IsNullOrWhiteSpace(Title))
// Title = GetType().Name;
}
}
}
21 changes: 18 additions & 3 deletions Bible.App/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<vm:MainPageViewModel />
</ContentPage.BindingContext>
-->
<!--<ContentPage.ToolbarItems>
<ToolbarItem
Command="{Binding NavigateCommand}"
CommandParameter="{x:Type views:SettingsPage}"
IconImageSource="{StaticResource FontIconSettings}"
Text="Setup" />
</ContentPage.ToolbarItems>-->

<Shell.TitleView>
<StackLayout>
Expand All @@ -35,13 +42,21 @@
WidthRequest="70" />
<Picker
x:Name="bibleTranslationPicker"
ItemsSource="{Binding Translations, Mode=OneTime}"
SelectedIndex="{Binding TranslationIndex, Mode=TwoWay}"
ItemsSource="{Binding Translations, Mode=OneWay}"
WidthRequest="120">
<Picker.Behaviors>
<mct:EventToCommandBehavior Command="{Binding TranslationSelectedCommand}" EventName="SelectedIndexChanged" />
<mct:EventToCommandBehavior
Command="{Binding TranslationSelectedCommand}"
CommandParameter="{Binding Source={x:Reference bibleTranslationPicker}, Path=SelectedItem, Mode=OneWay}"
EventName="SelectedIndexChanged" />
</Picker.Behaviors>
</Picker>
<Picker
x:Name="bibleLanguagePicker"
ItemsSource="{Binding Languages, Mode=OneTime}"
SelectedIndexChanged="OnLanguageSelectionChanged"
SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}"
WidthRequest="90" />
</HorizontalStackLayout>
</StackLayout>
</Shell.TitleView>
Expand Down
27 changes: 22 additions & 5 deletions Bible.App/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@ public MainPage() : base()
InitializeComponent();
}

protected override void OnAppearing()
protected override async void OnAppearing()
{
await Task.CompletedTask;
base.OnAppearing();
ViewModel.TranslationIndex = 0;
bibleChapterPicker.Focus();
await ViewModel.RefreshIdentifiersAsync();
}

private void OnLanguageSelectionChanged(object sender, EventArgs e)
{
if (sender is Picker picker && picker.SelectedItem is string selectedLanguage &&
ViewModel.Identifiers.TryGetValue(selectedLanguage, out List<TranslationUiModel>? translations))
{
bibleTranslationPicker.ItemsSource = translations;
if (ViewModel.SelectedLanguage == MainPageViewModel.Eng)
bibleTranslationPicker.SelectedItem = translations
.FirstOrDefault(t => t.Identifier == MainPageViewModel.Web);
if (bibleTranslationPicker.SelectedItem == null)
bibleTranslationPicker.SelectedIndex = 0;
bibleChapterPicker.Focus();
}
}

private void OnBookSelectionChanged(object sender, EventArgs e)
Expand All @@ -29,13 +44,15 @@ private void OnChapterSelectionChanged(object sender, EventArgs e)
{
if (isChapterViewChange)
isChapterViewChange = false;
else if (sender is Picker picker && picker.SelectedItem is ChapterUiModel chapter && chapter.Id > 0)
else if (sender is Picker picker && picker.SelectedItem is ChapterUiModel chapter && chapter.Id > 1)
{
chapterCollectionView.ScrollTo(chapter.Id - 1, position: ScrollToPosition.Start, animate: false);
}
}

private void OnChapterCollectionViewScrolled(object sender, ItemsViewScrolledEventArgs e)
{
if (ViewModel.ChapterIndex != e.FirstVisibleItemIndex)
if (ViewModel.ChapterIndex != e.FirstVisibleItemIndex && e.FirstVisibleItemIndex >= 0) // && e.VerticalDelta > 10
{
isChapterViewChange = true;
ViewModel.ChapterIndex = e.FirstVisibleItemIndex;
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Android.Content.PM;
using Android.OS;

namespace BibleApp
namespace Bible.App
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public sealed class MainActivity : MauiAppCompatActivity
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Platforms/Android/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Android.App;
using Android.Runtime;

namespace BibleApp
namespace Bible.App
{
[Application]
public sealed class MainApplication : MauiApplication
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Platforms/MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Foundation;

namespace BibleApp
namespace Bible.App
{
[Register("AppDelegate")]
public sealed class AppDelegate : MauiUIApplicationDelegate
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Platforms/MacCatalyst/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ObjCRuntime;
using UIKit;

namespace BibleApp
namespace Bible.App
{
public sealed class Program
{
Expand Down
Loading

0 comments on commit 53c52df

Please sign in to comment.