コード例 #1
0
 public SimpleLaunchData(LaunchData launchData)
 {
     this.LaunchId = launchData.Launch.Id;
     this.Name = launchData.Launch.Name;
     this.Description = launchData.Mission.Description ?? launchData.Launch.Missions[0].Description ?? "No mission description";
     this.Status = LaunchStatusEnum.GetLaunchStatusStringById(LaunchStatusEnum.GetLaunchStatusById(launchData.Launch.Status), TimeConverter.DetermineTimeSettings(launchData.Launch.Net, App.Settings.UseLocalTime));
     this.Net = TimeConverter.DetermineTimeSettings(launchData.Launch.Net, App.Settings.UseLocalTime);
     this.LaunchNet = launchData.Launch.Status == 2 
         ? "TBD" 
         : TimeConverter.SetStringTimeFormat(launchData.Launch.Net, App.Settings.UseLocalTime);
 }
コード例 #2
0
ファイル: WebViewModel.cs プロジェクト: threezool/LaunchPal
        private void SetLaunchWeatherPrediction(LaunchData launchData)
        {
            if (launchData.Forecast == null)
            {
                ForecastTemp = "No forecast availible";
                return;
            }

            var forecast = launchData.Forecast.List.OrderBy(t => Math.Abs((t.Date - launchData.Launch.Net).Ticks))
                             .First();

            ForecastCloud = !string.IsNullOrEmpty(forecast?.Clouds?.All.ToString()) ? "Clouds: " + forecast.Clouds?.All + "% coverage" : "Clouds: N/A";
            ForecastRain = !string.IsNullOrEmpty(forecast?.Rain?.ThreeHours.ToString()) ? "Rain: " + forecast.Rain?.ThreeHours + "mm" : "Rain: 0mm";
            ForecastWind = !string.IsNullOrEmpty(forecast?.Wind?.Speed.ToString()) ? "Wind: " + forecast.Wind?.Speed + " meter/sec" : "Wind: N/A";
            ForecastTemp = !string.IsNullOrEmpty(forecast?.Main?.Temp.ToString()) ? "Temp: " + forecast.Main?.Temp + "°C" : "Temp: N/A";
        }
コード例 #3
0
        public void AddNotification(LaunchData launchData, NotificationType type)
        {
            DeleteNotification(launchData.Launch.Id, type);

            Intent alarmIntent = new Intent(Forms.Context, typeof(AlarmReceiver));
            alarmIntent.PutExtra("id", launchData.Launch.Id.ToString());
            alarmIntent.PutExtra("title", "Launch Alert!");
            alarmIntent.PutExtra("message", $"{launchData?.Launch?.Name} is about to launch.{Environment.NewLine}" +
                                          $"Time: {TimeConverter.SetStringTimeFormat(launchData.Launch.Net, LaunchPal.App.Settings.UseLocalTime).Replace(" Local", "")}");

            PendingIntent pendingIntent = Android.App.PendingIntent.GetBroadcast(Forms.Context, launchData.Launch.Id, alarmIntent, PendingIntentFlags.UpdateCurrent);

            PendingIntent.Add(launchData.Launch.Id, pendingIntent);

            //TODO: For demo set after 5 seconds.
            AlarmManager.Set(AlarmType.ElapsedRealtime, SetTriggerTime(TimeConverter.DetermineTimeSettings(launchData.Launch.Net, App.Settings.UseLocalTime)), pendingIntent);
        }
コード例 #4
0
ファイル: WebViewModel.cs プロジェクト: threezool/LaunchPal
        public WebViewModel(int id)
        {
            LaunchData launchData = new LaunchData();

            try
            {
                launchData = CacheManager.TryGetLaunchById(id).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SetError(ex);
            }

            LaunchName = $"{launchData.Launch.Name} Launch Coverage";
            LaunchStatus = DetermineLaunchStatus(launchData);
            LaunchNet = TimeConverter.SetStringTimeFormat(launchData.Launch.Net, App.Settings.UseLocalTime);
            SetLaunchWeatherPrediction(launchData);
        }
コード例 #5
0
        public LaunchViewModel()
        {
            LaunchData launchData = new LaunchData();

            try
            {
                launchData = CacheManager.TryGetNextLaunch().Result;
                if (launchData.Forecast == null && App.Settings.SuccessfullIap)
                {
                    launchData.Forecast = ApiManager.GetForecastByCoordinates(launchData.Launch.Location.Pads[0].Latitude, launchData.Launch.Location.Pads[0].Longitude).GetAwaiter().GetResult();
                    CacheManager.TryStoreUpdatedLaunchData(launchData);
                }
            }
            catch (Exception ex)
            {
                SetError(ex);
            }

            PrepareViewModelData(launchData);
        }
コード例 #6
0
ファイル: CacheManager.cs プロジェクト: threezool/LaunchPal
        public static async Task<LaunchData> TryGetNextLaunch()
        {
            if (DateTime.Now < NextLaunch?.CacheTimeOut)
                return NextLaunch;

            var nextLaunch = await ApiManager.NextLaunch();
            var nextMission = await ApiManager.MissionByLaunchId(nextLaunch.Id);

            NextLaunch = new LaunchData
            {
                Launch = nextLaunch,
                Mission = nextMission,
                Forecast = null,
                CacheTimeOut = GetCacheTimeOutForLaunches(nextLaunch.Net)
            };

            TrackingManager.UpdateTrackedLaunches(NextLaunch);

            DependencyService.Get<INotify>().UpdateNotification(NextLaunch, NotificationType.NextLaunch);

            return NextLaunch;
        }
コード例 #7
0
 public void UpdateNotification(LaunchData launchData, NotificationType type)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
        public LaunchViewModel(int launchId)
        {
            LaunchData launchData = new LaunchData();

            try
            {
                launchData = CacheManager.TryGetLaunchById(launchId).Result;
                if (launchData.Forecast == null && (launchData.Launch.Net - DateTime.Now).TotalDays < 5 && App.Settings.SuccessfullIap)
                {
                    launchData.Forecast = ApiManager.GetForecastByCoordinates(launchData.Launch.Location.Pads[0].Latitude, launchData.Launch.Location.Pads[0].Longitude).GetAwaiter().GetResult();
                    CacheManager.TryStoreUpdatedLaunchData(launchData);
                }
                if (launchData?.Launch == null)
                {
                    throw new HttpRequestException();
                }
            }
            catch (Exception ex)
            {
                SetError(ex);
            }

            PrepareViewModelData(launchData);
        }
コード例 #9
0
 private static string SetMissionDescriptionText(LaunchData launchData)
 {
     if (!string.IsNullOrEmpty(launchData.Mission?.Description))
     {
         return launchData.Mission.Description;
     }
     else if (launchData.Launch.Missions?.Length > 0 && !string.IsNullOrEmpty(launchData.Launch.Missions?[0].Description))
     {
         return launchData.Launch.Missions[0].Description;
     }
     else
     {
         return "No mission description";
     }
 }
コード例 #10
0
ファイル: CacheManager.cs プロジェクト: threezool/LaunchPal
        public static void ClearCache()
        {
            NextLaunch = new LaunchData();
            CachedRockets = new List<CacheRocket>();
            CachedLaunches = new LaunchRangeList
            {
                CacheTimeOut = DateTime.Now.AddDays(-1),
                LaunchPairs = new List<LaunchData>()

            };
            CachedCacheNewsFeed = new CacheNews
            {
                NewsFeeds = new List<NewsFeed>(),
                CacheTimeOut = DateTime.Now
            };
            TrackedAgencies = new List<TrackedAgency>();
        }
コード例 #11
0
        public void AddNotification(LaunchData launchData, NotificationType type)
        {
            if (launchData?.Launch == null)
                return;

            var deliverytime = TimeConverter.DetermineTimeSettings(launchData.Launch.Net, true)
                .AddMinutes(-LaunchPal.App.Settings.NotifyBeforeLaunch.ToIntValue());

            if (deliverytime < DateTime.Now)
            {
                return;
            }

            switch (type)
            {
                case NotificationType.NextLaunch:
                    if (!LaunchPal.App.Settings.LaunchInProgressNotifications)
                        return;
                    break;
                case NotificationType.TrackedLaunch:
                    if (!LaunchPal.App.Settings.TrackedLaunchNotifications)
                        return;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            var groupName = GetGroupNameFromNotificationType(type);

            ToastVisual visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = "Launch Alert!"
                        },
 
                        new AdaptiveText()
                        {
                            Text = $"{launchData?.Launch?.Name} is about to launch."
                        },

                        new AdaptiveText()
                        {
                            Text = $"Time: {TimeConverter.SetStringTimeFormat(launchData.Launch.Net, LaunchPal.App.Settings.UseLocalTime).Replace(" Local", "")}"
                        }
                    },
 
                    AppLogoOverride = new ToastGenericAppLogo()
                    {
                        Source = "Assets/BadgeLogo.scale-200.png",
                        HintCrop = ToastGenericAppLogoCrop.Default
                    }
                }
            };
 

            // Now we can construct the final toast content
            ToastContent toastContent = new ToastContent()
            {
                Visual = visual,
 
                // Arguments when the user taps body of toast
                Launch = new QueryString()
                {
                    { "action", "viewLaunch" },
                    { "LaunchId", launchData?.Launch?.Id.ToString() }
 
                }.ToString(),

                Actions = new ToastActionsCustom()
                {
                    Inputs =
                    {
                        new ToastSelectionBox("snoozeTime")
                        {
                            DefaultSelectionBoxItemId = "15",
                            Items =
                            {
                                new ToastSelectionBoxItem("5", "5 minutes"),
                                new ToastSelectionBoxItem("15", "15 minutes"),
                                new ToastSelectionBoxItem("30", "30 minutes"),
                                new ToastSelectionBoxItem("45", "45 minutes"),
                                new ToastSelectionBoxItem("60", "1 hour")
                            }
                        }
                    },
                    Buttons =
                    {
                        new ToastButtonSnooze()
                        {
                            SelectionBoxId = "snoozeTime"
                        },
                        new ToastButtonDismiss()
                    }
                }
            };

            // And create the toast notification
            var scheduleToast = new ScheduledToastNotification(toastContent.GetXml(), deliverytime)
            {
                Id = launchData?.Launch?.Id.ToString() ?? "0",
                Tag = launchData?.Launch?.Id.ToString() ?? "0",
                Group = groupName,
                NotificationMirroring = NotificationMirroring.Allowed,
            };
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduleToast);
        }
コード例 #12
0
        /// <summary>
        /// Update any existing notification if the launch provided is tracked
        /// </summary>
        /// <param name="launch">A LaunchData object</param>
        public static void UpdateTrackedLaunches(LaunchData launch)
        {
            var trackedLaunch = _trackedLaunches.TrackingList.FirstOrDefault(x => x.Launch.Id == launch?.Launch?.Id);

            if (trackedLaunch == null)
                return;

            trackedLaunch = launch;

            DependencyService.Get<INotify>().UpdateNotification(trackedLaunch, NotificationType.TrackedLaunch);
        }
コード例 #13
0
 private static string SetAgencyText(LaunchData launchData)
 {
     if (launchData.Mission?.Agencies?.Length > 0 && !string.IsNullOrEmpty(launchData.Mission.Agencies?[0].Name))
     {
         return launchData.Mission.Agencies[0].Name;
     }
     else
     {
         return "No agency recorded";
     }
 }
コード例 #14
0
 private string SetRocketType(LaunchData launchData)
 {
     if (!string.IsNullOrEmpty(launchData.Launch?.Rocket?.Name))
     {
         return launchData.Launch?.Rocket?.Name;
     }
     else
     {
         return "No rocket recorded";
     }
 }
コード例 #15
0
        private static Image SetRocketImage(LaunchData launchData)
        {
            var image = CacheManager.TryGetImageFromUriAndCache(launchData.Launch.Rocket.ImageUrl);

            image.Opacity = 0.25;

            return image;
        }
コード例 #16
0
        private void PrepareViewModelData(LaunchData launchData)
        {
            _endDate = TimeConverter.DetermineTimeSettings(launchData.Launch.Net, App.Settings.UseLocalTime);

            if (launchData.Launch.Status == 2 || launchData.Launch.Status == 0 && launchData.Launch.Net.TimeOfDay.Ticks == 0)
            {
                this.LaunchTime = "TBD";
                this.MissionClock = "TBD";
            }
            else
            {
                this.LaunchTime = TimeConverter.SetStringTimeFormat(launchData.Launch.Net, App.Settings.UseLocalTime);
                Device.StartTimer(TimeSpan.FromMilliseconds(100), OnTimerTick);
            }

            this.Id = launchData.Launch.Id;
            this.Name = launchData.Launch.Name;
            this.HasLaunched = TimeConverter.DetermineTimeSettings(launchData.Launch.Net, App.Settings.UseLocalTime).AddHours(2) < DateTime.Now;
            this.LaunchStatus = LaunchStatusEnum.GetLaunchStatusById(launchData.Launch.Status);
            this.LaunchWindow = CalculateLaunchWindow(launchData.Launch.Windowstart, launchData.Launch.Windowend);
            this.Rocket = SetRocketType(launchData);
            this.RocketId = launchData.Launch.Rocket.Id;
            if (!launchData.Launch.Rocket.ImageUrl.Contains("placeholder") && App.Settings.CurrentTheme != AppTheme.Contrast)
            {
                this.RocketImage = SetRocketImage(launchData);
            }
            this.Agency = SetAgencyText(launchData);
            this.MissionType = SetMissionTypeText(launchData);
            this.LaunchSite = SetLaunchSiteName(launchData);
            this.LaunchPad = SetLaunchPad(launchData);
            this.MissionDescription = SetMissionDescriptionText(launchData);
            this.VideoUrl = new List<string>();
            SetLaunchWeatherPrediction(launchData);
            foreach (var launchVidUrL in launchData.Launch.VidURLs)
            {
                this.VideoUrl.Add(launchVidUrL);
            }
            bool beingTracked = TrackingManager.IsLaunchBeingTracked(launchData.Launch.Id);
            TrackingButtonText = beingTracked ? "Remove Tracking" : "Track Launch";
        }
コード例 #17
0
ファイル: CacheManager.cs プロジェクト: threezool/LaunchPal
        public static async Task<LaunchData> TryGetLaunchById(int id)
        {
            if (NextLaunch.Launch.Id == id)
                return NextLaunch;

            var selectedLaunch = CachedLaunches.LaunchPairs.FirstOrDefault(x => x.Launch.Id == id);

            if (selectedLaunch != null)
            {
                if (DateTime.Now < selectedLaunch.CacheTimeOut)
                {
                    if (selectedLaunch.Mission != null)
                        return selectedLaunch;

                    selectedLaunch.Mission = ApiManager.MissionById(selectedLaunch.Launch.Id).Result;
                    return selectedLaunch;
                }

                CachedLaunches.LaunchPairs.Remove(selectedLaunch);
            }

            var newLaunch = await ApiManager.NextLaunchById(id);
            var newMission = await ApiManager.MissionByLaunchId(newLaunch.Id);

            var newLaunchPair = new LaunchData
            {
                Launch = newLaunch,
                Mission = newMission,
                Forecast = null,
                CacheTimeOut = GetCacheTimeOutForLaunches(newLaunch.Net)
            };

            TrackingManager.UpdateTrackedLaunches(newLaunchPair);

            CachedLaunches.LaunchPairs.Add(newLaunchPair);
            return newLaunchPair;
        }
コード例 #18
0
ファイル: CacheManager.cs プロジェクト: threezool/LaunchPal
        public static void TryStoreUpdatedLaunchData(LaunchData launchdata)
        {
            if (NextLaunch.Launch.Id == launchdata.Launch.Id)
            {
                NextLaunch.Launch = launchdata.Launch;
                NextLaunch.Mission = launchdata.Mission;
                NextLaunch.Forecast = launchdata.Forecast;
                TrackingManager.UpdateTrackedLaunches(NextLaunch);
            }

            foreach (var cachedLaunch in CachedLaunches.LaunchPairs)
            {
                if (cachedLaunch.Launch.Id != launchdata.Launch.Id)
                    continue;

                cachedLaunch.Launch = launchdata.Launch;
                cachedLaunch.Mission = launchdata.Mission;
                cachedLaunch.Forecast = launchdata.Forecast;
            }
        }
コード例 #19
0
ファイル: WebViewModel.cs プロジェクト: threezool/LaunchPal
        private static string DetermineLaunchStatus(LaunchData launchData)
        {
            var status = LaunchStatusEnum.GetLaunchStatusById(launchData.Launch.Status);

            return LaunchStatusEnum.GetLaunchStatusStringById(status, launchData.Launch.Net);
        }
コード例 #20
0
        public void UpdateNotification(LaunchData launchData, NotificationType type)
        {
            DeleteNotification(launchData.Launch.Id, type);

            AddNotification(launchData, type);
        }
コード例 #21
0
 private string SetLaunchSiteName(LaunchData launchData)
 {
     return launchData.Launch?.Location?.Pads?.Count(x => x.Latitude != "0" && x.Longitude != "0") > 0 
         ? launchData.Launch.Location.Pads[0].Name 
         : "No launch site recorded";
 }
コード例 #22
0
 public void UpdateNotification(LaunchData launchData, NotificationType type)
 {
     AddNotification(launchData, type);
 }
コード例 #23
0
 private Pad SetLaunchPad(LaunchData launchData)
 {
     return launchData.Launch?.Location?.Pads?.Count(x => x.Latitude != "0" && x.Longitude != "0") > 0
         ? launchData.Launch.Location.Pads[0]
         : null;
 }
コード例 #24
0
 private static string SetMissionTypeText(LaunchData launchdata)
 {
     if (!string.IsNullOrEmpty(launchdata.Mission?.TypeName))
     {
         return launchdata.Mission.TypeName;
     }
     if (launchdata.Launch.Missions?.Length > 0 && !string.IsNullOrEmpty(launchdata.Launch.Missions?[0].TypeName))
     {
         return launchdata.Launch.Missions[0].TypeName;
     }
     
     return "No mission type recorded";
     
 }
コード例 #25
0
ファイル: CacheManager.cs プロジェクト: threezool/LaunchPal
        public static async Task<TrackedAgency> TryGetAgencyByType(AgencyType agencyType)
        {
            var trackedAgency = TrackedAgencies.FirstOrDefault(x => x.AgencyType == agencyType);

            if (trackedAgency?.CacheTimeOut > DateTime.Now)
                return trackedAgency;

            var agencyLaunches = await ApiManager.TryGetLaunchesBasedOnAgency(agencyType.ToAbbreviationString());

            var scheduledLaunches = new List<LaunchData>();
            var planedLaunches = new List<LaunchData>();

            foreach (var agencyLaunch in agencyLaunches)
            {
                var launchData = new LaunchData
                {
                    Launch = agencyLaunch
                };

                switch (LaunchStatusEnum.GetLaunchStatusById(launchData.Launch.Status))
                {
                    case LaunchStatus.Go:
                        scheduledLaunches.Add(launchData);
                        continue;
                    case LaunchStatus.Hold:
                        planedLaunches.Add(launchData);
                        continue;
                    case LaunchStatus.Unknown:
                        if (launchData.Launch.Net > DateTime.Now.AddDays(-7) && launchData.Launch.Net.TimeOfDay.Ticks != 0)
                        {
                            scheduledLaunches.Add(launchData);
                        }
                        else
                        {
                            planedLaunches.Add(launchData);
                        }
                        continue;
                    default:
                        continue;
                }
            }

            var newTrackedAgency = new TrackedAgency
            {
                AgencyType = agencyType,
                ScheduledLaunchData = scheduledLaunches.OrderBy(x => x.Launch.Net).ToList(),
                PlanedLaunchData = planedLaunches.OrderBy(x => x.Launch.Net).ToList(),
                CacheTimeOut = GetCacheTimeOutForLaunches(scheduledLaunches.OrderBy(x => x.Launch.Net).FirstOrDefault()?.Launch?.Net ?? DateTime.Now.AddDays(1))
            };

            TrackedAgencies.Add(newTrackedAgency);

            return newTrackedAgency;
        }