Skip to content

Instantly share code, notes, and snippets.

View sthewissen's full-sized avatar
🤷‍♂️
Developing tings.

Steven Thewissen sthewissen

🤷‍♂️
Developing tings.
View GitHub Profile
@sthewissen
sthewissen / data.json
Created June 20, 2017 13:22
Dummy data for YouTube embed
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/tXySRT-f4qSG4YdRv0YhL_k79fE\"",
"nextPageToken": "CBQQAA",
"regionCode": "NL",
"pageInfo": {
"totalResults": 587,
"resultsPerPage": 20
},
"items": [
@sthewissen
sthewissen / YouTube.cs
Last active June 20, 2017 13:46
Calling the YouTube API
using (var httpClient = new HttpClient())
{
var videoIds = new List<string>();
var json = await httpClient.GetStringAsync(channelUrl);
// Deserialize our data, this is in a simple List format
var response = JsonConvert.DeserializeObject<YouTubeApiListRoot>(json);
// Add all the video id's we've found to our list.
videoIds.AddRange(response.items.Select(item => item.id.videoId));
@sthewissen
sthewissen / YouTubeDetails.cs
Last active June 20, 2017 14:31
Getting the details for a list of video IDs
var videoIdString = string.Join(",", videoIds);
var youtubeItems = new List<YouTubeItem>();
using (var httpClient = new HttpClient())
{
var json = await httpClient.GetStringAsync(string.Format(detailsUrl, videoIdString));
var response = JsonConvert.DeserializeObject<YouTubeApiDetailsRoot>(json);
foreach (var item in response.items)
{
@sthewissen
sthewissen / YouTubeChannel.xaml
Created June 20, 2017 15:52
The look and feel for the YouTube sample
<ListView ItemsSource="{Binding Items}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical" Padding="15,20,15,20">
<Image Source="{Binding HighThumbnailUrl}" Aspect="AspectFill" />
<Label Text="{Binding Title}" TextColor="Black" Margin="0,5,0,0" FontSize="15"/>
<Label Text="{Binding ChannelTitle}" Margin="0,-5,0,0" TextColor="#767676" FontSize="13"/>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding ViewCount, StringFormat='{0:n0} views'}" TextColor="#767676" FontSize="13"/>
private readonly ObservableRangeCollection<Grouping<string, MyItem>> _myItems = new ObservableRangeCollection<Grouping<string, MyItem>>();
public ObservableCollection<Grouping<string, MyItem>> MyItems => _myItems;
var sorted = from item in myItems
orderby item.Name
group item by item.Name[0].ToString().ToUpperInvariant() into itemGroup
select new Grouping<string, MyItem>(itemGroup.Key, itemGroup);
_myItems.ReplaceRange(sorted);
[assembly: ExportRenderer(typeof(ListView), typeof(ColoredListViewIndexRenderer))]
namespace MyApp.iOS.Renderers
{
public class ColoredListViewIndexRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Control == null)
<ListView ItemsSource="{Binding MyItems}" GroupDisplayBinding="{Binding Key}" GroupShortNameBinding="{Binding Key}">
....
</ListView>
<ListView ItemsSource="{Binding MyItems}" GroupDisplayBinding="{Binding Key}">
....
</ListView>
public class UntintedNavigationPageRenderer : NavigationRenderer
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
var item = this.NavigationBar?.TopItem?.LeftBarButtonItem;
if (item != null)
item.Image = item.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);