Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame^] | 1 | #pragma once
|
| 2 | /**************************************************************************
|
| 3 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 4 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 5 | * *
|
| 6 | * This program is free software; you can redistribute it and/or modify *
|
| 7 | * it under the terms of the GNU General Public License as published by *
|
| 8 | * the Free Software Foundation; either version 3 of the License, or *
|
| 9 | * (at your option) any later version. *
|
| 10 | * *
|
| 11 | * This program is distributed in the hope that it will be useful, *
|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 14 | * GNU General Public License for more details. *
|
| 15 | * *
|
| 16 | * You should have received a copy of the GNU General Public License *
|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 18 | **************************************************************************/
|
| 19 | using namespace Platform::Collections;
|
| 20 |
|
| 21 | namespace RingClientUWP
|
| 22 | {
|
| 23 |
|
| 24 | delegate void NewContactSelected(Contact^ contact);
|
| 25 | delegate void NoContactSelected();
|
| 26 |
|
| 27 | namespace ViewModel {
|
| 28 | public ref class ContactsViewModel sealed
|
| 29 | {
|
| 30 | internal:
|
| 31 | /* singleton */
|
| 32 | static property ContactsViewModel^ instance
|
| 33 | {
|
| 34 | ContactsViewModel^ get()
|
| 35 | {
|
| 36 | static ContactsViewModel^ instance_ = ref new ContactsViewModel();
|
| 37 | return instance_;
|
| 38 | }
|
| 39 | }
|
| 40 |
|
| 41 | /* functions */
|
| 42 | Contact^ findContactByName(String^ name);
|
| 43 |
|
| 44 | Contact^ addNewContact(String^ name, String^ ringId);
|
| 45 |
|
| 46 | /* properties */
|
| 47 | property Contact^ selectedContact
|
| 48 | {
|
| 49 | Contact^ get()
|
| 50 | {
|
| 51 | return currentItem_;
|
| 52 | }
|
| 53 | void set(Contact^ value)
|
| 54 | {
|
| 55 | oldItem_ = currentItem_;
|
| 56 | currentItem_ = value;
|
| 57 | if (value)
|
| 58 | newContactSelected(currentItem_);
|
| 59 | else
|
| 60 | noContactSelected();
|
| 61 | }
|
| 62 | }
|
| 63 |
|
| 64 | property Vector<Contact^>^ contactsList
|
| 65 | {
|
| 66 | Vector<Contact^>^ get()
|
| 67 | {
|
| 68 | return contactsList_;
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | /* events */
|
| 73 | event NewContactSelected^ newContactSelected;
|
| 74 | event NoContactSelected^ noContactSelected;
|
| 75 |
|
| 76 | private:
|
| 77 | ContactsViewModel(); // singleton
|
| 78 | Vector<Contact^>^ contactsList_;
|
| 79 | Contact^ currentItem_;
|
| 80 | Contact^ oldItem_;
|
| 81 |
|
| 82 | };
|
| 83 | }
|
| 84 | }
|