Inheritance: Cirrious.MvvmCross.Droid.Fragging.Fragments.MvxFragment
Exemplo n.º 1
0
        protected override void OnViewModelSet()
        {
            //this.Parent.RequestWindowFeature (WindowFeatures.NoTitle);

            //RequestWindowFeature (WindowFeatures.NoTitle);

            homeViewModel = (HomeViewModel)ViewModel;

            SetContentView(Resource.Layout.Content_Frame);

            MenuId = Resource.Menu.HomeMenu;


            LegacyBar = FindViewById <LegacyBar.Library.Bar.LegacyBar>(Resource.Id.actionbar);

            //LegacyBar.SetHomeLogo(Resource.Drawable.jabbr_home_icon);
            AddHomeAction(() => {
                slidingMenu.Toggle();
            }, Resource.Drawable.jabbr_home_icon);

            LegacyBar.Click += (sender, e) => {
                slidingMenu.Toggle();
            };
            LegacyBar.Title = "JabbR";



            slidingMenu = new SlidingMenu(this)
            {
                Mode                       = MenuMode.LeftRight,
                TouchModeAbove             = TouchMode.Fullscreen,
                BehindOffset               = 80,
                ShadowWidth                = 20,
                ShadowDrawableRes          = Resource.Drawable.SlidingMenuShadow,
                SecondaryShadowDrawableRes = Resource.Drawable.SlidingMenuShadowRight
            };

            slidingMenu.AttachToActivity(this, SlideStyle.Content);
            slidingMenu.SetMenu(Resource.Layout.Menu_Frame);
            //slidingMenu.ShadowDrawableRes = Resource.Drawable.SlidingMenuShadow;

            menuFragment           = new MenuFragment();
            menuFragment.ViewModel = ViewModel;

            SupportFragmentManager.BeginTransaction()
            .Replace(Resource.Id.menu_frame, menuFragment).Commit();

            slidingMenu.SetSecondaryMenu(Resource.Layout.UserList_Frame);
            //slidingMenu.SecondaryShadowDrawableRes = Resource.Drawable.SlidingMenuShadowRight;

            emptyFragment           = new EmptyFragment();
            emptyFragment.ViewModel = this.ViewModel;

            SupportFragmentManager.BeginTransaction()
            .Replace(Resource.Id.content_frame, emptyFragment).Commit();


            //TODO: Put some kind of default view in the chat fragment space

            homeViewModel.PropertyChanged += (sender, e) => {
                Console.WriteLine("PropertyChanged: " + e.PropertyName);

                if (e.PropertyName == "CurrentRoom")
                {
                    if (homeViewModel.CurrentRoom == null)
                    {
                        if (emptyFragment == null)
                        {
                            emptyFragment = new EmptyFragment();
                        }

                        chatFragment = null;

                        SupportFragmentManager.BeginTransaction()
                        .Replace(Resource.Id.content_frame, emptyFragment).Commit();

                        LegacyBar.Title = "JabbR";

                        showActions = false;
                        ToggleActions();

                        userListFragment.ViewModel = null;

                        SupportFragmentManager.BeginTransaction()
                        .Replace(Resource.Id.userlist_frame, userListFragment).Commit();
                        return;
                    }

                    showActions = true;


                    if (chatFragment == null)
                    {
                        chatFragment           = new ChatFragment();
                        chatFragment.ViewModel = homeViewModel.CurrentRoom;

                        SupportFragmentManager.BeginTransaction()
                        .Replace(Resource.Id.content_frame, chatFragment).Commit();
                    }
                    else
                    {
                        chatFragment.ViewModel = homeViewModel.CurrentRoom;
                    }

                    if (userListFragment == null)
                    {
                        userListFragment           = new UserListFragment();
                        userListFragment.ViewModel = homeViewModel.CurrentRoom;

                        SupportFragmentManager.BeginTransaction()
                        .Replace(Resource.Id.userlist_frame, userListFragment).Commit();
                    }
                    else
                    {
                        userListFragment.ViewModel = homeViewModel.CurrentRoom;
                    }


                    ToggleActions();

                    slidingMenu.Toggle();

                    this.RunOnUiThread(() => LegacyBar.Title = homeViewModel.CurrentRoom.Room.Name);
                }
            };

            messenger = Mvx.Resolve <IMvxMessenger> ();
            _mvxMsgTokUserSelected = messenger.SubscribeOnMainThread <UserSelectedMessage> (msg => {
                chatFragment.AppendText("@" + msg.User.Name);

                slidingMenu.ShowContent(true);
            });
        }
Exemplo n.º 2
0
        protected override void OnViewModelSet()
        {
            //this.Parent.RequestWindowFeature (WindowFeatures.NoTitle);

            //RequestWindowFeature (WindowFeatures.NoTitle);

            homeViewModel = (HomeViewModel)ViewModel;

            SetContentView (Resource.Layout.Content_Frame);

            MenuId = Resource.Menu.HomeMenu;

            LegacyBar = FindViewById<LegacyBar.Library.Bar.LegacyBar>(Resource.Id.actionbar);

            //LegacyBar.SetHomeLogo(Resource.Drawable.jabbr_home_icon);
            AddHomeAction (() => {
                slidingMenu.Toggle();
            }, Resource.Drawable.jabbr_home_icon);

            LegacyBar.Click += (sender, e) => {
                slidingMenu.Toggle();
            };
            LegacyBar.Title = "JabbR";

            slidingMenu = new SlidingMenu (this) {
                Mode = MenuMode.LeftRight,
                TouchModeAbove = TouchMode.Fullscreen,
                BehindOffset = 80,
                ShadowWidth = 20,
                ShadowDrawableRes = Resource.Drawable.SlidingMenuShadow,
                SecondaryShadowDrawableRes = Resource.Drawable.SlidingMenuShadowRight
            };

            slidingMenu.AttachToActivity (this, SlideStyle.Content);
            slidingMenu.SetMenu (Resource.Layout.Menu_Frame);
            //slidingMenu.ShadowDrawableRes = Resource.Drawable.SlidingMenuShadow;

            menuFragment = new MenuFragment ();
            menuFragment.ViewModel = ViewModel;

            SupportFragmentManager.BeginTransaction ()
                .Replace (Resource.Id.menu_frame, menuFragment).Commit ();

            slidingMenu.SetSecondaryMenu (Resource.Layout.UserList_Frame);
            //slidingMenu.SecondaryShadowDrawableRes = Resource.Drawable.SlidingMenuShadowRight;

            emptyFragment = new EmptyFragment ();
            emptyFragment.ViewModel = this.ViewModel;

            SupportFragmentManager.BeginTransaction ()
                .Replace (Resource.Id.content_frame, emptyFragment).Commit ();

            //TODO: Put some kind of default view in the chat fragment space

            homeViewModel.PropertyChanged += (sender, e) => {

                Console.WriteLine("PropertyChanged: "+  e.PropertyName);

                if (e.PropertyName == "CurrentRoom")
                {
                    if (homeViewModel.CurrentRoom == null)
                    {
                        if (emptyFragment == null)
                            emptyFragment = new EmptyFragment();

                        chatFragment = null;

                        SupportFragmentManager.BeginTransaction ()
                            .Replace (Resource.Id.content_frame, emptyFragment).Commit ();

                        LegacyBar.Title = "JabbR";

                        showActions = false;
                        ToggleActions();

                        userListFragment.ViewModel = null;

                        SupportFragmentManager.BeginTransaction ()
                            .Replace (Resource.Id.userlist_frame, userListFragment).Commit ();
                        return;
                    }

                    showActions = true;

                    if (chatFragment == null)
                    {
                        chatFragment = new ChatFragment();
                        chatFragment.ViewModel = homeViewModel.CurrentRoom;

                        SupportFragmentManager.BeginTransaction()
                            .Replace(Resource.Id.content_frame, chatFragment).Commit();
                    }
                    else
                    {
                        chatFragment.ViewModel = homeViewModel.CurrentRoom;
                    }

                    if (userListFragment == null)
                    {
                        userListFragment = new UserListFragment();
                        userListFragment.ViewModel = homeViewModel.CurrentRoom;

                        SupportFragmentManager.BeginTransaction ()
                            .Replace (Resource.Id.userlist_frame, userListFragment).Commit ();

                    }
                    else
                    {
                        userListFragment.ViewModel = homeViewModel.CurrentRoom;
                    }

                    ToggleActions();

                    slidingMenu.Toggle();

                    this.RunOnUiThread(() => LegacyBar.Title = homeViewModel.CurrentRoom.Room.Name);
                }
            };

            messenger = Mvx.Resolve<IMvxMessenger> ();
            _mvxMsgTokUserSelected = messenger.SubscribeOnMainThread<UserSelectedMessage> (msg => {
                chatFragment.AppendText("@" + msg.User.Name);

                slidingMenu.ShowContent(true);
            });
        }