Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Added SelectFoldersFragment/View/Presenter. Does not have lo…
…gic yet. Related to issue #406.
- Loading branch information
1 parent
dd32ecf
commit 9e2a719
Showing
20 changed files
with
1,106 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
MPfm/MPfm.Android/Classes/Fragments/SelectFoldersFragment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.