Skip to content

Commit

Permalink
Android: Moved splash and update library dialogs from MainActivity to…
Browse files Browse the repository at this point in the history
… separate DialogFragments.

Related to issue #406.


git-svn-id: http://hamster-svn/svn/repos/base@694 765c1f7c-9fb8-954f-9ff8-dd0915cb3117
  • Loading branch information
animal committed Feb 6, 2013
1 parent e8ccc7f commit 6c00f1f
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 156 deletions.
143 changes: 18 additions & 125 deletions MPfm/branches/current/MPfm.Android/Classes/Activities/MainActivity.cs
Expand Up @@ -3,15 +3,13 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Support.V4.View;
using Android.Views;
using Android.OS;
using Android.Widget;
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;
Expand All @@ -21,33 +19,26 @@
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<Fragment> _fragments;
private ProgressBar _updateLibraryDialog_progressBar;
private SplashFragment _splashFragment;
private UpdateLibraryFragment _updateLibraryFragment;

protected override void OnCreate(Bundle bundle)
{
Console.WriteLine("MainActivity - OnCreate");
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);
Expand All @@ -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)
Expand Down Expand Up @@ -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")
{
Expand All @@ -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<UpdateLibraryMode, List<string>, 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, "");
}
}
}
@@ -1,5 +1,4 @@
using MPfm.Android.Classes.Fragments;
using MPfm.MVP;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;

Expand All @@ -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();
Expand Down
Expand Up @@ -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<IBaseView> onViewReady)
: base(onViewReady)
Expand All @@ -21,9 +25,16 @@ public SplashFragment(Action<IBaseView> onViewReady)
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
_view = inflater.Inflate(Resource.Layout.Splash, container, false);
_textView = _view.FindViewById<TextView>(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)
{

Expand All @@ -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
Expand Down
Expand Up @@ -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<IBaseView> onViewReady)
public UpdateLibraryFragment(System.Action<IBaseView> 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<Button>(Resource.Id.fragment_updateLibrary_button);
_lblTitle = _view.FindViewById<TextView>(Resource.Id.fragment_updateLibrary_lblTitle);
_lblSubtitle = _view.FindViewById<TextView>(Resource.Id.fragment_updateLibrary_lblSubtitle);
_progressBar = _view.FindViewById<ProgressBar>(Resource.Id.fragment_updateLibrary_progressBar);

_button.Click += ButtonOnClick;

return _view;
}

public void OnClick(View v)
public override void OnCreate(Bundle savedInstanceState)
{

base.OnCreate(savedInstanceState);
SetStyle(DialogFragmentStyle.Normal, Resource.Style.UpdateLibraryTheme);
}

public override void OnStart()
{
base.OnStart();

// Start update library process
string musicPath = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic).ToString();
OnStartUpdateLibrary(UpdateLibraryMode.SpecificFolder, null, musicPath);
//OnStartUpdateLibrary(UpdateLibraryMode.WholeLibrary, null, null);
}

private void ButtonOnClick(object sender, EventArgs eventArgs)
{
Dismiss();
//if (_updateLibraryDialog_button.Text == "Cancel")
//{
// // TODO: Cancel update
//}

//RemoveUpdateLibrary();
}

#region IUpdateLibraryView implementation
Expand All @@ -37,17 +72,26 @@ public void OnClick(View v)

public void RefreshStatus(UpdateLibraryEntity entity)
{
throw new NotImplementedException();
Activity.RunOnUiThread(() =>
{
_lblTitle.Text = entity.Title;
_lblSubtitle.Text = entity.Subtitle;
});
}

public void AddToLog(string entry)
{
throw new NotImplementedException();
}

public void ProcessEnded(bool canceled)
{
throw new NotImplementedException();
Activity.RunOnUiThread(() =>
{
_lblTitle.Text = "Update successful.";
_lblSubtitle.Text = string.Empty;
_button.Text = "OK";
_progressBar.Visibility = ViewStates.Gone;
});
}

#endregion
Expand Down

0 comments on commit 6c00f1f

Please sign in to comment.