Skip to content

Commit

Permalink
moved bibles to App/Resources/Raw
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Dec 2, 2023
1 parent cc6c261 commit 7af9b1d
Show file tree
Hide file tree
Showing 33 changed files with 265 additions and 3,466 deletions.
10 changes: 10 additions & 0 deletions Bible.App/Abstractions/IUiDataService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Bible.Core.Abstractions;
using Bible.App.Models;

namespace Bible.App.Abstractions
{
public interface IUiDataService : IDataService<BibleUiModel>
{
Task<BibleUiModel> LoadAsync(string fileName);
}
}
15 changes: 7 additions & 8 deletions Bible.App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Bible.Interfaces;
using Bible.App.Abstractions;
using Bible.App.ViewModels;
using Bible.Core.Abstractions;
using Bible.Core.Models;
using Bible.Reader.Services;
using BibleApp.Models;
using BibleApp.ViewModels;
using CommunityToolkit.Mvvm.DependencyInjection;

namespace BibleApp
Expand All @@ -21,12 +22,10 @@ public App()
Ioc.Default.ConfigureServices(
new ServiceCollection()
//Services
.AddSingleton<IDataService<BibleModel>, BibleReader>()
.AddSingleton<IUiDataService, BibleUiData>()
#if DEBUG
//.AddSingleton<IDataService<BibleUiModel>, TestUiData>()
.AddSingleton<IDataService<BibleUiModel>, BibleUiData>()
#else
//.AddSingleton<IBibleService, BibleReader>()
.AddSingleton<IDataService<BibleUiModel>, BibleUiData>()
//.AddSingleton<IUiDataService, TestUiData>()
#endif
//ViewModels
.AddTransient<MainPageViewModel>()
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
x:Class="BibleApp.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:BibleApp.Pages"
xmlns:pages="clr-namespace:Bible.App.Pages"
Title="BibleApp"
Shell.FlyoutBehavior="Disabled">

Expand Down
2 changes: 1 addition & 1 deletion Bible.App/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BibleApp.Pages;
using Bible.App.Pages;

namespace BibleApp
{
Expand Down
54 changes: 34 additions & 20 deletions Bible.App/Bible.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,50 @@
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>BibleApp</ApplicationTitle>
<ApplicationTitle>Open Bible app</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.bibleapp</ApplicationId>
<ApplicationId>com.danzuep.bibleapp</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- %APPDATA%\Microsoft\UserSecrets\ -->
<UserSecretsId>BibleApp-0e005d03-3ba9-41c2-9309-7994ffddc789</UserSecretsId>
</PropertyGroup>

<PropertyGroup>
<Authors>Daniel Collingwood</Authors>
<Description>Open-source Bible app for any platform.</Description>
<RepositoryUrl>https://github.com/danzuep/BibleApp</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageReleaseNotes>
0.1.0 Simple Bible reader
</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<UserSecretsId>0e005d03-3ba9-41c2-9309-7994ffddc789</UserSecretsId>
</PropertyGroup>

</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<SupportedOSPlatformVersion>10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
</PropertyGroup>

<!-- https://learn.microsoft.com/en-us/dotnet/maui/android/deployment/publish-cli?view=net-maui-8.0#define-build-properties-in-your-project-file -->
<PropertyGroup Condition="$(TargetFramework.Contains('-android')) and '$(Configuration)' == 'Release'">
<AndroidPackageFormats>apk</AndroidPackageFormats>
<AndroidSigningKeyStore>../release/BibleApp.keystore</AndroidSigningKeyStore>
<AndroidSigningKeyAlias>BibleApp-key</AndroidSigningKeyAlias>
<AndroidSigningKeyPass>env:AndroidSigningPassword</AndroidSigningKeyPass>
<AndroidSigningStorePass>env:AndroidSigningPassword</AndroidSigningStorePass>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
Expand All @@ -56,7 +82,7 @@
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="7.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
Expand All @@ -72,16 +98,4 @@
<ProjectReference Include="..\Bible.Reader\Bible.Reader.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Views\BookView.xaml.cs">
<DependentUpon>BookView.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Views\BookView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions Bible.App/Models/BibleUiModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace BibleApp.Models
namespace Bible.App.Models
{
public sealed partial class BibleUiModel : List<BookUiModel>
{
public string Translation { get; } = default!;
public string Translation { get; }

public BibleUiModel(string translation) : base(new List<BookUiModel>())
public BibleUiModel(string? translation) : base(new List<BookUiModel>())
{
Translation = translation;
Translation = translation ?? string.Empty;
}

public BibleUiModel(List<BookUiModel> books, string translation) : base(books)
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Models/BookUiModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;

namespace BibleApp.Models
namespace Bible.App.Models
{
[ObservableObject]
public sealed partial class BookUiModel : List<ChapterUiModel>
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Models/ChapterUiModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BibleApp.Models
namespace Bible.App.Models
{
public sealed partial class ChapterUiModel : List<VerseUiModel>
{
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Models/VerseUiModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BibleApp.Models
namespace Bible.App.Models
{
public sealed partial class VerseUiModel
{
Expand Down
2 changes: 1 addition & 1 deletion Bible.App/Pages/BasePage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;

namespace BibleApp.Pages
namespace Bible.App.Pages
{
public abstract class BasePage<TViewModel> : BasePage where TViewModel : ObservableObject
{
Expand Down
10 changes: 5 additions & 5 deletions Bible.App/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<pages:BasePage
x:Class="BibleApp.Pages.MainPage"
x:Class="Bible.App.Pages.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:m="clr-namespace:BibleApp.Models"
xmlns:m="clr-namespace:Bible.App.Models"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:pages="clr-namespace:BibleApp.Pages"
xmlns:views="clr-namespace:BibleApp.Views"
xmlns:vm="clr-namespace:BibleApp.ViewModels"
xmlns:pages="clr-namespace:Bible.App.Pages"
xmlns:views="clr-namespace:Bible.App.Views"
xmlns:vm="clr-namespace:Bible.App.ViewModels"
x:DataType="vm:MainPageViewModel"
x:TypeArguments="vm:MainPageViewModel">
<!--
Expand Down
25 changes: 16 additions & 9 deletions Bible.App/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using BibleApp.Models;
using BibleApp.ViewModels;
using BibleApp.Views;
using Bible.App.Models;
using Bible.App.ViewModels;
using Bible.App.Views;

namespace BibleApp.Pages
namespace Bible.App.Pages
{
public sealed partial class MainPage : BasePage<MainPageViewModel>
{
Expand All @@ -23,16 +23,23 @@ private void OnBookSelectionChanged(object sender, EventArgs e)
ViewModel.ChapterIndex = 0;
}

bool isChapterViewChange;

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

private void OnChapterCollectionViewScrolled(object sender, ItemsViewScrolledEventArgs e)
{
if (ViewModel.ChapterIndex != e.FirstVisibleItemIndex)
{
isChapterViewChange = true;
ViewModel.ChapterIndex = e.FirstVisibleItemIndex;
}
}

private async void OnChapterClickedEvent(object sender, EventArgs e)
Expand All @@ -47,14 +54,14 @@ private async void OnChapterClickedEvent(object sender, EventArgs e)

private void OnSwipeLeft(object sender, SwipedEventArgs e)
{
if (ViewModel.Bible?[ViewModel.BookIndex]?.Count > bibleChapterPicker.SelectedIndex + 1)
bibleChapterPicker.SelectedIndex++;
if (ViewModel.BookIndex >= 0 && ViewModel.Bible?[ViewModel.BookIndex]?.Count > ViewModel.ChapterIndex + 1)
ViewModel.ChapterIndex++;
}

private void OnSwipeRight(object sender, SwipedEventArgs e)
{
if (bibleChapterPicker.SelectedIndex > 0)
bibleChapterPicker.SelectedIndex--;
if (ViewModel.ChapterIndex > 0)
ViewModel.ChapterIndex--;
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
86 changes: 76 additions & 10 deletions Bible.App/Services/BibleUiData.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,94 @@
using Bible.Core.Models;
using Bible.Interfaces;
using BibleApp.Models;
using Bible.App.Abstractions;
using Bible.Core.Abstractions;
using Bible.Core.Models;
using Bible.Reader.Models;
using Bible.Reader.Adapters;
using Bible.App.Models;
using System.Xml.Serialization;

namespace Bible.Reader.Services
{
public sealed class BibleUiData : IDataService<BibleUiModel>
public sealed class BibleUiData : IUiDataService
{
private readonly IDataService<BibleModel> _dataService;

public BibleUiData(IDataService<BibleModel> dataService)
{
_dataService = dataService;
}

/// <summary>
/// Map XML file data to an object.
/// </summary>
/// <typeparam name="T">Object to map to.</typeparam>
/// <param name="xmlFileName">XML file name.</param>
/// <inheritdoc cref="XmlSerializer.Deserialize(Stream)"/>
internal static async Task<T?> GetFromXmlFileAsync<T>(string xmlFileName, FileType fileType = FileType.Xml) where T : class
{
var typeName = fileType == FileType.Xml ? "xml" : fileType.ToString().ToLowerInvariant();
(string prefix, string suffix) = (typeName, $".{typeName}");
//string suffix = Path.GetExtension(xmlFileName);
//string prefix = suffix.TrimStart('.');
if (!Path.HasExtension(xmlFileName) || !xmlFileName.EndsWith(suffix))
xmlFileName += suffix;
var xmlFilePath = Path.Combine(prefix, xmlFileName);
T? result = default;
if (await FileSystem.AppPackageFileExistsAsync(xmlFilePath))
{
using var fileStream = await FileSystem.OpenAppPackageFileAsync(xmlFilePath);
var serializer = new XmlSerializer(typeof(T));
result = serializer.Deserialize(fileStream) as T;
}
else
{
//var xmlFilePath2 = Path.Combine("..", xmlFilePath);
//bool found2 = await FileSystem.Current.AppPackageFileExistsAsync(xmlFilePath2);
//var xmlFilePath3 = Path.Combine("..", xmlFilePath2);
//bool found3 = await FileSystem.Current.AppPackageFileExistsAsync(xmlFilePath3);
//var xmlFilePath4 = Path.Combine("Bible.Data", xmlFilePath3);
//bool found4 = await FileSystem.Current.AppPackageFileExistsAsync(xmlFilePath4);
//string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
//var path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location);
//var fullPath = Path.GetFullPath(xmlFilePath);
//var appDataDirectory = FileSystem.Current.AppDataDirectory;
//var folders1 = Directory.EnumerateDirectories(appDataDirectory).ToList();
//var files1 = Directory.EnumerateFiles(appDataDirectory).ToList();
//var cacheDirectory = FileSystem.Current.CacheDirectory;
//var folders2 = Directory.EnumerateDirectories(cacheDirectory).ToList();
//var files2 = Directory.EnumerateFiles(cacheDirectory).ToList();
//var personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
//var folders3 = Directory.EnumerateDirectories(personalFolder).ToList();
//var files3 = Directory.EnumerateFiles(personalFolder).ToList();
System.Diagnostics.Debugger.Break();
}
return result;
}

private BibleModel? _bible = null;

public BibleUiModel Load(string fileName, string suffix = ".xml")
{
_bible = new BibleReader().Load(fileName);
var translation = Path.GetFileName(fileName);
return GetBible(_bible, translation);
_bible = _dataService.Load(fileName, suffix);
return GetBible(_bible);
}

public async Task<BibleUiModel> LoadAsync(string fileName)
{
var info = fileName.Split('/');
var translation = Path.GetFileName(info[1]);
var bibleFile = await GetFromXmlFileAsync<XmlZefania05>(fileName);
_bible = bibleFile?.ToBibleFormat(info[0], translation);
return GetBible(_bible);
}

public static BibleUiModel GetBible(BibleModel? bible, string translation, bool addChapters = true)
public static BibleUiModel GetBible(BibleModel? bible, bool addChapters = true)
{
var bibleModel = new BibleUiModel(translation);
var bibleModel = new BibleUiModel(bible?.Information?.Translation);
if (bible != null)
{
foreach (var book in bible.Books)
{
var bibleBook = new BookUiModel(book.Id, book.Reference.BookName, book.ChapterCount) { Copyright = translation };
var bibleBook = new BookUiModel(book.Id, book.Reference.BookName, book.ChapterCount) { Copyright = bibleModel.Translation };
if (addChapters)
{
foreach (var chapter in book.Chapters)
Expand Down
12 changes: 9 additions & 3 deletions Bible.App/Services/TestUiData.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using Bible.Interfaces;
using BibleApp.Models;
using Bible.App.Models;
using Bible.App.Abstractions;

namespace Bible.Reader.Services
{
public sealed class TestUiData : IDataService<BibleUiModel>
public sealed class TestUiData : IUiDataService
{
public BibleUiModel Load(string fileName, string suffix = ".xml") =>
LoadTest(66, suffix.Length * 3, fileName.Length * 3);

public async Task<BibleUiModel> LoadAsync(string fileName)
{
await Task.CompletedTask;
return Load(fileName);
}

public BibleUiModel LoadTest(int bookCount, int chapterCount, int verseCount, string name = "Books, Chapters, and Verses")
{
var books = Enumerable.Range(1, bookCount);
Expand Down
Loading

0 comments on commit 7af9b1d

Please sign in to comment.