From 69cb1cf5094efd5d820bce166f9823b4dfcf53f0 Mon Sep 17 00:00:00 2001 From: Lyndon Date: Mon, 2 Sep 2019 19:04:55 +0200 Subject: [PATCH] =?UTF-8?q?Benachrichtigungen:=20Ist=20das=20Fenster=20min?= =?UTF-8?q?imiert=20oder=20im=20Hintergrund,=20wird=20bei=20einem=20Klick?= =?UTF-8?q?=20auf=20die=20Benachrichtigung=20der=20richtige=20Chat=20ausge?= =?UTF-8?q?w=C3=A4hlt=20und=20das=20Fenster=20zur=C3=BCck=20in=20den=20Vor?= =?UTF-8?q?dergrund=20geholt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bewoplaner-chat-android/build.gradle | 2 +- ChatController/ChatMainControl.xaml.cs | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/BeWoPlanerChat/bewoplaner-chat-android/build.gradle b/BeWoPlanerChat/bewoplaner-chat-android/build.gradle index b39a065..f70304d 100644 --- a/BeWoPlanerChat/bewoplaner-chat-android/build.gradle +++ b/BeWoPlanerChat/bewoplaner-chat-android/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.4.2' classpath 'io.realm:realm-gradle-plugin:5.3.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/ChatController/ChatMainControl.xaml.cs b/ChatController/ChatMainControl.xaml.cs index b7c34f2..8b14784 100644 --- a/ChatController/ChatMainControl.xaml.cs +++ b/ChatController/ChatMainControl.xaml.cs @@ -40,7 +40,22 @@ namespace ChatController private readonly Dictionary _GroupId2DateTime = new Dictionary(); - public Window ContainingWindow { get; set; } + private Window _ContainingWindow; + + public Window ContainingWindow + { + get => _ContainingWindow; + + set + { + _ContainingWindow = value; + if(value != null) + { + _ContainingWindow.Deactivated += ContainingWindowOnDeactivated; + _ContainingWindow.Activated += ContainingWindowOnActivated; + } + } + } private Chat _Chat; private CurrentContact _CurrentContact; @@ -59,6 +74,8 @@ namespace ChatController private bool _IsDesktopVersion = true; + private bool _IsInBackground; + public ChatMainControl() { InitializeComponent(); @@ -66,6 +83,16 @@ namespace ChatController ReloadGruppen.Visibility = Visibility.Collapsed; } + private void ContainingWindowOnDeactivated(object sender, EventArgs e) + { + _IsInBackground = true; + } + + private void ContainingWindowOnActivated(object sender, EventArgs e) + { + _IsInBackground = false; + } + public void InitMitChatdaten(ChatDatenUebergabe cdu) { _Chat = new Chat(cdu); @@ -119,6 +146,13 @@ namespace ChatController { DisposeAndRemoveNotification((NotifyIcon)sender, pGroupId); + if (_ContainingWindow.WindowState == WindowState.Minimized) + { + _ContainingWindow.WindowState = WindowState.Normal; + } + + _ContainingWindow.Activate(); + SelectContact(_ContactList.FirstOrDefault(f => f.GroupId.Equals(pGroupId))); }; @@ -202,7 +236,12 @@ namespace ChatController AktChatUserList.Items.Add(currentContact); _CurrentContact = currentContact; - + + if(Clientlist.Items.Contains(pContact)) + { + Clientlist.SelectedItem = pContact; + } + var chatMessages = _Chat.LoadChatMessagesForContact(currentContact); ChatListBox.ItemsSource = chatMessages; @@ -667,7 +706,8 @@ namespace ChatController contact.ReceivedMessage = newContact.ReceivedMessage; contact.TimeStamp = newContact.TimeStamp; - if (Clientlist.SelectedItem != null && !((Contact)Clientlist.SelectedItem).GroupId.Equals(newContact.GroupId) || Clientlist.SelectedItem == null) + // TODO: Prüfen, ob die App im Hintergrund oder minimiert ist + if ((Clientlist.SelectedItem != null && !((Contact)Clientlist.SelectedItem).GroupId.Equals(newContact.GroupId) || Clientlist.SelectedItem == null) || _IsInBackground) { ContainingWindow.Icon = Utils.GetImageSourceFromIcon(Resource.oC_favico_NewMessage); ShowNotification(newContact.Name, "Sie haben eine neue Nachricht", newContact.GroupId);