#include "winrtshare.h"

#ifdef Q_OS_WINPHONE

// Method to call the ShareUI interface
void WinRtShare::ShowShareUI()
{
    MessageDialog^ msg = ref new MessageDialog("Message box is being shown.");
    msg->ShowAsync();

//    // DataTransferManager^ dataTransferManager = DataTransferManager::GetForCurrentView();
//    // dataTransferManager->ShowShareUI();
//    // Windows::ApplicationModel::DataTransfer::DataTransferManager::ShowShareUI();
}

// Method to register for share
//void WinRtShare::RegisterForShare()
//{
    //MessageDialog^ msg = ref new MessageDialog("Message box is being shown.");
    //msg->ShowAsync();

//     CoreWindow::GetForCurrentThread()->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,
//                                                             ref new DispatchedHandler([]()
//                                                             {
//    DataTransferManager::GetForCurrentView();
//         DataTransferManager^ dataTransferManager = DataTransferManager::GetForCurrentView();
//         auto dataRequestedToken = dataTransferManager->DataRequested +=
//                                   ref new TypedEventHandler<DataTransferManager^, DataRequestedEventArgs^>(
//                                   this, &WinRtShare::ShareImageHandler);

//         Windows::ApplicationModel::DataTransfer::DataTransferManager::ShowShareUI();

//     }));
//}

// Handler for image sharing
//void WinRtShare::ShareImageHandler(DataTransferManager^ sender, DataRequestedEventArgs^ e)
//{
//    DataRequest^ request = e->Request;
//    request->Data->Properties->Title = "Share Image Example";
//    request->Data->Properties->Description = "Demonstrates how to share an image.";

//    // Because we are making async calls in the DataRequested event handler,
//    // we need to get the deferral first.
//    DataRequestDeferral^ deferral = request->GetDeferral();

//    create_task(Package::Current->InstalledLocation->GetFileAsync("Assets\\SmallLogo.png")).then(
//        [this, request](StorageFile^ thumbnailFile)
//    {
//        request->Data->Properties->Thumbnail =
//            RandomAccessStreamReference::CreateFromFile(thumbnailFile);
//        return Package::Current->InstalledLocation->GetFileAsync("Assets\\Logo.png");
//    }).then([this, request, deferral](task<StorageFile^> getImageFileTask)
//    {
//        try
//        {
//            auto imageFile = getImageFileTask.get();
//            request->Data->SetBitmap(RandomAccessStreamReference::CreateFromFile(imageFile));
//            deferral->Complete();
//        }
//        catch (Exception^ ex)
//        {
//            // Calling FailWithDisplayText() also calls Complete the deferral.
//            request->FailWithDisplayText(ex->Message);
//        }
//    });
//}

#endif
