diff --git a/MPfm/branches/current/MPfm.Android/Classes/Activities/MainActivity.cs b/MPfm/branches/current/MPfm.Android/Classes/Activities/MainActivity.cs index ce3070e6..7a892973 100644 --- a/MPfm/branches/current/MPfm.Android/Classes/Activities/MainActivity.cs +++ b/MPfm/branches/current/MPfm.Android/Classes/Activities/MainActivity.cs @@ -3,7 +3,6 @@ using Android.App; using Android.Content; using Android.Content.PM; -using Android.Runtime; using Android.Support.V4.View; using Android.Views; using Android.OS; @@ -11,7 +10,6 @@ using MPfm.Android.Classes; using MPfm.Android.Classes.Adapters; using MPfm.Android.Classes.Fragments; -using MPfm.Android.Classes.Listeners; using MPfm.Android.Classes.Objects; using MPfm.Library.UpdateLibrary; using MPfm.MVP.Models; @@ -21,17 +19,13 @@ namespace MPfm.Android { [Activity(MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait, Theme = "@style/MyAppTheme")] - public class MainActivity : BaseActivity, ISplashView, IUpdateLibraryView, View.IOnClickListener + public class MainActivity : BaseActivity { private ViewPager _viewPager; private TabPagerAdapter _tabPagerAdapter; - private Dialog _splashDialog; - private Dialog _updateLibraryDialog; - private Button _updateLibraryDialog_button; - private TextView _updateLibraryDialog_lblTitle; - private TextView _updateLibraryDialog_lblSubtitle; private List _fragments; - private ProgressBar _updateLibraryDialog_progressBar; + private SplashFragment _splashFragment; + private UpdateLibraryFragment _updateLibraryFragment; protected override void OnCreate(Bundle bundle) { @@ -39,15 +33,12 @@ protected override void OnCreate(Bundle bundle) base.OnCreate(bundle); // Get application state - ApplicationState state = (ApplicationState) LastNonConfigurationInstance; + ApplicationState state = (ApplicationState)LastNonConfigurationInstance; if (state != null) { // Restore state here } - // TODO: Move Splash and Update Library to DialogFragment. - ShowSplashScreen(); - // Request features RequestWindowFeature(WindowFeatures.ActionBar); SetContentView(Resource.Layout.Main); @@ -64,8 +55,7 @@ protected override void OnCreate(Bundle bundle) // Bind this activity to splash and update library views AndroidNavigationManager.Instance.MainActivity = this; - AndroidNavigationManager.Instance.BindUpdateLibraryView(this); - AndroidNavigationManager.Instance.Start(this); + AndroidNavigationManager.Instance.Start(); } public void AddTab(string title, Fragment fragment) @@ -128,15 +118,15 @@ public override bool OnCreateOptionsMenu(IMenu menu) public override bool OnOptionsItemSelected(IMenuItem menuItem) { + // TODO: Determine if the menu should call the NavMgr directly, or the presenter... something like a MainMenuPresenter? string text = menuItem.TitleFormatted.ToString(); - if (text.ToUpper() == "EFFECTS") { - ProgressDialog progressDialog = ProgressDialog.Show(this, "Update Library", "Updating library...", true); + } else if (text.ToUpper() == "UPDATE LIBRARY") { - ShowUpdateLibrary(); + ShowUpdateLibrary((UpdateLibraryFragment)AndroidNavigationManager.Instance.CreateUpdateLibraryView()); } else if (text.ToUpper() == "PREFERENCES") { @@ -146,125 +136,28 @@ public override bool OnOptionsItemSelected(IMenuItem menuItem) else if (text.ToUpper() == "ABOUT MPFM") { //ShowSplashScreen(); - var dialog = new DialogTest(); - dialog.Show(FragmentManager, "tagnumber"); + //var dialog = new DialogTest(); + //dialog.Show(FragmentManager, "tagnumber"); } return base.OnOptionsItemSelected(menuItem); } - public void ShowSplashScreen() + public void ShowSplashScreen(SplashFragment fragment) { - _splashDialog = new Dialog(this, Resource.Style.SplashTheme); - _splashDialog.SetContentView(Resource.Layout.Splash); - _splashDialog.SetCancelable(false); - _splashDialog.Show(); + // Display fragment in a dialog + _splashFragment = fragment; + _splashFragment.Show(FragmentManager, ""); } public void RemoveSplashScreen() { - if (_splashDialog != null) - { - _splashDialog.Dismiss(); - _splashDialog = null; - } - } - - private void ShowUpdateLibrary() - { - // Configure dialog for Update Library - _updateLibraryDialog = new Dialog(this, Resource.Style.UpdateLibraryTheme); - _updateLibraryDialog.SetContentView(Resource.Layout.Fragment_UpdateLibrary); - _updateLibraryDialog.SetCancelable(false); - _updateLibraryDialog.SetTitle("Update Library"); - - // Get controls from dialog - _updateLibraryDialog_button = (Button)_updateLibraryDialog.FindViewById(Resource.Id.fragment_updateLibrary_button); - _updateLibraryDialog_button.SetOnClickListener(this); - _updateLibraryDialog_lblTitle = (TextView) _updateLibraryDialog.FindViewById(Resource.Id.fragment_updateLibrary_lblTitle); - _updateLibraryDialog_lblSubtitle = (TextView)_updateLibraryDialog.FindViewById(Resource.Id.fragment_updateLibrary_lblSubtitle); - _updateLibraryDialog_progressBar = (ProgressBar) _updateLibraryDialog.FindViewById(Resource.Id.fragment_updateLibrary_progressBar); - _updateLibraryDialog.Show(); - - // Start update library process - string musicPath = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic).ToString(); - OnStartUpdateLibrary(UpdateLibraryMode.SpecificFolder, null, musicPath); - //OnStartUpdateLibrary(UpdateLibraryMode.WholeLibrary, null, null); - } - - private void RemoveUpdateLibrary() - { - if (_updateLibraryDialog != null) - { - _updateLibraryDialog.Dismiss(); - _updateLibraryDialog = null; - } - } - - #region ISplashView implementation - - public void RefreshStatus(string message) - { - RunOnUiThread(() => - { - TextView splashTextView = (TextView)_splashDialog.FindViewById(Resource.Id.splash_text); - splashTextView.Text = message; - }); - } - - public void InitDone() - { + _splashFragment.Dialog.Dismiss(); } - #endregion - - #region IUpdateLibraryView implementation - - public Action, string> OnStartUpdateLibrary { get; set; } - - public void RefreshStatus(UpdateLibraryEntity entity) - { - RunOnUiThread(() => - { - _updateLibraryDialog_lblTitle.Text = entity.Title; - _updateLibraryDialog_lblSubtitle.Text = entity.Subtitle; - }); - } - - public void AddToLog(string entry) - { - } - - public void ProcessEnded(bool canceled) - { - RunOnUiThread(() => - { - _updateLibraryDialog_lblTitle.Text = "Update successful."; - _updateLibraryDialog_lblSubtitle.Text = string.Empty; - _updateLibraryDialog_button.Text = "OK"; - _updateLibraryDialog_progressBar.Visibility = ViewStates.Gone; - }); - } - - #endregion - - public void OnClick(View v) - { - if (_updateLibraryDialog_button.Text == "Cancel") - { - // TODO: Cancel update - } - - RemoveUpdateLibrary(); - } - } - - public class DialogTest : DialogFragment - { - public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) + private void ShowUpdateLibrary(UpdateLibraryFragment fragment) { - View view = inflater.Inflate(Resource.Layout.Fragment_UpdateLibrary, container); - Dialog.SetTitle("Hello world!"); - return view; + _updateLibraryFragment = fragment; + _updateLibraryFragment.Show(FragmentManager, ""); } } } diff --git a/MPfm/branches/current/MPfm.Android/Classes/AndroidNavigationManager.cs b/MPfm/branches/current/MPfm.Android/Classes/AndroidNavigationManager.cs index 8b317ecd..02d01506 100644 --- a/MPfm/branches/current/MPfm.Android/Classes/AndroidNavigationManager.cs +++ b/MPfm/branches/current/MPfm.Android/Classes/AndroidNavigationManager.cs @@ -1,5 +1,4 @@ using MPfm.Android.Classes.Fragments; -using MPfm.MVP; using MPfm.MVP.Navigation; using MPfm.MVP.Views; @@ -15,6 +14,11 @@ public static AndroidNavigationManager Instance public MainActivity MainActivity { get; set; } + public override void ShowSplash(ISplashView view) + { + MainActivity.ShowSplashScreen((SplashFragment)view); + } + public override void HideSplash() { MainActivity.RemoveSplashScreen(); diff --git a/MPfm/branches/current/MPfm.Android/Classes/Fragments/SplashFragment.cs b/MPfm/branches/current/MPfm.Android/Classes/Fragments/SplashFragment.cs index 54508af2..3a0d6c19 100644 --- a/MPfm/branches/current/MPfm.Android/Classes/Fragments/SplashFragment.cs +++ b/MPfm/branches/current/MPfm.Android/Classes/Fragments/SplashFragment.cs @@ -7,10 +7,14 @@ using MPfm.MVP.Views; namespace MPfm.Android.Classes.Fragments -{ +{ public class SplashFragment : BaseDialogFragment, ISplashView, View.IOnClickListener { private View _view; + private TextView _textView; + + // Leave an empty constructor or the application will crash at runtime + public SplashFragment() : base(null) {} public SplashFragment(Action onViewReady) : base(onViewReady) @@ -21,9 +25,16 @@ public SplashFragment(Action onViewReady) public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { _view = inflater.Inflate(Resource.Layout.Splash, container, false); + _textView = _view.FindViewById(Resource.Id.splash_text); return _view; } + public override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + SetStyle(DialogFragmentStyle.NoFrame, Resource.Style.SplashTheme); + } + public void OnClick(View v) { @@ -33,10 +44,15 @@ public void OnClick(View v) public void RefreshStatus(string message) { + Activity.RunOnUiThread(() => + { + _textView.Text = message; + }); } public void InitDone() { + //this.Dismiss(); } #endregion diff --git a/MPfm/branches/current/MPfm.Android/Classes/Fragments/UpdateLibraryFragment.cs b/MPfm/branches/current/MPfm.Android/Classes/Fragments/UpdateLibraryFragment.cs index 1ab299d7..8a037463 100644 --- a/MPfm/branches/current/MPfm.Android/Classes/Fragments/UpdateLibraryFragment.cs +++ b/MPfm/branches/current/MPfm.Android/Classes/Fragments/UpdateLibraryFragment.cs @@ -8,27 +8,62 @@ using MPfm.Library.UpdateLibrary; using MPfm.MVP.Models; using MPfm.MVP.Views; +using Environment = Android.OS.Environment; namespace MPfm.Android.Classes.Fragments { - public class UpdateLibraryFragment : BaseDialogFragment, IUpdateLibraryView, View.IOnClickListener + public class UpdateLibraryFragment : BaseDialogFragment, IUpdateLibraryView { - private View _view; + private View _view; + private Button _button; + private TextView _lblTitle; + private TextView _lblSubtitle; + private ProgressBar _progressBar; - public UpdateLibraryFragment(Action onViewReady) + public UpdateLibraryFragment(System.Action onViewReady) : base(onViewReady) { } public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + Dialog.SetTitle("Update Library"); _view = inflater.Inflate(Resource.Layout.Fragment_UpdateLibrary, container, false); + _button = _view.FindViewById