Skip to content

Commit

Permalink
Add progressing ring when downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Aug 4, 2015
1 parent a1655ba commit e869695
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 34 deletions.
13 changes: 13 additions & 0 deletions Converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ Object^ IsoImageConverter::ConvertBack(Object^ value, TypeName targetType, Objec
}


Object^ VisibilityConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
bool visible = (bool)value;
if (visible)
return Windows::UI::Xaml::Visibility::Visible;
else
return Windows::UI::Xaml::Visibility::Collapsed;
}

Object^ VisibilityConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
return nullptr;
}
9 changes: 9 additions & 0 deletions Converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@ namespace VBA10
task<void> LoadImageFromPath(BitmapImage^ bitmap, String^ filepath);
};

[Windows::Foundation::Metadata::WebHostHidden]
public ref class VisibilityConverter sealed : Windows::UI::Xaml::Data::IValueConverter
{
public:
virtual Object^ Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language);
virtual Object^ ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language);

};


}
11 changes: 11 additions & 0 deletions Definitions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Definitions.h"

using namespace VBA10;
using namespace Windows::UI::Xaml::Data;

void OneDriveFileItem::OnPropertyChanged(Platform::String^ propertyName)
{
PropertyChangedEventArgs^ args =
ref new PropertyChangedEventArgs(propertyName);
PropertyChanged(this, args);
}
24 changes: 22 additions & 2 deletions Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,38 @@ namespace VBA10


[Windows::UI::Xaml::Data::BindableAttribute]
public ref class OneDriveFileItem sealed
public ref class OneDriveFileItem sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
{
public:

property Platform::String^ Name;
property OneDriveItemType Type;
property bool Downloading;
property bool Downloading
{
bool get()
{
return _downloading;
}
void set(bool value)
{
_downloading = value;

OnPropertyChanged("Downloading");
}
}
//public Stream Stream{ get; set; } //the Stream corresponding to this item
property Platform::String^ OneDriveID;
property Platform::String^ ParentID;
property Platform::String^ OneDriveLink;
property int FolderChildrenCount;

virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;
protected:
void OnPropertyChanged(Platform::String^ propertyName);

private:
bool _downloading;

};

}
25 changes: 18 additions & 7 deletions FileBrowserPane.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl
<Page
x:Class="VBA10.FileBrowserPane"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -10,7 +10,6 @@
d:DesignWidth="400">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
BorderThickness="2,0,2,2" BorderBrush="{ThemeResource ListBoxBorderThemeBrush}"
>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand All @@ -20,6 +19,7 @@

<Grid.Resources>
<CollectionViewSource x:Name="FileListvs"/>
<local:VisibilityConverter x:Key="VisibilityConverter" />
</Grid.Resources>


Expand All @@ -29,7 +29,7 @@
<AppBarButton Icon="Back" Label="Back" x:Name="backBtn"
IsTabStop="False"
IsCompact="True"
Width="36"
Width="44"
Click="backBtn_Click"
IsEnabled="False"/>
<TextBlock Text="Root"
Expand All @@ -53,16 +53,27 @@
>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="7"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
<Setter Property="Padding" Value="12"/>
<!--<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>-->
</Style>
</ListBox.ItemContainerStyle>

<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock Text="{Binding Name}"
FontSize="18"/>
FontSize="18" Grid.Column="0"/>

<ProgressRing IsActive="True"
Grid.Column="1"
Margin="8,0,0,0"
Visibility="{Binding Downloading, Converter={StaticResource VisibilityConverter}}"/>

</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
Expand All @@ -75,4 +86,4 @@
x:Name="closeBtn"
Click="closeBtn_Click"/>
</Grid>
</UserControl>
</Page>
30 changes: 22 additions & 8 deletions FileBrowserPane.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ FileBrowserPane::FileBrowserPane()

//create the root item
OneDriveFileItem^ root = ref new OneDriveFileItem();
root->Name = "Root";
root->Name = "OneDrive";
root->OneDriveID = "me/skydrive";
root->Type = OneDriveItemType::Folder;
root->ParentID = "";
Expand Down Expand Up @@ -138,6 +138,7 @@ void FileBrowserPane::client_GetCompleted(web::json::value v)

void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{

if (this->loading)
return;

Expand Down Expand Up @@ -181,8 +182,9 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window
}
else if (item->Type == OneDriveItemType::ROM)
{
item->Downloading = true;
//download file
DownloadFile(item).then([this](size_t size)
DownloadFile(item).then([this, item](size_t size)
{
//update rom dabatase
//calculate snapshot name
Expand Down Expand Up @@ -211,10 +213,10 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window
StorageFolder ^installDir = Windows::ApplicationModel::Package::Current->InstalledLocation;
return installDir->GetFolderAsync("Assets/");

}).then([entry](StorageFolder^ assetFolder)
}).then([entry, item](StorageFolder^ assetFolder)
{
return assetFolder->GetFileAsync("no_snapshot.png");
}).then([entry](StorageFile ^file)
}).then([entry, item](StorageFile ^file)
{
//copy snapshot file to would be location
return file->CopyAsync(entry->Folder, entry->SnapshotUri, NameCollisionOption::ReplaceExisting);
Expand All @@ -223,19 +225,20 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window
{
//open file
return file->OpenAsync(FileAccessMode::Read);
}).then([entry](IRandomAccessStream^ stream)
}).then([entry, item](IRandomAccessStream^ stream)
{
//load bitmap image for snapshot
entry->Snapshot = ref new BitmapImage();
return entry->Snapshot->SetSourceAsync(stream);


}).then([](task<void> t)
}).then([item](task<void> t)
{
try
{
t.get();
// .get() didn't throw, so we succeeded, print out success message
item->Downloading = false;
MessageDialog ^dialog = ref new MessageDialog("File imported successfully.");
dialog->ShowAsync();
}
Expand All @@ -247,6 +250,11 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window


}
else
{
MessageDialog ^dialog = ref new MessageDialog("This file type is not supported.");
dialog->ShowAsync();
}

}

Expand All @@ -266,14 +274,20 @@ task<size_t> FileBrowserPane::DownloadFile(OneDriveFileItem^ item)
catch (COMException^ e)
{
// We'll handle the specific errors below.
size_t length = 0;
return length;
}

});
}


void FileBrowserPane::closeBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
(safe_cast<Popup ^>(this->Parent))->IsOpen = false;
if (Frame->CanGoBack)
{
Frame->GoBack();
}
}

OneDriveItemType FileBrowserPane::GetOneDriveItemType(wstring ext)
Expand Down Expand Up @@ -329,7 +343,7 @@ void FileBrowserPane::backBtn_Click(Platform::Object^ sender, Windows::UI::Xaml:

if (this->onedriveStack->Size == 2) //special case
{
parentName = "Root";
parentName = this->onedriveStack->GetAt(0)->GetAt(0)->Name;
this->backBtn->IsEnabled = false;
}
else
Expand Down
37 changes: 21 additions & 16 deletions ImportPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,31 @@ void ImportPage::signin_Completed(bool isLoggedIn)

void ImportPage::importOneDriveROMbtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
//open panel to let user select file
Popup ^statePopup = ref new Popup();
statePopup->IsLightDismissEnabled = true;
Frame->Navigate(
TypeName(FileBrowserPane::typeid),
nullptr,
ref new Windows::UI::Xaml::Media::Animation::DrillInNavigationTransitionInfo());

FileBrowserPane ^pane = ref new FileBrowserPane();
statePopup->Child = pane;
pane->Width = titleBar->ActualWidth;//statePopup->Width;
pane->Height = Window::Current->Bounds.Height - 48; //statePopup->MaxHeight;
////open panel to let user select file
//Popup ^statePopup = ref new Popup();
//statePopup->IsLightDismissEnabled = false;

//pane->FileSelectedCallback = ref new FileSelectedDelegate([=](StorageFile ^file)
//{
//FileBrowserPane ^pane = ref new FileBrowserPane();
//statePopup->Child = pane;
//pane->Width = titleBar->ActualWidth;//statePopup->Width;
//pane->Height = Window::Current->Bounds.Height - 48; //statePopup->MaxHeight;

//});
////pane->FileSelectedCallback = ref new FileSelectedDelegate([=](StorageFile ^file)
////{

//auto transform = ((UIElement^)sender)->TransformToVisual(nullptr); //nullptr to get position related to windows
auto transform = ((UIElement^)titleBar)->TransformToVisual(nullptr);
////});

Windows::Foundation::Point point = transform->TransformPoint(Windows::Foundation::Point());
statePopup->HorizontalOffset = point.X + 1; //+ selectStateBtn->ActualWidth / 2.0f - pane->Width / 2.0f;
statePopup->VerticalOffset = point.Y + titleBar->ActualHeight;
////auto transform = ((UIElement^)sender)->TransformToVisual(nullptr); //nullptr to get position related to windows
//auto transform = ((UIElement^)titleBar)->TransformToVisual(nullptr);

statePopup->IsOpen = true;
//Windows::Foundation::Point point = transform->TransformPoint(Windows::Foundation::Point());
//statePopup->HorizontalOffset = point.X + 1; //+ selectStateBtn->ActualWidth / 2.0f - pane->Width / 2.0f;
//statePopup->VerticalOffset = point.Y + titleBar->ActualHeight;

//statePopup->IsOpen = true;
}
20 changes: 19 additions & 1 deletion VBA10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<AdditionalOptions>/bigobj /Zm130</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions);METRO_APP;__WIN32__;C_CORE;NO_ASM;NO_OGL;NO_OAL;NO_LINK;NO_PNG;_CRT_SECURE_NO_WARNINGS;DNO_DEFLATE;FINAL_VERSION;NO_DEFLATE;TILED_RENDERING</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
Expand All @@ -179,6 +180,7 @@
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);METRO_APP;__WIN32__;C_CORE;NO_ASM;NO_OGL;NO_OAL;NO_LINK;NO_PNG;_CRT_SECURE_NO_WARNINGS;DNO_DEFLATE;FINAL_VERSION;NO_DEFLATE;TILED_RENDERING</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down Expand Up @@ -209,6 +211,7 @@
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);METRO_APP;__WIN32__;C_CORE;NO_ASM;NO_OGL;NO_OAL;NO_LINK;NO_PNG;_CRT_SECURE_NO_WARNINGS;DNO_DEFLATE;FINAL_VERSION;NO_DEFLATE</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -223,6 +226,7 @@
<AdditionalOptions>/bigobj /Zm130</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions);METRO_APP;__WIN32__;C_CORE;NO_ASM;NO_OGL;NO_OAL;NO_LINK;NO_PNG;NO_XBOX;_CRT_SECURE_NO_WARNINGS;DNO_DEFLATE;FINAL_VERSION;NO_DEFLATE;TILED_RENDERING</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -237,6 +241,7 @@
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);METRO_APP;__WIN32__;C_CORE;NO_ASM;NO_OGL;NO_OAL;NO_LINK;NO_PNG;_CRT_SECURE_NO_WARNINGS;DNO_DEFLATE;FINAL_VERSION;NO_DEFLATE;TILED_RENDERING</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down Expand Up @@ -500,6 +505,14 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Definitions.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ExportPage.xaml.cpp">
<DependentUpon>ExportPage.xaml</DependentUpon>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
Expand Down Expand Up @@ -606,7 +619,12 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Converter.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="KeyboardInput.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
Expand Down
1 change: 1 addition & 0 deletions VBA10.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
<ClCompile Include="PurchasePage.xaml.cpp" />
<ClCompile Include="AdControl.xaml.cpp" />
<ClCompile Include="stringhelper.cpp" />
<ClCompile Include="Definitions.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="App.xaml.h" />
Expand Down

0 comments on commit e869695

Please sign in to comment.