public AmpachePhoneStateListener(AmpacheModel model)
 {
     if(model == null){
         throw new System.ArgumentNullException("model");
     }
     _model = model;
 }
Ejemplo n.º 2
0
        public void AmpachePlayerNextNotShufflingPlayingRollsToStartTest()
        {
            var model = new AmpacheModel();
            var mock = new PlayerHandle(model);

            mock.SetPauseState(false);
            var first = new AmpacheSong();
            var second = new AmpacheSong();
            model.Playlist = new List<AmpacheSong>{ first, second };
            model.PlayingSong = second;
            model.IsPlaying = true;
            model.PercentPlayed = 90;
            model.PercentDownloaded = 100;
            model.NextRequested = true;
            System.Threading.Thread.Sleep(100);
            Assert.That(model.PlayPauseRequested, Is.False);
            Assert.That(model.PercentPlayed, Is.EqualTo(0));
            Assert.That(model.PercentDownloaded, Is.EqualTo(0));
            Assert.That(mock.PauseCalls, Is.EqualTo(0));
            Assert.That(mock.UnpauseCalls, Is.EqualTo(0));
            Assert.That(mock.PlaySongCalls, Is.EqualTo(1));
            Assert.That(mock.StopCalls, Is.EqualTo(0));
            Assert.That(mock.SeekToCalls, Is.EqualTo(0));
            Assert.That(mock.GetPauseState(), Is.False);
            Assert.That(model.IsPlaying, Is.True);
            Assert.That(model.PlayingSong, Is.SameAs(first));
            Assert.That(mock.LastStartedSong, Is.SameAs(first));
        }
Ejemplo n.º 3
0
        public void AlbumArtLoaderIgnoresCachingPersistedItemTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            var persistor = Substitute.For<IPersister<AlbumArt>>();
            container.Register<IPersister<AlbumArt>>().To(persistor);
            persistor.IsPersisted(Arg.Any<IEntity>()).Returns(true);
            var art = new AlbumArt();
            persistor.IsPersisted(Arg.Is(art)).Returns(true);
            int timesCalled = 0;
            persistor.When(x => x.Persist(Arg.Any<AlbumArt>())).Do( x => { ++timesCalled; });
            art.ArtStream = new MemoryStream();
            persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(new [] {art});
            var prefs = new UserConfiguration();
            prefs.CacheArt = true;
            model.Configuration = prefs;

            var target = new AlbumArtLoader(container, defaultStream);
            var sng = new AmpacheSong();
            sng.ArtUrl = "test";
            model.PlayingSong = sng;

            System.Threading.Thread.Sleep(100);
            Assert.That(model.AlbumArtStream, Is.SameAs(art.ArtStream));
            Assert.That(timesCalled, Is.EqualTo(0));
        }
Ejemplo n.º 4
0
 public AlbumArtLoader(Athena.IoC.Container container, MemoryStream defaultStream)
 {
     _container = container;
     _defaultStream = defaultStream;
     _model = container.Resolve<AmpacheModel>();
     _model.PropertyChanged += Handle_modelPropertyChanged;
     LoadAlbumImage();
 }
Ejemplo n.º 5
0
 public void Connected(Athena.IoC.Container container)
 {
     _model = container.Resolve<AmpacheModel>();
     if(!_uiActions.ContainsKey(AmpacheModel.ALBUM_ART_STREAM))
     {
         _uiActions.Add(AmpacheModel.ALBUM_ART_STREAM, UpdateArt);
         RunOnUiThread(() => UpdateArt());
     }
     if(!_uiActions.ContainsKey(AmpacheModel.NEXT_REQUESTED))
     {
         _uiActions.Add(AmpacheModel.NEXT_REQUESTED, UpdateNextButton);
         RunOnUiThread(() => UpdateNextButton());
     }
     if(!_uiActions.ContainsKey(AmpacheModel.PREVIOUS_REQUESTED))
     {
         _uiActions.Add(AmpacheModel.PREVIOUS_REQUESTED, UpdatePreviousButton);
         RunOnUiThread(() => UpdatePreviousButton());
     }
     if(!_uiActions.ContainsKey(AmpacheModel.SHUFFELING))
     {
         _uiActions.Add(AmpacheModel.SHUFFELING, UpdateShuffleButton);
         RunOnUiThread(() => UpdateShuffleButton());
     }
     if(!_uiActions.ContainsKey(AmpacheModel.PLAY_PAUSE_REQUESTED))
     {
         _uiActions.Add(AmpacheModel.PLAY_PAUSE_REQUESTED, UpdatePlayPauseButton);
         RunOnUiThread(() => UpdatePlayPauseButton());
     }
     if(!_uiActions.ContainsKey(AmpacheModel.USER_MESSAGE))
     {
         _uiActions.Add(AmpacheModel.USER_MESSAGE, DisplayMessage);
     }
     _model.PropertyChanged += Handle_modelPropertyChanged;
     _model.PropertyChanged += ModelDisposed;
     ImageButton btn = FindViewById<ImageButton>(Resource.Id.imgPlayingNext);
     if(btn != null)
     {
         btn.Click += HandleNextClick;
     }
     btn = FindViewById<ImageButton>(Resource.Id.imgPlayingPrevious);
     if(btn != null)
     {
         btn.Click += HandlePreviousClick;
     }
     btn = FindViewById<ImageButton>(Resource.Id.imgPlayingPlayPause);
     if(btn != null)
     {
         btn.Click += HandlePlayClick;
     }
     btn = FindViewById<ImageButton>(Resource.Id.imgPlayingShuffle);
     if(btn != null)
     {
         btn.Click += HandleShuffleClick;
     }
     OnModelLoaded();
 }
Ejemplo n.º 6
0
 public void AmapcheModelDisposalDisablesListenersTest()
 {
     int timesNotified = 0;
     var target = new AmpacheModel();
     target.PropertyChanged += (sender, e) => ++timesNotified;
     target.Dispose();
     timesNotified = 0;
     target.UserMessage = "message";
     Assert.That(timesNotified, Is.EqualTo(0));
 }
Ejemplo n.º 7
0
 public void AmapcheModelAlbumArtStreamNotifiesOnChange()
 {
     int timesNotified = 0;
     var target = new AmpacheModel();
     target.PropertyChanged += (sender, e) => ++timesNotified;
     target.PropertyChanged += (sender, e) => Assert.That(e.PropertyName, Is.EqualTo(AmpacheModel.ALBUM_ART_STREAM));
     target.AlbumArtStream = new System.IO.MemoryStream();
     Assert.That(timesNotified, Is.EqualTo(1));
     Assert.That(target.IsDisposed, Is.False);
 }
Ejemplo n.º 8
0
 public void AmapcheModelConfigurationNotifiesOnChange()
 {
     int timesNotified = 0;
     var target = new AmpacheModel();
     target.PropertyChanged += (sender, e) => ++timesNotified;
     target.PropertyChanged += (sender, e) => Assert.That(e.PropertyName, Is.EqualTo(AmpacheModel.CONFIGURATION));
     target.Configuration = new UserConfiguration();
     Assert.That(timesNotified, Is.EqualTo(1));
     Assert.That(target.IsDisposed, Is.False);
 }
Ejemplo n.º 9
0
 public AmpacheNotifications(Context context, AmpacheModel model)
 {
     _model = model;
     _context = context;
     _model.PropertyChanged += Handle_modelPropertyChanged;
     _builder = new Notification.Builder(context)
         .SetSmallIcon(Resource.Drawable.ic_stat_notify_musicplayer)
         .SetContentTitle("Ampache.NET")
         .SetContentIntent(PendingIntent.GetActivity(_context, 0, new Intent(_context, typeof(NowPlaying)), PendingIntentFlags.UpdateCurrent));
     ((NotificationManager)_context.GetSystemService(Context.NotificationService)).CancelAll();
 }
Ejemplo n.º 10
0
        public void ConfigurationPerformTestSuccessfulTest()
        {
            var model = new AmpacheModel();
            var factory = Substitute.For<AmpacheSelectionFactory>();
            model.Factory = factory;
            factory.AuthenticationTest(Arg.Any<string>(),Arg.Any<string>(),Arg.Any<string>()).Returns((Authenticate)null);

            var target = new Configuration(model);
            Assert.That(model.UserMessage, Is.Null);
            target.PerformTest(string.Empty, string.Empty, string.Empty);
            Assert.That(model.UserMessage, Is.Not.Null);
        }
Ejemplo n.º 11
0
        public void ConfigurationPerformTestErrorTest()
        {
            var model = new AmpacheModel();
            var factory = Substitute.For<AmpacheSelectionFactory>();
            model.Factory = factory;
            var message = "error message";
            factory.When(x => x.AuthenticationTest(Arg.Any<string>(),Arg.Any<string>(),Arg.Any<string>())).Do((obj) => { throw new Exception(message); });

            var target = new Configuration(model);
            Assert.That(model.UserMessage, Is.Null);
            target.PerformTest(string.Empty, string.Empty, string.Empty);
            Assert.That(model.UserMessage, Is.SameAs(message));
        }
Ejemplo n.º 12
0
        public void ConfigurationTrySaveConfigurationErrorTest()
        {
            var model = new AmpacheModel();
            var factory = Substitute.For<AmpacheSelectionFactory>();
            model.Factory = factory;
            var message = "error message";
            factory.When(x => x.AuthenticateToServer(Arg.Any<UserConfiguration>())).Do((obj) => { throw new Exception(message); });

            var target = new Configuration(model);
            Assert.That(model.UserMessage, Is.Null);
            var conf = new UserConfiguration();
            var actual = target.TrySaveConfiguration(conf);
            Assert.That(actual, Is.False);
            Assert.That(model.UserMessage, Is.SameAs(message));
            Assert.That(model.Configuration, Is.Null);
        }
Ejemplo n.º 13
0
        public void AlbumArtLoaderUsesDefaultWhenInitializedTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            Assert.That(model.AlbumArtStream, Is.Not.SameAs(defaultStream));
            var target = new AlbumArtLoader(container, defaultStream);
            Assert.That(model.AlbumArtStream, Is.SameAs(defaultStream));
        }
Ejemplo n.º 14
0
        public void AlbumArtLoaderUsesDefaultArtWhenNoArtAvailableTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            var target = new AlbumArtLoader(container, defaultStream);
            var sng = new AmpacheSong();
            sng.ArtUrl = string.Empty;
            model.PlayingSong = sng;

            System.Threading.Thread.Sleep(100);
            Assert.That(model.AlbumArtStream, Is.SameAs(defaultStream));
        }
Ejemplo n.º 15
0
        public void AlbumArtLoaderUsesDefaultArtWhenLoadingArtTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            var persistor = Substitute.For<IPersister<AlbumArt>>();
            persistor.IsPersisted(Arg.Any<IEntity>()).Returns(false);
            int timesCalled = 0;
            persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(x => { ++timesCalled; Assert.That(model.AlbumArtStream, Is.SameAs(defaultStream)); return Enumerable.Empty<AlbumArt>();});
            container.Register<IPersister<AlbumArt>>().To(persistor);

            var target = new AlbumArtLoader(container, defaultStream);
            var sng = new AmpacheSong();
            sng.ArtUrl = "test";
            model.PlayingSong = sng;

            System.Threading.Thread.Sleep(100);
            Assert.That(timesCalled, Is.EqualTo(1));
        }
Ejemplo n.º 16
0
 public BackgroundHandle(UserConfiguration config, string art, AmpacheSelectionFactory factory, AmpacheModel model, Athena.IoC.Container container)
     : this(config, art, model, container)
 {
     _factory = factory;
 }
Ejemplo n.º 17
0
 public BackgroundHandle(UserConfiguration config, string art, AmpacheModel model, Athena.IoC.Container container)
     : this(config, art)
 {
     _model = model;
     _container = container;
 }
Ejemplo n.º 18
0
 public override void OnCreate()
 {
     base.OnCreate ();
     Console.SetOut(new AndroidLogTextWriter());
     DataAccess.Configurator.ArtLocalDirectory = CacheDir.AbsolutePath;
     _container = new Athena.IoC.Container();
     _model = new AmpacheModel();
     _container.Register<AmpacheModel>().To(_model);
     DataAccess.Configurator.Configure(_container);
     var am = (AlarmManager)ApplicationContext.GetSystemService(Context.AlarmService);
     var ping = new Intent(PingReceiver.INTENT);
     _pingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, ping, PendingIntentFlags.UpdateCurrent);
     am.SetRepeating(AlarmType.RtcWakeup, Java.Lang.JavaSystem.CurrentTimeMillis() + (long)TimeSpan.FromMinutes(5).TotalMilliseconds, (long)TimeSpan.FromMinutes(5).TotalMilliseconds, _pingIntent);
     var stm = Resources.OpenRawResource(Resource.Drawable.ct_default_artwork);
     var stream = new System.IO.MemoryStream();
     stm.CopyTo(stream);
     stream.Position = 0;
     Start(stream);
     _player = new AndroidPlayer(_model, ApplicationContext);
     _notifications = new AmpacheNotifications(this.ApplicationContext, _model);
     var telSvc = this.ApplicationContext.GetSystemService(Context.TelephonyService) as Android.Telephony.TelephonyManager;
     if(telSvc != null) {
         telSvc.Listen(new AmpachePhoneStateListener(_model), Android.Telephony.PhoneStateListenerFlags.CallState);
     }
 }
Ejemplo n.º 19
0
 public PlayerHandle(AmpacheModel model)
     : base(model)
 {
     UnpauseCalls = 0;
     PauseCalls = 0;
     StopCalls = 0;
     SeekToCalls = 0;
     PlaySongCalls = 0;
     LastStartedSong = null;
 }
Ejemplo n.º 20
0
        public void AlbumArtLoaderUsesLoadedArtAfterLoadingTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            var persistor = Substitute.For<IPersister<AlbumArt>>();
            container.Register<IPersister<AlbumArt>>().To(persistor);
            persistor.IsPersisted(Arg.Any<IEntity>()).Returns(false);
            var art = new AlbumArt();
            art.ArtStream = new MemoryStream();
            persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(new [] {art});
            var prefs = new UserConfiguration();
            prefs.CacheArt = false;
            model.Configuration = prefs;

            var target = new AlbumArtLoader(container, defaultStream);
            var sng = new AmpacheSong();
            sng.ArtUrl = "test";
            model.PlayingSong = sng;

            System.Threading.Thread.Sleep(100);
            Assert.That(model.AlbumArtStream, Is.SameAs(art.ArtStream));
        }
Ejemplo n.º 21
0
 public PlayerErrorHandle(AmpacheModel model)
     : base(model)
 {
 }
Ejemplo n.º 22
0
 public void AmpachePlayerSettingPlayerPositionMilliSecondUpdatesPercentPlayedOnModelTest()
 {
     var model = new AmpacheModel();
     var mock = new PlayerHandle(model);
     var song = new AmpacheSong();
     song.TrackLength = TimeSpan.FromSeconds(60);
     model.PlayingSong = song;
     mock.SetPlayerPositionMilliSecond(15000);
     Assert.That(model.PercentPlayed, Is.EqualTo(25));
 }
Ejemplo n.º 23
0
        public void AmpachePlayerPlayPauseStartsPlaybackAtFirstSongTest()
        {
            var model = new AmpacheModel();
            var mock = new PlayerHandle(model);

            mock.SetPauseState(false);
            var first = new AmpacheSong();
            var second = new AmpacheSong();
            model.Playlist = new List<AmpacheSong>{ first, second };
            model.PlayPauseRequested = true;
            System.Threading.Thread.Sleep(100);
            Assert.That(model.PlayPauseRequested, Is.False);
            Assert.That(mock.PauseCalls, Is.EqualTo(0));
            Assert.That(mock.UnpauseCalls, Is.EqualTo(0));
            Assert.That(mock.PlaySongCalls, Is.EqualTo(1));
            Assert.That(mock.StopCalls, Is.EqualTo(0));
            Assert.That(mock.SeekToCalls, Is.EqualTo(0));
            Assert.That(mock.GetPauseState(), Is.False);
            Assert.That(model.IsPlaying, Is.True);
            Assert.That(model.PlayingSong, Is.SameAs(first));
            Assert.That(mock.LastStartedSong, Is.SameAs(first));
        }
Ejemplo n.º 24
0
 public Configuration(AmpacheModel model)
 {
     _model = model;
 }
Ejemplo n.º 25
0
        public void AmpachePlayerPreviousAfterSomePlayTest()
        {
            var model = new AmpacheModel();
            var mock = new PlayerHandle(model);

            mock.SetPauseState(false);
            var first = new AmpacheSong();
            var second = new AmpacheSong();
            model.Playlist = new List<AmpacheSong>{ first, second };
            model.PlayingSong = second;
            mock.SetPlayerPositionMilliSecond(10000);
            model.IsPlaying = true;
            model.PreviousRequested = true;
            System.Threading.Thread.Sleep(100);
            Assert.That(model.PlayPauseRequested, Is.False);
            Assert.That(mock.PauseCalls, Is.EqualTo(0));
            Assert.That(mock.UnpauseCalls, Is.EqualTo(0));
            Assert.That(mock.PlaySongCalls, Is.EqualTo(1));
            Assert.That(mock.StopCalls, Is.EqualTo(0));
            Assert.That(mock.SeekToCalls, Is.EqualTo(0));
            Assert.That(mock.GetPauseState(), Is.False);
            Assert.That(model.IsPlaying, Is.True);
            Assert.That(model.PlayingSong, Is.SameAs(second));
            Assert.That(mock.LastStartedSong, Is.SameAs(second));
        }
Ejemplo n.º 26
0
        public void AmpachePlayerSeekingTest()
        {
            var model = new AmpacheModel();
            var mock = new PlayerHandle(model);

            mock.SetPauseState(false);
            var first = new AmpacheSong();
            var second = new AmpacheSong();
            second.TrackLength = TimeSpan.FromMinutes(1);
            model.Playlist = new List<AmpacheSong>{ first, second };
            model.PlayingSong = second;
            model.IsPlaying = true;
            model.Configuration = new UserConfiguration();
            model.Configuration.AllowSeeking = true;
            model.RequestedSeekToPercentage = 50;
            System.Threading.Thread.Sleep(100);
            Assert.That(model.PlayPauseRequested, Is.False);
            Assert.That(mock.PauseCalls, Is.EqualTo(0));
            Assert.That(mock.UnpauseCalls, Is.EqualTo(0));
            Assert.That(mock.PlaySongCalls, Is.EqualTo(0));
            Assert.That(mock.StopCalls, Is.EqualTo(0));
            Assert.That(mock.SeekToCalls, Is.EqualTo(1));
            Assert.That(mock.GetPauseState(), Is.False);
            Assert.That(model.IsPlaying, Is.True);
            Assert.That(model.PlayingSong, Is.SameAs(second));
        }
Ejemplo n.º 27
0
        public void ConfigurationTrySaveConfigurationSuccessfulTest()
        {
            var model = new AmpacheModel();
            var factory = Substitute.For<AmpacheSelectionFactory>();
            model.Factory = factory;
            factory.AuthenticateToServer(Arg.Any<UserConfiguration>()).Returns((Authenticate)null);

            var target = new Configuration(model);
            Assert.That(model.UserMessage, Is.Null);
            var conf = new UserConfiguration();
            var actual = target.TrySaveConfiguration(conf);
            Assert.That(actual, Is.True);
            Assert.That(model.UserMessage, Is.Not.Null);
            Assert.That(model.Configuration, Is.SameAs(conf));
        }
Ejemplo n.º 28
0
        public void AmpachePlayerStopWhilePlayTest()
        {
            var model = new AmpacheModel();
            var mock = new PlayerHandle(model);

            mock.SetPauseState(false);
            var first = new AmpacheSong();
            var second = new AmpacheSong();
            model.Playlist = new List<AmpacheSong>{ first, second };
            model.PlayingSong = second;
            model.IsPlaying = true;
            model.StopRequested = true;
            System.Threading.Thread.Sleep(100);
            Assert.That(model.PlayPauseRequested, Is.False);
            Assert.That(mock.PauseCalls, Is.EqualTo(0));
            Assert.That(mock.UnpauseCalls, Is.EqualTo(0));
            Assert.That(mock.PlaySongCalls, Is.EqualTo(0));
            Assert.That(mock.StopCalls, Is.EqualTo(1));
            Assert.That(mock.SeekToCalls, Is.EqualTo(0));
            Assert.That(mock.GetPauseState(), Is.False);
            Assert.That(model.IsPlaying, Is.False);
            Assert.That(model.PlayingSong, Is.Null);
        }
Ejemplo n.º 29
0
 protected AmpachePlayer(AmpacheModel model)
 {
     _model = model;
     _model.PropertyChanged += Handle_modelPropertyChanged;
 }
Ejemplo n.º 30
0
 public void ConfigurationTrySaveNullInputTest()
 {
     var model = new AmpacheModel();
     var target = new Configuration(model);
     Assert.That(model.UserMessage, Is.Null);
     var actual = target.TrySaveConfiguration(null);
     Assert.That(actual, Is.False);
 }