Skip to content

Commit

Permalink
close #31
Browse files Browse the repository at this point in the history
  • Loading branch information
tkowalczyk committed Feb 14, 2016
1 parent 6f48d3f commit 2427475
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
20 changes: 20 additions & 0 deletions Application/DevTalkMobile/Helpers/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ public static List<string> GetImagesInHTMLString(string htmlString) {
return images;
}

public static string GetLinkToMp3File(this string input)
{
return (from link in GetLinksFromHTMLString(input)
where link.Contains(".mp3")
select link).FirstOrDefault();
}

public static List<string> GetLinksFromHTMLString(string htmlString) {
List<string> links = new List<string>();
string pattern = @"(?<=href="").*?(?="")";

Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(htmlString);

for(int i=0, l=matches.Count; i<l; i++) {
links.Add(matches[i].Value);
}

return links;
}

public static List<Partner> GetPartners(string htmlContent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public FeedRepository ()
public async Task<List<FeedItem>> GetAll(string rss)
{
XNamespace content = "http://purl.org/rss/1.0/modules/content/";
// XNamespace feedburner = "http://rssnamespace.org/feedburner/ext/1.0";

var httpClient = new HttpClient (new NativeMessageHandler ());

Expand All @@ -34,8 +33,6 @@ public async Task<List<FeedItem>> GetAll(string rss)
var xdoc = XDocument.Parse(responseString);
var id = 0;
return (from item in xdoc.Descendants("item")
// let enclosure = item.Element("enclosure")
// where enclosure != null
select new FeedItem
{
Title = (string)item.Element("title"),
Expand All @@ -44,7 +41,7 @@ public async Task<List<FeedItem>> GetAll(string rss)
FileImage = (string)item.Element(content.GetName("encoded")).Value.GetImageFile(),
Link = (string)item.Element("link"),
PublishDate = (string)item.Element("pubDate"),
// Mp3Url = (string)enclosure.Attribute("url"),
Mp3Url = (string)item.Element(content.GetName("encoded")).Value.GetLinkToMp3File(),
BlogPost = (string)item.Element("link"),
Id = id++
}).ToList();
Expand All @@ -53,6 +50,8 @@ public async Task<List<FeedItem>> GetAll(string rss)

public async Task<List<FeedItem>> GetFilteredFeed(string rss, string filter)
{
XNamespace content = "http://purl.org/rss/1.0/modules/content/";

var httpClient = new HttpClient(new NativeMessageHandler());

var responseString = await httpClient.GetStringAsync(rss);
Expand All @@ -62,15 +61,16 @@ public async Task<List<FeedItem>> GetFilteredFeed(string rss, string filter)
var xdoc = XDocument.Parse(responseString);
var id = 0;
return (from item in xdoc.Descendants("item")
let enclosure = item.Element("enclosure")
where enclosure != null
select new FeedItem
{
Title = (string)item.Element("title"),
Description = (string)item.Element("description"),
DescriptionLongHtml = (string)item.Element("description"),
FileImage = (string)item.Element(content.GetName("encoded")).Value.GetImageFile(),
Link = (string)item.Element("link"),
PublishDate = (string)item.Element("pubDate"),
Mp3Url = (string)enclosure.Attribute("url"),
Mp3Url = (string)item.Element(content.GetName("encoded")).Value.GetLinkToMp3File(),
BlogPost = (string)item.Element("link"),
Id = id++
}).ToList().Where(item => item.Title.ToLower().Contains(filter.ToLower())).ToList();
});
Expand Down
34 changes: 33 additions & 1 deletion Application/DevTalkMobile/ViewModels/PodcastPlayViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ public string PodcastDuration
get { return podcastDuration; }
set { podcastDuration = value; OnPropertyChanged("PodcastDuration"); }
}

private bool isPlayEnabled = true;
public bool IsPlayEnabled
{
get { return isPlayEnabled; }
set { isPlayEnabled = value; OnPropertyChanged("IsPlayEnabled"); }
}

private bool isStopEnabled = false;
public bool IsStopEnabled
{
get { return isStopEnabled; }
set { isStopEnabled = value; OnPropertyChanged("IsStopEnabled"); }
}

private bool isPauseEnabled = false;
public bool IsPauseEnabled
{
get { return isPauseEnabled; }
set { isPauseEnabled = value; OnPropertyChanged("IsPauseEnabled"); }
}
#endregion

#region Commands
Expand Down Expand Up @@ -103,18 +124,29 @@ public Command<FeedItem> GetSelectedItemInfoCommand
#region Private Methods
private async Task ExecutePlayCommand(string pathToFile)
{
if(!string.IsNullOrWhiteSpace(pathToFile))
if (!string.IsNullOrWhiteSpace (pathToFile))
{
await _soundService.Play (pathToFile);
IsPlayEnabled = false;
IsStopEnabled = true;
IsPauseEnabled = true;
}
}

private void ExecutePauseCommand()
{
_soundService.Pause ();
IsPlayEnabled = true;
IsStopEnabled = false;
IsPauseEnabled = false;
}

private void ExecuteStopCommand()
{
_soundService.Stop ();
IsPlayEnabled = true;
IsStopEnabled = false;
IsPauseEnabled = false;
}

private void ExecuteGetSelectedItemInfoCommand(FeedItem item)
Expand Down
2 changes: 1 addition & 1 deletion Application/DevTalkMobile/Views/HomeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public HomeView ()
this.Title = "DevTalk";

var buttonPlay = new Button () {
Text = "Play",
Text = "Show",
BackgroundColor = Color.FromHex ("#FF6600"),
WidthRequest = 150
};
Expand Down
5 changes: 4 additions & 1 deletion Application/DevTalkMobile/Views/PodcastPlayView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ public PodcastPlayView (FeedItem selectedFeedItem)
Button playButton = new Button ()
{
Text = "Play",
Image = "ic_play.png",
Image = "ic_play.png"
};

playButton.Clicked += (sender, e) =>
{
ViewModel.PlayCommand.Execute(_selectedFeedItem.Mp3Url);
};
playButton.SetBinding (Button.IsEnabledProperty, "IsPlayEnabled");

Button stopButton = new Button ()
{
Expand All @@ -75,6 +76,7 @@ public PodcastPlayView (FeedItem selectedFeedItem)
{
ViewModel.StopCommand.Execute(null);
};
stopButton.SetBinding (Button.IsEnabledProperty, "IsStopEnabled");

Button pauseButton = new Button ()
{
Expand All @@ -86,6 +88,7 @@ public PodcastPlayView (FeedItem selectedFeedItem)
{
ViewModel.PauseCommand.Execute(null);
};
pauseButton.SetBinding (Button.IsEnabledProperty, "IsPauseEnabled");
#endregion

WebView webPage = new WebView ()
Expand Down

0 comments on commit 2427475

Please sign in to comment.