Skip to content

Commit

Permalink
Android: Added SelectFoldersFragment/View/Presenter. Does not have lo…
Browse files Browse the repository at this point in the history
…gic yet.

Related to issue #406.
  • Loading branch information
ycastonguay committed Oct 3, 2013
1 parent dd32ecf commit 9e2a719
Show file tree
Hide file tree
Showing 20 changed files with 1,106 additions and 560 deletions.
76 changes: 76 additions & 0 deletions MPfm/MPfm.Android/Classes/Adapters/FolderListAdapter.cs
@@ -0,0 +1,76 @@
// 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.Collections.Generic;
using Android.App;
using Android.Views;
using Android.Widget;
using MPfm.Library.Objects;
using MPfm.MVP.Models;

namespace MPfm.Android.Classes.Adapters
{
public class FolderListAdapter : BaseAdapter<Folder>
{
readonly Activity _context;
readonly ListView _listView;
List<Folder> _folders;

public FolderListAdapter(Activity context, ListView listView, List<Folder> folders)
{
_context = context;
_listView = listView;
_folders = folders;
}

public void SetData(List<Folder> folders)
{
_folders = folders;
NotifyDataSetChanged();
}

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

public override Folder this[int position]
{
get { return _folders[position]; }
}

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

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

var title = view.FindViewById<TextView>(Resource.Id.playlistcell_title);
var count = view.FindViewById<TextView>(Resource.Id.playlistcell_count);
title.Text = _folders[position].FolderPath;
count.Text = "0";

return view;
}
}
}
1 change: 1 addition & 0 deletions MPfm/MPfm.Android/Classes/Application.cs
Expand Up @@ -173,6 +173,7 @@ private void BootstrapApp()
container.Register<IGeneralPreferencesView, GeneralPreferencesFragment>().AsMultiInstance();
container.Register<ILibraryPreferencesView, LibraryPreferencesFragment>().AsMultiInstance();
container.Register<IAboutView, AboutActivity>().AsMultiInstance();
container.Register<ISelectFoldersView, SelectFoldersFragment>().AsMultiInstance();
container.Register<ISelectPlaylistView, SelectPlaylistFragment>().AsMultiInstance();
container.Register<IAddPlaylistView, AddPlaylistFragment>().AsMultiInstance();
container.Register<IAddMarkerView, AddMarkerFragment>().AsMultiInstance();
Expand Down
Expand Up @@ -30,6 +30,7 @@ public class LibraryPreferencesFragment : BaseFragment, ILibraryPreferencesView
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(null) { }
Expand All @@ -44,8 +45,10 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
_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;
}

Expand All @@ -66,6 +69,7 @@ private void BtnResetLibraryOnClick(object sender, EventArgs eventArgs)

public Action OnResetLibrary { get; set; }
public Action OnUpdateLibrary { get; set; }
public Action OnSelectFolders { get; set; }
public Action OnEnableSyncListener { get; set; }
public Action<int> OnSetSyncListenerPort { get; set; }

Expand Down
120 changes: 120 additions & 0 deletions MPfm/MPfm.Android/Classes/Fragments/SelectFoldersFragment.cs
@@ -0,0 +1,120 @@
// 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.Content;
using Android.OS;
using Android.Views;
using Android.Widget;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.Library.Objects;
using MPfm.MVP.Models;
using MPfm.MVP.Presenters;
using MPfm.MVP.Views;
using MPfm.Sound.Playlists;

namespace MPfm.Android.Classes.Fragments
{
public class SelectFoldersFragment : BaseDialogFragment, ISelectFoldersView
{
private List<Folder> _folders;
private FolderListAdapter _listAdapter;
private View _view;
private ListView _listView;
private Button _btnCancel;
private Button _btnOK;
private int _selectedIndex;

public SelectFoldersFragment() : base(null)
{
}

public SelectFoldersFragment(Action<IBaseView> onViewReady)
: base(onViewReady)
{
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Dialog.SetTitle("Select folders to scan");
_view = inflater.Inflate(Resource.Layout.SelectFolders, container, false);

_listView = _view.FindViewById<ListView>(Resource.Id.selectFolders_listView);
_btnCancel = _view.FindViewById<Button>(Resource.Id.selectFolders_btnCancel);
_btnOK = _view.FindViewById<Button>(Resource.Id.selectFolders_btnOK);
_btnOK.Enabled = false;
_btnCancel.Click += (sender, args) => Dismiss();
_btnOK.Click += (sender, args) =>
{
OnSaveFolders();
Dismiss();
};

_folders = new List<Folder>();
_listAdapter = new FolderListAdapter(Activity, _listView, _folders);
_listView.SetAdapter(_listAdapter);
_listView.ItemClick += ListViewOnItemClick;

return _view;
}

private void ListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
_btnOK.Enabled = true;
_selectedIndex = e.Position;
}

public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle((int)DialogFragmentStyle.Normal, (int)Resource.Style.DialogTheme);
}

#region ISelectFoldersView implementation

public Action OnSaveFolders { get; set; }
public Action<Folder> OnSelectFolder { get; set; }

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

}

public void RefreshFolders(List<Folder> folders)
{
Activity.RunOnUiThread(() =>
{
_folders = folders.ToList();
_listAdapter.SetData(_folders);
});
}

#endregion
}
}
8 changes: 8 additions & 0 deletions MPfm/MPfm.Android/MPfm.Android.csproj
Expand Up @@ -75,6 +75,7 @@
<Compile Include="Classes\Activities\EqualizerPresetsActivity.cs" />
<Compile Include="Classes\Activities\MainActivity.cs" />
<Compile Include="Classes\Activities\PreferencesActivity.cs" />
<Compile Include="Classes\Adapters\FolderListAdapter.cs" />
<Compile Include="Classes\Adapters\PlaylistListAdapter.cs" />
<Compile Include="Classes\Adapters\PlaylistItemListAdapter.cs" />
<Compile Include="Classes\Adapters\SyncMenuListAdapter.cs" />
Expand Down Expand Up @@ -102,6 +103,7 @@
<Compile Include="Classes\Fragments\Base\BaseDialogFragment.cs" />
<Compile Include="Classes\Fragments\AddPlaylistFragment.cs" />
<Compile Include="Classes\Fragments\AddMarkerFragment.cs" />
<Compile Include="Classes\Fragments\SelectFoldersFragment.cs" />
<Compile Include="Classes\Fragments\SelectPlaylistFragment.cs" />
<Compile Include="Classes\Fragments\SyncManualConnectFragment.cs" />
<Compile Include="Classes\Fragments\PlayerMetadataFragment.cs" />
Expand Down Expand Up @@ -276,6 +278,12 @@
<AndroidResource Include="Resources\layout\AddMarker.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout\SelectFolders.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout\FolderCell.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Values\Strings.xml" />
Expand Down
39 changes: 39 additions & 0 deletions MPfm/MPfm.Android/Resources/Layout/FolderCell.axml
@@ -0,0 +1,39 @@
<?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="44dp"
android:orientation="horizontal">
<TextView
android:id="@+id/foldercell_title"
android:layout_width="0dp"
android:layout_height="44dp"
android:layout_weight="1"
android:minHeight="44dp"
android:maxHeight="44dp"
android:padding="6dp"
android:gravity="center_vertical"
android:textColor="@color/dialoglist_text"
android:textSize="16dp" />
<LinearLayout
android:layout_width="60dp"
android:layout_height="44dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/foldercell_count"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="@color/dialoglist_text"
android:textSize="16dp" />
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="songs"
android:textColor="#CCCCCC"
android:textSize="11dp" />
</LinearLayout>
</LinearLayout>

0 comments on commit 9e2a719

Please sign in to comment.