Inheritance: GalaSoft.MvvmLight.ObservableObject
Exemplo n.º 1
0
 public async void AddStationToRefreshingPool(Station station)
 {
     if (!station.Loaded)
     {
         var contract = station.Contract;
         if (contract != null)
         {
             if (await contract.RefreshAsync(station).ConfigureAwait(false))
             {
                 if (station.IsUiRefreshNeeded)
                 {
                     StationRefreshed?.Invoke(station, EventArgs.Empty);
                 }
             }
             if (contract.ImageAvailability)
             {
                 station.IsInRefreshPool = true;
                 refreshingPool.Add(station);
                 if (!IsStationWorkerRunning)
                 {
                     StartRefreshStationsAsync();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Helper method to provide the corresponding Icon for a station
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public BitmapDescriptor CreateStationIcon(Station station)
        {
            Bitmap bitmap = null;
            var value = _settingsService.Settings.IsBikeMode ? station.AvailableBikes : station.AvailableBikeStands;
            var printedValue = value.HasValue ? value.Value.ToString() : string.Empty;
            if (!station.Loaded)
            {
                printedValue = string.Empty;
                bitmap = _iconGreyLowAlpha;
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
            }
            else if (station.Status == false)
            {
                printedValue = "!";
                bitmap = _iconGrey;
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
            }
            else if (station.ImageAvailable != null || station.ImageDocks != null)
            {
                if (_metrics == null)
                {
                    _metrics = new DisplayMetrics();
                    (CrossCurrentActivity.Current.Activity as MainActivity).WindowManager.DefaultDisplay.GetMetrics(_metrics);
                }

                bitmap = _iconGrey;
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
                try
                {
                    var data = (byte[])(_settingsService.Settings.IsBikeMode ? station.ImageAvailable : station.ImageDocks);
                    var gifDecoder = new GifDecoder();
                    gifDecoder.read(data);
                    if (gifDecoder.getFrameCount() != 0)
                    {
                        gifDecoder.advance();
                        var bmp = gifDecoder.getNextFrame();
                        var canvas = new Canvas(bitmap);

                        int width = bmp.Width;
                        int height = bmp.Height;
                        float scaleWidth = _metrics.ScaledDensity;
                        float scaleHeight = _metrics.ScaledDensity;
                        // create a matrix for the scaling manipulation
                        Matrix matrix = new Matrix();
                        // resize the bitmap
                        matrix.PostScale(scaleWidth, scaleHeight);

                        // recreate the new Bitmap
                        var resizedBitmap = Bitmap.CreateBitmap(bmp, 0, 0, width, height, matrix, true);

                        int xPos = canvas.Width / 2 - resizedBitmap.Width / 2;
                        int yPos = canvas.Height / 2 - resizedBitmap.Height;
                        canvas.DrawBitmap(resizedBitmap, xPos, yPos, null);
                    }

                }
                catch (System.Exception e)
                {
                }

            }
            else {
                if (value == 0)
                {
                    bitmap = _iconRed;
                }
                else if (value < 5)
                {
                    bitmap = _iconOrange;
                }
                else if (value >= 5)
                {
                    bitmap = _iconGreen;
                }
                else
                {
                    printedValue = "?";
                    bitmap = _iconGrey;
                }
            }

            if (printedValue != string.Empty)
            {
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
                Canvas canvas = new Canvas(bitmap);
                int xPos = (canvas.Width / 2);
                int yPos = (int)((canvas.Height / 2) - ((_textPaint.Descent() + _textPaint.Ascent()) / 2));
                canvas.DrawText(printedValue, xPos + 1, yPos - LayoutHelper.ConvertDpToPixel(6), _textPaint);
            }

            var icon = BitmapDescriptorFactory.FromBitmap(bitmap);
            bitmap.Recycle();
            return icon;
        }
Exemplo n.º 3
0
 public virtual async Task<StationModelBase> InnerRefreshAsync(Station station)
 {
     return null;
 }
Exemplo n.º 4
0
        public async Task<bool> RefreshAsync(Station station)
        {
            if(retryStation > 10 && retryStation%30 != 0)
            {
                retryStation++;
                return false;
            }
            try
            {
                var refreshedStation = await InnerRefreshAsync(station).ConfigureAwait(false);
                // case where the availability comes from images (China)
                if(refreshedStation == null)
                {
                    retryStation = 0;
                    return true;
                }
                if (station.AvailableBikes != refreshedStation.AvailableBikes || station.AvailableBikeStands != refreshedStation.AvailableBikeStands)
                {
                    station.IsUiRefreshNeeded = true;
                    station.AvailableBikes = refreshedStation.AvailableBikes;
                    station.AvailableBikeStands = refreshedStation.AvailableBikeStands;
                }
                if (!station.Loaded)
                {
                    station.Loaded = true;
                    station.IsUiRefreshNeeded = true;
                }
               
                retryStation = 0;
                return true;
            }
            catch(Exception e)
            {
                retryStation++;
                //if(retryStation == 10) 
                //{
                //    //var contractService = SimpleIoc.Default.GetInstance<IContractService>();
                //    //contractService.
                //    var notificationService = SimpleIoc.Default.GetInstance<INotificationService>();
                //    try
                //    {
                //        notificationService.Notify(new RefreshFailureNotification()
                //        {
                //            Body = "You seems to struggle getting the stations information. It may be either that your network connection isn't healthy, the service provider is down or it has changed. If you think it could be the last option, then contact us and we will investigate. Thumbs up !",
                //            Subject = "Hey !",
                //            ContractName = station.Contract.Name,
                //            Exception = e
                //        });
                //    }
                //    catch
                //    {
                //        // Ignore
                //    }
                //}
            }

            return true;
        }
Exemplo n.º 5
0
 public void RemoveStationFromRefreshingPool(Station station)
 {
     refreshingPool.Remove(station);
     station.IsInRefreshPool = false;
 }
 public void RemoveStationFromRefreshingPool(Station station)
 {
 }
 public void AddStationToRefreshingPool(Station station)
 {
 }
Exemplo n.º 8
0
 private async void RefreshStation(Station station, Marker control)
 {
     try
     {
         station.IsUiRefreshNeeded = false;
         // this can raise a IllegalArgumentException: Released unknown imageData reference
         // as the marker may not be on the map anymore so better to check again for null ref
         control.SetIcon(_clusterRender.CreateStationIcon(station));
     }
     catch
     {
     }
 }