Commit 32f301f1 authored by Nicolas Jager's avatar Nicolas Jager

smartpannel : manage new contacts from ethereum

Change-Id: I49c6e9800a2d61f95d6d4dd8e06bc690ff0768ba
Tuleap: #790
parent c25f69d6
......@@ -85,7 +85,7 @@ ContactsViewModel::addNewContact(String^ name, String^ ringId)
{
auto trimmedName = Utils::Trim(name);
if (contactsList_ && !findContactByName(trimmedName)) {
Contact^ contact = ref new Contact(trimmedName, trimmedName, nullptr, 0);
Contact^ contact = ref new Contact(trimmedName, ringId, nullptr, 0);
contactsList_->Append(contact);
saveContactsToFile();
contactAdded(contact);
......
......@@ -675,16 +675,16 @@ RingD::registerCallbacks()
switch (status)
{
case 0: // everything went fine. Name/address pair was found.
registeredNameFound(LookupStatus::SUCCESS);
registeredNameFound(LookupStatus::SUCCESS, address, name);
break;
case 1: // provided name is not valid.
registeredNameFound(LookupStatus::INVALID_NAME);
registeredNameFound(LookupStatus::INVALID_NAME, address, name);
break;
case 2: // everything went fine. Name/address pair was not found.
registeredNameFound(LookupStatus::NOT_FOUND);
registeredNameFound(LookupStatus::NOT_FOUND, address, name);
break;
case 3: // An error happened
registeredNameFound(LookupStatus::ERRORR);
registeredNameFound(LookupStatus::ERRORR, address, name);
break;
}
}));
......
......@@ -38,7 +38,7 @@ delegate void ExportOnRingEnded(String^ accountId, String^ pin);
delegate void SummonWizard();
delegate void AccountUpdated(Account^ account);
delegate void IncomingVideoMuted(String^ callId, bool state);
delegate void RegisteredNameFound(LookupStatus status);
delegate void RegisteredNameFound(LookupStatus status, const std::string& address, const std::string& name);
delegate void FinishCaptureDeviceEnumeration();
using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
......
......@@ -223,7 +223,8 @@
<!-- template for smartpanelitems. -->
<DataTemplate x:Key="SmartPanelItemsTemplate"
x:DataType="controls:SmartPanelItem">
<Grid PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited" PointerMoved="Grid_PointerMoved">
<Grid PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited" PointerMoved="Grid_PointerMoved"
Visibility="{x:Bind _showMe, Mode=OneWay}">
<Grid.RowDefinitions>
<!-- row definition for the contact. -->
<RowDefinition Height="auto"/>
......@@ -1047,18 +1048,21 @@
<Grid.RowDefinitions>
<RowDefinition x:Name="_rowRingTxtBx_"
Height="40"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--Style="{StaticResource addContactTextBoxStyle}"-->
<TextBox x:Name="_ringTxtBx_"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="320"
TextWrapping="Wrap"
Style="{StaticResource addContactTextBoxStyle}"
KeyDown="_ringTxtBx__KeyDown"
KeyUp="_ringTxtBx__KeyUp"
Text=""/>
<ListBox x:Name="_smartList_"
Grid.Row="1"
Grid.Row="2"
Margin="0"
Padding="0"
SelectionChanged="_smartList__SelectionChanged"
......
......@@ -47,6 +47,7 @@ using namespace Platform::Collections;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Storage;
using namespace Windows::UI::Core;
using namespace Windows::System::Threading;
SmartPanel::SmartPanel()
{
......@@ -239,7 +240,7 @@ void RingClientUWP::Views::SmartPanel::_settingsMenu__Unchecked(Object^ sender,
auto vcm = Video::VideoManager::instance->captureManager();
if (vcm->deviceList->Size > 0) {
vcm->StopPreviewAsync()
.then([](task<void> stopPreviewTask)
.then([](task<void> stopPreviewTask)
{
try {
stopPreviewTask.get();
......@@ -416,15 +417,28 @@ void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sen
{
/* add contact, test purpose but will be reused later in some way */
if (e->Key == Windows::System::VirtualKey::Enter && !_ringTxtBx_->Text->IsEmpty()) {
ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
_ringTxtBx_->Text = "";
for (auto it : SmartPanelItemsViewModel::instance->itemsList) {
if (it->_contact->name_ == _ringTxtBx_->Text) {
_smartList_->SelectedItem = it;
_ringTxtBx_->Text = "";
return;
}
}
/* if the string has 40 chars, we simply consider it as a ring id. It has to be improved */
if (_ringTxtBx_->Text->Length() == 40) {
ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
_ringTxtBx_->Text = "";
}
RingD::instance->lookUpName(_ringTxtBx_->Text);
}
}
void RingClientUWP::Views::SmartPanel::_ringTxtBx__Click(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
_ringTxtBx_->Text = "";
RingD::instance->lookUpName(_ringTxtBx_->Text);
}
void
......@@ -703,6 +717,22 @@ void RingClientUWP::Views::SmartPanel::checkStateEditionMenu()
}
}
void RingClientUWP::Views::SmartPanel::ringTxtBxPlaceHolderDelay(String^ placeHolderText, int delayInMilliSeconds)
{
_ringTxtBx_->PlaceholderText = placeHolderText;
TimeSpan delay;
delay.Duration = 10000 * delayInMilliSeconds;
ThreadPoolTimer^ delayTimer = ThreadPoolTimer::CreateTimer(
ref new TimerElapsedHandler([this](ThreadPoolTimer^ source)
{
Dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler([this]()
{
_ringTxtBx_->PlaceholderText = "";
}));
}), delay);
}
Object ^ RingClientUWP::Views::IncomingVisibility::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
auto state = static_cast<CallStatus>(value);
......@@ -1171,38 +1201,72 @@ void RingClientUWP::Views::SmartPanel::_usernameTextBoxEdition__KeyUp(Platform::
}
void RingClientUWP::Views::SmartPanel::OnregisteredNameFound(RingClientUWP::LookupStatus status)
void RingClientUWP::Views::SmartPanel::OnregisteredNameFound(RingClientUWP::LookupStatus status, const std::string& address, const std::string& name)
{
switch (status)
if (_ringTxtBx_->Text->IsEmpty()) // if true, we consider we did the lookup for a new account
switch (status)
{
case LookupStatus::SUCCESS:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
//_registerOnBlockchainEdition_->IsEnabled = false;
break;
case LookupStatus::INVALID_NAME:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
//_registerOnBlockchainEdition_->IsEnabled = false;
break;
case LookupStatus::NOT_FOUND:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
//_registerOnBlockchainEdition_->IsEnabled = true;
break;
case LookupStatus::ERRORR:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
//_registerOnBlockchainEdition_->IsEnabled = false;
break;
}
else // if false, we consider we are looking for a registered user
{
case LookupStatus::SUCCESS:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
//_registerOnBlockchainEdition_->IsEnabled = false;
break;
case LookupStatus::INVALID_NAME:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
//_registerOnBlockchainEdition_->IsEnabled = false;
break;
case LookupStatus::NOT_FOUND:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
//_registerOnBlockchainEdition_->IsEnabled = true;
break;
case LookupStatus::ERRORR:
_usernameValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
//_registerOnBlockchainEdition_->IsEnabled = false;
break;
switch (status) {
case LookupStatus::SUCCESS:
ContactsViewModel::instance->addNewContact(Utils::toPlatformString(name), Utils::toPlatformString(address));
ringTxtBxPlaceHolderDelay("username found and added.", 1500);
break;
case LookupStatus::INVALID_NAME:
ringTxtBxPlaceHolderDelay("username invalid.", 1500);
break;
case LookupStatus::NOT_FOUND:
{
ringTxtBxPlaceHolderDelay("username not found.", 1500);
break;
}
case LookupStatus::ERRORR:
ringTxtBxPlaceHolderDelay("network error!", 1500);
break;
}
_ringTxtBx_->Text = "";
for (auto it : SmartPanelItemsViewModel::instance->itemsList) {
if (it->_contact->ringID_ == Utils::toPlatformString(address)) {
_smartList_->SelectedItem = it;
return;
}
}
_smartList_->SelectedItem = nullptr;
}
checkStateAddAccountMenu();
......@@ -1352,7 +1416,7 @@ SmartPanel::_videoRateComboBox__SelectionChanged(Platform::Object^ sender, Windo
vcm->activeDevice->currentResolution()->setActiveRate( resolution->rateList()->GetAt(index) );
if (vcm->isPreviewing) {
vcm->CleanupCameraAsync()
.then([=](task<void> cleanupCameraTask) {
.then([=](task<void> cleanupCameraTask) {
try {
cleanupCameraTask.get();
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
......@@ -1439,4 +1503,29 @@ SmartPanel::populateVideoRateSettingsComboBox()
}
if (!rateSelected && resolution->rateList()->Size > 0)
_videoRateComboBox_->SelectedIndex = 0;
}
}
void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyUp(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
if (e->Key == Windows::System::VirtualKey::Enter ) {
RingD::instance->lookUpName(_ringTxtBx_->Text);
for (auto it : SmartPanelItemsViewModel::instance->itemsList) {
it->_showMe = Windows::UI::Xaml::Visibility::Visible;
}
return;
}
for (auto it : SmartPanelItemsViewModel::instance->itemsList) {
auto str1 = Utils::toString(it->_contact->name_);
auto str2 = Utils::toString(_ringTxtBx_->Text);
if (str1.find(str2) != std::string::npos)
it->_showMe = Windows::UI::Xaml::Visibility::Visible;
else
it->_showMe = Windows::UI::Xaml::Visibility::Collapsed;
}
}
......@@ -128,6 +128,7 @@ private:
void populateVideoRateSettingsComboBox();
void checkStateAddAccountMenu();
void checkStateEditionMenu();
void ringTxtBxPlaceHolderDelay(String^ placeHolderText, int delayInMilliSeconds);
/* members */
void _devicesMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
......@@ -154,11 +155,12 @@ private:
void Grid_PointerMoved(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);
void _registerOnBlockchainEdition__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _usernameTextBoxEdition__KeyUp(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
void OnregisteredNameFound(RingClientUWP::LookupStatus status);
void OnregisteredNameFound(RingClientUWP::LookupStatus status, const std::string& address, const std::string& name);
void _RegisterState__Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _usernameTextBox__KeyUp(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
void _deleteAccountEdition__Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _RegisterStateEdition__Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _ringTxtBx__KeyUp(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
};
}
}
......@@ -83,11 +83,25 @@ public:
}
}
property Visibility _showMe
{
Visibility get()
{
return showMe_;
}
void set(Visibility value)
{
showMe_ = value;
NotifyPropertyChanged("_showMe");
}
}
protected:
void NotifyPropertyChanged(String^ propertyName);
private:
Visibility hovered_ = Visibility::Collapsed;
Visibility showMe_ = Visibility::Visible;
CallStatus callStatus_;
String^ callId_;
bool videoMuted_;
......
......@@ -266,7 +266,7 @@ void RingClientUWP::Views::Wizard::_step2button__Click(Platform::Object^ sender,
_addAccountYes_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
void RingClientUWP::Views::Wizard::OnregisteredNameFound(LookupStatus status)
void RingClientUWP::Views::Wizard::OnregisteredNameFound(LookupStatus status, const std::string& address, const std::string& name)
{
switch (status)
{
......
......@@ -27,7 +27,7 @@ private:
void collapseMenus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _step1button__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _step2button__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnregisteredNameFound(LookupStatus status);
void OnregisteredNameFound(LookupStatus status, const std::string& address, const std::string& name);
void _password__PasswordChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _passwordCheck__PasswordChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void checkState();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment