Skip to content

Commit

Permalink
Android: LibraryPreferencesFragment is now fully functional with new …
Browse files Browse the repository at this point in the history
…Preference-based UI. Added CloudPreferencesFragment. Added several new actionbar-style icons for preferences.
  • Loading branch information
ycastonguay committed Nov 5, 2013
1 parent 6753f93 commit 19107c0
Show file tree
Hide file tree
Showing 52 changed files with 700 additions and 460 deletions.
21 changes: 1 addition & 20 deletions MPfm/MPfm.Android/Classes/Activities/PreferencesActivity.cs
Expand Up @@ -18,40 +18,22 @@
using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Support.V4.View;
using Android.Views;
using Android.OS;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Navigation;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;

namespace MPfm.Android
{
[Activity(Label = "Preferences", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/PreferencesTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
public class PreferencesActivity : BasePreferenceActivity, IPreferencesView
{
private List<Fragment> _fragments;

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

//SetContentView(Resource.Layout.Preferences);
ActionBar.SetDisplayHomeAsUpEnabled(true);
//ActionBar.SetHomeButtonEnabled(true);

//_fragments = new List<Fragment>();
//_viewPager = FindViewById<ViewPager>(Resource.Id.preferences_pager);
//_viewPagerAdapter = new ViewPagerAdapter(FragmentManager, _fragments, _viewPager);
//_viewPager.Adapter = _viewPagerAdapter;
//_viewPager.SetOnPageChangeListener(_viewPagerAdapter);

//AddPreferencesFromResource(Resource.Xml.preferences);

// The PreferencesActivity is reused as a container for PreferenceFragment. So there is actually multiple instances of this activity.
// Thus is it not possible to bind to a presenter (or useful!)
Expand All @@ -63,7 +45,6 @@ protected override void OnCreate(Bundle bundle)

public override void OnBuildHeaders(IList<Header> target)
{
//base.OnBuildHeaders(target);
LoadHeadersFromResource(Resource.Xml.preferences_headers, target);
}

Expand Down Expand Up @@ -123,7 +104,7 @@ public override bool OnOptionsItemSelected(IMenuItem item)

public void PushSubView(IBaseView view)
{
Console.WriteLine("PreferencesActivity - PushSubView view: {0}", view.GetType().FullName);
//Console.WriteLine("PreferencesActivity - PushSubView view: {0}", view.GetType().FullName);
//_fragments.Add(new Tuple<MobileNavigationTabType, Fragment>(MobileNavigationTabType.More, (Fragment)view));
//_fragments.Add((Fragment)view);

Expand Down
7 changes: 6 additions & 1 deletion MPfm/MPfm.Android/Classes/Fragments/AddPlaylistFragment.cs
Expand Up @@ -24,6 +24,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;

Expand Down Expand Up @@ -62,7 +64,10 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle((int)DialogFragmentStyle.Normal, (int)Resource.Style.DialogTheme);
SetStyle((int)DialogFragmentStyle.Normal, (int)Resource.Style.DialogTheme);

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

#region IAddPlaylistView implementation
Expand Down
42 changes: 32 additions & 10 deletions MPfm/MPfm.Android/Classes/Fragments/AudioPreferencesFragment.cs
Expand Up @@ -17,34 +17,56 @@

using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;
using Android.Widget;
using MPfm.Android;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.Core;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;

namespace org.sessionsapp.android
{
public class AudioPreferencesFragment : BasePreferenceFragment, IAudioPreferencesView
public class AudioPreferencesFragment : BasePreferenceFragment, IAudioPreferencesView, ISharedPreferencesOnSharedPreferenceChangeListener
{
private View _view;
private TextView _lblTitle;

// Leave an empty constructor or the application will crash at runtime
public AudioPreferencesFragment() : base() { }

//public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
//{
// _view = inflater.Inflate(Resource.Layout.AudioPreferences, container, false);
// _lblTitle = _view.FindViewById<TextView>(Resource.Id.fragment_audioSettings_lblTitle);
// return _view;
//}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = base.OnCreateView(inflater, container, savedInstanceState);
view.SetBackgroundColor(Resources.GetColor(Resource.Color.background));
return view;
}

public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
AddPreferencesFromResource(Resource.Xml.preferences_audio);
Activity.ActionBar.Title = "Audio Preferences";

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

public override void OnResume()
{
base.OnResume();
PreferenceManager.SharedPreferences.RegisterOnSharedPreferenceChangeListener(this);
}

public override void OnPause()
{
base.OnPause();
PreferenceManager.SharedPreferences.UnregisterOnSharedPreferenceChangeListener(this);
}

public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key)
{
Tracing.Log("GeneralPreferencesFragment - OnSharedPreferenceChanged - key: {0}", key);
}
}
}
101 changes: 101 additions & 0 deletions MPfm/MPfm.Android/Classes/Fragments/CloudPreferencesFragment.cs
@@ -0,0 +1,101 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;
using Android.Widget;
using MPfm.Android;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.Core;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Config.Models;
using MPfm.MVP.Models;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;

namespace org.sessionsapp.android
{
public class CloudPreferencesFragment : BasePreferenceFragment, ICloudPreferencesView, ISharedPreferencesOnSharedPreferenceChangeListener
{
// Leave an empty constructor or the application will crash at runtime
public CloudPreferencesFragment() : base() { }

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = base.OnCreateView(inflater, container, savedInstanceState);
view.SetBackgroundColor(Resources.GetColor(Resource.Color.background));
return view;
}

public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
AddPreferencesFromResource(Resource.Xml.preferences_cloud);
Activity.ActionBar.Title = "Cloud Preferences";

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

public override void OnResume()
{
base.OnResume();
PreferenceManager.SharedPreferences.RegisterOnSharedPreferenceChangeListener(this);
}

public override void OnPause()
{
base.OnPause();
PreferenceManager.SharedPreferences.UnregisterOnSharedPreferenceChangeListener(this);
}

public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key)
{
Tracing.Log("GeneralPreferencesFragment - OnSharedPreferenceChanged - key: {0}", key);
}

#region ICloudPreferencesView implementation

public Action<CloudAppConfig> OnSetCloudPreferences { get; set; }
public Action OnDropboxLoginLogout { get; set; }

public void CloudPreferencesError(Exception ex)
{
Activity.RunOnUiThread(() => {
AlertDialog ad = new AlertDialog.Builder(Activity).Create();
ad.SetCancelable(false);
ad.SetMessage(string.Format("An error has occured in CloudPreferences: {0}", ex));
ad.SetButton("OK", (sender, args) => ad.Dismiss());
ad.Show();
});
}

public void RefreshCloudPreferences(CloudAppConfig config)
{
}

public void RefreshCloudPreferencesState(CloudPreferencesStateEntity entity)
{
}

#endregion

}
}
Expand Up @@ -25,6 +25,8 @@
using MPfm.Android;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.Core;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;

namespace org.sessionsapp.android
Expand All @@ -37,13 +39,6 @@ public class GeneralPreferencesFragment : BasePreferenceFragment, IGeneralPrefer
// Leave an empty constructor or the application will crash at runtime
public GeneralPreferencesFragment() : base() { }

//public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
//{
// _view = inflater.Inflate(Resource.Layout.GeneralPreferences, container, false);
// _lblTitle = _view.FindViewById<TextView>(Resource.Id.fragment_generalSettings_lblTitle);
// return _view;
//}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = base.OnCreateView(inflater, container, savedInstanceState);
Expand All @@ -56,6 +51,9 @@ public override void OnCreate(Bundle savedInstanceState)
base.OnCreate(savedInstanceState);
AddPreferencesFromResource(Resource.Xml.preferences_general);
Activity.ActionBar.Title = "General Preferences";

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

public override void OnResume()
Expand Down
88 changes: 63 additions & 25 deletions MPfm/MPfm.Android/Classes/Fragments/LibraryPreferencesFragment.cs
Expand Up @@ -17,48 +17,85 @@

using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Preferences;
using Android.Views;
using Android.Widget;
using MPfm.Android;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.Core;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Config.Models;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;

namespace MPfm.Android.Classes.Fragments
namespace org.sessionsapp.android
{
public class LibraryPreferencesFragment : BaseFragment, ILibraryPreferencesView
public class LibraryPreferencesFragment : BasePreferenceFragment, ILibraryPreferencesView, ISharedPreferencesOnSharedPreferenceChangeListener
{
private View _view;
private Button _btnResetLibrary;
private Button _btnUpdateLibrary;
private Button _btnSelectFolders;

// Leave an empty constructor or the application will crash at runtime
public LibraryPreferencesFragment() : base() { }

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
_view = inflater.Inflate(Resource.Layout.LibraryPreferences, container, false);
_btnResetLibrary = _view.FindViewById<Button>(Resource.Id.libraryPreferences_btnResetLibrary);
_btnUpdateLibrary = _view.FindViewById<Button>(Resource.Id.libraryPreferences_btnUpdateLibrary);
_btnSelectFolders = _view.FindViewById<Button>(Resource.Id.libraryPreferences_btnSelectFolders);
_btnResetLibrary.Click += BtnResetLibraryOnClick;
_btnUpdateLibrary.Click += (sender, args) => OnUpdateLibrary();
_btnSelectFolders.Click += (sender, args) => OnSelectFolders();
return _view;
View view = base.OnCreateView(inflater, container, savedInstanceState);
view.SetBackgroundColor(Resources.GetColor(Resource.Color.background));
return view;
}

public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
AddPreferencesFromResource(Resource.Xml.preferences_library);
Activity.ActionBar.Title = "Library Preferences";

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

private void BtnResetLibraryOnClick(object sender, EventArgs eventArgs)
public override void OnResume()
{
AlertDialog ad = new AlertDialog.Builder(Activity)
.SetIconAttribute(global::Android.Resource.Attribute.AlertDialogIcon)
.SetTitle("Reset Library")
.SetMessage("Are you sure you wish to reset your library?")
.SetCancelable(true)
.SetPositiveButton("OK", (sender2, args) => OnResetLibrary())
.SetNegativeButton("Cancel", (sender2, args) => { })
.Create();
ad.Show();
base.OnResume();
PreferenceManager.SharedPreferences.RegisterOnSharedPreferenceChangeListener(this);
}

public override void OnPause()
{
base.OnPause();
PreferenceManager.SharedPreferences.UnregisterOnSharedPreferenceChangeListener(this);
}

public override bool OnPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
{
//Tracing.Log("LibraryPrefs - OnPreferenceTreeClick - pref: {0}", preference.Title);
if (preference.Key == "select_folders")
{
OnSelectFolders();
}
else if (preference.Key == "update_library")
{
OnUpdateLibrary();
}
else if (preference.Key == "reset_library")
{
AlertDialog ad = new AlertDialog.Builder(Activity)
.SetIconAttribute(global::Android.Resource.Attribute.AlertDialogIcon)
.SetTitle("Reset Library")
.SetMessage("Are you sure you wish to reset your library?")
.SetCancelable(true)
.SetPositiveButton("OK", (sender2, args) => OnResetLibrary())
.SetNegativeButton("Cancel", (sender2, args) => { })
.Create();
ad.Show();
}

return base.OnPreferenceTreeClick(preferenceScreen, preference);
}

public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key)
{
Tracing.Log("GeneralPreferencesFragment - OnSharedPreferenceChanged - key: {0}", key);
}

#region ILibraryPreferencesView implementation
Expand Down Expand Up @@ -86,5 +123,6 @@ public void RefreshLibraryPreferences(LibraryAppConfig config)
}

#endregion

}
}

0 comments on commit 19107c0

Please sign in to comment.