<repo_name>FlorianVeys/BluetoothSender<file_sep>/BluetoothSender-Windows/BluetoothSender-Windows/ViewModel/Converters/BooleanToColorConverter.cs
﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace BluetoothSender_Windows.ViewModel.Converters
{
    public class BooleanToColorConverter : IValueConverter
    {
        private readonly String _colorBackgroundDefault = "DarkSlateGray";
        private readonly String _colorBackgroundUserControl = "#FF436060";

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                bool active = value != null && (bool) value;
                return active ? _colorBackgroundUserControl : _colorBackgroundDefault;
            }
            catch (Exception)
            {
                return _colorBackgroundDefault;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
<file_sep>/BluetoothSender-Windows/BluetoothSender-Windows/ViewModel/ReceiverViewModel.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;

namespace BluetoothSender_Windows.ViewModel
{
    public class ReceiverViewModel : ViewModelBase
    {
        private bool _bluetoothServiceIsActive;

        public bool BluetoothServiceActive
        {
            get => _bluetoothServiceIsActive;
            set
            {
                if (_bluetoothServiceIsActive != value)
                {
                    _bluetoothServiceIsActive = value;
                    if (value)
                    {
                        BluetoothServiceStart();
                    }
                    else
                    {
                        BluetoothServiceStop();
                    }
                    RaisePropertyChanged(nameof(BluetoothServiceActive));
                }
            }
        }

        public ReceiverViewModel()
        {
            //TODO
        }

        private void BluetoothServiceStart()
        {
            //TODO
        }

        private void BluetoothServiceStop()
        {
            //TODO
        }

    }
}
<file_sep>/BluetoothSender-Windows/BluetoothSender-Windows/ViewModel/EmitterViewModel.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;

namespace BluetoothSender_Windows.ViewModel
{
    public class EmitterViewModel : ViewModelBase
    {
        public ICommand RefreshDevicesList { get; }

        public EmitterViewModel()
        {
            RefreshDevicesList = new RelayCommand(RefreshList);
        }

        private void RefreshList()
        {
            //TODO
        }
    }
}
<file_sep>/BluetoothSender-Windows/BluetoothSender-Windows/ViewModel/Converters/VisibilityConverter.cs
﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace BluetoothSender_Windows.ViewModel.Converters
{
    public class VisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Boolean val = value != null && (Boolean)value;
            return val ? "Visible" : "Collapsed";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            String val = (String)value;
            return val != null && val.Equals("Visible");

        }
    }
}
<file_sep>/BluetoothSender-Windows/BluetoothSender-Windows/ViewModel/MainViewModel.cs
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;

namespace BluetoothSender_Windows.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public ICommand CloseApplication { get; }
        public ICommand MinimizeApplication { get; }
        public ICommand MenuControl { get; }

        public bool VisibilityHistory { get; set; }
        public bool VisibilityEmitter { get; set; }
        public bool VisibilityReceiver { get; set; }

        public MainViewModel()
        {
            CloseApplication = new RelayCommand(CloseAppli);
            MinimizeApplication = new RelayCommand(MinimizeAppli);
            MenuControl = new RelayCommand<string>(changeView);
            DisplayEmitterView();
        }

        private void changeView(string parameter)
        {
            switch (parameter)
            {
                case "History":
                    DisplayHistoryView();
                    break;
                case "Emitter":
                    DisplayEmitterView();
                    break;
                case "Receiver":
                    DisplayReceiverView();
                    break;
            }
            NotifyChange();
        }

        private void DisplayHistoryView()
        {
            VisibilityEmitter = false;
            VisibilityReceiver = false;
            VisibilityHistory = true;
        }

        private void DisplayEmitterView()
        {
            VisibilityEmitter = true;
            VisibilityReceiver = false;
            VisibilityHistory = false;
        }

        private void DisplayReceiverView()
        {
            VisibilityEmitter = false;
            VisibilityReceiver = true;
            VisibilityHistory = false;

        }

        private void CloseAppli()
        {
            App.Current.Shutdown();
        }

        private void MinimizeAppli()
        {
            App.Current.MainWindow.WindowState = WindowState.Minimized;
        }

        private void NotifyChange()
        {
            RaisePropertyChanged(nameof(VisibilityEmitter));
            RaisePropertyChanged(nameof(VisibilityReceiver));
            RaisePropertyChanged(nameof(VisibilityHistory));
        }

    }
}<file_sep>/BluetoothSender-Windows/BluetoothSender-Windows/ViewModel/Converters/BooleanToMessageConverter.cs
﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace BluetoothSender_Windows.ViewModel.Converters
{
    public class BooleanToMessageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool active = (bool) value;
            return active ? "Service activé" : "Service désactivé";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
