Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies>
<MandroidI18n />
<AndroidSupportedAbis>x86;x86_64</AndroidSupportedAbis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -54,8 +60,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down Expand Up @@ -101,4 +107,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.carouselviewchallenge">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="CarouselViewChallenge.Android"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.carouselviewchallenge" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="CarouselViewChallenge.Android"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarians.MediaPlayer">
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.9" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.9" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarouselViewChallenge\CarouselViewChallenge.csproj">
Expand All @@ -159,4 +162,4 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand All @@ -139,4 +139,4 @@
<Name>CarouselViewChallenge</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Luandersonn.iTunesPodcastFinder" Version="2.2.2" />
<PackageReference Include="Xamarians.MediaPlayer" Version="1.1.1" />
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
namespace CarouselViewChallenge.ViewModels
{
using System;
using System.Windows.Input;
using Xamarin.Forms;
using System.Collections.ObjectModel;
using System.ComponentModel;

/// <summary>
/// The podcast info
/// </summary>
public class Podcast
{
public string Title { get; set; }
public FormattedString Description { get; set; }
public string Url { get; set; }

public string ImageUrl { get; set; }
};

public class Episode
{
public string Title { get; set; }
public FormattedString Description { get; set; }
public string Url { get; set; }

public string Duration { get; set; }
}

/// <summary>
/// The Podcasts view model
/// </summary>
/// <seealso cref="System.ComponentModel.INotifyPropertyChanged" />
public class PodcastsViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

private ObservableCollection<Episode> _episodes;
public ObservableCollection<Episode> Episodes
{
get
{
return _episodes;
}
set
{
if (_episodes != value)
{
_episodes = value;
OnPropertyChanged(new PropertyChangedEventArgs("Podcasts"));
}
}
}

private ObservableCollection<Podcast> _podcasts;
public ObservableCollection<Podcast> Podcasts
{
get
{
return _podcasts;
}
set
{
if (_podcasts != value)
{
_podcasts = value;
OnPropertyChanged(new PropertyChangedEventArgs("Podcasts"));
}
}
}

public string PlayUrl { get; set; }

public ICommand PlayCommand { get; private set; }
public ICommand GetEpisodes { get; private set; }

public PodcastsViewModel()
{
Podcasts = new ObservableCollection<Podcast>();
Episodes = new ObservableCollection<Episode>();
PlayCommand = new Command<string>(Play);
GetEpisodes = new Command<string>(LoadEpisodes);

LoadPodcasts();
}

private void Play(string url)
{
PlayUrl = url;
}

private void OnPropertyChanged(PropertyChangedEventArgs eventArgs)
{
PropertyChanged?.Invoke(this, eventArgs);
}

private void LoadPodcasts()
{
var maxItems = 5; // Min:1 - max:200
var country = "nl"; // Two-letter country code (ISO 3166-1 alpha-2)


var finder = new iTunesPodcastFinder.PodcastFinder();
var results = finder.SearchPodcastsAsync("microsoft", maxItems);

foreach (var item in results.Result)
{


Podcasts.Add(
new Podcast
{
Title = item.Name,
Description = item.Summary,
Url = item.FeedUrl,
ImageUrl = item.ArtWork,

});
}

}
private void LoadEpisodes(string url)
{
var podcastFinder = new iTunesPodcastFinder.PodcastFinder();
var results = podcastFinder.GetPodcastEpisodesAsync(url);

Episodes.Clear();

foreach (var item in results.Result.Episodes)
{
Episodes.Add(
new Episode
{
Title = item.Title,
Description = item.Summary,
Url = item.FileUrl.ToString(),
Duration = item.Duration.ToString()
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;

namespace CarouselViewChallenge.ViewModels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,47 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mediaPlayer="clr-namespace:Xamarians.MediaPlayer;assembly=Xamarians.MediaPlayer"
mc:Ignorable="d"
x:Class="CarouselViewChallenge.Views.CarouselViewChallengePage">
<ContentPage.Content>
<StackLayout BackgroundColor="#cfd8dc">
<Label Text="You can use this page for the CarouselView Challenge!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</ContentPage.Content>
<StackLayout>
<CarouselView x:Name="MyCarousel" ItemsSource="{Binding Podcasts}" PeekAreaInsets="50" BackgroundColor="Black">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout >
<Frame BorderColor="Gray" Margin="8" HasShadow="True" HeightRequest="600" VerticalOptions="CenterAndExpand">
<StackLayout>
<Image Source="{Binding ImageUrl}" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" >
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding BindingContext.GetEpisodes, Source={x:Reference Name=MyCarousel}}"
CommandParameter="{Binding Url}" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<CarouselView x:Name="MyCarouselChild" ItemsSource="{Binding Episodes}" PeekAreaInsets="50" BackgroundColor="#202020" >
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout >
<Frame BorderColor="White" Margin="8" HasShadow="True" HeightRequest="200" WidthRequest="300" HorizontalOptions="Center">
<StackLayout>
<Label Text="{Binding Title}" FontSize="20" TextColor="Aqua"></Label>
<Label Text="{Binding Description}" FontSize="14" TextColor="Aqua"></Label>
<Label Text="{Binding Duration}" TextColor="Aqua"></Label>
<Button Text="Play" Command="{Binding BindingContext.PlayCommand, Source={x:Reference Name=MyCarouselChild}}"
CommandParameter="{Binding Url}" BackgroundColor="Orange"></Button>

</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<mediaPlayer:VideoPlayer Source="{Binding PlayUrl}" AutoPlay="True" />
</StackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CarouselViewChallenge.ViewModels;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

Expand All @@ -12,9 +7,14 @@ namespace CarouselViewChallenge.Views
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CarouselViewChallengePage : ContentPage
{
public PodcastsViewModel model { get; set; }

public CarouselViewChallengePage()
{
InitializeComponent();
model = new PodcastsViewModel();

BindingContext = model;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace CarouselViewChallenge.Views
{
Expand All @@ -21,7 +20,7 @@ public WelcomePage()
{
new Section
{
Header = "Thank you for participating in the CarouselView Challenge!",
Header = "😈 Thank you for participating in the CarouselView Challenge!",
Content = new FormattedString
{
Spans =
Expand All @@ -36,7 +35,8 @@ public WelcomePage()
FontAttributes = FontAttributes.Italic
}
}
}
},
Emoji = "😈"
},
new Section
{
Expand Down