Skip to content

Commit

Permalink
Moved translation selection to the top of the screen and book and cha…
Browse files Browse the repository at this point in the history
…pter to the bottom
  • Loading branch information
danzuep committed Nov 3, 2024
1 parent 5654808 commit f0beb84
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
echo "Project File: $projectFile";
echo "Project Version: $buildVersion";
echo "Target Framework: $targetFramework";
dotnet publish $projectFile /p:Version=$buildVersion -f $targetFramework --nologo;
dotnet publish $projectFile -f $targetFramework /p:Version=$buildVersion --nologo;
env:
projectFile: '${{ inputs.projectFile }}'
buildVersion: '${{ inputs.version }}'
Expand Down
12 changes: 12 additions & 0 deletions Bible.App/Abstractions/IStorageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Bible.App.Abstractions
{
public interface IStorageService
{
Task<T?> GetAsync<T>(string key);
Task SetAsync<T>(string key, T value);
bool Remove(string key);
Task<Dictionary<string, string>> GetAsync(IEnumerable<string> keys);
Task SetAsync(IReadOnlyDictionary<string, string> keyValuePairs);
bool RemoveAll(IEnumerable<string>? keys = null);
}
}
87 changes: 49 additions & 38 deletions Bible.App/Bible.App.csproj
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<TargetFrameworks>$(NetVersion)-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('macOS'))">$(TargetFrameworks);$(NetVersion)-ios;$(NetVersion)-macios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>

<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks> -->

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<RootNamespace>Bible.App</RootNamespace>

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

<!-- App Identifier -->
<ApplicationId>com.danzuep.bibleapp</ApplicationId>
<Description>Open-source Bible app for any platform.</Description>
<Authors>Daniel Collingwood</Authors>
<RepositoryUrl>https://github.com/danzuep/BibleApp</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PublishDir>../publish</PublishDir>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<RootNamespace>Bible.App</RootNamespace>
<PackageReleaseNotes>
0.1.0 Simple Bible reader
</PackageReleaseNotes>

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

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

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>$(Version)</ApplicationDisplayVersion>
<ApplicationVersion>$(Version)</ApplicationVersion>

<!-- C# Hot Reload -->
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>

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

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>$(NetVersion)-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('macOS'))">$(TargetFrameworks);$(NetVersion)-ios;$(NetVersion)-macios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>

<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks> -->

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
Expand Down Expand Up @@ -105,7 +106,17 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bible.Core\Bible.Core.csproj" />
<ProjectReference Include="..\Bible.Data\Bible.Data.csproj" />
<ProjectReference Include="..\Bible.Reader\Bible.Reader.csproj" />
Expand Down
62 changes: 55 additions & 7 deletions Bible.App/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Bible.App.Abstractions;
using System.ComponentModel;
using Bible.App.Abstractions;
using Bible.App.Models.Options;
using Bible.App.Pages;
using Bible.App.Services;
using Bible.App.ViewModels;
using Bible.Reader.Services;
using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.ComponentModel;

namespace Bible.App
{
Expand All @@ -25,7 +28,11 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("MaterialIconsOutlined-Regular.ttf", "MaterialOutlined");
});

builder.Services.Register();
var configuration = BuildConfiguration();
builder.Configuration.AddConfiguration(configuration);

builder.Services.ConfigureLogging();
builder.Services.RegisterServices();

return builder.Build();
}
Expand All @@ -36,12 +43,11 @@ public static MauiApp CreateMauiApp()
public static T GetRequiredService<T>() where T : notnull =>
Ioc.Default.GetRequiredService<T>();

static IServiceProvider Register(this IServiceCollection services)
static IServiceProvider RegisterServices(this IServiceCollection services)
{
#if DEBUG
services.AddLogging(o => o.AddDebug());
#endif
// Services
services.AddSingleton((_) => SecureStorage.Default);
services.AddSingleton<IStorageService, StorageService>();
services.AddSingleton<WebZefaniaService>();
services.AddSingleton<IUiDataService, BibleUiDataService>();
//services.AddSingleton<IDataService<BibleModel>, BibleReader>()
Expand All @@ -55,6 +61,48 @@ static IServiceProvider Register(this IServiceCollection services)
return provider;
}

public static IConfiguration BuildConfiguration(string? prefix = "Azure")
{
var configurationBuilder = new ConfigurationBuilder();
if (DeviceInfo.Platform == DevicePlatform.WinUI)
{
#if WINDOWS
// Add configuration sources
configurationBuilder.AddUserSecrets<App>();
configurationBuilder.AddEnvironmentVariables(prefix);
#endif
}
var configuration = configurationBuilder.Build();
return configuration;
}

static void ConfigureOptions(this IServiceCollection services, IConfiguration configuration)
{
if (DeviceInfo.Platform == DevicePlatform.WinUI)
{
#if WINDOWS
// Bind typed configuration sources
services.Configure<AppOptions>(configuration); //configuration.GetSection(AppOptions.SectionName)
#endif
}
}

static void ConfigureLogging(this IServiceCollection services)
{
services.AddLogging(o =>
{
var appName = typeof(MauiProgram).Assembly.GetName().ToString();
#if ANDROID
o.AddProvider(new AndroidLoggerProvider());
#else
o.AddConsole();
#endif
#if DEBUG
o.AddDebug().SetMinimumLevel(LogLevel.Debug);
#endif
});
}

static void Register<TView>(this IServiceCollection services)
where TView : class, IView
{
Expand Down
9 changes: 9 additions & 0 deletions Bible.App/Models/Options/AppOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bible.App.Models.Options
{
internal class AppOptions
{
public const string SectionName = "App";

public string? HostAddress { get; set; }
}
}
55 changes: 30 additions & 25 deletions Bible.App/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,29 @@

<Shell.TitleView>
<StackLayout>
<HorizontalStackLayout Spacing="25">
<HorizontalStackLayout Padding="0,0" Spacing="15">
<Picker
x:Name="bibleBookPicker"
ItemDisplayBinding="{Binding Name, Mode=OneWay}"
ItemsSource="{Binding Bible, Mode=OneWay}"
SelectedIndex="{Binding BookIndex, Mode=TwoWay}"
SelectedIndexChanged="OnBookSelectionChanged"
WidthRequest="160" />
<Picker
x:Name="bibleChapterPicker"
ItemDisplayBinding="{Binding Id, Mode=OneWay}"
ItemsSource="{Binding Source={x:Reference bibleBookPicker}, Path=SelectedItem, Mode=OneWay}"
SelectedIndex="{Binding ChapterIndex, Mode=TwoWay}"
SelectedIndexChanged="OnChapterSelectionChanged"
WidthRequest="70" />
x:Name="bibleLanguagePicker"
ItemsSource="{Binding Languages, Mode=OneTime}"
SelectedIndexChanged="OnLanguageSelectionChanged"
SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}"
WidthRequest="90" />
<Picker
x:Name="bibleTranslationPicker"
ItemsSource="{Binding Translations, Mode=OneWay}"
WidthRequest="120">
WidthRequest="240">
<Picker.Behaviors>
<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>

<Grid RowDefinitions="*,30">
<Grid RowDefinitions="*,50">
<CollectionView
x:Name="chapterCollectionView"
ItemsSource="{Binding Source={x:Reference bibleBookPicker}, Path=SelectedItem, Mode=OneWay}"
Expand All @@ -77,10 +63,29 @@
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Label
<HorizontalStackLayout
Grid.Row="1"
Text="{Binding Source={x:Reference bibleBookPicker}, Path=SelectedItem.Copyright, StringFormat='© {0}'}"
TextColor="Gray" />
Padding="15,0"
Spacing="15">
<Picker
x:Name="bibleBookPicker"
ItemDisplayBinding="{Binding Name, Mode=OneWay}"
ItemsSource="{Binding Bible, Mode=OneWay}"
SelectedIndex="{Binding BookIndex, Mode=TwoWay}"
SelectedIndexChanged="OnBookSelectionChanged"
WidthRequest="160" />
<Picker
x:Name="bibleChapterPicker"
ItemDisplayBinding="{Binding Id, Mode=OneWay}"
ItemsSource="{Binding Source={x:Reference bibleBookPicker}, Path=SelectedItem, Mode=OneWay}"
SelectedIndex="{Binding ChapterIndex, Mode=TwoWay}"
SelectedIndexChanged="OnChapterSelectionChanged"
WidthRequest="70" />
<Label
Text="{Binding Source={x:Reference bibleBookPicker}, Path=SelectedItem.Copyright, StringFormat='© {0}'}"
TextColor="Gray"
VerticalOptions="Center" />
</HorizontalStackLayout>
<Grid.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Swiped="OnSwipeLeft" />
<SwipeGestureRecognizer Direction="Right" Swiped="OnSwipeRight" />
Expand Down
6 changes: 6 additions & 0 deletions Bible.App/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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))
{
//SemanticScreenReader.Announce(selectedLanguage);
bibleTranslationPicker.ItemsSource = translations;
if (ViewModel.SelectedLanguage == MainPageViewModel.Eng)
bibleTranslationPicker.SelectedItem = translations
Expand All @@ -35,6 +36,10 @@ private void OnLanguageSelectionChanged(object sender, EventArgs e)
private void OnBookSelectionChanged(object sender, EventArgs e)
{
ViewModel.ChapterIndex = 0;
//if (sender is Picker picker && picker.SelectedItem is BookUiModel book && book.Id > 1)
//{
// SemanticScreenReader.Announce(book.Id.ToString());
//}
}

bool isChapterViewChange;
Expand All @@ -45,6 +50,7 @@ private void OnChapterSelectionChanged(object sender, EventArgs e)
isChapterViewChange = false;
else if (sender is Picker picker && picker.SelectedItem is ChapterUiModel chapter && chapter.Id > 1)
{
//SemanticScreenReader.Announce(chapter.Id.ToString());
chapterCollectionView.ScrollTo(chapter.Id - 1, position: ScrollToPosition.Start, animate: false);
}
}
Expand Down
Loading

0 comments on commit f0beb84

Please sign in to comment.