Debian Codegraph @

Release/samples/FacebookDemo/MainPage.xaml.cpp

raw
1 /***
2 * Copyright (C) Microsoft. All rights reserved.
3 * Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4 *
5 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
6 *
7 * MainPage.xaml.cpp - Implementation of the MainPage and
8 * FacebookAlbum classes.
9 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
10 ****/
11
12 #include "pch.h"
13
14 #include "MainPage.xaml.h"
15
16 #include "Facebook.h"
17 #include <collection.h>
18
19 using namespace FacebookDemo;
20
21 using namespace Platform;
22 using namespace Platform::Collections;
23 using namespace Windows::Foundation;
24 using namespace Windows::Foundation::Collections;
25 using namespace Windows::UI::Xaml;
26 using namespace Windows::UI::Xaml::Controls;
27 using namespace Windows::UI::Xaml::Controls::Primitives;
28 using namespace Windows::UI::Xaml::Data;
29 using namespace Windows::UI::Xaml::Input;
30 using namespace Windows::UI::Xaml::Media;
31 using namespace Windows::UI::Xaml::Navigation;
32
33 MainPage::MainPage() { InitializeComponent(); }
34
35 /// <summary>
36 /// Invoked when this page is about to be displayed in a Frame.
37 /// </summary>
38 /// <param name="e">Event data that describes how this page was reached. The Parameter
39 /// property is typically used to configure the page.</param>
40 void MainPage::OnNavigatedTo(NavigationEventArgs ^ e)
41 {
42 (void)e; // Unused parameter
43 }
44
45 void MainPage::LoginButton_Click_1(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
46 {
47 LoginButton->IsEnabled = false; // Disable button to prevent double-login
48
49 facebook_client::instance()
50 .login(L"user_photos")
51 .then([=]() { AlbumButton->IsEnabled = true; }, pplx::task_continuation_context::use_current());
52 }
53
54 void MainPage::AlbumButton_Click_1(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
55 {
56 using namespace pplx;
57 AlbumButton->IsEnabled = false;
58
59 facebook_client::instance()
60 .get(L"/me/albums")
61 .then([](web::json::value v) {
62 web::json::object& obj = v.as_object();
63 std::vector<FacebookAlbum ^> albums;
64
65 for (auto& elem : obj[L"data"].as_array())
66 {
67 albums.push_back(ref new FacebookAlbum(elem[L"name"].as_string(),
68 elem[L"count"].as_integer(),
69 elem[L"id"].as_string(),
70 elem[L"cover_photo"].as_string()));
71 }
72
73 return task_from_result(std::move(albums));
74 })
75 .then(
76 [=](std::vector<FacebookAlbum ^> albums) {
77 AlbumGrid->ItemsSource = ref new Vector<FacebookAlbum ^>(std::move(albums));
78 },
79 task_continuation_context::use_current());
80 }
81
82 String ^ FacebookAlbum::Title::get() { return ref new String(title_.c_str()); }
83
84 int FacebookAlbum::Count::get() { return count_; }
85
86 ImageSource ^ FacebookAlbum::Preview::get()
87 {
88 if (preview_ == nullptr)
89 {
90 auto preview_uri = facebook_client::instance().base_uri(true);
91
92 preview_uri.append_path(photo_id_);
93 preview_uri.append_path(L"/picture");
94
95 preview_ = ref new Imaging::BitmapImage(ref new Uri(StringReference(preview_uri.to_string().c_str())));
96 }
97
98 return preview_;
99 }