Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ycastonguay/MPfm
Browse files Browse the repository at this point in the history
  • Loading branch information
ycastonguay committed Oct 26, 2013
2 parents 3c92b03 + 3d684a3 commit 6ae64f4
Show file tree
Hide file tree
Showing 55 changed files with 2,242 additions and 581 deletions.
92 changes: 16 additions & 76 deletions MPfm/MPfm.Android/Classes/Activities/ResumePlaybackActivity.cs
Expand Up @@ -39,12 +39,9 @@ namespace MPfm.Android
public class ResumePlaybackActivity : BaseActivity, IResumePlaybackView
{
private MobileNavigationManager _navigationManager;
private TextView _lblIPAddress;
private TextView _lblStatus;
private Button _btnConnectManually;
private ListView _listView;
private SyncListAdapter _listAdapter;
private List<SyncDevice> _devices;
private ResumePlaybackListAdapter _listAdapter;
private List<CloudDeviceInfo> _devices;

protected override void OnCreate(Bundle bundle)
{
Expand All @@ -56,28 +53,18 @@ protected override void OnCreate(Bundle bundle)
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);

_lblIPAddress = FindViewById<TextView>(Resource.Id.resumePlayback_lblIPAddress);
_lblStatus = FindViewById<TextView>(Resource.Id.resumePlayback_lblStatus);
_btnConnectManually = FindViewById<Button>(Resource.Id.resumePlayback_btnConnectManually);
_btnConnectManually.Click += BtnConnectManuallyOnClick;

_listView = FindViewById<ListView>(Resource.Id.resumePlayback_listView);
//_listAdapter = new SyncListAdapter(this, new List<SyncDevice>());
//_listView.SetAdapter(_listAdapter);
//_listView.ItemClick += ListViewOnItemClick;
_listAdapter = new ResumePlaybackListAdapter(this, new List<CloudDeviceInfo>());
_listView.SetAdapter(_listAdapter);
_listView.ItemClick += ListViewOnItemClick;

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetResumePlaybackActivityInstance(this);
}

private void BtnConnectManuallyOnClick(object sender, EventArgs eventArgs)
{
}

private void ListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs itemClickEventArgs)
{
OnCancelDiscovery();
OnConnectDevice(_devices[itemClickEventArgs.Position]);
OnResumePlayback(_devices[itemClickEventArgs.Position]);
}

protected override void OnStart()
Expand Down Expand Up @@ -116,78 +103,31 @@ protected override void OnDestroy()
base.OnDestroy();
}

public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case global::Android.Resource.Id.Home:
var intent = new Intent(this, typeof (MainActivity));
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
OnCancelDiscovery();
this.StartActivity(intent);
this.Finish();
return true;
break;
default:
return base.OnOptionsItemSelected(item);
break;
}
}
#region IResumePlaybackView implementation

public override void OnBackPressed()
{
OnCancelDiscovery();
base.OnBackPressed();
}

#region ISyncView implementation
public Action<CloudDeviceInfo> OnResumePlayback { get; set; }

public Action<SyncDevice> OnConnectDevice { get; set; }
public Action<string> OnConnectDeviceManually { get; set; }
public Action OnStartDiscovery { get; set; }
public Action OnCancelDiscovery { get; set; }

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

public void RefreshIPAddress(string address)
public void RefreshDevices(IEnumerable<CloudDeviceInfo> devices)
{
RunOnUiThread(() => {
_lblIPAddress.Text = address;
});
}

public void RefreshDiscoveryProgress(float percentageDone, string status)
{
RunOnUiThread(() => {
_lblStatus.Text = status;
});
}

public void RefreshDevices(IEnumerable<SyncDevice> devices)
{
RunOnUiThread(() => {
RunOnUiThread(() =>
{
_devices = devices.ToList();
_listAdapter.SetData(_devices);
});
}

public void RefreshDevicesEnded()
{
}

public void SyncDevice(SyncDevice device)
{
}


#endregion

}
Expand Down
87 changes: 87 additions & 0 deletions MPfm/MPfm.Android/Classes/Adapters/ResumePlaybackListAdapter.cs
@@ -0,0 +1,87 @@
// 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 System.Linq;
using Android.App;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using MPfm.Core;
using MPfm.Library.Objects;
using MPfm.Player.Objects;

namespace MPfm.Android.Classes.Adapters
{
public class ResumePlaybackListAdapter : BaseAdapter<CloudDeviceInfo>
{
readonly Activity _context;
List<CloudDeviceInfo> _items;

public ResumePlaybackListAdapter(Activity context, List<CloudDeviceInfo> items)
{
_context = context;
_items = items;
}

public void SetData(IEnumerable<CloudDeviceInfo> items)
{
_items = items.ToList();
NotifyDataSetChanged();
}

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

public override CloudDeviceInfo this[int position]
{
get { return _items[position]; }
}

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

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

var lblTitle = view.FindViewById<TextView>(Resource.Id.resumePlaybackCell_lblTitle);
var lblSubtitle = view.FindViewById<TextView>(Resource.Id.resumePlaybackCell_lblSubtitle);
var lblArtistName = view.FindViewById<TextView>(Resource.Id.resumePlaybackCell_lblArtistName);
var lblAlbumTitle = view.FindViewById<TextView>(Resource.Id.resumePlaybackCell_lblAlbumTitle);
var lblSongTitle = view.FindViewById<TextView>(Resource.Id.resumePlaybackCell_lblSongTitle);
var lblTimestamp = view.FindViewById<TextView>(Resource.Id.resumePlaybackCell_lblTimestamp);
var imageAlbum = view.FindViewById<ImageView>(Resource.Id.resumePlaybackCell_imageAlbum);

lblTitle.Text = item.DeviceName;
lblSubtitle.Text = "On-the-fly playlist";
lblArtistName.Text = item.ArtistName;
lblAlbumTitle.Text = item.AlbumTitle;
lblSongTitle.Text = item.SongTitle;
lblTimestamp.Text = string.Format("Last updated on {0}", item.Timestamp);

return view;
}
}
}
55 changes: 55 additions & 0 deletions MPfm/MPfm.Android/Classes/Services/AndroidDropboxService.cs
Expand Up @@ -23,6 +23,7 @@
using Com.Dropbox.Sync.Android;
using MPfm.Core;
using MPfm.Library;
using MPfm.Library.Objects;
using MPfm.Library.Services.Interfaces;
using MPfm.Sound.AudioFiles;
using MPfm.Sound.Playlists;
Expand Down Expand Up @@ -172,6 +173,59 @@ public void InitializeAppFolder()
}
}

public string PushDeviceInfo(AudioFile audioFile, long positionBytes, string position)
{
return PushNowPlaying_File(audioFile, positionBytes, position);
}

public IEnumerable<CloudDeviceInfo> PullDeviceInfos()
{
List<CloudDeviceInfo> devices = new List<CloudDeviceInfo>();
DbxFile file = null;

try
{
var fileInfos = _fileSystem.ListFolder(new DbxPath("/Devices"));

foreach (var fileInfo in fileInfos)
{
try
{
file = _fileSystem.Open(fileInfo.Path);
//file.Update();
string json = file.ReadString();

CloudDeviceInfo device = null;
try
{
device = JsonConvert.DeserializeObject<CloudDeviceInfo>(json);
devices.Add(device);
}
catch (Exception ex)
{
Tracing.Log("AndroidDropboxService - PullDeviceInfos - Failed to deserialize JSON for path {0} - ex: {1}", fileInfo.Path.Name, ex);
}
}
catch (Exception ex)
{
Tracing.Log("AndroidDropboxService - PullDeviceInfos - Failed to download file {0} - ex: {1}", fileInfo.Path.Name, ex);
}
finally
{
if (file != null)
file.Close();
}
}
}
catch (Exception ex)
{
Tracing.Log("AndroidDropboxService - PullDeviceInfos - Exception: {0}", ex);
throw;
}

return devices;
}

public string PushNowPlaying(AudioFile audioFile, long positionBytes, string position)
{
return PushNowPlaying_File(audioFile, positionBytes, position);
Expand Down Expand Up @@ -518,6 +572,7 @@ public void OnFileChange(DbxFile file)

Console.WriteLine("AndroidDropboxService - OnFileChange {0}", file.Path.ToString());
}

}

public class SerializablePlaylist
Expand Down
4 changes: 4 additions & 0 deletions MPfm/MPfm.Android/MPfm.Android.csproj
Expand Up @@ -91,6 +91,7 @@
<Compile Include="Classes\Adapters\FolderListAdapter.cs" />
<Compile Include="Classes\Adapters\PlaylistListAdapter.cs" />
<Compile Include="Classes\Adapters\PlaylistItemListAdapter.cs" />
<Compile Include="Classes\Adapters\ResumePlaybackListAdapter.cs" />
<Compile Include="Classes\Adapters\SyncMenuListAdapter.cs" />
<Compile Include="Classes\Adapters\SyncListAdapter.cs" />
<Compile Include="Classes\Adapters\MobileLibraryBrowserGridAdapter.cs" />
Expand Down Expand Up @@ -308,6 +309,9 @@
<AndroidResource Include="Resources\layout\ResumePlayback.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout\ResumePlaybackCell.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Values\Strings.xml" />
Expand Down
35 changes: 2 additions & 33 deletions MPfm/MPfm.Android/Resources/Layout/ResumePlayback.axml
Expand Up @@ -6,34 +6,12 @@
android:orientation="vertical"
android:background="@color/background">
<TextView
android:id="@+id/resumePlayback_lblIPAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="Please select a device to resume from:"
android:padding="8dp"
android:text="Please select a device from the list to resume playback:"
android:textSize="14dp"
android:textColor="#CCCCCC" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="horizontal"
android:gravity="center_vertical">
<ProgressBar
android:id="@+id/resumePlayback_progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small"
android:indeterminate="true" />
<TextView
android:id="@+id/resumePlayback_lblStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="Refreshing devices..."
android:textSize="16dp"
android:textColor="#FFFFFF" />
</LinearLayout>
<ListView
android:id="@+id/resumePlayback_listView"
android:layout_width="fill_parent"
Expand All @@ -44,13 +22,4 @@
android:divider="#BBBBBB"
android:dividerHeight="1px"
android:listSelector="@drawable/list" />
<Button
android:id="@+id/resumePlayback_btnConnectManually"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/button"
android:text="Connect manually to device"
android:textColor="@color/button_textcolor"
android:textSize="14dp" />
</LinearLayout>

0 comments on commit 6ae64f4

Please sign in to comment.