Example #1
0
        async Task Initialize()
        {
            var accounts = accountDataRepository?.GetAccounts();

            if (accounts != null && accounts.Any())
            {
                Accounts = accounts;
                if (accounts.Count == 1)
                {
                    CurrentAccount = accounts[0];
#warning "Optimistic: any account/cookies is supposed valid, proper implementation needed (cookies timeout check)"
                    await ThreadUI.Invoke(() =>
                    {
                        Loc.NavigationService.Navigate(View.Connect);
                        Loc.Main.AccountManager.CurrentAccount.ConnectionErrorStatus = "Connecting";
                        Loc.Main.AccountManager.CurrentAccount.IsConnecting          = true;
                    });

                    bool success = await CurrentAccount.BeginAuthentication(false);

                    if (success)
                    {
                        await ThreadUI.Invoke(() =>
                        {
                            Loc.Main.AccountManager.CurrentAccount.IsConnected = false;
                            Loc.NavigationService.Navigate(View.Main);
                        });
                    }
                    else
                    {
                        Debug.WriteLine("Login failed");
                    }
                }
                else
                {
                    // Handle selection of one of the multi accounts
                }
            }
            else
            {
                // navigate to connectpage
                await ThreadUI.Invoke(() =>
                {
                    CurrentAccount = new Account();
                    Loc.NavigationService.Navigate(View.Connect);
                    // Trying to detect login and password stored in RoamingSettings
                    if (ApplicationSettingsHelper.Contains(nameof(CurrentAccount.Pseudo), false) && ApplicationSettingsHelper.Contains(nameof(CurrentAccount.Password), false))
                    {
                        ToastHelper.Simple("Connexion automatique ...");
                        var pseudo              = ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentAccount.Pseudo), false).ToString();
                        var password            = ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentAccount.Password), false).ToString();
                        CurrentAccount.Pseudo   = pseudo;
                        CurrentAccount.Password = password;
                        ConnectCommand.Execute(null);
                    }
                });
            }
        }
Example #2
0
        private async Task RestorePlaylist()
        {
            try
            {
                var playlist = await BackgroundTrackRepository.LoadPlaylist();

                if (!playlist.Any())
                {
                    return;
                }

                var trackIds         = playlist.Select(node => node.TrackId);
                var restoredplaylist = new SmartCollection <IMediaItem>();
                foreach (int trackId in trackIds)
                {
                    var trackItem = await Locator.MediaLibrary.LoadTrackById(trackId);

                    if (trackItem != null)
                    {
                        restoredplaylist.Add(trackItem);
                    }
                }

                if (!ApplicationSettingsHelper.Contains(nameof(CurrentMedia)))
                {
                    return;
                }
                var index = (int)ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentMedia));
                if (restoredplaylist.Any())
                {
                    if (index == -1)
                    {
                        // Background Audio was terminated
                        // We need to reset the playlist, or set the current track 0.
                        ApplicationSettingsHelper.SaveSettingsValue(nameof(CurrentMedia), 0);
                        index = 0;
                    }
                    SetCurrentMediaPosition(index);
                }

                if (CurrentMedia >= restoredplaylist.Count || CurrentMedia == -1)
                {
                    CurrentMedia = 0;
                }

                if (restoredplaylist.Any())
                {
                    await SetPlaylist(restoredplaylist, true, false, restoredplaylist[CurrentMedia]);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to restore the playlist");
            }
        }
Example #3
0
 internal void DeleteCurrentAccount()
 {
     if (CurrentAccount == null)
     {
         return;
     }
     accountDataRepository?.Delete(CurrentAccount);
     if (ApplicationSettingsHelper.Contains(nameof(CurrentAccount.Pseudo), false) &&
         ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentAccount.Pseudo), false).ToString() == CurrentAccount.Pseudo)
     {
         ApplicationSettingsHelper.ReadResetSettingsValue(nameof(CurrentAccount.Pseudo), false);
         ApplicationSettingsHelper.ReadResetSettingsValue(nameof(CurrentAccount.Password), false);
     }
     CurrentAccount = null;
 }
Example #4
0
 public static bool NeedsToDrop()
 {
     if (ApplicationSettingsHelper.Contains(Strings.AlreadyLaunched, true) && ApplicationSettingsHelper.Contains(Strings.DatabaseVersion, true) && (int)ApplicationSettingsHelper.ReadSettingsValue(Strings.DatabaseVersion, true) == Numbers.DbVersion)
     {
         LogHelper.Log("DB does not need to be dropped.");
         return(false);
     }
     else
     {
         LogHelper.Log("DB needs to be dropped.");
         ApplicationSettingsHelper.SaveSettingsValue(Strings.DatabaseVersion, Numbers.DbVersion, true);
         ApplicationSettingsHelper.SaveSettingsValue(Strings.AlreadyLaunched, true, true);
         return(true);
     }
 }
Example #5
0
        private bool NeedsToDrop()
        {
            Package        thisPackage = Package.Current;
            PackageVersion version     = thisPackage.Id.Version;

            if (ApplicationSettingsHelper.Contains(Strings.DatabaseVersion) && (int)ApplicationSettingsHelper.ReadSettingsValue(Strings.DatabaseVersion) == Numbers.DbVersion)
            {
                LogHelper.Log("DB does not need to be dropped.");
                return(false);
            }
            else
            {
                LogHelper.Log("DB needs to be dropped.");
                ApplicationSettingsHelper.SaveSettingsValue(Strings.DatabaseVersion, Numbers.DbVersion);
                return(true);
            }
        }
Example #6
0
        public async Task UpdateTrackFromMF()
        {
            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
#if WINDOWS_PHONE_APP
                // TODO : this shouldn't be here
                Locator.MediaPlaybackViewModel.OnLengthChanged((long)BackgroundMediaPlayer.Current.NaturalDuration.TotalMilliseconds);
#endif
                if (!ApplicationSettingsHelper.Contains(BackgroundAudioConstants.CurrentTrack))
                {
                    return;
                }
                int index = (int)ApplicationSettingsHelper.ReadSettingsValue(BackgroundAudioConstants.CurrentTrack);
                Locator.MediaPlaybackViewModel.TrackCollection.CurrentTrack = index;
                await SetCurrentArtist();
                await SetCurrentAlbum();
                await UpdatePlayingUI();
            });
        }
Example #7
0
        public void Restore()
        {
            if (!ApplicationSettingsHelper.Contains(nameof(Index)))
            {
                return;
            }

            var playlist = BackgroundTrackRepository.LoadPlaylist();

            if (!playlist.Any())
            {
                return;
            }

            var trackIds         = playlist.Select(node => node.TrackId);
            var restoredplaylist = new SmartCollection <IMediaItem>();

            foreach (int trackId in trackIds)
            {
                var trackItem = Locator.MediaLibrary.LoadTrackById(trackId);
                if (trackItem != null)
                {
                    restoredplaylist.Add(trackItem);
                }
            }

            if (restoredplaylist.Count == 0)
            {
                return;
            }
            clear();
            _playlist = restoredplaylist;
            OnPlaylistChanged?.Invoke();
            _index = (int)ApplicationSettingsHelper.ReadSettingsValue(nameof(Index));
            OnCurrentMediaChanged?.Invoke(_playlist[_index], true);
        }
Example #8
0
        public override async void Execute(object parameter)
        {
            /* Connect when ENTER key is pressed */
            var keyStroke = parameter as KeyRoutedEventArgs;

            if (keyStroke != null)
            {
                if (keyStroke.Key == Windows.System.VirtualKey.Enter)
                {
                    keyStroke.Handled = true;
                }
                else
                {
                    return;
                }
            }

            if (Loc.Main.AccountManager.Accounts.FirstOrDefault(x => x.Pseudo == Loc.Main.AccountManager.CurrentAccount.Pseudo) != null)
            {
                return;
            }
            await ThreadUI.Invoke(() =>
            {
                Loc.Main.AccountManager.CurrentAccount.ConnectionErrorStatus = "Connecting";
                Loc.Main.AccountManager.CurrentAccount.IsConnecting          = true;
            });

            bool success = await Loc.Main.AccountManager.CurrentAccount.BeginAuthentication(true);

            if (success)
            {
                Loc.Main.AccountManager.Accounts.Add(Loc.Main.AccountManager.CurrentAccount);
                Loc.Main.AccountManager.AddCurrentAccountInDB();

                var autoConnectFromRoamingSettings = ApplicationSettingsHelper.Contains(nameof(Loc.Main.AccountManager.CurrentAccount.Pseudo), false);
                var md = new MessageDialog("Voulez-vous être connecté automatiquement à ce compte ?", "Juste une question");
                if (!autoConnectFromRoamingSettings)
                {
                    md.Commands.Add(new UICommand()
                    {
                        Label   = "Oui",
                        Invoked = async(command) =>
                        {
                            await ThreadUI.Invoke(() =>
                            {
                                Loc.Main.AccountManager.AddCurrentAccountInRoamingSettings();
                            });
                        },
                    });
                    md.Commands.Add(new UICommand()
                    {
                        Label   = "Non",
                        Invoked = (command) =>
                        {
                        },
                    });
                }
                await ThreadUI.Invoke(async() =>
                {
                    if (!autoConnectFromRoamingSettings)
                    {
                        await md.ShowAsync();
                    }
                    Loc.Main.AccountManager.CurrentAccount.IsConnecting          = false;
                    Loc.Main.AccountManager.CurrentAccount.ConnectionErrorStatus = "Login succeeded";
                    Loc.NavigationService.Navigate(View.Main);
                });
            }
            else
            {
                await ThreadUI.Invoke(() =>
                {
                    Loc.Main.AccountManager.CurrentAccount.IsConnecting          = false;
                    Loc.Main.AccountManager.CurrentAccount.ConnectionErrorStatus = "Login failed";
                    ToastHelper.Simple("Echec de la connexion");
                });

                Debug.WriteLine("Login failed");
            }
        }