예제 #1
0
        public async Task TryLoadBitmapAsync()
        {
            if (BitmapSource.Bitmap != null)
            {
                return;
            }
            var url = GetUrlFromSettings();

            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            var task = CheckAndGetDownloadedFileAsync();

            BitmapSource.ExpectedFileName = Image.ID + ".jpg";
            BitmapSource.RemoteUrl        = url;
            await BitmapSource.LoadBitmapAsync();

            if (Image?.IsUnsplash == false && App.AppSettings.EnableTile && BitmapSource.LocalPath != null)
            {
                Debug.WriteLine("About to update tile.");
                await LiveTileUpdater.UpdateImagesTileAsync(new List <string>() { BitmapSource.LocalPath });
            }
        }
예제 #2
0
        private async void PinCoin_click(object sender, RoutedEventArgs e)
        {
            bool success;

            if (vm.Coin.IsPin)
            {
                success = await LiveTileUpdater.RemoveSecondaryTileAction(vm.Coin.Name);

                /// reset it even if it fails
                vm.Coin.IsPin = false;
                if (success)
                {
                    vm.InAppNotification($"Unpinned {vm.Coin.Name} from start screen");
                }
            }
            else
            {
                var grid = await LiveTileGenerator.SecondaryTileGridOperation(vm.Coin.Name);

                try {
                    RenderTargetBitmap rtb = new RenderTargetBitmap();
                    MainGrid.Children.Add(grid);
                    grid.Opacity = 0;
                    await rtb.RenderAsync(grid);

                    MainGrid.Children.Remove(grid);
                    var pixelBuffer = await rtb.GetPixelsAsync();

                    var pixels             = pixelBuffer.ToArray();
                    var displayInformation = DisplayInformation.GetForCurrentView();
                    var file = await ApplicationData.Current.LocalFolder.CreateFileAsync($"tile-{vm.Coin.Name}.png",
                                                                                         CreationCollisionOption.ReplaceExisting);

                    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) {
                        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

                        encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                             BitmapAlphaMode.Premultiplied,
                                             (uint)rtb.PixelWidth,
                                             (uint)rtb.PixelHeight,
                                             displayInformation.RawDpiX,
                                             displayInformation.RawDpiY,
                                             pixels);
                        await encoder.FlushAsync();
                    }
                }
                catch (Exception ex) {
                    var z = ex.Message;
                }

                success = await LiveTileUpdater.AddSecondaryTileAction(vm.Coin.Name);

                if (success)
                {
                    vm.Coin.IsPin = true;
                    vm.InAppNotification($"Pinned {vm.Coin.Name} to start screen");
                }
            }
        }
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            this.AssignedToTextBox.Text = SelectedSensorTag.AssignedToName;
            liveTileUpdater             = new LiveTileUpdater();
            liveTileUpdater.Start();
            startLoggedOnTimer();

            RecordingQueue.SingleRecordingQueue.OnRecordingEvent += OnRecordingQueueEvent;
        }
예제 #4
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (_baconProvider == null)
            {
                _baconProvider = new BaconProvider();
                _baconProvider.AddService(typeof(IDynamicViewLocator), new DynamicViewLocator());

                await _baconProvider.Initialize(rootFrame);

                ViewModelLocator.Initialize(_baconProvider);
            }
            else
            {
                await _baconProvider.Initialize(rootFrame);
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(_baconProvider.GetService <IDynamicViewLocator>().RedditView, args.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();

            LiveTileUpdater ltu = new LiveTileUpdater();

            ltu.RunBody(_baconProvider);
        }
        private async Task UpdateLiveTileAsync()
        {
            var list = new List <string>();

            if (DataList == null)
            {
                return;
            }

            foreach (var item in DataList)
            {
                list.Add(item.ListImageBitmap.LocalPath);
            }
            if (App.AppSettings.EnableTile && list.Count > 0)
            {
                Debug.WriteLine("About to update tile.");
                await LiveTileUpdater.UpdateImagesTileAsync(list);
            }
        }
예제 #6
0
 void liveTileUpdater_NewLiveTileGenerated(LiveTileUpdater sender, object args)
 {
     DispatchUpdateUI();
 }
예제 #7
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (_baconProvider == null)
            {
                _baconProvider = new BaconProvider(new Tuple<Type, Object>[] { new Tuple<Type, Object>(typeof(IDynamicViewLocator), new DynamicViewLocator()) });

                await _baconProvider.Initialize(rootFrame);
				var settingsService = _baconProvider.GetService<ISettingsService>();
				settingsService.AllowAdvertising = false;

                ViewModelLocator.Initialize(_baconProvider);
            }
            else
            {
                await _baconProvider.Initialize(rootFrame);
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(_baconProvider.GetService<IDynamicViewLocator>().RedditView, args.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();

            LiveTileUpdater ltu = new LiveTileUpdater();
            ltu.RunBody(_baconProvider);
        }
예제 #8
0
        public MainViewModel(TvDbSeriesRepository repository, ConnectivityService connectivityService, ReminderService reminderService, AgentScheduler agentScheduler)
        {
            this.connectivityService          = connectivityService;
            this.reminderService              = reminderService;
            this.agentScheduler               = agentScheduler;
            connectivityService.InternetDown += connectivityService_InternetDown;
            connectivityService.InternetUp   += connectivityService_InternetUp;

            Series = new SelfSortingObservableCollection <TvDbSeries, DateTime?>(s => s.NextEpisodeAirDateTime, new SoonestFirstComparer());
            repository.Subscribed   += (sender, args) => DispatcherHelper.UIDispatcher.BeginInvoke(() => Series.Add(args.Series));
            repository.Unsubscribed += (sender, args) => DispatcherHelper.UIDispatcher.BeginInvoke(() => Series.Remove(args.Series));

            AlphabeticalSortingEnabled = AppSettings.Instance.AlphabeticalSortingEnabled;

            if (!IsInDesignMode)
            {
                this.repository    = repository;
                IsSearchBoxEnabled = true;
                searchResults      = new SelfSortingObservableCollection <TvDbSeries, float>(s => s.Rating, order: SortOrder.Desc);
                ltUpdater          = new LiveTileUpdater(this);

                MessengerInstance.Register <AppSettings>(this, s => AlphabeticalSortingEnabled = s.AlphabeticalSortingEnabled);
                //series = new SelfSortingObservableCollection<TvDbSeries, string>(s => s.Title);
            }
            else if (IsInDesignMode)
            {
                searchResults = new ObservableCollection <TvDbSeries>();

                Search = "Simpsons";
                Series.Add(new TvDbSeries()
                {
                    Title    = "Futurama",
                    Image    = "http://thetvdb.com/banners/posters/73871-2.jpg",
                    Rating   = 5,
                    AirsTime = "11 PM",
                    Episodes = new ObservableCollection <TvDbSeriesEpisode>()
                    {
                        new TvDbSeriesEpisode()
                        {
                            Name          = "Episode 1",
                            FirstAired    = DateTime.Now.AddDays(14).AddHours(5),
                            SeriesNumber  = "1",
                            EpisodeNumber = "1",
                            Description   = "bla bla bla bla bla lba",
                            Image         = "http://thetvdb.com/banners/episodes/121361/3254641.jpg"
                        },
                        new TvDbSeriesEpisode()
                        {
                            Name          = "Episode 2",
                            FirstAired    = DateTime.Now.AddDays(7),
                            SeriesNumber  = "1",
                            EpisodeNumber = "2",
                            Description   = "bla bla bla bla bla lba",
                            Image         = "http://thetvdb.com/banners/episodes/121361/3254641.jpg"
                        },
                        new TvDbSeriesEpisode()
                        {
                            Name          = "Episode 1",
                            FirstAired    = DateTime.Now,
                            SeriesNumber  = "2",
                            EpisodeNumber = "1",
                            Description   = "bla bla bla bla bla lba",
                            Image         = "http://thetvdb.com/banners/episodes/121361/3254641.jpg"
                        }
                    }
                });

                Series.Add(new TvDbSeries()
                {
                    Title  = "Simpsons",
                    Image  = "http://thetvdb.com/banners/posters/71663-10.jpg",
                    Rating = 10
                });

                searchResults = series;

                AlphabeticalSortingEnabled = true;
            }
        }
예제 #9
0
        private async void PinUnpinCoin(object sender, RoutedEventArgs e)
        {
            var    card   = (HomeCard)((FrameworkElement)sender).DataContext;
            string crypto = card.Info.Name;

            var priceCard = vm.PriceCards.FirstOrDefault(c => c.Info.Name == crypto);

            if (priceCard == null)
            {
                return;
            }

            int  i       = vm.PriceCards.IndexOf(priceCard);
            bool success = false;

            if (card.Info.IsPin)
            {
                success = await LiveTileUpdater.RemoveSecondaryTileAction(crypto);

                vm.PriceCards[i].Info.IsPin = false;
                vm.InAppNotification($"Unpinned {crypto} from start screen.");
            }
            else
            {
                var grid = await LiveTileGenerator.SecondaryTileGridOperation(crypto);

                try {
                    RenderTargetBitmap rtb = new RenderTargetBitmap();
                    MainGrid.Children.Add(grid);
                    grid.Opacity = 0;
                    await rtb.RenderAsync(grid);

                    MainGrid.Children.Remove(grid);
                    var pixelBuffer = await rtb.GetPixelsAsync();

                    var pixels             = pixelBuffer.ToArray();
                    var displayInformation = DisplayInformation.GetForCurrentView();
                    var file = await ApplicationData.Current.LocalFolder.CreateFileAsync($"tile-{crypto}.png",
                                                                                         CreationCollisionOption.ReplaceExisting);

                    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) {
                        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

                        encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                             BitmapAlphaMode.Premultiplied,
                                             (uint)rtb.PixelWidth,
                                             (uint)rtb.PixelHeight,
                                             displayInformation.RawDpiX,
                                             displayInformation.RawDpiY,
                                             pixels);
                        await encoder.FlushAsync();
                    }
                }
                catch (Exception ex) {
                    var z = ex.Message;
                }


                success = await LiveTileUpdater.AddSecondaryTileAction(crypto);

                if (success)
                {
                    vm.PriceCards[i].Info.IsPin = true;
                    vm.InAppNotification($"Pinned {crypto} to start screen.");
                }
            }
        }