Skip to content
Snippets Groups Projects
Commit 2425ddd0 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Andreas Traczyk
Browse files

profile: allow user to use an avatar when creating first account

- adds camera capture UI to wizard.
- stores avatar image to disk and logs a reference in the user's preferences.
- loads avatar from disk when loading preferences at application start.
- removes avatar icons from account list.
- removes camera capture UI from add accounts widget

Change-Id: Id3467a7214c2f52ec70690df360ce9e3a0cb2df2
Tuleap: #989
parent b77f7c78
No related branches found
No related tags found
No related merge requests found
...@@ -110,38 +110,32 @@ ...@@ -110,38 +110,32 @@
x:DataType="local:Account"> x:DataType="local:Account">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/> <ColumnDefinition Width="260"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="60"/> <ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Image x:Name="_accountAvatar_"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="0"
Grid.RowSpan="2"
Width="55"
Height="55"
Source="Assets\TESTS\contactAvatar.png"/>
<TextBlock x:Name="_accountName_" <TextBlock x:Name="_accountName_"
Grid.Column="1" Grid.Column="0"
Grid.Row="0" Grid.Row="0"
Margin="10,5,10,0"
Text="{x:Bind name_}"/> Text="{x:Bind name_}"/>
<TextBlock x:Name="_accountType_" <TextBlock x:Name="_accountType_"
Grid.Column="2" Grid.Column="1"
Grid.Row="0" Grid.Row="0"
TextAlignment="Right" TextAlignment="Right"
Margin="0,0,10,0" Margin="0,5,10,0"
Foreground="ForestGreen" Foreground="ForestGreen"
Text="{x:Bind accountType_}"/> Text="{x:Bind accountType_}"/>
<TextBlock x:Name="_ringID_" <TextBlock x:Name="_ringID_"
Grid.Column="1" Grid.Column="0"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="1" Grid.Row="1"
Foreground="Crimson" Foreground="Crimson"
Margin="10,5,10,0"
FontSize="14"
TextTrimming="CharacterEllipsis" TextTrimming="CharacterEllipsis"
Text="{x:Bind ringID_}"/> Text="{x:Bind ringID_}"/>
</Grid> </Grid>
...@@ -172,12 +166,18 @@ ...@@ -172,12 +166,18 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/> <ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Image x:Name="_selectedAccountAvatar_" <Ellipse
Source="Assets\TESTS\contactAvatar.png" x:Name="_selectedAccountAvatarContainer_"
Height="80"
Width="80" Width="80"
Margin="5"
Grid.Column="0" Grid.Column="0"
Height="80"/> Margin="5">
<Ellipse.Fill>
<ImageBrush
x:Name="_selectedAccountAvatar_"
ImageSource="Assets\TESTS\contactAvatar.png"/>
</Ellipse.Fill>
</Ellipse>
<StackPanel Grid.Column="1" <StackPanel Grid.Column="1"
VerticalAlignment="Bottom"> VerticalAlignment="Bottom">
<TextBlock x:Name="_selectedAccountName_" <TextBlock x:Name="_selectedAccountName_"
...@@ -263,12 +263,6 @@ ...@@ -263,12 +263,6 @@
<ComboBoxItem Content="Sip"/> <ComboBoxItem Content="Sip"/>
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>
<Button x:Name="_avatarWebcamCaptureBtn_"
VerticalAlignment="Center"
Content="&#xE8B8;"
Style="{StaticResource ButtonStyle3}"
Click="_avatarWebcamCaptureBtn__Click"
HorizontalAlignment="Center"/>
<!-- RING account. --> <!-- RING account. -->
<StackPanel x:Name="_ringAccountCreationStack_" <StackPanel x:Name="_ringAccountCreationStack_"
Visibility="Visible"> Visibility="Visible">
......
...@@ -38,9 +38,16 @@ SmartPanel::SmartPanel() ...@@ -38,9 +38,16 @@ SmartPanel::SmartPanel()
{ {
InitializeComponent(); InitializeComponent();
/* connect delegates */
Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) { Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {
_accountsList_->SelectedIndex = index; _accountsList_->SelectedIndex = index;
}); });
Configuration::UserPreferences::instance->loadProfileImage += ref new LoadProfileImage([this]() {
StorageFolder^ localfolder = ApplicationData::Current->LocalFolder;
String^ image_path = localfolder->Path + "\\.profile\\profile_image.png";
auto uri = ref new Windows::Foundation::Uri(image_path);
_selectedAccountAvatar_->ImageSource = ref new BitmapImage(uri);
});
_accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;
_smartList_->ItemsSource = ContactsViewModel::instance->contactsList; _smartList_->ItemsSource = ContactsViewModel::instance->contactsList;
...@@ -87,18 +94,18 @@ void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel: ...@@ -87,18 +94,18 @@ void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel:
{ {
if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) {
_rowRingTxtBx_->Height = 40; _rowRingTxtBx_->Height = 40;
_selectedAccountAvatar_->Height = 80; _selectedAccountAvatarContainer_->Height = 80;
_selectedAccountAvatarColumn_->Width = 90; _selectedAccountAvatarColumn_->Width = 90;
_selectedAccountRow_->Height = 90; _selectedAccountRow_->Height = 90;
} }
else { else {
_rowRingTxtBx_->Height = 0; _rowRingTxtBx_->Height = 0;
_selectedAccountAvatar_->Height = 50; _selectedAccountAvatarContainer_->Height = 50;
_selectedAccountAvatarColumn_->Width = 60; _selectedAccountAvatarColumn_->Width = 60;
_selectedAccountRow_->Height = 60; _selectedAccountRow_->Height = 60;
} }
_selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; _selectedAccountAvatarContainer_->Width = _selectedAccountAvatarContainer_->Height;
_settingsTBtn_->IsChecked = false; _settingsTBtn_->IsChecked = false;
_accountsMenuButton_->IsChecked = false; _accountsMenuButton_->IsChecked = false;
_shareMenuButton_->IsChecked = false; _shareMenuButton_->IsChecked = false;
...@@ -134,37 +141,6 @@ void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ ...@@ -134,37 +141,6 @@ void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^
} }
void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI();
cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png;
cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100);
create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo)
{
if (photo != nullptr) {
// maybe it would be possible to move some logics to the style sheet
auto brush = ref new ImageBrush();
auto circle = ref new Ellipse();
circle->Height = 80; // TODO : use some global constant when ready
circle->Width = 80;
auto path = photo->Path;
auto uri = ref new Windows::Foundation::Uri(path);
auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
bitmapImage->UriSource = uri;
brush->ImageSource = bitmapImage;
circle->Fill = brush;
_avatarWebcamCaptureBtn_->Content = circle;
}
});
}
void void
SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{ {
......
...@@ -50,7 +50,6 @@ private: ...@@ -50,7 +50,6 @@ private:
void _addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void _smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void _accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void _accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
......
...@@ -71,6 +71,8 @@ UserPreferences::load() ...@@ -71,6 +71,8 @@ UserPreferences::load()
Destringify(fileContents); Destringify(fileContents);
// select account index after loading preferences // select account index after loading preferences
selectIndex(PREF_ACCOUNT_INDEX); selectIndex(PREF_ACCOUNT_INDEX);
if (PREF_PROFILE_PHOTO)
loadProfileImage();
} }
}); });
}); });
...@@ -89,7 +91,10 @@ String^ ...@@ -89,7 +91,10 @@ String^
UserPreferences::Stringify() UserPreferences::Stringify()
{ {
JsonObject^ preferencesObject = ref new JsonObject(); JsonObject^ preferencesObject = ref new JsonObject();
preferencesObject->SetNamedValue("PREF_ACCOUNT_INDEX", JsonValue::CreateNumberValue( PREF_ACCOUNT_INDEX)); preferencesObject->SetNamedValue("PREF_ACCOUNT_INDEX", JsonValue::CreateNumberValue( PREF_ACCOUNT_INDEX));
preferencesObject->SetNamedValue("PREF_PROFILE_PHOTO", JsonValue::CreateBooleanValue( PREF_PROFILE_PHOTO));
return preferencesObject->Stringify(); return preferencesObject->Stringify();
} }
...@@ -97,6 +102,9 @@ void ...@@ -97,6 +102,9 @@ void
UserPreferences::Destringify(String^ data) UserPreferences::Destringify(String^ data)
{ {
JsonObject^ jsonObject = JsonObject::Parse(data); JsonObject^ jsonObject = JsonObject::Parse(data);
PREF_ACCOUNT_INDEX = static_cast<int>(jsonObject->GetNamedNumber( "PREF_ACCOUNT_INDEX" )); PREF_ACCOUNT_INDEX = static_cast<int>(jsonObject->GetNamedNumber( "PREF_ACCOUNT_INDEX" ));
PREF_PROFILE_PHOTO = jsonObject->GetNamedBoolean( "PREF_PROFILE_PHOTO" );
JsonArray^ preferencesList = jsonObject->GetNamedArray("Account.index", ref new JsonArray()); JsonArray^ preferencesList = jsonObject->GetNamedArray("Account.index", ref new JsonArray());
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ namespace RingClientUWP ...@@ -23,6 +23,7 @@ namespace RingClientUWP
{ {
delegate void SelectIndex(int index); delegate void SelectIndex(int index);
delegate void LoadProfileImage();
namespace Configuration namespace Configuration
{ {
...@@ -44,6 +45,7 @@ public: ...@@ -44,6 +45,7 @@ public:
/* properties */ /* properties */
property int PREF_ACCOUNT_INDEX; property int PREF_ACCOUNT_INDEX;
property bool PREF_PROFILE_PHOTO;
/* functions */ /* functions */
void save(); void save();
...@@ -55,9 +57,9 @@ internal: ...@@ -55,9 +57,9 @@ internal:
/* events */ /* events */
event SelectIndex^ selectIndex; event SelectIndex^ selectIndex;
event LoadProfileImage^ loadProfileImage;
private: private:
UserPreferences() { }; UserPreferences() { PREF_PROFILE_PHOTO = false; };
}; };
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
Margin="0,10,0,0" Margin="0,10,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
Content="&#xE8B8;" Content="&#xE8B8;"
Click="_avatarWebcamCaptureBtn__Click"
Style="{StaticResource ButtonStyle3}" Style="{StaticResource ButtonStyle3}"
HorizontalAlignment="Center"/> HorizontalAlignment="Center"/>
<!-- RING account. --> <!-- RING account. -->
......
...@@ -19,6 +19,9 @@ using namespace Windows::UI::Xaml::Input; ...@@ -19,6 +19,9 @@ using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation; using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::Media::Capture; using namespace Windows::Media::Capture;
using namespace Windows::Storage;
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Xaml::Shapes;
Wizard::Wizard() Wizard::Wizard()
{ {
...@@ -63,3 +66,52 @@ Wizard::_showAddAccountMenuBtn__Click(Object^ sender, RoutedEventArgs^ e) ...@@ -63,3 +66,52 @@ Wizard::_showAddAccountMenuBtn__Click(Object^ sender, RoutedEventArgs^ e)
_showAddAccountMenuTitle_->Visibility = Windows::UI::Xaml::Visibility::Visible; _showAddAccountMenuTitle_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_showAddAccountMenuBtn_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _showAddAccountMenuBtn_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
} }
void
Wizard::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI();
cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png;
cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100);
create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo))
.then([this](StorageFile^ photoFile)
{
if (photoFile != nullptr) {
// maybe it would be possible to move some logics to the style sheet
auto brush = ref new ImageBrush();
auto circle = ref new Ellipse();
circle->Height = 80; // TODO : use some global constant when ready
circle->Width = 80;
auto path = photoFile->Path;
auto uri = ref new Windows::Foundation::Uri(path);
auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
bitmapImage->UriSource = uri;
StorageFolder^ localfolder = ApplicationData::Current->LocalFolder;
String^ profilefolder = ".profile";
create_task(localfolder->CreateFolderAsync(profilefolder,
Windows::Storage::CreationCollisionOption::OpenIfExists))
.then([=](StorageFolder^ copytofolder){
try {
create_task(photoFile->CopyAsync(copytofolder))
.then([=](StorageFile^ copiedfile){
copiedfile->RenameAsync("profile_image.png",
Windows::Storage::NameCollisionOption::ReplaceExisting);
});
}
catch (Exception^ e) {
RingDebug::instance->print("Exception while saving profile image");
}
});
Configuration::UserPreferences::instance->PREF_PROFILE_PHOTO = true;
brush->ImageSource = bitmapImage;
circle->Fill = brush;
_avatarWebcamCaptureBtn_->Content = circle;
}
});
}
\ No newline at end of file
...@@ -15,6 +15,7 @@ private: ...@@ -15,6 +15,7 @@ private:
void _createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _showCreateAccountMenuBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _showCreateAccountMenuBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _showAddAccountMenuBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _showAddAccountMenuBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment