private List <GalleryItem> GetWebPagePhotos(TLMessage message, TLWebPage webPage) { var result = new List <GalleryItem>(); var blocks = webPage.CachedPage?.Blocks ?? new TLVector <TLPageBlockBase>(); foreach (var block in blocks) { if (block is TLPageBlockSlideshow slideshow) { foreach (var item in slideshow.Items) { result.Add(GetBlock(message, webPage, item)); } } else if (block is TLPageBlockCollage collage) { foreach (var item in collage.Items) { result.Add(GetBlock(message, webPage, item)); } } } return(result); }
private GalleryItem GetBlock(TLMessage message, TLWebPage webPage, TLPageBlockBase pageBlock) { if (pageBlock is TLPageBlockPhoto photoBlock) { var photo = TLWebPage.GetPhotoWithId(webPage, photoBlock.PhotoId) as TLPhoto; if (photo == null) { return(null); } return(new GalleryPhotoItem(photo, message.From)); } else if (pageBlock is TLPageBlockVideo videoBlock) { var document = TLWebPage.GetDocumentWithId(webPage, videoBlock.VideoId) as TLDocument; if (document == null) { return(null); } return(new GalleryDocumentItem(document, message.From)); } return(null); }
public static double GetWebPageDimension(TLWebPage webPage, bool isWidth) { const double width = 311.0 - 12.0; if (isWidth) { return(width); } var photo = webPage.Photo as TLPhoto; if (photo == null) { return(double.NaN); } TLPhotoSize size = null; var sizes = photo.Sizes.OfType <TLPhotoSize>(); foreach (var photoSize in sizes) { if (size == null || Math.Abs(width - size.W.Value) > Math.Abs(width - photoSize.W.Value)) { size = photoSize; } } if (size != null) { return(width / size.W.Value * size.H.Value); //* 0.75; } return(double.NaN); }
public IAsyncOperation <ContentDialogBaseResult> ShowAsync(TLWebPage webPage) { if (webPage.HasEmbedUrl) { Image.Constraint = webPage; View.Navigate(new Uri(webPage.EmbedUrl)); } return(base.ShowAsync()); }
public InstantGalleryViewModel(TLMessage message, TLWebPage webPage) : base(null, null, null) { _shouldGroup = true; Items = new MvxObservableCollection <GalleryItem>(GetWebPagePhotos(message, webPage)); FirstItem = Items.FirstOrDefault(); SelectedItem = Items.FirstOrDefault(); TotalItems = Items.Count; }
public void AddAndFilterMessages(List <TLMessage> msgs) { try { Regex reg = new Regex(@"https\:\/\/[www\.]*instagram\.com\/p\/[\w-]+[\/]*"); // regex linku do zdjecia MatchCollection matches; foreach (TLMessage msg in msgs) { if (msg.Media != null) { if (msg.Media is TLMessageMediaWebPage) { TLMessageMediaWebPage mm = (TLMessageMediaWebPage)msg.Media; if (mm is TLMessageMediaWebPage) { TLWebPage wp = mm.Webpage as TLWebPage; if (wp is TLWebPage) { matches = reg.Matches(wp.Url); if (matches.Count == 1) { filtered_messages.Add(msg); } else { System.Diagnostics.Debug.Write($"\nNie znaleziono jednoznacznego przyporządkowania dla wiadomości o URL = {wp.Url}"); } } else { System.Diagnostics.Debug.Write($"\nmm.WebPage nie jest typu TLWebPage, tylko {msg.Media.GetType().ToString()}"); } } else { System.Diagnostics.Debug.Write($"\nmsg.Media nie jest typu TLMessageMediaWebPage, tylko {msg.Media.GetType().ToString()}"); } } else { System.Diagnostics.Debug.Write("\nMedia != null, ale tonie WebPage, tylko " + msg.Media.GetType().ToString()); } } } } catch (Exception ex) { System.Diagnostics.Debug.Write("Filtrowanie wiadomosci telegrama nie powiodlo sie: " + ex.Message.ToString()); } }
public static bool IsWebPagePhotoTemplate(TLWebPage webPage) { if (webPage.Photo != null && webPage.Type != null) { if (string.Equals(webPage.Type, "photo", StringComparison.OrdinalIgnoreCase) || string.Equals(webPage.Type, "video", StringComparison.OrdinalIgnoreCase)) { return(true); } else if (string.Equals(webPage.Type, "article", StringComparison.OrdinalIgnoreCase)) { var photo = webPage.Photo as TLPhoto; var full = photo?.Full as TLPhotoSize; var fullCache = photo?.Full as TLPhotoCachedSize; return((full?.W > 400 || fullCache?.W > 400) && webPage.HasCachedPage); } } return(false); }
public List <InstagramPost> CreatePostsFromMessages() { List <InstagramPost> insta_posts = new List <InstagramPost>(); System.Diagnostics.Debug.Write("Krok 4.1: Wchodze do foreach\n"); foreach (var msg in filtered_messages) { System.Diagnostics.Debug.Write("Krok 4.2: We foreach\n"); InstagramPost tmp_post = new InstagramPost(); TLMessageMediaWebPage wp = (TLMessageMediaWebPage)msg.Media; TLWebPage webPage = (TLWebPage)wp.Webpage; System.Diagnostics.Debug.Write("Krok 4.3: Webpage gotowe\n"); Regex reg = new Regex(@"https\:\/\/[www\.]*instagram\.com\/p\/[\w-]+[\/]*"); // regex linku do zdjecia MatchCollection matches; matches = reg.Matches(webPage.Url); System.Diagnostics.Debug.Write("Krok 4.4: Sprawdzam czy znaleziono odwzorowanie\n"); if (matches.Count > 0) { System.Diagnostics.Debug.Write("Krok 4.5: Znaleziono odwzorowanie (msg.Date = " + msg.Date.ToString() + ")\n"); if (tmp_post.SetTelegramInfo(matches[0].Value, msg.Message, (long)msg.Date)) { System.Diagnostics.Debug.Write("Krok 4.5: Znaleziono odwzorowanie (msg.Date = " + msg.Date.ToString() + ")\n"); insta_posts.Add(tmp_post); System.Diagnostics.Debug.Write("Krok 4.6: Dodano post do insta_posts\n"); } else { System.Diagnostics.Debug.Write("Krok 4.5: Nie udalo sie dodac Telegram Data\n"); } } else { System.Diagnostics.Debug.Write("\nPomijam " + webPage.Url); } } return(insta_posts); }
public IAsyncOperation <ContentDialogBaseResult> ShowAsync(TLWebPage webPage) { if (ApplicationView.GetForCurrentView().IsCompactOverlaySupported()) { return(AsyncInfo.Run(async token => { var w = webPage.EmbedWidth ?? 340; var h = webPage.EmbedHeight ?? 200; double ratioX = (double)340 / w; double ratioY = (double)340 / h; double ratio = Math.Min(ratioX, ratioY); var preferences = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay); preferences.CustomSize = new Size(w * ratio, h * ratio); var newView = CoreApplication.CreateNewView(); var newViewId = 0; await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var request = new HttpRequestMessage(HttpMethod.Get, new Uri(webPage.EmbedUrl)); request.Headers.Referer = new Uri("https://youtube.com"); var view = new WebView(); view.NavigateWithHttpRequestMessage(request); //view.Navigate(new Uri(webPage.EmbedUrl)); var yolo = new GlyphButton(); yolo.HorizontalAlignment = HorizontalAlignment.Right; yolo.VerticalAlignment = VerticalAlignment.Bottom; yolo.Glyph = "\uE740"; yolo.Click += async(s, args) => { var current = ApplicationView.GetForCurrentView(); if (current.ViewMode == ApplicationViewMode.CompactOverlay) { current.TryEnterFullScreenMode(); } else { await current.TryEnterViewModeAsync(ApplicationViewMode.CompactOverlay, preferences); } }; var ciccio = new Grid(); ciccio.RequestedTheme = ElementTheme.Dark; ciccio.Children.Add(view); ciccio.Children.Add(yolo); Window.Current.Content = ciccio; Window.Current.Activate(); Window.Current.VisibilityChanged += (s, args) => { if (args.Visible) { return; } view.NavigateToString(string.Empty); }; newViewId = ApplicationView.GetForCurrentView().Id; var coreTitleBar = CoreApplication.GetCurrentView().TitleBar; coreTitleBar.ExtendViewIntoTitleBar = true; var titleBar = ApplicationView.GetForCurrentView().TitleBar; titleBar.ButtonBackgroundColor = Colors.Transparent; titleBar.ButtonForegroundColor = Colors.White; titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; titleBar.ButtonInactiveForegroundColor = Colors.White; }); var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay, preferences); return ContentDialogBaseResult.OK; })); } else { if (webPage.HasEmbedUrl) { Image.Constraint = webPage; View.Navigate(new Uri(webPage.EmbedUrl)); } return(base.ShowAsync()); } }