Skip to content

Commit

Permalink
Android: Partially fixed coming back into the application after a Mai…
Browse files Browse the repository at this point in the history
…nActivity destruction.

Related to issue #406.
  • Loading branch information
ycastonguay-cbc committed Jul 19, 2013
1 parent b9dec16 commit c124f56
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
4 changes: 3 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/MainActivity.cs
Expand Up @@ -297,7 +297,9 @@ public void ShowSplash(SplashFragment fragment)
public void HideSplash()
{
//Console.WriteLine("MainActivity - HideSplash");
_splashFragment.Dialog.Dismiss();

if(_splashFragment.Dialog != null)
_splashFragment.Dialog.Dismiss();
}

#region IMobileOptionsMenuView implementation
Expand Down
Expand Up @@ -213,16 +213,18 @@ public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities, Mo
_listView.Visibility = ViewStates.Visible;
_gridView.Visibility = ViewStates.Gone;
var audioFile = _entities[0].AudioFile;
_lblArtistName.Text = audioFile.ArtistName;
_lblAlbumTitle.Text = audioFile.AlbumTitle;
_lblAlbumSongCount.Text = _entities.Count.ToString() + " songs";
Task.Factory.StartNew(() =>
if (_entities.Count > 0)
{
byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath);
_bitmapCache.LoadBitmapFromByteArray(bytesImage, audioFile.FilePath, _imageAlbum);
});
var audioFile = _entities[0].AudioFile;
_lblArtistName.Text = audioFile.ArtistName;
_lblAlbumTitle.Text = audioFile.AlbumTitle;
_lblAlbumSongCount.Text = _entities.Count.ToString() + " songs";
Task.Factory.StartNew(() => {
byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath);
_bitmapCache.LoadBitmapFromByteArray(bytesImage, audioFile.FilePath, _imageAlbum);
});
}
break;
case MobileLibraryBrowserType.Playlists:
_layoutAlbum.Visibility = ViewStates.Gone;
Expand Down
3 changes: 1 addition & 2 deletions MPfm/MPfm.Android/Classes/Fragments/SplashFragment.cs
Expand Up @@ -70,9 +70,8 @@ public void RefreshStatus(string message)
});
}

public void InitDone()
public void InitDone(bool isFirstAppStart)
{
//this.Dismiss();
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.Android/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions MPfm/MPfm.MVP/Presenters/SplashPresenter.cs
Expand Up @@ -40,12 +40,17 @@ public SplashPresenter(IInitializationService initializationService, IPlayerServ

public void Initialize(Action onInitDone)
{
if (_playerService.IsInitialized)
{
onInitDone.Invoke();
return;
}

TaskScheduler taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
#if LINUX
// Mono on Linux crashes for some reason if FromCurrentSynchronizationContext is used... weird!
taskScheduler = TaskScheduler.Default;
#endif

Task.Factory.StartNew(() =>
{
View.RefreshStatus("Loading...");
Expand All @@ -58,7 +63,7 @@ public void Initialize(Action onInitDone)
Id = -1
};
_playerService.Initialize(device, 44100, 1000, 100);
View.InitDone();
View.InitDone(true);
onInitDone.Invoke();
View.RefreshStatus("Opening app...");
}, taskScheduler);
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/Services/Interfaces/IPlayerService.cs
Expand Up @@ -30,6 +30,7 @@ namespace MPfm.MVP.Services.Interfaces
/// </summary>
public interface IPlayerService
{
bool IsInitialized { get; }
bool IsSettingPosition { get; }
bool IsPlaying { get; }
bool IsPaused { get; }
Expand Down
2 changes: 2 additions & 0 deletions MPfm/MPfm.MVP/Services/PlayerService.cs
Expand Up @@ -39,6 +39,7 @@ public class PlayerService : IPlayerService
private IPlayer _player;
private PlayerStatusType _status;

public bool IsInitialized { get; private set; }
public bool IsSettingPosition { get { return _player.IsSettingPosition; } }
public bool IsPlaying { get { return _player.IsPlaying; } }
public bool IsPaused { get { return _player.IsPaused; } }
Expand Down Expand Up @@ -69,6 +70,7 @@ public void Initialize(Device device, int sampleRate, int bufferSize, int update
_player.OnAudioInterrupted += HandleOnAudioInterrupted;
_player.OnBPMDetected += HandleOnBPMDetected;
_messengerHub.Subscribe<PlayerCommandMessage>(PlayerCommandMessageReceived);
IsInitialized = true;
}

void HandleOnBPMDetected(float bpm)
Expand Down
4 changes: 1 addition & 3 deletions MPfm/MPfm.MVP/Views/ISplashView.cs
Expand Up @@ -22,9 +22,7 @@ namespace MPfm.MVP.Views
/// </summary>
public interface ISplashView : IBaseView
{
//Action OnViewReady { get; set; }

void RefreshStatus(string message);
void InitDone();
void InitDone(bool isAppFirstStart);
}
}
16 changes: 8 additions & 8 deletions MPfm/MPfm.Sound/BassNetKey.cs
Expand Up @@ -2,11 +2,11 @@
// To build MPfm correctly, you need to generate your own BASS.NET key at this website: http://bass.radio42.com/bass_register.html
// Simply uncomment this file and add your email/key.

//namespace MPfm.Sound
//{
// public static class BassNetKey
// {
// public const string Email = "";
// public const string RegistrationKey = "";
// }
//}
namespace MPfm.Sound
{
public static class BassNetKey
{
public const string Email = "yanick.castonguay@gmail.com";
public const string RegistrationKey = "2X3433427152222";
}
}
1 change: 0 additions & 1 deletion MPfm/MPfm.Sound/MPfm.Sound.Android.csproj
Expand Up @@ -150,7 +150,6 @@
<Compile Include="BassNetWrapper\WASAPI\BaseWASAPI.cs" />
<Compile Include="Readers\XingInfoHeaderReader.cs" />
<Compile Include="BassNetKey.cs" />
<Compile Include="MyBassNetKey.cs" />
<Compile Include="BassNetWrapper\BassWrapper.cs" />
<Compile Include="BassNetWrapper\BaseFx.cs" />
</ItemGroup>
Expand Down

0 comments on commit c124f56

Please sign in to comment.