Skip to content

Commit

Permalink
Android: MobileNavigationManager refactoring is almost done; a few ab…
Browse files Browse the repository at this point in the history
…stract methods still have to be removed. The Android app partially works after all these changes, still have a lot to fix.
  • Loading branch information
ycastonguay committed Oct 30, 2013
1 parent 88c8fe1 commit ad68229
Show file tree
Hide file tree
Showing 30 changed files with 574 additions and 834 deletions.
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/AboutActivity.cs
Expand Up @@ -73,7 +73,8 @@ protected override void OnCreate(Bundle bundle)
_webView.SetWebViewClient(_webViewClient);

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetAboutActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetAboutActivityInstance(this);
_navigationManager.BindAboutView(this);
}

protected override void OnStart()
Expand Down
Expand Up @@ -73,7 +73,7 @@ protected override void OnCreate(Bundle bundle)
_sourceActivityType = Intent.GetStringExtra("sourceActivity");

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetEqualizerPresetDetailsActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetEqualizerPresetDetailsActivityInstance(this);
}

protected override void OnStart()
Expand Down
Expand Up @@ -76,7 +76,8 @@ protected override void OnCreate(Bundle bundle)
_sourceActivityType = Intent.GetStringExtra("sourceActivity");

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetEqualizerPresetsActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetEqualizerPresetsActivityInstance(this);
_navigationManager.BindEqualizerPresetsView(null, this);
}

private void ListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs itemClickEventArgs)
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/FirstRunActivity.cs
Expand Up @@ -61,7 +61,8 @@ protected override void OnCreate(Bundle bundle)

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
_navigationManager = (AndroidNavigationManager)Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
((AndroidNavigationManager)_navigationManager).SetFirstRunActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetFirstRunActivityInstance(this);
_navigationManager.BindFirstRunView(this);
}

protected override void OnStart()
Expand Down
103 changes: 93 additions & 10 deletions MPfm/MPfm.Android/Classes/Activities/MainActivity.cs
Expand Up @@ -35,10 +35,12 @@
using MPfm.Android.Classes.Cache;
using MPfm.Android.Classes.Fragments;
using MPfm.Android.Classes.Navigation;
using MPfm.Library.Objects;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Messages;
using MPfm.MVP.Models;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;
using MPfm.Sound.AudioFiles;
using MPfm.Sound.Playlists;
Expand All @@ -55,6 +57,8 @@ public class MainActivity : BaseActivity, View.IOnTouchListener, ActionBar.IOnNa
{
private ITinyMessengerHub _messengerHub;
private AndroidNavigationManager _navigationManager;
private List<Tuple<MobileNavigationTabType, List<Tuple<MobileLibraryBrowserType, LibraryQuery>>>> _tabHistory;
private Dictionary<Tuple<MobileNavigationTabType, MobileLibraryBrowserType>, Tuple<IMobileLibraryBrowserView, IMobileLibraryBrowserPresenter>> _mobileLibraryBrowserList = new Dictionary<Tuple<MobileNavigationTabType, MobileLibraryBrowserType>, Tuple<IMobileLibraryBrowserView, IMobileLibraryBrowserPresenter>>();
private SplashFragment _splashFragment;
private ViewFlipper _viewFlipper;
private LinearLayout _miniPlayer;
Expand Down Expand Up @@ -91,6 +95,7 @@ protected override void OnCreate(Bundle bundle)
base.OnCreate(bundle);

_messengerHub = Bootstrapper.GetContainer().Resolve<ITinyMessengerHub>();
_tabHistory = new List<Tuple<MobileNavigationTabType, List<Tuple<MobileLibraryBrowserType, LibraryQuery>>>>();

RequestWindowFeature(WindowFeatures.ActionBar);
SetContentView(Resource.Layout.Main);
Expand Down Expand Up @@ -159,17 +164,77 @@ protected override void OnCreate(Bundle bundle)
_navigationManager.BindOptionsMenuView(this);
_navigationManager.BindPlayerStatusView(this);
//_navigationManager.Start();
_navigationManager.SetMainActivityInstance(this);
//_navigationManager.SetMainActivityInstance(this);
_navigationManager.BindMobileMainView(this);
}

public void AddTab(MobileNavigationTabType type, string title, Fragment fragment)
// This needs to be moved to MainActivity. Only MainActivity manages a backstack of MLBs.
public bool CanGoBackInMobileLibraryBrowserBackstack(MobileNavigationTabType tabType)
{
Console.WriteLine("MainActivity - Adding tab {0}", title);
var tab = _tabHistory.FirstOrDefault(x => x.Item1 == tabType);
if (tab != null)
return tab.Item2.Count > 1;
return false;
}

_fragment = fragment;
FragmentTransaction transaction = FragmentManager.BeginTransaction();
transaction.Replace(Resource.Id.main_fragmentContainer, fragment);
transaction.Commit();
public void PopMobileLibraryBrowserBackstack(MobileNavigationTabType tabType)
{
var tab = _tabHistory.FirstOrDefault(x => x.Item1 == tabType);
var tabItem = tab.Item2.Last();
tab.Item2.Remove(tabItem);
tabItem = tab.Item2.Last();

//Console.WriteLine("ANDROID NAVMGR -- PopMobileLibraryBrowserBackstack - About to restore: tabType: {0} browserType: {1}", tabType.ToString(), tabItem.Item1.ToString());
MobileLibraryBrowserType browserType = MobileLibraryBrowserType.Artists;
switch (tabType)
{
case MobileNavigationTabType.Artists:
browserType = MobileLibraryBrowserType.Artists;
break;
case MobileNavigationTabType.Albums:
browserType = MobileLibraryBrowserType.Albums;
break;
case MobileNavigationTabType.Songs:
browserType = MobileLibraryBrowserType.Songs;
break;
case MobileNavigationTabType.Playlists:
browserType = MobileLibraryBrowserType.Playlists;
break;
}

// Refresh query using presenter
// How to get presenter? Well. we have the instance of the view, right? so we can use the view to call the presenter.
//var presenter = GetMobileLibraryBrowserPresenter(tabType, browserType);
//presenter.PopBackstack(tabItem.Item1, tabItem.Item2);
}

public void ChangeMobileLibraryBrowserType(MobileNavigationTabType tabType, MobileLibraryBrowserType newBrowserType)
{
MobileLibraryBrowserType browserType = MobileLibraryBrowserType.Artists;
switch (tabType)
{
case MobileNavigationTabType.Artists:
browserType = MobileLibraryBrowserType.Artists;
break;
case MobileNavigationTabType.Albums:
browserType = MobileLibraryBrowserType.Albums;
break;
case MobileNavigationTabType.Songs:
browserType = MobileLibraryBrowserType.Songs;
break;
case MobileNavigationTabType.Playlists:
browserType = MobileLibraryBrowserType.Playlists;
break;
}

_tabHistory.Clear();
_tabHistory.Add(new Tuple<MobileNavigationTabType, List<Tuple<MobileLibraryBrowserType, LibraryQuery>>>(tabType, new List<Tuple<MobileLibraryBrowserType, LibraryQuery>>() {
new Tuple<MobileLibraryBrowserType, LibraryQuery>(newBrowserType, new LibraryQuery())
}));

//var presenter = GetMobileLibraryBrowserPresenter(tabType, browserType);
//if (presenter != null)
// presenter.ChangeBrowserType(newBrowserType);
}

public void PushDialogView(string viewTitle, IBaseView sourceView, IBaseView view)
Expand All @@ -191,7 +256,7 @@ public bool OnNavigationItemSelected(int itemPosition, long itemId)
if (_fragment is MobileLibraryBrowserFragment)
{
Console.WriteLine("MainActivity - OnNavigationItemSelected - Updating fragment - itemPosition: {0} - itemId: {1}", itemPosition, itemId);
_navigationManager.ChangeMobileLibraryBrowserType(MobileNavigationTabType.Artists, (MobileLibraryBrowserType)itemPosition);
ChangeMobileLibraryBrowserType(MobileNavigationTabType.Artists, (MobileLibraryBrowserType)itemPosition);
}
return true;
}
Expand Down Expand Up @@ -240,10 +305,10 @@ protected override void OnDestroy()
public override void OnBackPressed()
{
var tabType = MobileNavigationTabType.Artists;
if (_navigationManager.CanGoBackInMobileLibraryBrowserBackstack(tabType))
if (CanGoBackInMobileLibraryBrowserBackstack(tabType))
{
//Console.WriteLine("MainActivity - OnBackPressed - CanRemoveFragment");
_navigationManager.PopMobileLibraryBrowserBackstack(tabType);
PopMobileLibraryBrowserBackstack(tabType);
}
else
{
Expand Down Expand Up @@ -426,6 +491,24 @@ public void ShowMiniPlaylist()
ShowMiniPlayerSlide(1);
}

#region IMobileMainView implementation

public void AddTab(MobileNavigationTabType type, string title, MobileLibraryBrowserType browserType, LibraryQuery query, IBaseView view)
{
Console.WriteLine("MainActivity - Adding tab {0}", title);

//_tabHistory.Add(new Tuple<MobileNavigationTabType, List<Tuple<MobileLibraryBrowserType, LibraryQuery>>>(type, new List<Tuple<MobileLibraryBrowserType, LibraryQuery>>() {
// new Tuple<MobileLibraryBrowserType, LibraryQuery>(browserType, query)
//}));

_fragment = (Fragment)view;
FragmentTransaction transaction = FragmentManager.BeginTransaction();
transaction.Replace(Resource.Id.main_fragmentContainer, _fragment);
transaction.Commit();
}

#endregion

#region IMobileOptionsMenuView implementation

public Action<MobileOptionsMenuType> OnItemClick { get; set; }
Expand Down
Expand Up @@ -48,7 +48,8 @@ protected override void OnCreate(Bundle bundle)
ActionBar.SetHomeButtonEnabled(true);

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetMarkerDetailsActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetMarkerDetailsActivityInstance(this);
//_navigationManager.BindMarkerDetailsView(this, );
}

protected override void OnStart()
Expand Down
4 changes: 3 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/PlayerActivity.cs
Expand Up @@ -152,6 +152,7 @@ protected override void OnCreate(Bundle bundle)
}
else
{

Console.WriteLine("PlayerActivity - OnCreate - State is null - isInitialized: {0}", _isInitialized);
}

Expand All @@ -162,7 +163,8 @@ protected override void OnCreate(Bundle bundle)
// Console.WriteLine("PlayerActivity - OnCreate - Bundle is null!");

// When Android stops an activity, it recalls OnCreate after, even though the activity is not destroyed (OnDestroy). It actually goes through creating a new object (the ctor is called).
((AndroidNavigationManager)_navigationManager).SetPlayerActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetPlayerActivityInstance(this);
_navigationManager.BindPlayerView(MobileNavigationTabType.Playlists, this);

// Activate lock screen if not already activated
_messengerHub.PublishAsync<ActivateLockScreenMessage>(new ActivateLockScreenMessage(this, true));
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/PlaylistActivity.cs
Expand Up @@ -70,7 +70,8 @@ protected override void OnCreate(Bundle bundle)
_sourceActivityType = Intent.GetStringExtra("sourceActivity");

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetPlaylistActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetPlaylistActivityInstance(this);
_navigationManager.BindPlaylistView(null, this);
}

//public override void OnAttachedToWindow()
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/PreferencesActivity.cs
Expand Up @@ -58,7 +58,8 @@ protected override void OnCreate(Bundle bundle)
_viewPager.SetOnPageChangeListener(_viewPagerAdapter);

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager) _navigationManager).SetPreferencesActivityInstance(this);
//((AndroidNavigationManager) _navigationManager).SetPreferencesActivityInstance(this);
_navigationManager.BindPreferencesView(this);
}

protected override void OnStart()
Expand Down
Expand Up @@ -59,7 +59,8 @@ protected override void OnCreate(Bundle bundle)
_listView.ItemClick += ListViewOnItemClick;

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetResumePlaybackActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetResumePlaybackActivityInstance(this);
_navigationManager.BindResumePlaybackView(this);
}

private void ListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs itemClickEventArgs)
Expand Down
7 changes: 2 additions & 5 deletions MPfm/MPfm.Android/Classes/Activities/SplashActivity.cs
Expand Up @@ -30,18 +30,15 @@ namespace MPfm.Android
[Activity(Label = "Sessions Splash", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize, WindowSoftInputMode = SoftInput.StateHidden, NoHistory = true)]
public class SplashActivity : BaseActivity, ISplashView
{
private AndroidNavigationManager _navigationManager;

protected override void OnCreate(Bundle bundle)
{
Console.WriteLine("SplashActivity - OnCreate");
base.OnCreate(bundle);

_navigationManager = (AndroidNavigationManager)Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
SetContentView(Resource.Layout.Splash);
//_navigationManager.Start();

_navigationManager.BindSplashView(this);
var navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
navigationManager.BindSplashView(this);

//AppConfigManager.Instance.Load();
//Console.WriteLine("LaunchActivity - OnCreate - isFirstRun: {0} resumePlayback.currentAudioFileId: {1} resumePlayback.currentPlaylistId: {2}", AppConfigManager.Instance.Root.IsFirstRun, AppConfigManager.Instance.Root.ResumePlayback.CurrentAudioFileId, AppConfigManager.Instance.Root.ResumePlayback.CurrentPlaylistId);
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/SyncActivity.cs
Expand Up @@ -67,7 +67,8 @@ protected override void OnCreate(Bundle bundle)
_listView.ItemClick += ListViewOnItemClick;

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetSyncActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetSyncActivityInstance(this);
_navigationManager.BindSyncView(this);
}

private void BtnConnectManuallyOnClick(object sender, EventArgs eventArgs)
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/SyncCloudActivity.cs
Expand Up @@ -76,7 +76,8 @@ protected override void OnCreate(Bundle bundle)
_lblConnected.Text = string.Format("Is Linked: {0} {1}", _cloudLibrary.HasLinkedAccount, DateTime.Now.ToLongTimeString());

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetSyncCloudActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetSyncCloudActivityInstance(this);
_navigationManager.BindSyncCloudView(this);
}

private void BtnLoginOnClick(object sender, EventArgs e)
Expand Down
Expand Up @@ -67,7 +67,7 @@ protected override void OnCreate(Bundle bundle)
_lblTotalFilesValue = FindViewById<TextView>(Resource.Id.syncDownload_lblTotalFilesValue);

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetSyncDownloadActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetSyncDownloadActivityInstance(this);
}

protected override void OnStart()
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/SyncMenuActivity.cs
Expand Up @@ -76,7 +76,8 @@ protected override void OnCreate(Bundle bundle)
_listView.ItemLongClick += ListViewOnItemLongClick;

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetSyncMenuActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetSyncMenuActivityInstance(this);
//_navigationManager.BindSyncMenuView(this, null);
}

private void ListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs itemClickEventArgs)
Expand Down
Expand Up @@ -55,7 +55,8 @@ protected override void OnCreate(Bundle bundle)
_lblCode = FindViewById<TextView>(Resource.Id.syncWebBrowser_lblCode);

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetSyncWebBrowserActivityInstance(this);
//((AndroidNavigationManager)_navigationManager).SetSyncWebBrowserActivityInstance(this);
_navigationManager.BindSyncWebBrowserView(this);
}

protected override void OnStart()
Expand Down
11 changes: 8 additions & 3 deletions MPfm/MPfm.Android/Classes/Fragments/LoopsFragment.cs
Expand Up @@ -22,12 +22,14 @@
using Android.Views;
using Android.Widget;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;
using MPfm.Player.Objects;

namespace MPfm.Android.Classes.Fragments
{
public class LoopsFragment : BaseFragment, ILoopsView, View.IOnClickListener
public class LoopsFragment : BaseFragment, ILoopsView
{
private View _view;

Expand All @@ -40,9 +42,12 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
return _view;
}

public void OnClick(View v)
public override void OnResume()
{

base.OnResume();

var navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
navigationManager.BindLoopsView(this);
}

#region ILoopsView implementation
Expand Down
5 changes: 5 additions & 0 deletions MPfm/MPfm.Android/Classes/Fragments/MarkersFragment.cs
Expand Up @@ -23,6 +23,8 @@
using Android.Widget;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters;
using MPfm.MVP.Views;
using MPfm.Player.Objects;
Expand Down Expand Up @@ -72,6 +74,9 @@ public override void OnResume()
{
Console.WriteLine("MarkersFragment - OnResume");
base.OnResume();

var navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
navigationManager.BindMarkersView(this);
}

public override void OnStart()
Expand Down

0 comments on commit ad68229

Please sign in to comment.