public LinkViewModel(Thing linkThing, IBaconProvider baconProvider, bool? wasStreamed = null) { _linkThing = new TypedThing<Link>(linkThing); _baconProvider = baconProvider; _redditService = _baconProvider.GetService<IRedditService>(); _navigationService = _baconProvider.GetService<INavigationService>(); _imagesService = _baconProvider.GetService<IImagesService>(); _dynamicViewLocator = _baconProvider.GetService<IDynamicViewLocator>(); _settingsService = _baconProvider.GetService<ISettingsService>(); _isPreviewShown = false; _isExtendedOptionsShown = false; _loading = false; _registeredLongNav = false; ShowPreview = new RelayCommand(() => IsPreviewShown = !IsPreviewShown); ShowExtendedOptions = new RelayCommand(() => IsExtendedOptionsShown = !IsExtendedOptionsShown); WasStreamed = wasStreamed ?? false; ContentIsFocused = !WasStreamed; if (Url != null) { if (_imagesService.MightHaveImagesFromUrl(Url) && !Url.EndsWith(".jpg") && !Url.EndsWith(".gif") && !Url.EndsWith(".png")) { MessengerInstance.Register<LongNavigationMessage>(this, OnLongNav); _registeredLongNav = true; } } }
private static async Task<ViewModelBase> MakeContextedTuple(IImagesService imagesService, IOfflineService offlineService, ISettingsService settingsService, NeverEndingRedditView linksEnumerator) { ViewModelBase vm; while ((vm = await linksEnumerator.Next()) != null) { if (vm is LinkViewModel && imagesService.MightHaveImagesFromUrl(((LinkViewModel)vm).Url) && (!settingsService.OnlyFlipViewUnread || !offlineService.HasHistory(((LinkViewModel)vm).Url))) { var targetViewModel = vm as LinkViewModel; var smartOfflineService = ServiceLocator.Current.GetInstance<ISmartOfflineService>(); smartOfflineService.NavigatedToOfflineableThing(targetViewModel.LinkThing, false); Messenger.Default.Send<LoadingMessage>(new LoadingMessage { Loading = true }); await ServiceLocator.Current.GetInstance<IOfflineService>().StoreHistory(targetViewModel.Url); var imageResults = await ServiceLocator.Current.GetInstance<IImagesService>().GetImagesFromUrl(targetViewModel.LinkThing == null ? "" : targetViewModel.LinkThing.Data.Title, targetViewModel.Url); Messenger.Default.Send<LoadingMessage>(new LoadingMessage { Loading = false }); if (imageResults != null && imageResults.Count() > 0) { var imageTuple = new Tuple<string, IEnumerable<Tuple<string, string>>, string>(targetViewModel.LinkThing != null ? targetViewModel.LinkThing.Data.Title : "", imageResults, targetViewModel.LinkThing != null ? targetViewModel.LinkThing.Data.Id : ""); Messenger.Default.Send<LongNavigationMessage>(new LongNavigationMessage { Finished = true, TargetUrl = targetViewModel.Url }); return new LinkedPictureViewModel { LinkTitle = imageTuple.Item1.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\"").Replace("'", "'").Trim(), LinkId = imageTuple.Item3, Pictures = imageTuple.Item2.Select(tpl => new LinkedPictureViewModel.LinkedPicture { Title = tpl.Item1.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\"").Replace("'", "'").Trim(), ImageSource = tpl.Item2, Url = tpl.Item2 }) }; } } else if (vm is LinkViewModel && LinkGlyphUtility.GetLinkGlyph(vm) == LinkGlyphUtility.WebGlyph && !settingsService.OnlyFlipViewImages && settingsService.ApplyReadabliltyToLinks && (!settingsService.OnlyFlipViewUnread || !offlineService.HasHistory(((LinkViewModel)vm).Url))) { var targetViewModel = vm as LinkViewModel; var smartOfflineService = ServiceLocator.Current.GetInstance<ISmartOfflineService>(); smartOfflineService.NavigatedToOfflineableThing(targetViewModel.LinkThing, true); await ServiceLocator.Current.GetInstance<IOfflineService>().StoreHistory(targetViewModel.Url); var result = await ReadableArticleViewModel.LoadAtLeastOne(ServiceLocator.Current.GetInstance<ISimpleHttpService>(), targetViewModel.Url, targetViewModel.LinkThing.Data.Id); result.WasStreamed = true; result.ContentIsFocused = false; return result; } else if (vm is LinkViewModel && ((LinkViewModel)vm).IsSelfPost && !settingsService.OnlyFlipViewImages && (!settingsService.OnlyFlipViewUnread || !offlineService.HasHistory(((LinkViewModel)vm).Url))) { var targetViewModel = vm as LinkViewModel; var smartOfflineService = ServiceLocator.Current.GetInstance<ISmartOfflineService>(); smartOfflineService.NavigatedToOfflineableThing(targetViewModel.LinkThing, true); await ServiceLocator.Current.GetInstance<IOfflineService>().StoreHistory(targetViewModel.Url); return vm; } } return null; }