예제 #1
0
        void RetrievePrayerRequests( )
        {
            ResultView.Hide( );

            BlockerView.Show(delegate
            {
                RequestingPrayers = true;

                // request the prayers each time this appears
                RockApi.Get_PrayerRequests_Public(delegate(System.Net.HttpStatusCode statusCode, string statusDescription, List <Rock.Client.PrayerRequest> prayerRequests)
                {
                    // force this onto the main thread so that if there's a race condition in requesting prayers we won't hit it.
                    InvokeOnMainThread(delegate
                    {
                        // only process this if the view is still active. It's possible this request came in after we left the view.
                        if (ViewActive == true)
                        {
                            PrayerRequests.Clear( );
                            Carousel.Clear( );

                            RequestingPrayers = false;

                            BlockerView.Hide(null);

                            // somestimes our prayers can be received with errors in the xml, so ensure we have a valid model.
                            if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) && prayerRequests != null)
                            {
                                if (prayerRequests.Count > 0)
                                {
                                    // sort the prayers based on prayer count (least prayed for first)
                                    prayerRequests.Sort(delegate(Rock.Client.PrayerRequest x, Rock.Client.PrayerRequest y)
                                    {
                                        if (x.PrayerCount < y.PrayerCount)
                                        {
                                            return(-1);
                                        }

                                        if (x.PrayerCount > y.PrayerCount)
                                        {
                                            return(1);
                                        }

                                        return(0);
                                    });

                                    // update our timestamp since this was successful
                                    LastDownload = DateTime.Now;

                                    // setup the card positions to be to the offscreen to the left, centered on screen, and offscreen to the right
                                    for (int i = 0; i < Math.Min(prayerRequests.Count, PrivatePrayerConfig.MaxPrayers); i++)
                                    {
                                        PrayerCard card = new PrayerCard(prayerRequests[i], CardSize);
                                        PrayerRequests.Add(card);
                                        Carousel.AddCard(card.View);
                                    }
                                }
                                else
                                {
                                    ResultView.Show(PrayerStrings.ViewPrayer_StatusText_NoPrayers, null, PrayerStrings.ViewPrayer_Result_NoPrayersText, GeneralStrings.Retry);
                                }

                                // add a read analytic
                                PrayerAnalytic.Instance.Trigger(PrayerAnalytic.Read);
                            }
                            else
                            {
                                ResultView.Show(PrayerStrings.ViewPrayer_StatusText_Failed,
                                                PrivateControlStylingConfig.Result_Symbol_Failed,
                                                PrayerStrings.Error_Retrieve_Message,
                                                GeneralStrings.Retry);

                                Task.NavToolbar.SetCreateButtonEnabled(false);
                            }
                        }
                    });
                });
            });
        }
예제 #2
0
                void DownloadPrayers( )
                {
                    // protect against double requests
                    IsRequesting = true;

                    SetUIRequestingPrayers( );

                    // request the prayers each time this appears
                    RockApi.Get_PrayerRequests_Public(
                        delegate(System.Net.HttpStatusCode statusCode, string statusDescription, List <Rock.Client.PrayerRequest> prayerRequests)
                    {
                        IsRequesting = false;

                        PrayerRequestCards.Clear( );

                        // only process this if the view is still active. It's possible this request came in after we left the view.
                        if (IsActive == true)
                        {
                            ActivityIndicator.Visibility = ViewStates.Invisible;

                            if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true && prayerRequests.Count > 0)
                            {
                                // sort the prayers based on prayer count (least prayed for first)
                                prayerRequests.Sort(delegate(Rock.Client.PrayerRequest x, Rock.Client.PrayerRequest y)
                                {
                                    if (x.PrayerCount < y.PrayerCount)
                                    {
                                        return(-1);
                                    }

                                    if (x.PrayerCount > y.PrayerCount)
                                    {
                                        return(1);
                                    }

                                    return(0);
                                });

                                LastDownloadTime = DateTime.Now;

                                // success, so hide the status layer, we don't need it
                                StatusLayer.Visibility = ViewStates.Invisible;

                                // create our prayer request layouts
                                for (int i = 0; i < Math.Min(prayerRequests.Count, PrivatePrayerConfig.MaxPrayers); i++)
                                {
                                    PrayerCard prayerCard = new PrayerCard(prayerRequests[i], PrayerCardSize);
                                    PrayerRequestCards.Add(prayerCard);

                                    Carousel.AddCard(prayerCard.View);
                                }

                                // prayers received and are being viewed
                                PrayerAnalytic.Instance.Trigger(PrayerAnalytic.Read);
                            }
                            else
                            {
                                StatusLayer.Visibility = ViewStates.Visible;

                                ResultLayer.Visibility = ViewStates.Visible;
                                RetryButton.Visibility = ViewStates.Visible;

                                StatusText.Text = PrayerStrings.ViewPrayer_StatusText_Failed;
                                ResultText.Text = PrayerStrings.Error_Retrieve_Message;
                            }
                        }
                    });
                }