atraczyk | 8ce1dee | 2016-08-25 18:15:07 -0400 | [diff] [blame] | 1 | /***************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 4 | * Author: Traczyk Andreas <andreas.traczyk@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 |
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 20 | #pragma once
|
atraczyk | 82f8dda | 2016-08-25 16:34:52 -0400 | [diff] [blame] | 21 |
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 22 | using namespace Platform::Collections;
|
| 23 |
|
| 24 | namespace RingClientUWP
|
| 25 | {
|
| 26 |
|
atraczyk | 4a8cffc | 2016-08-25 20:01:25 -0400 | [diff] [blame] | 27 | delegate void NewAccountSelected();
|
| 28 | delegate void NoAccountSelected();
|
atraczyk | 196936e | 2016-09-02 15:31:53 -0400 | [diff] [blame] | 29 | delegate void UpdateScrollView();
|
atraczyk | 4a8cffc | 2016-08-25 20:01:25 -0400 | [diff] [blame] | 30 |
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 31 | namespace ViewModel {
|
| 32 | public ref class AccountsViewModel sealed
|
| 33 | {
|
| 34 | internal:
|
| 35 | /* singleton */
|
| 36 | static property AccountsViewModel^ instance
|
| 37 | {
|
| 38 | AccountsViewModel^ get()
|
| 39 | {
|
| 40 | static AccountsViewModel^ instance_ = ref new AccountsViewModel();
|
| 41 | return instance_;
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | /* functions */
|
atraczyk | 797fa1a | 2016-08-31 09:55:53 -0400 | [diff] [blame] | 46 | void add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID);
|
atraczyk | 82f8dda | 2016-08-25 16:34:52 -0400 | [diff] [blame] | 47 | void clearAccountList();
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 48 |
|
| 49 | /* properties */
|
atraczyk | 4a8cffc | 2016-08-25 20:01:25 -0400 | [diff] [blame] | 50 | property Account^ selectedAccount
|
| 51 | {
|
| 52 | Account^ get()
|
| 53 | {
|
| 54 | return currentItem_;
|
| 55 | }
|
| 56 | void set(Account^ value)
|
| 57 | {
|
| 58 | oldItem_ = currentItem_;
|
| 59 | currentItem_ = value;
|
| 60 | if (value)
|
| 61 | newAccountSelected();
|
| 62 | else
|
| 63 | noAccountSelected();
|
| 64 | }
|
| 65 | }
|
| 66 |
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 67 | property Vector<Account^>^ accountsList
|
| 68 | {
|
| 69 | Vector<Account^>^ get()
|
| 70 | {
|
| 71 | return accountsList_;
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | /* events */
|
atraczyk | 4a8cffc | 2016-08-25 20:01:25 -0400 | [diff] [blame] | 76 | event NewAccountSelected^ newAccountSelected;
|
| 77 | event NoAccountSelected^ noAccountSelected;
|
atraczyk | 196936e | 2016-09-02 15:31:53 -0400 | [diff] [blame] | 78 | event UpdateScrollView^ updateScrollView;
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 79 |
|
| 80 | private:
|
| 81 | AccountsViewModel(); // singleton
|
| 82 | Vector<Account^>^ accountsList_;
|
atraczyk | 4a8cffc | 2016-08-25 20:01:25 -0400 | [diff] [blame] | 83 | Account^ currentItem_;
|
| 84 | Account^ oldItem_;
|
| 85 |
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 86 | };
|
| 87 | }
|
| 88 | }
|