public static void AddNewNotification( GenericNotificationItem notificationItem, bool dontOverwrite = false) { lock (GenericNotificationManager.syncNotificationsReadWrite) { try { SerializableDictionary<string, GenericNotificationItem> savedNotifications = GenericNotificationManager.GetSavedNotifications(); if (!dontOverwrite) { savedNotifications[notificationItem.Id] = notificationItem; GenericNotificationManager.SaveNotifications(savedNotifications); } else { if (savedNotifications.ContainsKey(notificationItem.Id)) return; savedNotifications[notificationItem.Id] = notificationItem; GenericNotificationManager.SaveNotifications(savedNotifications); } } catch (Exception ex) { Logger.Error("Failed to add notification id : {0} titled : {1} and msg : {2}... Err : {3}", (object) notificationItem.Id, (object) notificationItem.Title, (object) notificationItem.Message, (object) ex.ToString()); } } }
internal void InitFromGenricNotificationItem(GenericNotificationItem item, MainWindow parentWin) { this.ParentWindow = parentWin; this.Id = item.Id; this.PackageName = item.Package; this.titleText.Text = item.Title; this.messageText.Text = item.Message; if (!item.IsRead) { this.ChangeToUnreadBackground(); } else { this.ChangeToReadBackground(); } if (string.Equals(item.Title, Strings.ProductDisplayName, StringComparison.InvariantCultureIgnoreCase)) { this.mSnoozeBtn.IsEnabled = false; this.mSnoozeBtn.Opacity = 0.5; } if (!string.IsNullOrEmpty(item.NotificationMenuImageName) && !string.IsNullOrEmpty(item.NotificationMenuImageUrl) && !File.Exists(Path.Combine(RegistryStrings.PromotionDirectory, item.NotificationMenuImageName))) { item.NotificationMenuImageName = Utils.TinyDownloader(item.NotificationMenuImageUrl, item.NotificationMenuImageName, RegistryStrings.PromotionDirectory, false); } this.icon.ImageName = item.NotificationMenuImageName; this.dateText.Text = DateTimeHelper.GetReadableDateTimeString(item.CreationTime); }
private void AddNotificationItem(GenericNotificationItem notifItem) { try { NotificationDrawerItem notificationDrawerItem = new NotificationDrawerItem(); notificationDrawerItem.InitFromGenricNotificationItem(notifItem, this.ParentWindow); if (notifItem.Priority == NotificationPriority.Important) { StackPanel content = this.mImportantNotificationScroll.Content as StackPanel; Separator separator = new Separator(); if (this.FindResource((object)ToolBar.SeparatorStyleKey) is Style resource) { separator.Style = resource; } BlueStacksUIBinding.BindColor((DependencyObject)separator, Panel.BackgroundProperty, "HorizontalSeparator"); separator.Margin = new Thickness(0.0); if (content.Children.OfType <NotificationDrawerItem>().Any <NotificationDrawerItem>()) { content.Children.Insert(0, (UIElement)separator); } content.Children.Insert(0, (UIElement)notificationDrawerItem); this.grdImportantUpdates.Visibility = Visibility.Visible; } else { StackPanel content = this.mNotificationScroll.Content as StackPanel; Separator separator = new Separator(); if (this.FindResource((object)ToolBar.SeparatorStyleKey) is Style resource) { separator.Style = resource; } BlueStacksUIBinding.BindColor((DependencyObject)separator, Panel.BackgroundProperty, "HorizontalSeparator"); separator.Margin = new Thickness(0.0); if (content.Children.OfType <NotificationDrawerItem>().Any <NotificationDrawerItem>()) { content.Children.Insert(0, (UIElement)separator); } content.Children.Insert(0, (UIElement)notificationDrawerItem); this.grdNormalUpdates.Visibility = Visibility.Visible; } } catch (Exception ex) { Logger.Error("Could not add notificationdraweritem. Id " + notifItem.Id + "Error:" + ex.ToString()); } }
internal void Init(GenericNotificationItem notifItem) { this.mNotificationItem = notifItem; this.titleText.Text = notifItem.Title; this.titleText.Foreground = (Brush) new SolidColorBrush((Color)ColorConverter.ConvertFromString(notifItem.NotificationDesignItem.TitleForeGroundColor)); this.messageText.Text = notifItem.Message; this.messageText.Foreground = (Brush) new SolidColorBrush((Color)ColorConverter.ConvertFromString(notifItem.NotificationDesignItem.MessageForeGroundColor)); this.notificationBorder.BorderBrush = (Brush) new SolidColorBrush((Color)ColorConverter.ConvertFromString(notifItem.NotificationDesignItem.BorderColor)); this.ribbonStroke.Stroke = (Brush) new SolidColorBrush((Color)ColorConverter.ConvertFromString(notifItem.NotificationDesignItem.BorderColor)); if (notifItem.NotificationDesignItem.BackgroundGradient.Count == 0) { notifItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>("#FFF350", 0.0)); notifItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>("#FFF8AF", 0.3)); notifItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>("#FFE940", 0.6)); notifItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>("#FCE74E", 0.8)); notifItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>("#FDF09C", 0.9)); notifItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>("#FFE227", 1.0)); } this.backgroundPanel.Background = (Brush) new LinearGradientBrush(new GradientStopCollection(notifItem.NotificationDesignItem.BackgroundGradient.Select <SerializableKeyValuePair <string, double>, GradientStop>((Func <SerializableKeyValuePair <string, double>, GradientStop>)(_ => new GradientStop((Color)ColorConverter.ConvertFromString(_.Key), _.Value))))); if (string.IsNullOrEmpty(notifItem.NotificationDesignItem.Ribboncolor)) { this.ribbonBack.Fill = (Brush) new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFF350")); } else { this.ribbonBack.Fill = (Brush) new SolidColorBrush((Color)ColorConverter.ConvertFromString(notifItem.NotificationDesignItem.Ribboncolor)); } if (string.IsNullOrEmpty(notifItem.NotificationDesignItem.LeftGifName)) { this.pikaGif.Visibility = Visibility.Collapsed; } else { this.pikaGif.Visibility = Visibility.Visible; this.pikaGif.ImageName = notifItem.NotificationDesignItem.LeftGifName; } Canvas.SetLeft((UIElement)this, 0.0); }
private static void HandleDeferredNotification(GenericNotificationItem genericItem) { PromotionManager.sDeferredNotificationsList.Add(genericItem, AppUsageTimer.GetTotalTimeForPackageAfterReset(genericItem.DeferredApp.ToLower(CultureInfo.InvariantCulture))); }
internal static void HandleGenericNotification(JObject resJson, string vmName) { GenericNotificationItem genericItem = new GenericNotificationItem(); try { JObject resJson1 = JObject.Parse(resJson["bluestacks_notification"][(object)"payload"][(object)"GenericNotificationItem"].ToString()); resJson1.AssignIfContains <string>("id", (System.Action <string>)(x => genericItem.Id = x)); resJson1.AssignIfContains <string>("priority", (System.Action <string>)(x => genericItem.Priority = EnumHelper.Parse <NotificationPriority>(x, NotificationPriority.Normal))); resJson1.AssignIfContains <string>("title", (System.Action <string>)(x => genericItem.Title = x)); resJson1.AssignIfContains <string>("message", (System.Action <string>)(x => genericItem.Message = x)); resJson1.AssignIfContains <bool>("showribbon", (System.Action <bool>)(x => genericItem.ShowRibbon = x)); resJson1.AssignIfContains <string>("menuimagename", (System.Action <string>)(x => genericItem.NotificationMenuImageName = x)); resJson1.AssignIfContains <string>("menuimageurl", (System.Action <string>)(x => genericItem.NotificationMenuImageUrl = x)); resJson1.AssignIfContains <bool>("isread", (System.Action <bool>)(x => genericItem.IsRead = x)); resJson1.AssignIfContains <bool>("isdeleted", (System.Action <bool>)(x => genericItem.IsDeleted = x)); resJson1.AssignIfContains <bool>("deferred", (System.Action <bool>)(x => genericItem.IsDeferred = x)); resJson1.AssignIfContains <string>("creationtime", (System.Action <string>)(x => genericItem.CreationTime = DateTime.ParseExact(x, "yyyy/MM/dd HH:mm:ss", (IFormatProvider)CultureInfo.InvariantCulture))); if (!string.IsNullOrEmpty(genericItem.NotificationMenuImageName) && !string.IsNullOrEmpty(genericItem.NotificationMenuImageUrl)) { genericItem.NotificationMenuImageName = Utils.TinyDownloader(genericItem.NotificationMenuImageUrl, genericItem.NotificationMenuImageName, RegistryStrings.PromotionDirectory, false); } if (resJson1["ExtraPayload"] != null && !JsonExtensions.IsNullOrEmptyBrackets(resJson1.GetValue("ExtraPayload", StringComparison.InvariantCulture).ToString())) { resJson1["ExtraPayload"].AssignIfContains <string>("payloadtype", (System.Action <string>)(x => genericItem.PayloadType = EnumHelper.Parse <NotificationPayloadType>(x, NotificationPayloadType.Generic))); SerializableDictionary <string, string> extraPayload = genericItem.ExtraPayload; if (extraPayload != null) { extraPayload.ClearAddRange <string, string>((Dictionary <string, string>)CloudNotificationManager.HandleExtraPayload(resJson1.GetValue("ExtraPayload", StringComparison.InvariantCulture).ToObject <JObject>(), genericItem.PayloadType)); } } ClientStats.SendMiscellaneousStatsAsync("notification_received", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, genericItem.Id, genericItem.Title, genericItem.ExtraPayload.ContainsKey("campaign_id") ? genericItem.ExtraPayload["campaign_id"] : "", (string)null, (string)null, (string)null, "Android"); genericItem.IsReceivedStatSent = true; if (resJson1["conditions"] != null && !JsonExtensions.IsNullOrEmptyBrackets(resJson1.GetValue("conditions", StringComparison.InvariantCulture).ToString())) { resJson1["conditions"].AssignIfContains <string>("app_pkg_on_top", (System.Action <string>)(x => genericItem.DeferredApp = x)); resJson1["conditions"].AssignIfContains <long>("app_usage_seconds", (System.Action <long>)(x => genericItem.DeferredAppUsage = x)); } if (genericItem.ShowRibbon) { if (resJson["bluestacks_notification"][(object)"payload"].ToObject <JObject>()["RibbonDesign"] != null) { if (!JsonExtensions.IsNullOrEmptyBrackets(resJson["bluestacks_notification"][(object)"payload"].GetValue("RibbonDesign"))) { genericItem.NotificationDesignItem = new GenericNotificationDesignItem(); JObject resJson2 = JObject.Parse(resJson["bluestacks_notification"][(object)"payload"][(object)"RibbonDesign"].ToString()); resJson2.AssignIfContains <string>("titleforegroundcolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.TitleForeGroundColor = x)); resJson2.AssignIfContains <string>("messageforegroundcolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.MessageForeGroundColor = x)); resJson2.AssignIfContains <string>("bordercolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.BorderColor = x)); resJson2.AssignIfContains <string>("ribboncolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.Ribboncolor = x)); resJson2.AssignIfContains <double>("auto_hide_timer", (System.Action <double>)(x => genericItem.NotificationDesignItem.AutoHideTime = x)); resJson2.AssignIfContains <string>("hoverbordercolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.HoverBorderColor = x)); resJson2.AssignIfContains <string>("hoverribboncolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.HoverRibboncolor = x)); resJson2.AssignIfContains <string>("leftgifname", (System.Action <string>)(x => genericItem.NotificationDesignItem.LeftGifName = x)); resJson2.AssignIfContains <string>("leftgifurl", (System.Action <string>)(x => genericItem.NotificationDesignItem.LeftGifUrl = x)); if (!string.IsNullOrEmpty(genericItem.NotificationDesignItem.LeftGifName) && !string.IsNullOrEmpty(genericItem.NotificationDesignItem.LeftGifUrl)) { Utils.TinyDownloader(genericItem.NotificationDesignItem.LeftGifUrl, genericItem.NotificationDesignItem.LeftGifName, RegistryStrings.PromotionDirectory, false); } if (resJson2["background_gradient"] != null) { foreach (JObject jobject in JArray.Parse(resJson2["background_gradient"].ToString()).ToObject <List <JObject> >()) { genericItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>(jobject["color"].ToString(), jobject["offset"].ToObject <double>())); } } if (resJson2["hover_background_gradient"] != null) { foreach (JObject jobject in JArray.Parse(resJson2["hover_background_gradient"].ToString()).ToObject <List <JObject> >()) { genericItem.NotificationDesignItem.HoverBackGroundGradient.Add(new SerializableKeyValuePair <string, double>(jobject["color"].ToString(), jobject["offset"].ToObject <double>())); } } } } } } catch (Exception ex) { Logger.Error("Exception while parsing generic notification. Not showing notification and not adding in notification menu." + ex.ToString()); return; } try { if (string.IsNullOrEmpty(genericItem.Title) && string.IsNullOrEmpty(genericItem.Message)) { genericItem.IsDeleted = true; } if (!genericItem.IsDeferred) { GenericNotificationManager.AddNewNotification(genericItem, false); } if (genericItem.ShowRibbon && resJson["bluestacks_notification"][(object)"payload"].ToObject <JObject>()["RibbonDesign"] != null && !JsonExtensions.IsNullOrEmptyBrackets(resJson["bluestacks_notification"][(object)"payload"].GetValue("RibbonDesign"))) { if (!genericItem.IsDeferred) { BlueStacksUIUtils.DictWindows[vmName].HandleGenericNotificationPopup(genericItem); } else { CloudNotificationManager.HandleDeferredNotification(genericItem); } } BlueStacksUIUtils.DictWindows[vmName].mTopBar.RefreshNotificationCentreButton(); } catch (Exception ex) { Logger.Error("Exception when handling notification json. Id " + genericItem.Id + " Error: " + ex.ToString()); } }
private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { string fileName = RegistryStrings.InstallDir + "\\HD-RunApp.exe"; GenericNotificationItem notificationItem = GenericNotificationManager.Instance.GetNotificationItem(this.Id); JsonParser jsonParser = new JsonParser(this.ParentWindow.mVmName); if (this.ParentWindow != null && this.ParentWindow.mGuestBootCompleted) { if (notificationItem == null) { return; } ClientStats.SendMiscellaneousStatsAsync("NotificationDrawerItemClicked", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, notificationItem.Id, notificationItem.Title, JsonConvert.SerializeObject((object)notificationItem.ExtraPayload), notificationItem.ExtraPayload.ContainsKey("campaign_id") ? notificationItem.ExtraPayload["campaign_id"] : "", (string)null, (string)null, "Android"); GenericNotificationManager.MarkNotification((IEnumerable <string>) new List <string>() { notificationItem.Id }, (System.Action <GenericNotificationItem>)(x => x.IsRead = true)); this.ChangeToReadBackground(); this.ParentWindow.mTopBar.RefreshNotificationCentreButton(); if (notificationItem.ExtraPayload.Keys.Count > 0) { this.ParentWindow.Utils.HandleGenericActionFromDictionary((Dictionary <string, string>)notificationItem.ExtraPayload, "notification_drawer", notificationItem.NotificationMenuImageName); } else { try { if (string.Compare(notificationItem.Title, "Successfully copied files:", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(notificationItem.Title, "Cannot copy files:", StringComparison.OrdinalIgnoreCase) == 0) { NotificationPopup.LaunchExplorer(notificationItem.Message); } else { Logger.Info("launching " + notificationItem.Title); AppInfo infoFromPackageName = jsonParser.GetAppInfoFromPackageName(this.PackageName); if (infoFromPackageName != null) { string str = "-json \"" + new JObject() { { "app_icon_url", (JToken)"" }, { "app_name", (JToken)infoFromPackageName.Name }, { "app_url", (JToken)"" }, { "app_pkg", (JToken)this.PackageName } }.ToString(Formatting.None).Replace("\"", "\\\"") + "\""; Process.Start(fileName, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0} -vmname {1}", (object)str, (object)this.ParentWindow.mVmName)); } else { this.ParentWindow.Utils.HandleGenericActionFromDictionary(new Dictionary <string, string>() { { "click_generic_action", GenericAction.InstallPlay.ToString() }, { "click_action_packagename", notificationItem.Package } }, "notification_drawer", ""); } } } catch (Exception ex) { Logger.Error(ex.ToString()); } finally { this.ParentWindow.mTopBar.mNotificationCentrePopup.IsOpen = false; } } } else { if (notificationItem == null) { return; } this.ParentWindow.mPostBootNotificationAction = this.PackageName; this.ParentWindow.mTopBar.mNotificationCentrePopup.IsOpen = false; } }