コード例 #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 RetrievePrayerRequests( )
        {
            // show the retrieve layer
            RetrievingPrayersView.Layer.Opacity = 1.00f;
            StatusLabel.Text = PrayerStrings.ViewPrayer_StatusText_Retrieving;
            ResultLabel.Hidden = true;
            RetryButton.Hidden = true;

            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) 
                                                    {
                                                        return x.PrayerCount < y.PrayerCount ? -1 : 1;
                                                    });
                                                
                                                // update our timestamp since this was successful
                                                LastDownload = DateTime.Now;

                                                RetrievingPrayersView.Layer.Opacity = 0.00f;

                                                // 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
                                            {
                                                // let them know there aren't any prayer requests
                                                StatusLabel.Text = PrayerStrings.ViewPrayer_StatusText_NoPrayers;
                                                RetryButton.Hidden = false;
                                                ResultLabel.Hidden = false;
                                                ResultLabel.Text = PrayerStrings.ViewPrayer_Result_NoPrayersText;
                                            }

                                            // add a read analytic
                                            PrayerAnalytic.Instance.Trigger( PrayerAnalytic.Read );
                                        }
                                        else
                                        {
                                            StatusLabel.Text = PrayerStrings.ViewPrayer_StatusText_Failed;
                                            RetryButton.Hidden = false;
                                            ResultLabel.Hidden = false;
                                            ResultLabel.Text = PrayerStrings.Error_Retrieve_Message;

                                            Task.NavToolbar.SetCreateButtonEnabled( false );
                                        }
                                    }
                                } );
                        } );
                } );
        }