Skip to content

Commit

Permalink
Add an option for disabling background images
Browse files Browse the repository at this point in the history
  • Loading branch information
Heufneutje committed Dec 3, 2024
1 parent 92550f0 commit c029b7a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions SpeedrunTracker/Models/LocalStorage/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class UserSettings
public int MaxLeaderboardResults { get; set; }
public string? DateFormat { get; set; }
public string? TimeFormat { get; set; }
public bool? DisplayBackgrounds { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public async Task LoadSettingsAsync()
{
UserSettings = new()
{
MaxLeaderboardResults = Convert.ToInt32(_configuration["defaults:max-leaderboard-results"])
MaxLeaderboardResults = _configuration.GetValue<int>("defaults:max-leaderboard-results"),
DisplayBackgrounds = _configuration.GetValue<bool>("defaults:display-backgrounds")
};

await GetConnection().InsertAsync(UserSettings);
Expand All @@ -32,6 +33,9 @@ public async Task LoadSettingsAsync()

if (UserSettings.TimeFormat == null)
UserSettings.TimeFormat = _configuration["defaults:time-format"];

if (UserSettings.DisplayBackgrounds == null)
UserSettings.DisplayBackgrounds = _configuration.GetValue<bool>("defaults:display-backgrounds");
}

public async Task SaveSettingsAsync()
Expand Down
3 changes: 3 additions & 0 deletions SpeedrunTracker/ViewModels/GameDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public Game? Game
_followEntity = value;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(Platforms));
NotifyPropertyChanged(nameof(BackgroundUri));
}
}

Expand Down Expand Up @@ -163,6 +164,8 @@ public string Platforms

public override ShareDetails ShareDetails => new(Game?.Weblink, Game?.Names?.International);

public string? BackgroundUri => _settingsService.UserSettings.DisplayBackgrounds == true ? Game?.Assets?.Background?.Uri : null;

public async Task<bool> LoadCategoriesAsync()
{
if (Game == null)
Expand Down
8 changes: 7 additions & 1 deletion SpeedrunTracker/ViewModels/GameSeriesDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Mvvm.Input;
using Refit;
using SpeedrunTracker.Extensions;
using SpeedrunTracker.Navigation;
using System.Collections.ObjectModel;
Expand All @@ -10,6 +11,7 @@ namespace SpeedrunTracker.ViewModels;
public class GameSeriesDetailViewModel : BaseFollowViewModel<GameSeries>
{
private readonly IGameSeriesService _gameSeriesService;
private readonly ILocalSettingsService _settingsService;
private int _offset;
private bool _hasReachedEnd;

Expand All @@ -22,6 +24,7 @@ public GameSeries? Series
{
_followEntity = value;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(BackgroundUri));
}
}
}
Expand Down Expand Up @@ -49,10 +52,13 @@ public Game? SelectedGame

public override ShareDetails ShareDetails => new(Series?.Weblink, Series?.Names?.International);

public GameSeriesDetailViewModel(IGameSeriesService gameSeriesService, ILocalFollowService followService, IShareService shareService, IToastService toastService, IPopupService popupService) : base(followService, shareService, toastService, popupService)
public string? BackgroundUri => _settingsService.UserSettings.DisplayBackgrounds == true ? Series?.Assets?.Background?.Uri : null;

public GameSeriesDetailViewModel(IGameSeriesService gameSeriesService, ILocalFollowService followService, IShareService shareService, IToastService toastService, IPopupService popupService, ILocalSettingsService settingsService) : base(followService, shareService, toastService, popupService)
{
Games = [];
_gameSeriesService = gameSeriesService;
_settingsService = settingsService;
}

protected override Task FollowAsync(GameSeries entity) => _followService.FollowSeriesAsync(entity);
Expand Down
4 changes: 3 additions & 1 deletion SpeedrunTracker/ViewModels/RunDetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public RunDetails? RunDetails
{
_runDetails = value;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(BackgroundUri));

if (value?.Run.Videos?.Links != null)
VideoUrls.AddRange(_embedService.GetEmbeddableUrls(value.Run.Videos));
Expand Down Expand Up @@ -129,6 +130,8 @@ public string? StatusDescription

private bool ShouldShowTimingType(TimingType timingType) => RunDetails?.Ruleset?.TimingTypes?.Contains(timingType) == true && RunDetails?.Ruleset?.DefaultTimingType != timingType;

public string? BackgroundUri => _settingsService.UserSettings.DisplayBackgrounds == true ? RunDetails?.GameAssets?.Background?.Uri : null;

public override ShareDetails ShareDetails => new(RunDetails?.Run?.Weblink, Title);

public RunDetailsViewModel(IBrowserService browserService, IUserService userService, IEmbedService embedService, IShareService shareService, IToastService toastService, IConfiguration config, ILocalSettingsService settingsService, IPopupService popupService) : base(shareService, toastService, popupService)
Expand All @@ -147,7 +150,6 @@ private async Task ShowVideo()
await _browserService.OpenAsync(_selectedVideo.Url);
}


public async Task LoadData()
{
if (RunDetails?.Examiner == null && RunDetails?.Run.Status?.ExaminerId != null)
Expand Down
14 changes: 14 additions & 0 deletions SpeedrunTracker/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ public FormatSetting? TimeFormat
}
}

public bool DisplayBackgrounds
{
get => _settingsService.UserSettings.DisplayBackgrounds ?? false;
set
{
if (_settingsService.UserSettings.DisplayBackgrounds != value)
{
_settingsService.UserSettings.DisplayBackgrounds = value;
_hasChanges = true;
NotifyPropertyChanged();
}
}
}

private ObservableCollection<ThemeSetting>? _themeSettings;

public ObservableCollection<ThemeSetting> Themes
Expand Down
4 changes: 2 additions & 2 deletions SpeedrunTracker/Views/GameDetailsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
x:Class="SpeedrunTracker.Views.GameDetailPage"
Appearing="ContentPage_Appearing">
<Shell.TitleView>
<Label Text="{Binding Game.Names.International}" TextColor="White" FontSize="Medium" FontAttributes="Bold" VerticalTextAlignment="Center" MaxLines="2" FontAutoScalingEnabled="True"/>
<Label Text="{Binding Game.Names.International}" TextColor="White" FontSize="Medium" FontAttributes="Bold" VerticalTextAlignment="Center" MaxLines="2" FontAutoScalingEnabled="True" />
</Shell.TitleView>
<Grid>
<Image Source="{Binding Game.Assets.Background.Uri}" Style="{StaticResource CustomBackgroundImage}" />
<Image Source="{Binding BackgroundUri}" Style="{StaticResource CustomBackgroundImage}" />
<Grid Padding="20">
<CollectionView Style="{StaticResource ThresholdCollectionViewStyle}" ItemsSource="{Binding LeaderboardEntries}" ItemTemplate="{StaticResource LeaderboardTemplate}" RemainingItemsThresholdReachedCommand="{Binding DisplayLeaderboardEntriesCommand}" SelectedItem="{Binding SelectedLeaderboardEntry}" SelectionChangedCommand="{Binding NavigateToRunCommand}">
<CollectionView.Header>
Expand Down
2 changes: 1 addition & 1 deletion SpeedrunTracker/Views/GameSeriesDetailsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Label Text="{Binding Series.Names.International}" TextColor="White" FontSize="Medium" FontAttributes="Bold" VerticalTextAlignment="Center" MaxLines="2" FontAutoScalingEnabled="True" />
</Shell.TitleView>
<Grid>
<Image Source="{Binding Series.Assets.Background.Uri}" Style="{StaticResource CustomBackgroundImage}" />
<Image Source="{Binding BackgroundUri}" Style="{StaticResource CustomBackgroundImage}" />
<Grid Padding="20">
<CollectionView Style="{StaticResource ThresholdCollectionViewStyle}"
ItemsSource="{Binding Games}"
Expand Down
2 changes: 1 addition & 1 deletion SpeedrunTracker/Views/RunDetailsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ToolbarItem IconImageSource="share" Text="Share" Command="{Binding ShareCommand}" />
</ContentPage.ToolbarItems>
<Grid>
<Image Source="{Binding RunDetails.GameAssets.Background.Uri}" Style="{StaticResource CustomBackgroundImage}" />
<Image Source="{Binding BackgroundUri}" Style="{StaticResource CustomBackgroundImage}" />
<ScrollView>
<Grid Padding="10" RowDefinitions="Auto,Auto,Auto,Auto,Auto">
<Border Style="{StaticResource TransparentGridElementBorder}" Grid.Row="0">
Expand Down
8 changes: 4 additions & 4 deletions SpeedrunTracker/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
<VerticalStackLayout Padding="10">
<Border Style="{StaticResource TransparentGridElementBorder}">
<VerticalStackLayout>
<Label Text="Theme" Style="{StaticResource GroupHeaderLabel}" />
<Line />
<Label Text="Interface" Style="{StaticResource GroupHeaderLabel}" />
<Label Text="Theme" Style="{StaticResource SettingsItemSubLabel}" />
<Picker ItemsSource="{Binding Themes}" SelectedItem="{Binding Theme}" Margin="20,5,20,5" />
<Label Text="Display Backgrounds" Style="{StaticResource SettingsItemSubLabel}" />
<Switch IsToggled="{Binding DisplayBackgrounds}" HorizontalOptions="Start" Margin="15,5,20,5" />
</VerticalStackLayout>
</Border>

<Border Style="{StaticResource TransparentGridElementBorder}">
<VerticalStackLayout>
<Label Text="Date and Time" Style="{StaticResource GroupHeaderLabel}" />
<Line />
<Label Text="Date Format" Style="{StaticResource SettingsItemSubLabel}" />
<Picker ItemsSource="{Binding DateFormats}" SelectedItem="{Binding DateFormat}" Margin="20,5,20,5" />
<Label Text="Time Format" Style="{StaticResource SettingsItemSubLabel}" />
Expand All @@ -29,7 +30,6 @@
<Border Style="{StaticResource TransparentGridElementBorder}">
<VerticalStackLayout>
<Label Text="Maximum Leaderboard Results" Style="{StaticResource GroupHeaderLabel}" />
<Line />
<Grid ColumnDefinitions="*,Auto" Margin="0,0,10,0">
<Slider Grid.Column="0" Margin="10" Minimum="1" Maximum="1000" Value="{Binding MaxLeaderboardResults, Mode=TwoWay}" />
<Label Grid.Column="1" Margin="10" Text="{Binding MaxLeaderboardResults}" />
Expand Down
3 changes: 2 additions & 1 deletion SpeedrunTracker/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"defaults": {
"max-leaderboard-results": 500,
"date-format": "yyyy-MM-dd",
"time-format": "HH:mm"
"time-format": "HH:mm",
"display-backgrounds": true
}
}

0 comments on commit c029b7a

Please sign in to comment.