Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
Add activity type for tracking in settings
Browse files Browse the repository at this point in the history
Fix #105
  • Loading branch information
Depechie committed Oct 8, 2017
1 parent af6c3a8 commit 57485b9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Kliva/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Settings

public ActivitySort ActivitySort { get; set; }

public ActivityRecording ActivityRecordingType { get; set; }

public AppVersion AppVersion { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/Kliva/Services/Interfaces/ISettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public interface ISettingsService : IApplicationInfoService
Task<ActivitySort> GetStoredActivitySortAsync();
Task SetActivitySortAsync(ActivitySort sort);

Task<ActivityRecording> GetStoredActivityRecordingTypeAsync();
Task SetActivityRecordingTypeAsync(ActivityRecording activityRecordingType);

Task<AppVersion> GetStoredAppVersionAsync();
Task SetAppVersionAsync(AppVersion appVersionB);
}
Expand Down
15 changes: 15 additions & 0 deletions src/Kliva/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public async Task SetDistanceUnitTypeAsync(DistanceUnitType distanceUnitType)
await SaveSettingsToStorageAsync();
}

public async Task<ActivityRecording> GetStoredActivityRecordingTypeAsync()
{
await LoadSettingsAsync();
return _settings?.ActivityRecordingType ?? ActivityRecording.Cycling;
}

public async Task SetActivityRecordingTypeAsync(ActivityRecording activityRecordingType)
{
await LoadSettingsAsync(createIfNotExisting: true);

_settings.ActivityRecordingType = activityRecordingType;

await SaveSettingsToStorageAsync();
}

public async Task<ActivityFeedFilter> GetStoredActivityFeedFilterAsync()
{
await LoadSettingsAsync();
Expand Down
8 changes: 5 additions & 3 deletions src/Kliva/ViewModels/RecordViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class RecordViewModel : KlivaBaseViewModel
private string _gpxFile;
private readonly ILocationService _locationService;
private readonly IStravaService _stravaService;
private readonly ISettingsService _settingsService;
private readonly IGPXService _gpxService;
private readonly IMessageBoxService _messageBoxService;

Expand Down Expand Up @@ -78,10 +79,11 @@ public ActivityTracking RecordStatus

public RecordViewModel(INavigationService navigationService,
ILocationService locationService, IGPXService gpxService,
IStravaService stravaService, IMessageBoxService messageBoxService) : base(navigationService)
ISettingsService settingsService, IStravaService stravaService, IMessageBoxService messageBoxService) : base(navigationService)
{
_gpxService = gpxService;
_locationService = locationService;
_settingsService = settingsService;
_stravaService = stravaService;
_messageBoxService = messageBoxService;
//_locationService.StatusChanged += OnLocationServiceStatusChanged;
Expand All @@ -102,8 +104,8 @@ private async Task ViewLoaded()
{
_loading = true;

//TODO: Glenn - refactor to settings option
ActivityText = ActivityRecording.Cycling.ToString();
var activityRecordingType = await _settingsService.GetStoredActivityRecordingTypeAsync();
ActivityText = activityRecordingType.ToString();

//TODO: Glenn - Better the GPS tracking based on sport type and during activity
/*
Expand Down
25 changes: 24 additions & 1 deletion src/Kliva/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public string SelectedSortType
set { Set(() => SelectedSortType, ref _selectedSortType, value); }
}

private ObservableCollection<string> _activityTypes = new ObservableCollection<string>();
public ObservableCollection<string> ActivityTypes
{
get => _activityTypes;
set => Set(() => ActivityTypes, ref _activityTypes, value);
}

private string _selectedActivityType;
public string SelectedActivityType
{
get => _selectedActivityType;
set => Set(() => SelectedActivityType, ref _selectedActivityType, value);
}

private string _mapSizes;
public string MapSizes
{
Expand Down Expand Up @@ -93,6 +107,9 @@ public SettingsViewModel(INavigationService navigationService, ISettingsService

SortTypes.Add(ActivitySort.StartTime.ToString());
SortTypes.Add(ActivitySort.EndTime.ToString());

ActivityTypes.Add(ActivityRecording.Cycling.ToString());
ActivityTypes.Add(ActivityRecording.Running.ToString());
}

private async void OnSettingsViewModelPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand All @@ -107,8 +124,11 @@ private async void OnSettingsViewModelPropertyChanged(object sender, System.Comp
await _settingsService.SetDistanceUnitTypeAsync(newValue);
}

else if (e.PropertyName.Equals("SelectedSortType", StringComparison.OrdinalIgnoreCase))
if (e.PropertyName.Equals("SelectedSortType", StringComparison.OrdinalIgnoreCase))
await _settingsService.SetActivitySortAsync(Enum<ActivitySort>.Parse(SelectedSortType));

if (e.PropertyName.Equals(nameof(SelectedActivityType), StringComparison.OrdinalIgnoreCase))
await _settingsService.SetActivityRecordingTypeAsync(Enum<ActivityRecording>.Parse(SelectedActivityType));
}

private async Task ViewLoaded()
Expand All @@ -121,6 +141,9 @@ private async Task ViewLoaded()
ActivitySort activitySort = await _settingsService.GetStoredActivitySortAsync();
SelectedSortType = activitySort.ToString();

ActivityRecording activityRecordingType = await _settingsService.GetStoredActivityRecordingTypeAsync();
SelectedActivityType = activityRecordingType.ToString();

var appInfoList = await _settingsService.GetAppInfoAsync();
CurrentVersion = appInfoList.FirstOrDefault();
//TODO: Glenn - refactor initialization in settings service? While converting json to class?
Expand Down
17 changes: 16 additions & 1 deletion src/Kliva/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Setter Target="TitleTextBlock.Style" Value="{StaticResource TitleTextBlockMobile}" />
<Setter Target="MeasurementUnitsCombobox.HorizontalAlignment" Value="Stretch" />
<Setter Target="SortTypeCombobox.HorizontalAlignment" Value="Stretch" />
<Setter Target="ActivityRecordingTypeCombobox.HorizontalAlignment" Value="Stretch" />
<Setter Target="ClearMapsButton.Visibility" Value="Collapsed" />
<Setter Target="BottomAppBar.Visibility" Value="Visible" />
</VisualState.Setters>
Expand All @@ -64,6 +65,7 @@
<Setter Target="TitleTextBlock.Style" Value="{StaticResource TitleTextBlockDesktopWithSideBar}" />
<Setter Target="MeasurementUnitsCombobox.HorizontalAlignment" Value="Left" />
<Setter Target="SortTypeCombobox.HorizontalAlignment" Value="Left" />
<Setter Target="ActivityRecordingTypeCombobox.HorizontalAlignment" Value="Left" />
<Setter Target="ClearMapsButton.Visibility" Value="Visible" />
<Setter Target="BottomAppBar.Visibility" Value="Collapsed" />
</VisualState.Setters>
Expand Down Expand Up @@ -149,10 +151,23 @@
TextWrapping="WrapWholeWords"
RelativePanel.Below="SortTypeCombobox"
Text="* We usually sort the activities on the time they started, but the Strava website shows them sorted by end time. This difference is mostly visible in longer running activities." />
<TextBlock FontSize="12" Foreground="{StaticResource SubTextBrush}"
<TextBlock x:Name="RemarkMoreTextBlock" FontSize="12" Foreground="{StaticResource SubTextBrush}"
TextWrapping="WrapWholeWords"
RelativePanel.Below="RemarkTextBlock"
Text="** Changing these settings currently need a restart of the application." />

<TextBlock x:Name="ActivityRecordingTypeTextBlock" Text="defaut activity type for activity tracking" Margin="0,10,0,0"
FontFamily="{StaticResource OpenSansFontLight}"
RelativePanel.Below="RemarkMoreTextBlock"
RelativePanel.AlignLeftWithPanel="True"/>
<ComboBox x:Name="ActivityRecordingTypeCombobox"
HorizontalContentAlignment="Stretch"
ItemsSource="{x:Bind ViewModel.ActivityTypes, Mode=OneWay}"
SelectedItem="{x:Bind ViewModel.SelectedActivityType, Mode=TwoWay}"
Margin="0,10"
MinWidth="150"
RelativePanel.Below="ActivityRecordingTypeTextBlock"
RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" />
</RelativePanel>
</PivotItem>
<PivotItem x:Name="CachePivot"
Expand Down

0 comments on commit 57485b9

Please sign in to comment.