Skip to content

Commit

Permalink
Android: Added list adapter for equalizer presets; can now select, ad…
Browse files Browse the repository at this point in the history
…d and edit presets.

Related to issue #406.
  • Loading branch information
ycastonguay committed Jul 10, 2013
1 parent e8d377a commit cc140c2
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Reflection;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Support.V4.App;
using Android.Views;
using Android.OS;
using Android.Widget;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Navigation;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters;
using MPfm.MVP.Views;
using MPfm.Player.Objects;

Expand Down Expand Up @@ -138,6 +134,7 @@ public override bool OnOptionsItemSelected(IMenuItem item)
case Resource.Id.equalizerPresetDetailsMenu_item_save:
Console.WriteLine("EqualizerPresetDetailsActivity - Menu item click - Saving preset...");
OnSavePreset(_txtPresetName.Text);
_listAdapter.HasPresetChanged = false;
return true;
break;
default:
Expand Down
36 changes: 36 additions & 0 deletions MPfm/MPfm.Android/Classes/Activities/EqualizerPresetsActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Support.V4.App;
using Android.Views;
using Android.OS;
using Android.Widget;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Navigation;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
Expand All @@ -37,6 +40,11 @@ public class EqualizerPresetsActivity : BaseActivity, IEqualizerPresetsView
{
private MobileNavigationManager _navigationManager;
private string _sourceActivityType;
private SeekBar _seekBarVolume;
private ToggleButton _btnBypass;
private ListView _listView;
private EqualizerPresetsListAdapter _listAdapter;
private List<EQPreset> _presets;

protected override void OnCreate(Bundle bundle)
{
Expand All @@ -48,13 +56,35 @@ protected override void OnCreate(Bundle bundle)
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);

_seekBarVolume = FindViewById<SeekBar>(Resource.Id.equalizerPresets_seekBarVolume);
_seekBarVolume.ProgressChanged += (sender, args) => OnSetVolume(1);

_btnBypass = FindViewById<ToggleButton>(Resource.Id.equalizerPresets_btnBypass);
_btnBypass.Click += (sender, args) => OnBypassEqualizer();

_listView = FindViewById<ListView>(Resource.Id.equalizerPresets_listView);
_listAdapter = new EqualizerPresetsListAdapter(this, new List<EQPreset>());
_listView.SetAdapter(_listAdapter);
_listView.ItemClick += ListViewOnItemClick;
_listView.ItemLongClick += ListViewOnItemLongClick;

// Save the source activity type for later (for providing Up navigation)
_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);
}

private void ListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs itemClickEventArgs)
{
OnLoadPreset(_presets[itemClickEventArgs.Position].EQPresetId);
}

private void ListViewOnItemLongClick(object sender, AdapterView.ItemLongClickEventArgs itemLongClickEventArgs)
{
OnEditPreset(_presets[itemLongClickEventArgs.Position].EQPresetId);
}

protected override void OnStart()
{
Console.WriteLine("EqualizerPresetsActivity - OnStart");
Expand Down Expand Up @@ -143,6 +173,12 @@ public void EqualizerPresetsError(Exception ex)

public void RefreshPresets(IEnumerable<EQPreset> presets, Guid selectedPresetId, bool isEQBypassed)
{
RunOnUiThread(() => {
_btnBypass.Checked = isEQBypassed;
_presets = presets.ToList();
_listAdapter.SetData(_presets);
_listAdapter.SetSelected(selectedPresetId);
});
}

public void RefreshOutputMeter(float[] dataLeft, float[] dataRight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class EqualizerPresetFadersListAdapter : BaseAdapter<EQPresetBand>
private readonly EqualizerPresetDetailsActivity _context;
private EQPreset _preset;

public bool HasPresetChanged { get; private set; }
public bool HasPresetChanged { get; set; }

public EqualizerPresetFadersListAdapter(EqualizerPresetDetailsActivity context, EQPreset preset)
{
Expand All @@ -42,6 +42,7 @@ public EqualizerPresetFadersListAdapter(EqualizerPresetDetailsActivity context,

public void SetData(EQPreset preset)
{
_preset = preset;
NotifyDataSetChanged();
}

Expand Down
82 changes: 82 additions & 0 deletions MPfm/MPfm.Android/Classes/Adapters/EqualizerPresetsListAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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 System.Collections.Generic;
using System.Linq;
using Android.App;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using MPfm.Core;
using MPfm.Player.Objects;

namespace MPfm.Android.Classes.Adapters
{
public class EqualizerPresetsListAdapter : BaseAdapter<EQPreset>
{
private readonly EqualizerPresetsActivity _context;
private List<EQPreset> _presets;

public bool HasPresetChanged { get; private set; }

public EqualizerPresetsListAdapter(EqualizerPresetsActivity context, List<EQPreset> presets)
{
_context = context;
_presets = presets;
}

public void SetData(List<EQPreset> presets)
{
_presets = presets;
NotifyDataSetChanged();
}

public void SetSelected(Guid presetId)
{

}

public override long GetItemId(int position)
{
return position;
}

public override EQPreset this[int position]
{
get { return _presets[position]; }
}

public override int Count
{
get { return _presets.Count; }
}

public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = _presets[position];
View view = convertView;
if (view == null) // no view to re-use, create new
view = _context.LayoutInflater.Inflate(Resource.Layout.EqualizerPresetCell, null);

var lblName = view.FindViewById<TextView>(Resource.Id.equalizerPresetCell_lblName);
lblName.Text = _presets[position].Name;

return view;
}
}
}
4 changes: 4 additions & 0 deletions MPfm/MPfm.Android/MPfm.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="Classes\Activities\EqualizerPresetsActivity.cs" />
<Compile Include="Classes\Activities\MainActivity.cs" />
<Compile Include="Classes\Activities\PreferencesActivity.cs" />
<Compile Include="Classes\Adapters\EqualizerPresetsListAdapter.cs" />
<Compile Include="Classes\Adapters\EqualizerPresetFadersListAdapter.cs" />
<Compile Include="Classes\Adapters\MarkersListAdapter.cs" />
<Compile Include="Classes\Adapters\PreferencesFragmentPagerAdapter.cs" />
Expand Down Expand Up @@ -179,6 +180,9 @@
<AndroidResource Include="Resources\Layout\EqualizerPresetFaderCell.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\Layout\EqualizerPresetCell.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Values\Strings.xml" />
Expand Down
16 changes: 16 additions & 0 deletions MPfm/MPfm.Android/Resources/Layout/EqualizerPresetCell.axml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="56dp"
android:padding="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/equalizerPresetCell_lblName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Default"
android:textColor="#000000"
android:textSize="14dp" />
</LinearLayout>
Loading

0 comments on commit cc140c2

Please sign in to comment.