Example #1
0
 private void ViewModelOnMediaElementCollapsed()
 {
     MainPageVideoView.StopPlayback();
     MainPageVideoView.SetMediaController(null);
     MainPageVideoView.SetVideoURI(null);
 }
Example #2
0
        private void InitBindings()
        {
            Bindings.Add(
                this.SetBinding(() => ViewModel.CurrentStatus,
                                () => MainPageCurrentStatus.Text));


            Bindings.Add(
                this.SetBinding(() => ViewModel.RefreshButtonVisibility,
                                () => MainPageRefreshButton.Visibility).ConvertSourceToTarget(Converters.BoolToVisibility));
            MainPageRefreshButton.Click += (sender, args) => ViewModel.RefreshDataCommand.Execute(null);

            Bindings.Add(
                this.SetBinding(() => ViewModel.SearchToggleVisibility,
                                () => MainPageSearchView.Visibility).ConvertSourceToTarget(Converters.BoolToVisibility));
            Bindings.Add(
                this.SetBinding(() => ViewModel.SearchInputVisibility).WhenSourceChanges(() =>
            {
                MainPageSearchView.Iconified = !ViewModel.SearchInputVisibility;
                if (ViewModel.SearchInputVisibility)
                {
                    MainPageSearchView.SetQuery(ViewModel.CurrentSearchQuery, false);
                }
                MainPageSearchView.ClearFocus();
            }));


            Bindings.Add(this.SetBinding(() => ViewModel.CurrentStatusSub).WhenSourceChanges(() =>
            {
                MainPageCurrentSatusSubtitle.Text = ViewModel.CurrentStatusSub;
                if (string.IsNullOrEmpty(ViewModel.CurrentStatusSub))
                {
                    MainPageCurrentSatusSubtitle.Visibility = ViewStates.Gone;
                    MainPageCurrentStatus.SetMaxLines(2);
                }
                else
                {
                    MainPageCurrentSatusSubtitle.Visibility = ViewStates.Visible;
                    MainPageCurrentStatus.SetMaxLines(1);
                }
            }));

            _searchFrame = MainPageSearchView.FindViewById(Resource.Id.search_edit_frame);

            Bindings.Add(this.SetBinding(() => ViewModel.SearchToggleLock).WhenSourceChanges(
                             () =>
            {
                if (ViewModel.SearchToggleLock)
                {
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Alpha     = 0;
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Clickable = false;
                    if (ViewModel.CurrentMainPage == PageIndex.PageSearch)
                    {
                        InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                        imm.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.NotAlways);
                    }
                }
                else
                {
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Alpha     = 1;
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Clickable = true;
                }
            }));

            //MainPageSearchView.LayoutChange += MainPageSearchViewOnLayoutChange;

            //var padding = (int)(11*Resources.DisplayMetrics.Density);
            //searchBtn.SetScaleType(ImageView.ScaleType.FitEnd);
            //searchBtn.SetPadding(padding, padding, padding, padding);
            var observer       = _searchFrame.ViewTreeObserver;
            var prevVisibility = _searchFrame.Visibility;

            observer.GlobalLayout += (sender, args) =>
            {
                if (prevVisibility == _searchFrame.Visibility)
                {
                    return;
                }
                prevVisibility = _searchFrame.Visibility;
                MainPageCurrentStatus.Visibility = Converters.VisibilityInverterConverter(_searchFrame.Visibility);
                var param = MainPageSearchView.LayoutParameters as LinearLayout.LayoutParams;
                Debug.WriteLine(_searchFrame.Visibility);
                if (_searchFrame.Visibility == ViewStates.Visible)
                {
                    var diff = ViewModel.SearchToggleStatus != true;
                    ViewModel.SearchToggleStatus = true;
                    param.Width = ViewGroup.LayoutParams.MatchParent;
                    param.SetMargins(0, 0, DimensionsHelper.DpToPx(20), 0);
                    param.Weight = 1;
                    if (diff)
                    {
                        MainPageSearchView.RequestFocusFromTouch();
                        InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                        imm.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.None);
                    }
                }
                else
                {
                    var diff = ViewModel.SearchToggleStatus != false;
                    ViewModel.SearchToggleStatus = false;
                    param.Width = (int)DimensionsHelper.DpToPx(50);
                    param.SetMargins(0, 0, 0, 0);
                    param.Weight = 0;
                    if (diff)
                    {
                        InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                        imm.HideSoftInputFromWindow(MainPageSearchView.WindowToken, HideSoftInputFlags.None);
                    }
                }
            };

            _searchSuggestionAdapter = new SimpleCursorAdapter(this, Resource.Layout.SuggestionItem,
                                                               null, new string[] { "hint" }, new int[]
            {
                Resource.Id.SuggestionItemTextView
            });

            //
            MainPageStatusContainer.SetOnClickListener(new OnClickListener(view =>
            {
                if (ViewModel.CurrentMainPage == PageIndex.PageAnimeList)
                {
                    if (ViewModelLocator.AnimeList.WorkMode == AnimeListWorkModes.SeasonalAnime)
                    {
                        _upperFilterMenu = FlyoutMenuBuilder.BuildGenericFlyout(this, MainPageCurrentStatus,
                                                                                ViewModelLocator.AnimeList.SeasonSelection.Select(season => season.Name).ToList(),
                                                                                OnUpperStatusSeasonSelected);
                    }
                    else
                    {
                        _upperFilterMenu = AnimeListPageFlyoutBuilder.BuildForAnimeStatusSelection(this, MainPageCurrentStatus,
                                                                                                   OnUpperFlyoutStatusChanged, (AnimeStatus)ViewModelLocator.AnimeList.CurrentStatus,
                                                                                                   ViewModelLocator.AnimeList.IsMangaWorkMode);
                    }

                    _upperFilterMenu.Show();
                }
            }));


            Bindings.Add(this.SetBinding(() => ViewModel.MediaElementVisibility)
                         .WhenSourceChanges(() =>
            {
                if (ViewModel.MediaElementVisibility)
                {
                    MainPageVideoViewContainer.Visibility = ViewStates.Visible;
                    MainPageVideoView.Visibility          = ViewStates.Visible;
                    MainUpperNavBar.Visibility            = ViewStates.Gone;
                    MainPageVideoView.SetZOrderOnTop(true);
                    _drawer?.DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed);
                }
                else
                {
                    MainPageVideoViewContainer.Visibility = ViewStates.Gone;
                    MainPageVideoView.Visibility          = ViewStates.Gone;
                    MainUpperNavBar.Visibility            = ViewStates.Visible;
                    MainPageVideoView.SetZOrderOnTop(false);
                    _drawer?.DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeUnlocked);
                    ViewModelLocator.NavMgr.ResetOneTimeOverride();
                }
            }));



            Bindings.Add(
                this.SetBinding(() => ViewModel.MediaElementSource).WhenSourceChanges(() =>
            {
                if (string.IsNullOrEmpty(ViewModel.MediaElementSource))
                {
                    return;
                }

                var mediaController = new MediaController(this);
                mediaController.SetAnchorView(MainPageVideoView);
                MainPageVideoView.SetMediaController(mediaController);
                MainPageVideoView.SetVideoURI(Uri.Parse(ViewModel.MediaElementSource));
                MainPageVideoView.RequestFocus();
            }));

            MainPageSearchView.SuggestionsAdapter = _searchSuggestionAdapter;
            MainPageSearchView.QueryTextChange   += MainPageSearchViewOnQueryTextChange;
            MainPageSearchView.QueryTextSubmit   += MainPageSearchViewOnQueryTextSubmit;
            MainPageSearchView.SuggestionClick   += MainPageSearchViewOnSuggestionClick;
            MainPageCloseVideoButton.Click       += MainPageCloseVideoButtonOnClick;
            MainPageCopyVideoLinkButton.Click    += MainPageCopyVideoLinkButtonOnClick;
            MainPageVideoView.Prepared           += MainPageVideoViewOnPrepared;
            MainPageSearchView.Visibility         = ViewStates.Visible;
            ((EditText)MainPageSearchView.FindViewById(Resource.Id.search_src_text)).SetTextColor(Color.White);


            MainPageHamburgerButton.Click += MainPageHamburgerButtonOnClick;
            ViewModel.PropertyChanged     += ViewModelOnPropertyChanged;
            BuildDrawer();
            _drawer.OnDrawerItemClickListener = new HamburgerItemClickListener(OnHamburgerItemClick);

            MainPageCloseVideoButton.SetZ(0);
            MainPageCopyVideoLinkButton.SetZ(0);
        }
Example #3
0
        private void InitBindings()
        {
            Bindings.Add(MainPageCurrentStatus.Id, new List <Binding>());
            Bindings[MainPageCurrentStatus.Id].Add(
                this.SetBinding(() => ViewModel.CurrentStatus,
                                () => MainPageCurrentStatus.Text));

            Bindings.Add(MainPageRefreshButton.Id, new List <Binding>());
            Bindings[MainPageRefreshButton.Id].Add(
                this.SetBinding(() => ViewModel.RefreshButtonVisibility,
                                () => MainPageRefreshButton.Visibility).ConvertSourceToTarget(Converters.BoolToVisibility));

            Bindings.Add(MainPageSearchView.Id, new List <Binding>());
            Bindings[MainPageSearchView.Id].Add(
                this.SetBinding(() => ViewModel.SearchToggleVisibility,
                                () => MainPageSearchView.Visibility).ConvertSourceToTarget(Converters.BoolToVisibility));
            Bindings[MainPageSearchView.Id].Add(
                this.SetBinding(() => ViewModel.SearchInputVisibility).WhenSourceChanges(() =>
            {
                MainPageSearchView.Iconified = !ViewModel.SearchInputVisibility;
                if (ViewModel.SearchInputVisibility)
                {
                    MainPageSearchView.SetQuery(ViewModel.CurrentSearchQuery, false);
                }
                MainPageSearchView.ClearFocus();
            }));

            Bindings.Add(MainPageCurrentSatusSubtitle.Id, new List <Binding>());
            Bindings[MainPageCurrentSatusSubtitle.Id].Add(
                this.SetBinding(() => ViewModel.CurrentStatusSub,
                                () => MainPageCurrentSatusSubtitle.Text));

            _searchFrame = MainPageSearchView.FindViewById(Resource.Id.search_edit_frame);

            Bindings[MainPageSearchView.Id].Add(this.SetBinding(() => ViewModel.SearchToggleLock).WhenSourceChanges(
                                                    () =>
            {
                if (ViewModel.SearchToggleLock)
                {
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Alpha     = 0;
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Clickable = false;
                }
                else
                {
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Alpha     = 1;
                    MainPageSearchView.FindViewById(Resource.Id.search_close_btn).Clickable = true;
                }
            }));

            //MainPageSearchView.LayoutChange += MainPageSearchViewOnLayoutChange;

            //var padding = (int)(11*Resources.DisplayMetrics.Density);
            //searchBtn.SetScaleType(ImageView.ScaleType.FitEnd);
            //searchBtn.SetPadding(padding, padding, padding, padding);
            var observer = _searchFrame.ViewTreeObserver;

            observer.GlobalLayout += (sender, args) =>
            {
                MainPageCurrentStatus.Visibility = Converters.VisibilityInverterConverter(_searchFrame.Visibility);
                var param = MainPageSearchView.LayoutParameters as LinearLayout.LayoutParams;
                if (_searchFrame.Visibility == ViewStates.Visible)
                {
                    ViewModel.SearchToggleStatus = true;
                    param.Width  = ViewGroup.LayoutParams.WrapContent;
                    param.Weight = 1;
                }
                else
                {
                    ViewModel.SearchToggleStatus = false;
                    param.Width  = (int)DimensionsHelper.DpToPx(50);
                    param.Weight = 0;
                }
            };

            _searchSuggestionAdapter = new SimpleCursorAdapter(this, Resource.Layout.SuggestionItem,
                                                               null, new string[] { "hint" }, new int[]
            {
                Resource.Id.SuggestionItemTextView
            });

            //
            MainPageCurrentStatus.Clickable = true;
            MainPageCurrentStatus.SetOnClickListener(new OnClickListener(view =>
            {
                if (ViewModel.CurrentMainPage == PageIndex.PageAnimeList)
                {
                    _upperFilterMenu = AnimeListPageFlyoutBuilder.BuildForAnimeStatusSelection(this, MainPageCurrentStatus,
                                                                                               OnUpperFlyoutStatusChanged, (AnimeStatus)ViewModelLocator.AnimeList.CurrentStatus,
                                                                                               ViewModelLocator.AnimeList.IsMangaWorkMode);
                    _upperFilterMenu.Show();
                }
            }));



            Bindings.Add(MainPageVideoViewContainer.Id, new List <Binding>());
            Bindings[MainPageVideoViewContainer.Id].Add(
                this.SetBinding(() => ViewModel.MediaElementVisibility,
                                () => MainPageVideoViewContainer.Visibility).ConvertSourceToTarget(Converters.BoolToVisibility));

            Bindings.Add(MainPageVideoView.Id, new List <Binding>());
            Bindings[MainPageVideoView.Id].Add(
                this.SetBinding(() => ViewModel.MediaElementSource).WhenSourceChanges(() =>
            {
                if (string.IsNullOrEmpty(ViewModel.MediaElementSource))
                {
                    return;
                }

                var mediaController = new MediaController(this);
                mediaController.SetAnchorView(MainPageVideoView);

                MainPageVideoView.SetMediaController(mediaController);
                MainPageVideoView.SetVideoURI(Uri.Parse(ViewModel.MediaElementSource));
                MainPageVideoView.RequestFocus();
            }));

            MainPageSearchView.SuggestionsAdapter = _searchSuggestionAdapter;
            MainPageSearchView.QueryTextChange   += MainPageSearchViewOnQueryTextChange;
            MainPageSearchView.QueryTextSubmit   += MainPageSearchViewOnQueryTextSubmit;
            MainPageSearchView.SuggestionClick   += MainPageSearchViewOnSuggestionClick;
            MainPageSearchView.QueryTextSubmit   += MainPageSearchViewOnQueryTextSubmit;
            MainPageCloseVideoButton.Click       += MainPageCloseVideoButtonOnClick;
            MainPageVideoView.Prepared           += MainPageVideoViewOnPrepared;
            MainPageSearchView.Visibility         = ViewStates.Visible;


            MainPageHamburgerButton.Click += MainPageHamburgerButtonOnClick;
            ViewModel.PropertyChanged     += ViewModelOnPropertyChanged;
            BuildDrawer();
            _drawer.OnDrawerItemClickListener = new HamburgerItemClickListener(OnHamburgerItemClick);
        }