From 4a8cffc6578fe6bc6b5535cb26e987e4dd6a00c3 Mon Sep 17 00:00:00 2001
From: atraczyk <andreastraczyk@gmail.com>
Date: Thu, 25 Aug 2016 20:01:25 -0400
Subject: [PATCH] account: change account name title upon account selection

- changes smart panel account title when an account has
  been selected from the account list

Change-Id: I94172f8e991d783ef3460b11c9cfea9e83038e6d
Tuleap: #964
---
 AccountsViewModel.h | 25 +++++++++++++++++++++++++
 RingD.cpp           |  6 ++++--
 SmartPanel.xaml     |  4 +++-
 SmartPanel.xaml.cpp | 21 ++++++++++++++++++++-
 SmartPanel.xaml.h   |  2 ++
 5 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/AccountsViewModel.h b/AccountsViewModel.h
index b9c8d64..0aa5977 100644
--- a/AccountsViewModel.h
+++ b/AccountsViewModel.h
@@ -24,6 +24,9 @@ using namespace Platform::Collections;
 namespace RingClientUWP
 {
 
+delegate void NewAccountSelected();
+delegate void NoAccountSelected();
+
 namespace ViewModel {
 public ref class AccountsViewModel sealed
 {
@@ -43,6 +46,23 @@ internal:
     void clearAccountList();
 
     /* properties */
+    property Account^ selectedAccount
+    {
+        Account^ get()
+        {
+            return currentItem_;
+        }
+        void set(Account^ value)
+        {
+            oldItem_ = currentItem_;
+            currentItem_ = value;
+            if (value)
+                newAccountSelected();
+            else
+                noAccountSelected();
+        }
+    }
+
     property Vector<Account^>^ accountsList
     {
         Vector<Account^>^ get()
@@ -52,10 +72,15 @@ internal:
     }
 
     /* events */
+    event NewAccountSelected^ newAccountSelected;
+    event NoAccountSelected^ noAccountSelected;
 
 private:
     AccountsViewModel(); // singleton
     Vector<Account^>^ accountsList_;
+    Account^ currentItem_;
+    Account^ oldItem_;
+
 };
 }
 }
diff --git a/RingD.cpp b/RingD.cpp
index 2d4ef73..922b6d1 100644
--- a/RingD.cpp
+++ b/RingD.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 * Copyright (C) 2016 by Savoir-faire Linux                                *
-* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com>              *
+* Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
 * Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com>          *
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
@@ -27,6 +27,8 @@
 
 #include "account_schema.h"
 
+#include "SmartPanel.xaml.h"
+
 using namespace Windows::ApplicationModel::Core;
 using namespace Windows::Storage;
 using namespace Windows::UI::Core;
@@ -184,4 +186,4 @@ RingD::dequeueTasks()
         }
         tasksList_.pop();
     }
-}
\ No newline at end of file
+}
diff --git a/SmartPanel.xaml b/SmartPanel.xaml
index 41d32d9..0be5085 100644
--- a/SmartPanel.xaml
+++ b/SmartPanel.xaml
@@ -181,7 +181,8 @@
                        Height="80"/>
                 <StackPanel Grid.Column="1"
                             VerticalAlignment="Bottom">
-                    <TextBlock Text="TOT fdsfds fdsO"
+                    <TextBlock x:Name="_selectedAccountName_"
+                               Text="default name"
                                Margin="10"
                                Style="{StaticResource TextStyle2}"/>
                     <StackPanel Orientation="Horizontal">
@@ -224,6 +225,7 @@
                 </Grid.RowDefinitions>
                 <ListBox x:Name="_accountsList_"
                          Grid.Row="0"
+                         SelectionChanged="_accountList__SelectionChanged"
                          ScrollViewer.HorizontalScrollBarVisibility="Auto"
                          ScrollViewer.HorizontalScrollMode="Enabled"
                          Width="320"
diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp
index 99731d9..b773477 100644
--- a/SmartPanel.xaml.cpp
+++ b/SmartPanel.xaml.cpp
@@ -41,6 +41,16 @@ SmartPanel::SmartPanel()
     _smartList_->ItemsSource = ContactsViewModel::instance->contactsList;
 }
 
+void
+RingClientUWP::Views::SmartPanel::updatePageContent()
+{
+    auto account = AccountsViewModel::instance->selectedAccount;
+    if (!account)
+        return;
+
+    _selectedAccountName_->Text = account->name_;
+}
+
 void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
 {
     _shareMenuButton_->IsChecked = false;
@@ -151,6 +161,15 @@ SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::
     ContactsViewModel::instance->selectedContact = contact;
 }
 
+void
+SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
+{
+    auto listbox = safe_cast<ListBox^>(sender);
+    auto account = safe_cast<Account^>(listbox->SelectedItem);
+    AccountsViewModel::instance->selectedAccount = account;
+    updatePageContent();
+}
+
 void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
 {
     /* add contact, test purpose but will be reused later in some way */
@@ -158,4 +177,4 @@ void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sen
         ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
         _ringTxtBx_->Text = "";
     }
-}
+}
diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h
index e5d3601..f65b213 100644
--- a/SmartPanel.xaml.h
+++ b/SmartPanel.xaml.h
@@ -31,6 +31,7 @@ public ref class SmartPanel sealed
 {
 public:
     SmartPanel();
+    void updatePageContent();
 
 internal:
     enum class Mode { Minimized, Normal };
@@ -51,6 +52,7 @@ private:
     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 _accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
     void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
 };
 }
-- 
GitLab