File: MainPage.xaml.cpp

package info (click to toggle)
cpprest 2.10.19-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,916 kB
  • sloc: cpp: 71,086; sh: 275; makefile: 170; javascript: 147
file content (99 lines) | stat: -rw-r--r-- 3,398 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/***
 * Copyright (C) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 *
 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 *
 * MainPage.xaml.cpp - Implementation of the MainPage and
 *  FacebookAlbum classes.
 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 ****/

#include "pch.h"

#include "MainPage.xaml.h"

#include "Facebook.h"
#include <collection.h>

using namespace FacebookDemo;

using namespace Platform;
using namespace Platform::Collections;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;

MainPage::MainPage() { InitializeComponent(); }

/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.  The Parameter
/// property is typically used to configure the page.</param>
void MainPage::OnNavigatedTo(NavigationEventArgs ^ e)
{
    (void)e; // Unused parameter
}

void MainPage::LoginButton_Click_1(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
    LoginButton->IsEnabled = false; // Disable button to prevent double-login

    facebook_client::instance()
        .login(L"user_photos")
        .then([=]() { AlbumButton->IsEnabled = true; }, pplx::task_continuation_context::use_current());
}

void MainPage::AlbumButton_Click_1(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
    using namespace pplx;
    AlbumButton->IsEnabled = false;

    facebook_client::instance()
        .get(L"/me/albums")
        .then([](web::json::value v) {
            web::json::object& obj = v.as_object();
            std::vector<FacebookAlbum ^> albums;

            for (auto& elem : obj[L"data"].as_array())
            {
                albums.push_back(ref new FacebookAlbum(elem[L"name"].as_string(),
                                                       elem[L"count"].as_integer(),
                                                       elem[L"id"].as_string(),
                                                       elem[L"cover_photo"].as_string()));
            }

            return task_from_result(std::move(albums));
        })
        .then(
            [=](std::vector<FacebookAlbum ^> albums) {
                AlbumGrid->ItemsSource = ref new Vector<FacebookAlbum ^>(std::move(albums));
            },
            task_continuation_context::use_current());
}

String ^ FacebookAlbum::Title::get() { return ref new String(title_.c_str()); }

int FacebookAlbum::Count::get() { return count_; }

ImageSource ^ FacebookAlbum::Preview::get()
{
    if (preview_ == nullptr)
    {
        auto preview_uri = facebook_client::instance().base_uri(true);

        preview_uri.append_path(photo_id_);
        preview_uri.append_path(L"/picture");

        preview_ = ref new Imaging::BitmapImage(ref new Uri(StringReference(preview_uri.to_string().c_str())));
    }

    return preview_;
}