-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
296 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using CastIt.Common.Utils; | ||
using CastIt.Interfaces; | ||
using CastIt.ViewModels.Items; | ||
using MvvmCross.Logging; | ||
using MvvmCross.Navigation; | ||
using MvvmCross.Plugin.Messenger; | ||
using MvvmCross.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Timers; | ||
|
||
namespace CastIt.ViewModels | ||
{ | ||
public class SplashViewModel : BaseViewModel | ||
{ | ||
private readonly IMvxNavigationService _navigationService; | ||
private readonly ITelemetryService _telemetryService; | ||
private readonly IAppSettingsService _settingsService; | ||
private readonly IPlayListsService _playListsService; | ||
private readonly Timer _timer; | ||
|
||
private string _loadingText; | ||
|
||
private readonly MvxInteraction _beforeNavigatingToMainViewModel = new MvxInteraction(); | ||
|
||
public string LoadingText | ||
{ | ||
get => _loadingText; | ||
set => SetProperty(ref _loadingText, value); | ||
} | ||
|
||
public IMvxInteraction BeforeNavigatingToMainViewModel | ||
=> _beforeNavigatingToMainViewModel; | ||
|
||
public SplashViewModel( | ||
ITextProvider textProvider, | ||
IMvxMessenger messenger, | ||
IMvxLogProvider logProvider, | ||
IMvxNavigationService navigationService, | ||
ITelemetryService telemetryService, | ||
IAppSettingsService settingsService, | ||
IPlayListsService playListsService) : base(textProvider, messenger, logProvider.GetLogFor<SplashViewModel>()) | ||
{ | ||
_navigationService = navigationService; | ||
_telemetryService = telemetryService; | ||
_settingsService = settingsService; | ||
_playListsService = playListsService; | ||
|
||
_timer = new Timer(800) | ||
{ | ||
AutoReset = false | ||
}; | ||
_timer.Elapsed += TimerElapsed; | ||
} | ||
|
||
public override Task Initialize() | ||
{ | ||
LoadingText = $"{GetText("Loading")}..."; | ||
Logger.Info($"{nameof(Initialize)}: Applying app theme and accent color..."); | ||
WindowsUtils.ChangeTheme(_settingsService.AppTheme, _settingsService.AccentColor); | ||
|
||
Logger.Info($"{nameof(Initialize)}: Deleting old preview / log files..."); | ||
try | ||
{ | ||
FileUtils.DeleteFilesInDirectory(FileUtils.GetPreviewsPath(), DateTime.Now.AddDays(-1)); | ||
FileUtils.DeleteFilesInDirectory(FileUtils.GetLogsPath(), DateTime.Now.AddDays(-3)); | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.Error(e, $"{nameof(Initialize)}: Error occurred while trying to delete previews"); | ||
_telemetryService.TrackError(e); | ||
} | ||
return base.Initialize(); | ||
} | ||
|
||
public override void ViewAppeared() | ||
{ | ||
base.ViewAppeared(); | ||
_timer.Start(); | ||
} | ||
|
||
public (double, double) GetWindowWidthAndHeight() | ||
{ | ||
return (_settingsService.WindowWidth, _settingsService.WindowHeight); | ||
} | ||
|
||
private async void TimerElapsed(object sender, ElapsedEventArgs e) | ||
{ | ||
_timer.Stop(); | ||
_timer.Elapsed -= TimerElapsed; | ||
_timer.Dispose(); | ||
|
||
Logger.Info($"{nameof(Initialize)}: Getting all playlists..."); | ||
var playLists = await _playListsService.GetAllPlayLists(); | ||
foreach (var playlist in playLists) | ||
{ | ||
var files = await _playListsService.GetAllFiles(playlist.Id); | ||
playlist.Items.AddRange(files.OrderBy(f => f.Position)); | ||
playlist.SetPositionIfChanged(); | ||
} | ||
|
||
Logger.Info($"{nameof(Initialize)}: Navigating to main view model..."); | ||
await _navigationService.Navigate<MainViewModel, List<PlayListItemViewModel>>(playLists); | ||
_beforeNavigatingToMainViewModel.Raise(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.