Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.Layer.AnchorPoint = CGPoint.Empty;
            View.BackgroundColor   = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BackgroundColor);

            // this is totally a hack, but in order to seamlessly transition from the splash screen
            // to our logo, we need to use a PER-DEVICE image. Sigh.
            string backgroundName = GetSplashBackground(UIKit.UIScreen.MainScreen.ApplicationFrame.Size, UIKit.UIScreen.MainScreen.Scale);
            string logoName       = OOBEViewController.GetSplashLogo(UIKit.UIScreen.MainScreen.ApplicationFrame.Size, UIKit.UIScreen.MainScreen.Scale);

            SplashView = new UISplash();
            SplashView.Create(View, backgroundName, logoName, true, View.Frame.ToRectF( ), delegate
            {
                Springboard.SplashComplete( );
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad( );

            TraitSize = UIScreen.MainScreen.Bounds.Size;
            CurrentTraitCollection = TraitCollection;

            // if we're on an iphone and they're holding it landscape, force a portrait traitsize
            if ( UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone && IsDeviceLandscape( ) )
            {
                UITraitCollection horzTrait = UITraitCollection.FromHorizontalSizeClass( UIUserInterfaceSizeClass.Compact );
                UITraitCollection vertTrait = UITraitCollection.FromVerticalSizeClass( UIUserInterfaceSizeClass.Regular );
                CurrentTraitCollection = UITraitCollection.FromTraitsFromCollections( new UITraitCollection[] { horzTrait, vertTrait } );

                TraitSize = new CGSize( TraitSize.Height, TraitSize.Width );
            }

            View.Layer.AnchorPoint = CGPoint.Empty;
            View.Bounds = new CGRect( View.Bounds.Left, View.Bounds.Top, TraitSize.Width, TraitSize.Height );

            // create the login controller / profile view controllers
            LoginViewController = new LoginViewController( );
            LoginViewController.Springboard = this;

            ProfileViewController = new ProfileViewController( );
            ProfileViewController.Springboard = this;

            ImageCropViewController = new ImageCropViewController( );
            ImageCropViewController.Springboard = this;

            RegisterViewController = new RegisterViewController( );
            RegisterViewController.Springboard = this;

            OOBEViewController = new OOBEViewController( );
            OOBEViewController.Springboard = this;
            OOBEViewController.View.Layer.Position = CGPoint.Empty;

            SplashViewController = new SplashViewController( );
            SplashViewController.Springboard = this;
            SplashViewController.View.Layer.Position = CGPoint.Empty;


            ScrollView = new UIScrollViewWrapper( );
            ScrollView.Layer.AnchorPoint = CGPoint.Empty;
            ScrollView.Parent = this;
            View.AddSubview( ScrollView );

            // Instantiate all activities
            float elementWidth = 250;
            float elementHeight = 45;

            NewsElement = new UIView( new CGRect( 0, 0, elementWidth, elementHeight ) );
            ScrollView.AddSubview( NewsElement );

            MessagesElement = new UIView( new CGRect( 0, 0, elementWidth, elementHeight ) );
            ScrollView.AddSubview( MessagesElement );

            GiveElement = new UIView( new CGRect( 0, 0, elementWidth, elementHeight ) );
            ScrollView.AddSubview( GiveElement );

            ConnectElement = new UIView( new CGRect( 0, 0, elementWidth, elementHeight ) );
            ScrollView.AddSubview( ConnectElement );

            PrayerElement = new UIView( new CGRect( 0, 0, elementWidth, elementHeight ) );
            ScrollView.AddSubview( PrayerElement );

            MoreElement = new UIView( new CGRect( 0, 0, elementWidth, elementHeight ) );
            ScrollView.AddSubview( MoreElement );
            //

            EditPictureButton = new UIButton( new CGRect( 0, 0, 112, 112 )  );
            ScrollView.AddSubview( EditPictureButton );

            WelcomeField = new UILabel();
            ScrollView.AddSubview( WelcomeField );

            UserNameField = new UILabel();
            ScrollView.AddSubview( UserNameField );


            ViewProfileButton = new UIButton();
            ScrollView.AddSubview( ViewProfileButton );

            ViewProfileLabel = new UILabel();
            ScrollView.AddSubview( ViewProfileLabel );
        

            Elements.Add( new SpringboardElement( this, new NewsTask( "NewsStoryboard_iPhone" )      , NewsElement    , SpringboardConfig.Element_News_Icon    , SpringboardStrings.Element_News_Title ) );
            Elements.Add( new SpringboardElement( this, new NotesTask( "NotesStoryboard_iPhone" )    , MessagesElement, SpringboardConfig.Element_Messages_Icon, SpringboardStrings.Element_Messages_Title ) );
            Elements.Add( new SpringboardElement( this, new GiveTask( "GiveStoryboard_iPhone" )      , GiveElement    , SpringboardConfig.Element_Give_Icon    , SpringboardStrings.Element_Give_Title ) );
            Elements.Add( new SpringboardElement( this, new ConnectTask( "ConnectStoryboard_iPhone" ), ConnectElement , SpringboardConfig.Element_Connect_Icon , SpringboardStrings.Element_Connect_Title ) );
            Elements.Add( new SpringboardElement( this, new PrayerTask( "PrayerStoryboard_iPhone" )  , PrayerElement  , SpringboardConfig.Element_Prayer_Icon  , SpringboardStrings.Element_Prayer_Title ) );
            Elements.Add( new SpringboardElement( this, new AboutTask( "" )                          , MoreElement    , SpringboardConfig.Element_More_Icon    , SpringboardStrings.Element_More_Title ) );

            // add a bottom seperator for the final element
            BottomSeperator = new UIView();
            BottomSeperator.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.BG_Layer_Color );
            ScrollView.AddSubview( BottomSeperator );
            BottomSeperator.Frame = new CGRect( 0, 0, View.Frame.Width, 1.0f );


            // set the profile image mask so it's circular
            CALayer maskLayer = new CALayer();
            maskLayer.AnchorPoint = new CGPoint( 0, 0 );
            maskLayer.Bounds = EditPictureButton.Layer.Bounds;
            maskLayer.CornerRadius = EditPictureButton.Bounds.Width / 2;
            maskLayer.BackgroundColor = UIColor.Black.CGColor;
            EditPictureButton.Layer.Mask = maskLayer;
            //

            // setup the campus selector and settings button
            CampusSelectionText = new UILabel();
            ControlStyling.StyleUILabel( CampusSelectionText, ControlStylingConfig.Font_Regular, ControlStylingConfig.Small_FontSize );
            CampusSelectionText.TextColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.Springboard_InActiveElementTextColor );
            ScrollView.AddSubview( CampusSelectionText );

            CampusSelectionIcon = new UILabel();
            ControlStyling.StyleUILabel( CampusSelectionIcon, PrivateControlStylingConfig.Icon_Font_Primary, ControlStylingConfig.Small_FontSize );
            CampusSelectionIcon.TextColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.Springboard_InActiveElementTextColor );
            CampusSelectionIcon.Text = PrivateSpringboardConfig.CampusSelectSymbol;
            CampusSelectionIcon.SizeToFit( );
            ScrollView.AddSubview( CampusSelectionIcon );

            CampusSelectionButton = new UIButton();
            ScrollView.AddSubview( CampusSelectionButton );
            CampusSelectionButton.TouchUpInside += SelectCampus;


            // setup the image that will display when the user is logged in
            ProfileImageView = new UIImageView( );
            ProfileImageView.ContentMode = UIViewContentMode.ScaleAspectFit;

            ProfileImageView.Layer.AnchorPoint = CGPoint.Empty;
            ProfileImageView.Bounds = EditPictureButton.Bounds;
            ProfileImageView.Layer.Position = CGPoint.Empty;
            EditPictureButton.AddSubview( ProfileImageView );

            EditPictureButton.Font = Rock.Mobile.PlatformSpecific.iOS.Graphics.FontManager.GetFont( PrivateControlStylingConfig.Icon_Font_Primary, PrivateSpringboardConfig.ProfileSymbolFontSize );
            EditPictureButton.SetTitleColor( Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.Springboard_InActiveElementTextColor ), UIControlState.Normal );
            EditPictureButton.Layer.BorderColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.Springboard_InActiveElementTextColor ).CGColor;
            EditPictureButton.Layer.CornerRadius = EditPictureButton.Bounds.Width / 2;
            EditPictureButton.Layer.BorderWidth = 4;

            WelcomeField.Font = Rock.Mobile.PlatformSpecific.iOS.Graphics.FontManager.GetFont( ControlStylingConfig.Font_Light, ControlStylingConfig.Large_FontSize );
            WelcomeField.TextColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.Springboard_InActiveElementTextColor );

            UserNameField.Font = Rock.Mobile.PlatformSpecific.iOS.Graphics.FontManager.GetFont( ControlStylingConfig.Font_Bold, ControlStylingConfig.Large_FontSize );
            UserNameField.TextColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.Springboard_InActiveElementTextColor );

            View.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.Springboard_BackgroundColor );

            AddChildViewController( NavViewController );
            View.AddSubview( NavViewController.View );

            SetNeedsStatusBarAppearanceUpdate( );

            EditPictureButton.TouchUpInside += (object sender, EventArgs e) => 
                {
                    // don't allow launching a model view controller unless the springboard is open.
                    if ( NavViewController.IsSpringboardOpen( ) )
                    {
                        if( RockMobileUser.Instance.LoggedIn == true )
                        {
                            // they're logged in, so let them set their profile pic
                            ManageProfilePic( );
                        }
                        else
                        {
                            //otherwise this button can double as a login button.
                            PresentModalViewController( LoginViewController );
                        }
                    }
                };
            
            ViewProfileButton.TouchUpInside += (object sender, EventArgs e) => 
                {
                    // don't allow launching a model view controller unless the springboard is open.
                    if ( NavViewController.IsSpringboardOpen( ) )
                    {
                        if( RockMobileUser.Instance.LoggedIn == true )
                        {
                            // Because we aren't syncing RIGHT HERE, Rock data could technically be overwritten.
                            // If WHILE they're running the app, their data is updated in Rock, those changes will
                            // be lost when they submit their profile changes.
                            // But, the odds that Rock data will update WHILE THE APP IS RUNNING, and they then decide to
                            // update their profile without having even backgrounded the app, are extremely low.
                            PresentModalViewController( ProfileViewController );
                        }
                        else
                        {
                            PresentModalViewController( LoginViewController );
                        }
                    }
                };

            // load our objects from disk
            Rock.Mobile.Util.Debug.WriteLine( "Loading objects from device." );
            RockNetworkManager.Instance.LoadObjectsFromDevice( );
            Rock.Mobile.Util.Debug.WriteLine( "Loading objects done." );

            // set the viewing campus now that their profile has loaded (if they have already done the OOBE)
            CampusSelectionText.Text = string.Format( SpringboardStrings.Viewing_Campus, RockGeneralData.Instance.Data.CampusIdToName( RockMobileUser.Instance.ViewingCampus ) ).ToUpper( );
            CampusSelectionText.SizeToFit( );

            // seed the last sync time with now, so that when OnActivated gets called we don't do it again.
            LastRockSync = DateTime.Now;

            // setup the Notification Banner for Taking Notes
            Billboard = new NotificationBillboard( View.Bounds.Width, View.Bounds.Height );
            Billboard.SetLabel( SpringboardStrings.TakeNotesNotificationIcon, 
                                PrivateControlStylingConfig.Icon_Font_Primary,
                                ControlStylingConfig.Small_FontSize,
                                SpringboardStrings.TakeNotesNotificationLabel, 
                                ControlStylingConfig.Font_Light,
                                ControlStylingConfig.Small_FontSize,
                                ControlStylingConfig.TextField_ActiveTextColor, 
                                ControlStylingConfig.Springboard_Element_SelectedColor, 
                delegate 
                {
                    // find the Notes task, activate it, and tell it to jump to the read page.
                    foreach( SpringboardElement element in Elements )
                    {
                        if ( element.Task as NotesTask != null )
                        {
                            ActivateElement( element, true );
                            PerformTaskAction( PrivateGeneralConfig.TaskAction_NotesRead );
                        }
                    }
                } 
            );

            Billboard.Layer.Position = new CGPoint( Billboard.Layer.Position.X, NavViewController.NavigationBar.Frame.Height );


            // only do the OOBE if the user hasn't seen it yet
            if ( RockMobileUser.Instance.OOBEComplete == false )
            //if( RanOOBE == false )
            {
                // sanity check for testers that didn't listen to me and delete / reinstall.
                // This will force them to be logged out so they experience the OOBE properly.
                RockMobileUser.Instance.LogoutAndUnbind( );

                //RanOOBE = true;
                IsOOBERunning = true;
                AddChildViewController( OOBEViewController );
                View.AddSubview( OOBEViewController.View );
            }
            else
            {
                // kick off the splash screen animation
                AddChildViewController( SplashViewController );
                View.AddSubview( SplashViewController.View );
            }
        }