Skip to content

Commit

Permalink
Add check for updates in settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
angelinn committed May 10, 2024
1 parent 63bd230 commit f813244
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IApplicationService

string GetVersion();
Task OpenUri(string uri);
Task OpenBrowserAsync(Uri uri);
void RunOnUIThread(Action action);
Task<Position?> GetCurrentPositionAsync();
Task<bool> HasLocationPermissions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
<PackageReference Include="Mapsui.Maui" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Octokit" Version="11.0.1" />
<PackageReference Include="OpenMeteo.dotnet" Version="2.0.0" />
<PackageReference Include="QuikGraph" Version="2.5.0" />
<PackageReference Include="QuikGraph.Serialization" Version="2.5.0" />
<PackageReference Include="YamlDotNet" Version="15.1.2" />
<PackageReference Include="Sentry.Maui" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CommunityToolkit.Mvvm.Messaging;

using SkgtService;
using SkgtService.Models.Json;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -34,10 +35,14 @@ public partial class SettingsViewModel : BaseViewModel

private Func<string, string, string, string[], Task<string>> displayActionSheet;

public SettingsViewModel()
private readonly VersionService versionService;

public SettingsViewModel(VersionService versionService)
{
RefreshStopsUpdatedTime();

this.versionService = versionService;

ShowNearestStop = ApplicationService.GetBoolSetting(Settings.ShowStopOnLaunch, false);
MaxTextZoom = ApplicationService.GetIntSetting(Settings.MaxTextZoom, 0);
MaxPinsZoom = ApplicationService.GetIntSetting(Settings.MaxPinsZoom, 0);
Expand All @@ -53,6 +58,26 @@ public void Initialize(Func<string, string, string, string[], Task<string>> disp
this.displayActionSheet = displayActionSheet;
}

[RelayCommand]
private async Task CheckForUpdates()
{

NewVersion version = await versionService.CheckForUpdates();
if (version != null)
{
bool result = await ApplicationService.DisplayAlertAsync("Нова версия", $"Има нова версия {version.VersionNumber} 🎉", "СВАЛЯНЕ", "ОТКАЗ");
if (result)
{
Uri url = new Uri(version.ReleaseUrl);
await ApplicationService.OpenBrowserAsync(url);
}
}
else
{
await ApplicationService.DisplayAlertAsync("", "Инсталирана е последна версия на Trammy! 🎉", "ОК");
}
}

[RelayCommand]
private async Task ChooseTileServer()
{
Expand Down
4 changes: 2 additions & 2 deletions src/TramlineFive/TramlineFive.Maui/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<FontImageSource FontFamily="MaterialIconsOutlinedRegular.otf" Glyph="history" />
</ShellContent.Icon>
</ShellContent>
<Tab Route="Lines" Shell.TabBarTitleColor="DodgerBlue" Title="Линии" Shell.BackgroundColor="DodgerBlue" Shell.FlyoutBehavior="Disabled" Shell.NavBarIsVisible="True">
<Tab Route="Lines" Shell.TabBarTitleColor="DodgerBlue" Shell.TabBarForegroundColor="DodgerBlue" Title="Линии" Shell.BackgroundColor="DodgerBlue" Shell.FlyoutBehavior="Disabled" Shell.NavBarIsVisible="True">
<Tab.Icon>
<FontImageSource FontFamily="MaterialIconsOutlinedRegular.otf" Glyph="departure_board" />
</Tab.Icon>
Expand Down Expand Up @@ -89,7 +89,7 @@

<ShellContent Style="{StaticResource TabStyle}" Route="Directions" Title="Пътуване (Експериментално)" ContentTemplate="{DataTemplate pages:Directions}">
<ShellContent.Icon>
<FontImageSource FontFamily="MaterialIconsOutlinedRegular.otf" Glyph="route" />
<FontImageSource FontFamily="MaterialIconsOutlinedRegular.otf" Glyph="route" Color="DodgerBlue" />
</ShellContent.Icon>
</ShellContent>

Expand Down
8 changes: 4 additions & 4 deletions src/TramlineFive/TramlineFive.Maui/Pages/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
BindingContext="{Binding AboutViewModel, Source={StaticResource Locator}}" BackgroundColor="{DynamicResource BackgroundColor}" >

<StackLayout Padding="10">
<Label Text="Tramline Five" FontSize="Large" />
<Label Text="{Binding Version, StringFormat='Version: {0}'}" FontSize="Large" />
<Label Text="Trammy" FontSize="Large" />
<Label Text="{Binding Version, StringFormat='Версия: {0}'}" FontSize="Large" />

<Button Text="FAQ" HorizontalOptions="Start" Margin="0,20,0,0" />
<Button Text="FAQ" HorizontalOptions="Start" Margin="0,20,0,10" />
<Button Text="Докладвай бъг/предложение" HorizontalOptions="Start" />

<Label Margin="0,20,0,0" Text="Това приложение е open source.&#x0a;&#x0a;Създадено е с цел улесняване на проверката на пристиганията на градския транспорт в България.&#x0a;&#x0a;Приложението не генерира печалба." />
<Label Margin="0,20,0,10" Text="Това приложение е open source.&#x0a;&#x0a;Създадено е с цел улесняване на проверката на пристиганията на градския транспорт в България.&#x0a;&#x0a;Приложението не генерира печалба." />

<Button Text="Open source лицензи" Command="{Binding OpenLicensesPage}" />
</StackLayout>
Expand Down
40 changes: 34 additions & 6 deletions src/TramlineFive/TramlineFive.Maui/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TramlineFive.Pages.SettingsPage"
xmlns:cv="clr-namespace:TramlineFive.Converters"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Title="Настройки"
Shell.NavBarIsVisible="True"
BindingContext="{Binding SettingsViewModel, Source={StaticResource Locator}}">
Expand All @@ -20,9 +21,14 @@
<ColumnDefinition Width="55" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding CleanHistoryCommand}" />
</Grid.GestureRecognizers>

<Grid.Behaviors>
<mct:TouchBehavior Command="{Binding CleanHistoryCommand}"
DefaultAnimationDuration="250"
DefaultAnimationEasing="{x:Static Easing.CubicInOut}"
PressedOpacity="0.6"
PressedScale="0.8"/>
</Grid.Behaviors>

<Label FontFamily="MaterialIconsOutlinedRegular.otf" Text="delete" FontSize="24" TextColor="{DynamicResource IconsColor}" VerticalOptions="Center" Margin="10,0,0,0"/>
<Label Grid.Column="1" Text="Изчистване на история" FontSize="16" VerticalTextAlignment="Center" />
Expand All @@ -34,9 +40,13 @@
<ColumnDefinition Width="55" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding UpdateStopsCommand}" />
</Grid.GestureRecognizers>
<Grid.Behaviors>
<mct:TouchBehavior Command="{Binding UpdateStopsCommand}"
DefaultAnimationDuration="250"
DefaultAnimationEasing="{x:Static Easing.CubicInOut}"
PressedOpacity="0.6"
PressedScale="0.8"/>
</Grid.Behaviors>

<Label FontFamily="MaterialIconsOutlinedRegular.otf" Text="refresh" FontSize="26" TextColor="{DynamicResource IconsColor}" VerticalOptions="Center" Margin="10,0,0,0"/>
<StackLayout Grid.Column="1" Spacing="3">
Expand All @@ -48,6 +58,24 @@
</ActivityIndicator>
</Grid>

<Grid Margin="0,20,0,0" HeightRequest="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.Behaviors>
<mct:TouchBehavior Command="{Binding CheckForUpdatesCommand}"
DefaultAnimationDuration="250"
DefaultAnimationEasing="{x:Static Easing.CubicInOut}"
PressedOpacity="0.6"
PressedScale="0.8"/>
</Grid.Behaviors>

<Label FontFamily="MaterialIconsOutlinedRegular.otf" Text="upgrade" FontSize="26" TextColor="{DynamicResource IconsColor}" VerticalOptions="Center" Margin="10,0,0,0"/>

<Label Grid.Column="1" Text="Проверка за нова версия" FontSize="16" VerticalTextAlignment="Center" />
</Grid>

<Grid Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public void VibrateShort()
}
}

public async Task OpenBrowserAsync(Uri uri)
{
await Browser.Default.OpenAsync(uri);
}

public async Task OpenUri(string uri)
{
await Launcher.OpenAsync(new Uri(uri));
Expand Down

0 comments on commit f813244

Please sign in to comment.