~haowenl/vorg-windows

a859e0a6e529c64965cd4b20fbe975bd2359c9ec — Haowen Liu 11 months ago 9eb1fe1
Refresh video data upon import
M libvorg => libvorg +1 -1
@@ 1,1 1,1 @@
Subproject commit ad947ddb215301323503ee07f25f46f0960c0eb5
Subproject commit c3c6e8bd5a331e390cf47e831faacc5eb51c8ba2

M vorg-windows/BrowsePage.idl => vorg-windows/BrowsePage.idl +2 -1
@@ 9,9 9,10 @@ namespace vorg_windows
{
    BrowsePage();

    Windows.Foundation.Collections.IIterable<IInspectable> VideoData
    Windows.Foundation.Collections.IObservableVector<Object> VideoData
    {
        get;
        set;
    };
}
} // namespace vorg_windows

M vorg-windows/BrowsePage.xaml.cpp => vorg-windows/BrowsePage.xaml.cpp +8 -9
@@ 10,23 10,22 @@ using namespace Microsoft::UI::Xaml;

namespace winrt::vorg_windows::implementation
{
BrowsePage::BrowsePage() : mVideoData(single_threaded_observable_vector<Windows::Foundation::IInspectable>())
BrowsePage::BrowsePage()
{
    InitializeComponent();

    // Initialize app ptr
    mApp.copy_from(get_self<vorg_windows::implementation::App>(
        Application::Current().as<default_interface<vorg_windows::implementation::App>>()));

    // Populate video data
    mApp->PopulateVideoData(mVideoData);
}

Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> BrowsePage::VideoData() const
Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> BrowsePage::VideoData() const
{
    return mVideoData;
}

void BrowsePage::VideoData(
    const Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> &videoData)
{
    mVideoData = videoData;
}

fire_and_forget BrowsePage::Thumbnail_DoubleTapped(Windows::Foundation::IInspectable const &sender,
                                                   Microsoft::UI::Xaml::Input::DoubleTappedRoutedEventArgs const &)
{

M vorg-windows/BrowsePage.xaml.h => vorg-windows/BrowsePage.xaml.h +3 -2
@@ 10,11 10,12 @@ struct BrowsePage : BrowsePageT<BrowsePage>
{
    BrowsePage();

    Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> VideoData() const;
    Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> VideoData() const;
    void VideoData(
        const Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> &videoData);

  private:
    Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> mVideoData;
    com_ptr<vorg_windows::implementation::App> mApp{nullptr};

  public:
    fire_and_forget Thumbnail_DoubleTapped(Windows::Foundation::IInspectable const &sender,

M vorg-windows/ImportEditPage.idl => vorg-windows/ImportEditPage.idl +2 -0
@@ 26,6 26,8 @@ namespace vorg_windows
            set;
        };

        void ClearState();

        event Windows.Foundation.TypedEventHandler<ImportEditPage, Object> EditFinished;
    }
}

M vorg-windows/ImportEditPage.xaml.cpp => vorg-windows/ImportEditPage.xaml.cpp +15 -0
@@ 115,6 115,11 @@ void ImportEditPage::TagNameInput_KeyUp(Windows::Foundation::IInspectable const 
void ImportEditPage::SubmitButton_Click(const Windows::Foundation::IInspectable &,
                                        const Microsoft::UI::Xaml::RoutedEventArgs &)
{
    // Add currrent Actor and Tag
    AddToActors(ActorNameInput().Text());
    AddToTags(TagNameInput().Text());

    // Import the file
    mApp->ImportNext(TitleInput().Text(), StudioInput().Text(), mActors, mTags);
    mEditFinishedEvent(*this, nullptr);
}


@@ 131,6 136,16 @@ void ImportEditPage::EditFinished(const event_token &token)
    mEditFinishedEvent.remove(token);
}

void ImportEditPage::ClearState()
{
    TitleInput().Text(L"");
    StudioInput().Text(L"");
    ActorNameInput().Text(L"");
    TagNameInput().Text(L"");
    mActors.Clear();
    mTags.Clear();
}

void ImportEditPage::DeleteFromVector(Windows::Foundation::Collections::IObservableVector<hstring> &vector,
                                      const hstring &item)
{

M vorg-windows/ImportEditPage.xaml.h => vorg-windows/ImportEditPage.xaml.h +2 -0
@@ 44,6 44,8 @@ struct ImportEditPage : ImportEditPageT<ImportEditPage>
                                                                          Windows::Foundation::IInspectable> &handler);
    void EditFinished(const event_token &token);

    void ClearState();

  private:
    Windows::Foundation::Collections::IObservableVector<hstring> mActors;
    Windows::Foundation::Collections::IObservableVector<hstring> mTags;

M vorg-windows/ImportPage.idl => vorg-windows/ImportPage.idl +2 -0
@@ 3,5 3,7 @@ namespace vorg_windows
[default_interface] runtimeclass ImportPage : Microsoft.UI.Xaml.Controls.Page
{
    ImportPage();

    event Windows.Foundation.TypedEventHandler<ImportPage, Object> VideoImported;
}
} // namespace vorg_windows

M vorg-windows/ImportPage.xaml.cpp => vorg-windows/ImportPage.xaml.cpp +18 -2
@@ 54,13 54,19 @@ void ImportPage::ImportSelectionPage_SelectionFinished(const vorg_windows::Impor
void ImportPage::ImportEditPage_EditFinished(const vorg_windows::ImportEditPage &,
                                             const Windows::Foundation::IInspectable &)
{
    // Emit VideoImported
    mVideoImportedEvent(*this, nullptr);

    // Clear ImportEditPage state
    vorg_windows::ImportEditPage editPage = ContentFrame().Content().as<vorg_windows::ImportEditPage>();
    editPage.ClearState();

    // Check for next file
    hstring filePath = mApp->GetNextFile();
    if (filePath.empty())
    {
        // No more file
        // Remove EditFinished handler
        vorg_windows::ImportEditPage editPage = ContentFrame().Content().as<vorg_windows::ImportEditPage>();
        editPage.EditFinished(mEditFinishedToken);

        // Navigate to ImportSelectionPage


@@ 74,11 80,21 @@ void ImportPage::ImportEditPage_EditFinished(const vorg_windows::ImportEditPage 
    {
        // Continue editing next file
        hstring fileName = mApp->GetNextFileName();
        vorg_windows::ImportEditPage editPage = ContentFrame().Content().as<vorg_windows::ImportEditPage>();
        editPage.FileName(fileName);
        Windows::Media::Core::MediaSource mediaSouce =
            Windows::Media::Core::MediaSource::CreateFromUri(Windows::Foundation::Uri{filePath});
        editPage.MediaSource(mediaSouce);
    }
}

event_token ImportPage::VideoImported(
    const Windows::Foundation::TypedEventHandler<vorg_windows::ImportPage, Windows::Foundation::IInspectable> &handler)
{
    return mVideoImportedEvent.add(handler);
}

void ImportPage::VideoImported(const event_token &token)
{
    mVideoImportedEvent.remove(token);
}
} // namespace winrt::vorg_windows::implementation

M vorg-windows/ImportPage.xaml.h => vorg-windows/ImportPage.xaml.h +9 -0
@@ 15,7 15,16 @@ struct ImportPage : ImportPageT<ImportPage>

    void ImportEditPage_EditFinished(const vorg_windows::ImportEditPage &, const Windows::Foundation::IInspectable &);

    event_token VideoImported(const Windows::Foundation::TypedEventHandler<vorg_windows::ImportPage,
                                                                           Windows::Foundation::IInspectable> &handler);
    void VideoImported(const event_token &token);

  private:
    // Event
    event<Windows::Foundation::TypedEventHandler<vorg_windows::ImportPage, Windows::Foundation::IInspectable>>
        mVideoImportedEvent;

    // Members
    event_token mSelectionFinishedToken;
    event_token mEditFinishedToken;
    com_ptr<vorg_windows::implementation::App> mApp{nullptr};

M vorg-windows/MainWindow.xaml.cpp => vorg-windows/MainWindow.xaml.cpp +28 -4
@@ 16,10 16,14 @@ using namespace Microsoft::UI::Xaml;
namespace winrt::vorg_windows::implementation
{

MainWindow::MainWindow()
MainWindow::MainWindow() : mVideoData(single_threaded_observable_vector<Windows::Foundation::IInspectable>())
{
    InitializeComponent();

    // Initialize app ptr
    mApp.copy_from(get_self<vorg_windows::implementation::App>(
        Application::Current().as<default_interface<vorg_windows::implementation::App>>()));

    // Titlebar
    ExtendsContentIntoTitleBar(true);
    SetTitleBar(AppTitleBar());


@@ 29,9 33,16 @@ MainWindow::MainWindow()
    mNavigationTypeMap.emplace(L"Browse", xaml_typename<vorg_windows::BrowsePage>());
    mNavigationTypeMap.emplace(L"Manage", xaml_typename<vorg_windows::ManagePage>());

    mNavigationHeaderMap.emplace(L"Import", box_value(L"Import Video"));
    mNavigationHeaderMap.emplace(L"Browse", box_value(L"Browse Repository"));
    mNavigationHeaderMap.emplace(L"Manage", box_value(L"Manage Repository"));
    mExtraSetupMap.emplace(L"Import", [this]() {
        // Handle VideoImported
        vorg_windows::ImportPage importPage = ContentFrame().Content().as<vorg_windows::ImportPage>();
        importPage.VideoImported([this](auto &sender, auto &args) { ImportPage_VideoImported(sender, args); });
    });
    mExtraSetupMap.emplace(L"Browse", [this]() {
        // Set videoData
        vorg_windows::BrowsePage browsePage = ContentFrame().Content().as<vorg_windows::BrowsePage>();
        browsePage.VideoData(mVideoData);
    });

    // Navigate to LandingPage
    ContentFrame().Navigate(xaml_typename<vorg_windows::LandingPage>());


@@ 47,6 58,11 @@ void MainWindow::NavigationView_ItemInvoked(const Controls::NavigationView &,
{
    const hstring &tag = args.InvokedItemContainer().Tag().as<hstring>();
    ContentFrame().Navigate(mNavigationTypeMap.at(tag));
    auto setupFuncIt = mExtraSetupMap.find(tag);
    if (setupFuncIt != mExtraSetupMap.end())
    {
        setupFuncIt->second();
    }
}

void MainWindow::LandingPage_OpenRepo(const vorg_windows::LandingPage &, const Windows::Foundation::IInspectable &)


@@ 55,6 71,9 @@ void MainWindow::LandingPage_OpenRepo(const vorg_windows::LandingPage &, const W
    vorg_windows::LandingPage landingPage = ContentFrame().Content().as<vorg_windows::LandingPage>();
    landingPage.OpenRepo(mOpenRepoEventToken);

    // Populate video data
    mApp->PopulateVideoData(mVideoData);

    // Navigate to ImportPage
    ContentFrame().Navigate(mNavigationTypeMap.at(L"Import"));



@@ 67,4 86,9 @@ void MainWindow::LandingPage_OpenRepo(const vorg_windows::LandingPage &, const W
    // Select ImportPage
    ImportItem().IsSelected(true);
}

void MainWindow::ImportPage_VideoImported(const vorg_windows::ImportPage &, const Windows::Foundation::IInspectable &)
{
    mApp->PopulateVideoData(mVideoData);
}
} // namespace winrt::vorg_windows::implementation

M vorg-windows/MainWindow.xaml.h => vorg-windows/MainWindow.xaml.h +9 -1
@@ 4,6 4,7 @@

#include "LandingPage.xaml.h"

#include <functional>
#include <map>

namespace winrt::vorg_windows::implementation


@@ 17,10 18,17 @@ struct MainWindow : MainWindowT<MainWindow>

    void LandingPage_OpenRepo(const vorg_windows::LandingPage &, const Windows::Foundation::IInspectable &);

    void ImportPage_VideoImported(const vorg_windows::ImportPage &, const Windows::Foundation::IInspectable &);

  private:
    // Members
    event_token mOpenRepoEventToken;
    std::map<hstring, Windows::UI::Xaml::Interop::TypeName> mNavigationTypeMap;
    std::map<hstring, Windows::Foundation::IInspectable> mNavigationHeaderMap;
    std::map<hstring, std::function<void()>> mExtraSetupMap;
    Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> mVideoData;

    // App ptr
    com_ptr<vorg_windows::implementation::App> mApp{nullptr};
};
} // namespace winrt::vorg_windows::implementation