Ejemplo n.º 1
0
 private void GetClientType()
 {
     try
     {
         var id = Context.QueryString["id"];
         if (Context.QueryString.Contains("session"))
         {
             var session = Context.QueryString["session"];
             _targetSession = int.Parse(session);
         }
         ClientIdent = (ClientType)int.Parse(id);
         Id          = Interlocked.Increment(ref _number);
         if (ClientIdent == ClientType.ControlClient)
         {
             RCH            = new RemoteControlHandler(this);
             SessionPointer = SessionHandler.AvailableSessions[_targetSession];
             SessionPointer.HandlerInstance.AddClientToSession(this);
         }
         if (ClientIdent == ClientType.Wrapper)
         {
             WE = new WrapperEvents(this);
         }
         GE = new GameEvents(this);
         var master = GetOpcodeCmd(Opcodes.ServerOpcodes.SMSG_HANDSHAKE_CLIENT);
         var cmd    = JToken.FromObject(new HandshakeClient());
         SendMsg(AddPayload(master, cmd));
     }
     catch (Exception)
     {
         SendMsg(GetErrorCmd(Opcodes.ServerOpcodes.SMSG_ERR_INVALID_CLIENTID));
         throw;
     }
 }
Ejemplo n.º 2
0
 public void Init()
 {
                 #if !__ANDROID__
     NativeTrackHandler.Shared.Init();
     RemoteControlHandler.Init();
                 #endif
     LoadPlaylist();
 }
Ejemplo n.º 3
0
        public SettingViewController() : base(UITableViewStyle.Plain, null)
        {
            Title           = Strings.Settings;
            accountsSection = new MenuSection("Accounts")
            {
                (addNewAccountElement = new SettingsElement("Add Streaming Service", async() => {
                    try{
                        var vc = new ServicePickerViewController();
                        this.PresentModalViewController(new UINavigationController(vc), true);
                        var service = await vc.GetServiceTypeAsync();
                        await ApiManager.Shared.CreateAndLogin(service);
                        UpdateAccounts();
                    }
                    catch (TaskCanceledException)
                    {
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                })),
                (lastFmElement = string.IsNullOrEmpty(ApiConstants.LastFmApiKey) ? null : new SettingsSwitch("Last.FM", Settings.LastFmEnabled)),
                (twitterScrobbleElement = new SettingsSwitch("Auto Tweet", Settings.TwitterEnabled)
                {
                    Detail = Settings.TwitterDisplay
                }),
                new SettingsSwitch("Import iPod Music", Settings.IncludeIpod)
                {
                    ValueUpdated = ToggleIPod
                },
                new MenuHelpTextElement(
                    "Automatically imports and plays music from your local library. This saves data and space on your phone."),
            };

            Root = new RootElement(Strings.Settings)
            {
                accountsSection,
                new MenuSection(Strings.Playback)
                {
                    new SettingsSwitch(Strings.EnableLikeOnTheLockScreen, Settings.ThubsUpOnLockScreen)
                    {
                        ValueUpdated = (b => {
                            Settings.ThubsUpOnLockScreen = b;
                            RemoteControlHandler.SetupThumbsUp();
                        })
                    },
                    new MenuHelpTextElement(Strings.EnableLikeHint),
                    new SettingsSwitch(Strings.EnableGaplessPlayback, Settings.ThubsUpOnLockScreen)
                    {
                        ValueUpdated = (b => {
                            Settings.ThubsUpOnLockScreen = b;
                            RemoteControlHandler.SetupThumbsUp();
                        })
                    },
                    new MenuHelpTextElement(Strings.EnableGapplessHint),
                    new SettingsSwitch(Strings.PlayVideosWhenAvailable, Settings.PreferVideos)
                    {
                        ValueUpdated = (b => { Settings.PreferVideos = b; })
                    },
                    new MenuHelpTextElement(Strings.PlaysMusicVideoHint),
                    new SettingsSwitch(Strings.PlayCleanVersionsOfSongs, Settings.FilterExplicit)
                    {
                        ValueUpdated = (b => { Settings.FilterExplicit = b; })
                    },
                    new MenuHelpTextElement(Strings.PlayesCleanVersionOfSongsHint),
                },
                new MenuSection(Strings.Streaming)
                {
                    new SettingsSwitch(Strings.DisableAllAccess, Settings.DisableAllAccess)
                    {
                        ValueUpdated = (on) => {
                            Settings.DisableAllAccess = on;
                        }
                    },
                    new MenuHelpTextElement(Strings.DisableAllAccessHint),
                    (CreateQualityPicker(Strings.CellularAudioQuality, Settings.MobileStreamQuality, (q) => Settings.MobileStreamQuality = q)),
                    (CreateQualityPicker(Strings.WifiAudioQuality, Settings.WifiStreamQuality, (q) => Settings.WifiStreamQuality = q)),
                    (CreateQualityPicker(Strings.VideoQuality, Settings.VideoStreamQuality, (q) => Settings.VideoStreamQuality = q)),
                    (CreateQualityPicker(Strings.OfflineAudioQuality, Settings.DownloadStreamQuality, (q) => Settings.DownloadStreamQuality = q)),
                    new MenuHelpTextElement(Strings.QualityHints)
                },
                new MenuSection(Strings.Feedback)
                {
                    new SettingsElement(Strings.SendFeedback, SendFeedback)
                    {
                        TextColor = iOS.Style.DefaultStyle.MainTextColor
                    },
                    new SettingsElement($"{Strings.PleaseRate} {AppDelegate.AppName}", RateAppStore)
                    {
                        TextColor = iOS.Style.DefaultStyle.MainTextColor
                    },
                    (ratingMessage = new MenuHelpTextElement(Strings.NobodyHasRatedYet))
                },
                new MenuSection(Strings.Settings)
                {
                    CreateThemePicker("Theme"),
                    new SettingsElement(Strings.ResyncDatabase, () =>
                    {
                        Settings.ResetApiModes();
                        ApiManager.Shared.ReSync();
                    }),
                    new MenuHelpTextElement(Strings.ResyncDatabaseHint),
                    new SettingsElement(Strings.DownloadQueue,
                                        () => NavigationController.PushViewController(new DownloadViewController(), true)),
                    (songsElement = new SettingsElement(Strings.SongsCount))
                }
            };
            if (lastFmElement != null)
            {
                lastFmElement.ValueUpdated = async b =>
                {
                    if (!b)
                    {
                        Settings.LastFmEnabled = false;
                        ScrobbleManager.Shared.LogOut();
                        return;
                    }
                    var success = false;
                    try
                    {
                        success = await ScrobbleManager.Shared.LoginToLastFm();
                    }
                    catch (TaskCanceledException ex)
                    {
                        lastFmElement.Value = Settings.LastFmEnabled = false;
                        TableView.ReloadData();
                        return;
                    }
                    Settings.LastFmEnabled = success;
                    if (success)
                    {
                        return;
                    }

                    lastFmElement.Value = false;
                    ReloadData();
                    App.ShowAlert($"{Strings.ErrorLoggingInto} Last.FM", Strings.PleaseTryAgain);
                };
            }
            twitterScrobbleElement.ValueUpdated = async b =>
            {
                if (!b)
                {
                    Settings.TwitterEnabled       = false;
                    Settings.TwitterDisplay       = "";
                    Settings.TwitterAccount       = "";
                    twitterScrobbleElement.Detail = "";
                    return;
                }

                var store       = new ACAccountStore();
                var accountType = store.FindAccountType(ACAccountType.Twitter);

                var success = false;
                var result  = await store.RequestAccessAsync(accountType);

                success = result.Item1;
                if (!success)
                {
                    Settings.TwitterEnabled      = false;
                    twitterScrobbleElement.Value = false;
                    ReloadData();
                    return;
                }

                var accounts = store.FindAccounts(accountType);
                if ((accounts?.Length ?? 0) == 0)
                {
                    Settings.TwitterEnabled      = false;
                    twitterScrobbleElement.Value = false;
                    ReloadData();
                    return;
                }

                if (accounts?.Length == 1)
                {
                    Settings.TwitterEnabled = true;
                    var a = accounts[0];
                    Settings.TwitterAccount       = a.Identifier;
                    twitterScrobbleElement.Detail = Settings.TwitterDisplay = a.UserFullName;
                    ReloadData();
                    return;
                }

                var sheet = new ActionSheet("Twitter");
                foreach (var a in accounts)
                {
                    sheet.Add(a.Identifier, () =>
                    {
                        Settings.TwitterEnabled       = true;
                        Settings.TwitterAccount       = a.Identifier;
                        twitterScrobbleElement.Detail = Settings.TwitterDisplay = a.UserFullName;
                        ReloadData();
                    });
                }
                sheet.Add(Strings.Nevermind, null, true);
                sheet.Show(this, TableView);
            };
        }
Ejemplo n.º 4
0
        public SettingViewController() : base(UITableViewStyle.Plain, null)
        {
            Title           = Strings.Settings;
            accountsSection = new MenuSection(Strings.Accounts)
            {
                (addNewAccountElement = new SettingsElement(Strings.AddStreamingService, async() => {
                    try{
                        var vc = new ServicePickerViewController();
                        this.PresentModalViewController(new UINavigationController(vc), true);
                        var service = await vc.GetServiceTypeAsync();
                        await ApiManager.Shared.CreateAndLogin(service);
                        UpdateAccounts();
                    }
                    catch (TaskCanceledException)
                    {
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                })),
                (lastFmElement = string.IsNullOrEmpty(ApiConstants.LastFmApiKey) ? null : new SettingsSwitch("Last.FM", Settings.LastFmEnabled)),
                (twitterScrobbleElement = new SettingsSwitch(Strings.AutoTweet, Settings.TwitterEnabled)
                {
                    Detail = Settings.TwitterDisplay
                }),
                new SettingsSwitch(Strings.ImportIPodMusic, Settings.IncludeIpod)
                {
                    ValueUpdated = ToggleIPod
                },
                new MenuHelpTextElement(Strings.ImportIpodHint),
            };

            Root = new RootElement(Strings.Settings)
            {
                accountsSection,
                new MenuSection(Strings.Playback)
                {
                    new SettingsSwitch(Strings.EnableLikeOnTheLockScreen, Settings.ThubsUpOnLockScreen)
                    {
                        ValueUpdated = (b => {
                            Settings.ThubsUpOnLockScreen = b;
                            RemoteControlHandler.SetupThumbsUp();
                        })
                    },
                    new MenuHelpTextElement(Strings.EnableLikeHint),
                    new SettingsSwitch(Strings.EnableGaplessPlayback, Settings.EnableGaplessPlayback)
                    {
                        ValueUpdated = (b => {
                            Settings.EnableGaplessPlayback = b;
                        })
                    },
                    new MenuHelpTextElement(Strings.EnableGapplessHint),
                    new SettingsSwitch(Strings.PlayVideosWhenAvailable, Settings.PreferVideos)
                    {
                        ValueUpdated = (b => { Settings.PreferVideos = b; })
                    },
                    new MenuHelpTextElement(Strings.PlaysMusicVideoHint),
                    new SettingsSwitch(Strings.PlayCleanVersionsOfSongs, Settings.FilterExplicit)
                    {
                        ValueUpdated = (b => { Settings.FilterExplicit = b; })
                    },
                    new MenuHelpTextElement(Strings.PlayesCleanVersionOfSongsHint),
                },
                new MenuSection(Strings.Streaming)
                {
                    new SettingsSwitch(Strings.DisableAllAccess, Settings.DisableAllAccess)
                    {
                        ValueUpdated = (on) => {
                            Settings.DisableAllAccess = on;
                        }
                    },
                    new MenuHelpTextElement(Strings.DisableAllAccessHint),
                    (CreateQualityPicker(Strings.CellularAudioQuality, Settings.MobileStreamQuality, (q) => Settings.MobileStreamQuality = q)),
                    (CreateQualityPicker(Strings.WifiAudioQuality, Settings.WifiStreamQuality, (q) => Settings.WifiStreamQuality = q)),
                    (CreateQualityPicker(Strings.VideoQuality, Settings.VideoStreamQuality, (q) => Settings.VideoStreamQuality = q)),
                    (CreateQualityPicker(Strings.OfflineAudioQuality, Settings.DownloadStreamQuality, (q) => Settings.DownloadStreamQuality = q)),
                    new MenuHelpTextElement(Strings.QualityHints)
                },
                new MenuSection(Strings.Feedback)
                {
                    new SettingsElement(Strings.SendFeedback, SendFeedback)
                    {
                        TextColor = iOS.Style.DefaultStyle.MainTextColor
                    },
                    new SettingsElement($"{Strings.PleaseRate} {AppDelegate.AppName}", RateAppStore)
                    {
                        TextColor = iOS.Style.DefaultStyle.MainTextColor
                    },
                    (ratingMessage = new MenuHelpTextElement(Strings.NobodyHasRatedYet))
                },
                new MenuSection(Strings.Settings)
                {
                    CreateLanguagePicker(Strings.Language),
                    CreateThemePicker(Strings.Theme),
                    new SettingsElement(Strings.ResyncDatabase, () =>
                    {
                        Database.Main.ResetDatabase();
                        Settings.ResetApiModes();
                        ApiManager.Shared.ReSync();
                    }),
                    new MenuHelpTextElement(Strings.ResyncDatabaseHint),
                    new SettingsSwitch(Strings.DisableAutoLock, Settings.DisableAutoLock)
                    {
                        ValueUpdated = (b => {
                            Settings.PreferVideos = b;
                            AutolockPowerWatcher.Shared.CheckStatus();
                        })
                    },
                    new MenuHelpTextElement(Strings.DisableAutoLockHelpText),
                    new SettingsElement(Strings.DownloadQueue,
                                        () => NavigationController.PushViewController(new DownloadViewController(), true)),
                    (songsElement = new SettingsElement(Strings.SongsCount)),
                    new SettingsElement(Strings.Version)
                    {
                        Value = Device.AppVersion(),
                    },
                    new StringElement(""),
                    new StringElement(""),
                    new StringElement(""),
                    new StringElement(""),
                }
            };
            if (lastFmElement != null)
            {
                lastFmElement.ValueUpdated = async b =>
                {
                    if (!b)
                    {
                        Settings.LastFmEnabled = false;
                        ScrobbleManager.Shared.LogOut();
                        return;
                    }
                    var success = false;
                    try
                    {
                        success = await ScrobbleManager.Shared.LoginToLastFm();
                    }
                    catch (TaskCanceledException ex)
                    {
                        lastFmElement.Value = Settings.LastFmEnabled = false;
                        TableView.ReloadData();
                        return;
                    }
                    Settings.LastFmEnabled = success;
                    if (success)
                    {
                        return;
                    }

                    lastFmElement.Value = false;
                    ReloadData();
                    App.ShowAlert(string.Format(Strings.ErrorLoggingInto, "Last.FM"), Strings.PleaseTryAgain);
                };
            }
            twitterScrobbleElement.ValueUpdated = async b =>
            {
                if (!b)
                {
                    Settings.TwitterEnabled       = false;
                    Settings.TwitterDisplay       = "";
                    Settings.TwitterAccount       = "";
                    twitterScrobbleElement.Detail = "";
                    ScrobbleManager.Shared.LogOutOfTwitter();

                    return;
                }
                var success = await ScrobbleManager.Shared.LoginToTwitter();

                if (!success)
                {
                    Settings.TwitterEnabled      = false;
                    twitterScrobbleElement.Value = false;
                    ReloadData();
                    return;
                }

                Settings.TwitterEnabled       = true;
                twitterScrobbleElement.Detail = Settings.TwitterDisplay;

                ReloadData();
            };
        }