2019-03-21 16:05:16 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Applications.Contracts;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.UserInterface.Mobile.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class ActionCenterApplicationControl : UserControl, IApplicationControl
|
|
|
|
|
{
|
|
|
|
|
private IApplicationInfo info;
|
|
|
|
|
|
|
|
|
|
public event ApplicationControlClickedEventHandler Clicked;
|
|
|
|
|
|
|
|
|
|
public ActionCenterApplicationControl(IApplicationInfo info)
|
|
|
|
|
{
|
|
|
|
|
this.info = info;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeApplicationControl(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterInstance(IApplicationInstance instance)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
var button = new ActionCenterApplicationButton(info, instance);
|
|
|
|
|
|
|
|
|
|
button.Clicked += (id) => Clicked?.Invoke(id);
|
|
|
|
|
instance.Terminated += (id) => Instance_OnTerminated(id, button);
|
|
|
|
|
InstancePanel.Children.Add(button);
|
|
|
|
|
|
|
|
|
|
ApplicationName.Visibility = Visibility.Visible;
|
|
|
|
|
ApplicationButton.Visibility = Visibility.Collapsed;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeApplicationControl(IApplicationInfo info)
|
|
|
|
|
{
|
|
|
|
|
var button = new ActionCenterApplicationButton(info);
|
|
|
|
|
|
|
|
|
|
button.Button.Click += (o, args) => Clicked?.Invoke();
|
|
|
|
|
ApplicationName.Text = info.Name;
|
|
|
|
|
ApplicationButton.Content = button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Instance_OnTerminated(InstanceIdentifier id, ActionCenterApplicationButton button)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.InvokeAsync(() =>
|
|
|
|
|
{
|
|
|
|
|
InstancePanel.Children.Remove(button);
|
|
|
|
|
|
|
|
|
|
if (InstancePanel.Children.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
ApplicationName.Visibility = Visibility.Collapsed;
|
|
|
|
|
ApplicationButton.Visibility = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|