Skip to content

Commit

Permalink
Android: Playlists can now be saved in the database (but not their it…
Browse files Browse the repository at this point in the history
…ems yet). Added 1.06 database script. Fixed bug in database gateway field mapping.

Related to issue #406.
  • Loading branch information
ycastonguay committed Sep 16, 2013
1 parent 98c7af6 commit 09c73aa
Show file tree
Hide file tree
Showing 22 changed files with 1,287 additions and 1,186 deletions.
13 changes: 7 additions & 6 deletions MPfm/MPfm.Android/Classes/Adapters/PlaylistListAdapter.cs
Expand Up @@ -25,23 +25,24 @@
using MPfm.Core;
using MPfm.MVP.Models;
using MPfm.Player.Objects;
using MPfm.Sound.Playlists;

namespace MPfm.Android.Classes.Adapters
{
public class PlaylistListAdapter : BaseAdapter<PlaylistEntity>
public class PlaylistListAdapter : BaseAdapter<Playlist>
{
readonly Activity _context;
readonly ListView _listView;
List<PlaylistEntity> _playlists;
List<Playlist> _playlists;

public PlaylistListAdapter(Activity context, ListView listView, List<PlaylistEntity> playlists)
public PlaylistListAdapter(Activity context, ListView listView, List<Playlist> playlists)
{
_context = context;
_listView = listView;
_playlists = playlists;
}

public void SetData(List<PlaylistEntity> playlists)
public void SetData(List<Playlist> playlists)
{
_playlists = playlists;
NotifyDataSetChanged();
Expand All @@ -52,7 +53,7 @@ public override long GetItemId(int position)
return position;
}

public override PlaylistEntity this[int position]
public override Playlist this[int position]
{
get { return _playlists[position]; }
}
Expand All @@ -70,7 +71,7 @@ public override View GetView(int position, View convertView, ViewGroup parent)
view = _context.LayoutInflater.Inflate(Resource.Layout.PlaylistCell, null);

var title = view.FindViewById<TextView>(Resource.Id.playlistcell_title);
title.Text = _playlists[position].Title;
title.Text = _playlists[position].Name;

return view;
}
Expand Down
14 changes: 13 additions & 1 deletion MPfm/MPfm.Android/Classes/Fragments/AddNewPlaylistFragment.cs
Expand Up @@ -54,7 +54,11 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
_btnCancel = _view.FindViewById<Button>(Resource.Id.addNewPlaylist_btnCancel);
_btnCreate = _view.FindViewById<Button>(Resource.Id.addNewPlaylist_btnCreate);
_btnCancel.Click += (sender, args) => Dismiss();
_btnCreate.Click += (sender, args) => { };
_btnCreate.Click += (sender, args) =>
{
OnSavePlaylist(_txtName.Text);
Dismiss();
};
_btnCreate.Enabled = false;

_txtName.TextChanged += (sender, args) => _btnCreate.Enabled = _txtName.Text.Length > 0;
Expand All @@ -74,6 +78,14 @@ public override void OnCreate(Bundle savedInstanceState)

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

#endregion
Expand Down
15 changes: 6 additions & 9 deletions MPfm/MPfm.Android/Classes/Fragments/SelectPlaylistFragment.cs
Expand Up @@ -28,12 +28,13 @@
using MPfm.MVP.Models;
using MPfm.MVP.Presenters;
using MPfm.MVP.Views;
using MPfm.Sound.Playlists;

namespace MPfm.Android.Classes.Fragments
{
public class SelectPlaylistFragment : BaseDialogFragment, ISelectPlaylistView
{
private List<PlaylistEntity> _playlists;
private List<Playlist> _playlists;
private PlaylistListAdapter _listAdapter;
private View _view;
private ListView _listView;
Expand Down Expand Up @@ -66,13 +67,9 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
//_parentFragment.OnAddItemToPlaylist(_position);
Dismiss();
};
_btnAddNewPlaylist.Click += (sender, args) =>
{
var fragment = new AddNewPlaylistFragment();
fragment.Show(FragmentManager, "AddNewPlaylistFragment");
};
_btnAddNewPlaylist.Click += (sender, args) => OnAddNewPlaylist();

_playlists = new List<PlaylistEntity>();
_playlists = new List<Playlist>();
_listAdapter = new PlaylistListAdapter(Activity, _listView, _playlists);
_listView.SetAdapter(_listAdapter);
_listView.ItemClick += ListViewOnItemClick;
Expand All @@ -94,7 +91,7 @@ public override void OnCreate(Bundle savedInstanceState)
#region ISelectPlaylistView implementation

public Action OnAddNewPlaylist { get; set; }
public Action<PlaylistEntity> OnSelectPlaylist { get; set; }
public Action<Playlist> OnSelectPlaylist { get; set; }

public void SelectPlaylistError(Exception ex)
{
Expand All @@ -108,7 +105,7 @@ public void SelectPlaylistError(Exception ex)
});
}

public void RefreshPlaylists(List<PlaylistEntity> playlists)
public void RefreshPlaylists(List<Playlist> playlists)
{
Activity.RunOnUiThread(() =>
{
Expand Down
17 changes: 13 additions & 4 deletions MPfm/MPfm.Android/Resources/Layout/AddNewPlaylist.axml
Expand Up @@ -7,20 +7,29 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="12dp"
android:paddingTop="12dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingBottom="0dp"
android:text="Please enter a name for the new playlist:"
android:textColor="#AAAAAA"
android:textSize="14dp" />
<EditText
android:id="@+id/addNewPlaylist_txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="0dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:singleLine="true"
android:lines="1"
android:textSize="16dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<Button
android:id="@+id/addNewPlaylist_btnCancel"
Expand Down
4 changes: 4 additions & 0 deletions MPfm/MPfm.Android/Resources/Layout/LibraryPreferences.axml
Expand Up @@ -41,6 +41,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/button_selector"
android:text="Reset Library"
android:textColor="@color/button_textcolor"
Expand All @@ -51,6 +53,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/button_selector"
android:text="Update Library"
android:textColor="@color/button_textcolor"
Expand Down
38 changes: 38 additions & 0 deletions MPfm/MPfm.Core/DatabaseFieldMap.cs
@@ -0,0 +1,38 @@
// 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/>.

namespace MPfm.Core
{
public class DatabaseFieldMap
{
public string PropertyName { get; set; }
public string FieldName { get; set; }
public bool SaveToDatabase { get; set; }

public DatabaseFieldMap()
{
SaveToDatabase = true;
}

public DatabaseFieldMap(string propertyName, string fieldName, bool saveToDatabase)
{
PropertyName = propertyName;
FieldName = fieldName;
SaveToDatabase = saveToDatabase;
}
}
}
1 change: 1 addition & 0 deletions MPfm/MPfm.Core/MPfm.Core.Android.csproj
Expand Up @@ -95,6 +95,7 @@
<ItemGroup>
<Compile Include="Conversion.cs" />
<Compile Include="Attributes\DatabaseFieldAttribute.cs" />
<Compile Include="DatabaseFieldMap.cs" />
<Compile Include="Extensions\DictionaryExtension.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tracing.cs" />
Expand Down

0 comments on commit 09c73aa

Please sign in to comment.