Ejemplo n.º 1
0
        protected virtual ValueTask <bool> ShowChildViewController(UIViewController viewController,
                                                                   MvxChildPresentationAttribute attribute,
                                                                   MvxViewModelRequest request)
        {
            if (viewController is MvxSplitViewController)
            {
                throw new MvxException("A SplitViewController can't be present in a child.  Consider using a Root instead.");
            }

            if (ModalViewControllers.Any())
            {
                if (ModalViewControllers.LastOrDefault() is UINavigationController navigationController)
                {
                    PushViewControllerIntoStack(navigationController, viewController, attribute.Animated);
                    return(new ValueTask <bool>(true));
                }
                else
                {
                    throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is currently a plain modal view presented!");
                }
            }

            if (TabBarViewController != null && TabBarViewController.ShowChildView(viewController))
            {
                return(new ValueTask <bool>(true));
            }

            if (MasterNavigationController != null)
            {
                PushViewControllerIntoStack(MasterNavigationController, viewController, attribute.Animated);
                return(new ValueTask <bool>(true));
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current stack!");
        }
Ejemplo n.º 2
0
        protected virtual ValueTask <bool> CloseChildViewController(IMvxViewModel viewModel, MvxChildPresentationAttribute?attribute)
        {
            if (ModalViewControllers.Any())
            {
                foreach (var navController in ModalViewControllers.Where(v => v is UINavigationController))
                {
                    if (TryCloseViewControllerInsideStack((UINavigationController)navController, viewModel))
                    {
                        return(new ValueTask <bool>(true));
                    }
                }
            }

            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(viewModel))
            {
                return(new ValueTask <bool>(true));
            }

            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, viewModel))
            {
                return(new ValueTask <bool>(true));
            }

            return(new ValueTask <bool>(false));
        }
Ejemplo n.º 3
0
        public override ValueTask <MvxBasePresentationAttribute?> CreatePresentationAttribute(Type?viewModelType, Type?viewType)
        {
            if (MasterNavigationController == null &&
                (TabBarViewController == null || !TabBarViewController.CanShowChildView()))
            {
                MvxLog.Instance.Trace($"PresentationAttribute nor MasterNavigationController found for {viewType.Name}. " +
                                      $"Assuming Root presentation");
                var rootAttribute = new MvxRootPresentationAttribute()
                {
                    WrapInNavigationController = true,
                    ViewType      = viewType,
                    ViewModelType = viewModelType
                };
                return(new ValueTask <MvxBasePresentationAttribute?>(rootAttribute));
            }
            MvxLog.Instance.Trace($"PresentationAttribute not found for {viewType?.Name}. " +
                                  $"Assuming animated Child presentation");
            var childAttribute = new MvxChildPresentationAttribute()
            {
                ViewType      = viewType,
                ViewModelType = viewModelType
            };

            return(new ValueTask <MvxBasePresentationAttribute?>(childAttribute));
        }
Ejemplo n.º 4
0
        protected MvxBasePresentationAttribute GetPresentationAttributes(UIViewController viewController)
        {
            if (viewController is IMvxOverridePresentationAttribute vc)
            {
                var presentationAttribute = vc.PresentationAttribute();

                if (presentationAttribute != null)
                {
                    return(presentationAttribute);
                }
            }

            var attribute = viewController.GetType().GetCustomAttributes(typeof(MvxBasePresentationAttribute), true).FirstOrDefault() as MvxBasePresentationAttribute;

            if (attribute != null)
            {
                return(attribute);
            }

            if (MasterNavigationController == null
                &&
                (TabBarViewController == null || !TabBarViewController.CanShowChildView(viewController))
                )
            {
                MvxTrace.Trace($"PresentationAttribute nor MasterNavigationController found for {viewController.GetType().Name}. Assuming Root presentation");
                return(new MvxRootPresentationAttribute()
                {
                    WrapInNavigationController = true
                });
            }

            MvxTrace.Trace($"PresentationAttribute not found for {viewController.GetType().Name}. Assuming animated Child presentation");
            return(new MvxChildPresentationAttribute());
        }
Ejemplo n.º 5
0
        public override MvxBasePresentationAttribute CreatePresentationAttribute(Type viewModelType, Type viewType)
        {
            if (MasterNavigationController == null &&
                (TabBarViewController == null || !TabBarViewController.CanShowChildView()))
            {
                _logger?.LogTrace(
                    "PresentationAttribute nor MasterNavigationController found for {viewTypeName}. Assuming Root presentation",
                    viewType.Name);
                return(new MvxRootPresentationAttribute()
                {
                    WrapInNavigationController = true,
                    ViewType = viewType,
                    ViewModelType = viewModelType
                });
            }

            _logger?.LogTrace(
                "PresentationAttribute not found for {viewTypeName}. Assuming Root presentation",
                viewType.Name);
            return(new MvxChildPresentationAttribute()
            {
                ViewType = viewType,
                ViewModelType = viewModelType
            });
        }
Ejemplo n.º 6
0
        protected virtual void ShowTabViewController(
            UIViewController viewController,
            MvxTabPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            if (TabBarViewController == null)
            {
                throw new MvxException("Trying to show a tab without a TabBarViewController, this is not possible!");
            }

            if (viewController is IMvxTabBarItemViewController tabBarItem)
            {
                attribute.TabName             = tabBarItem.TabName;
                attribute.TabIconName         = tabBarItem.TabIconName;
                attribute.TabSelectedIconName = tabBarItem.TabSelectedIconName;
            }

            if (attribute.WrapInNavigationController)
            {
                viewController = CreateNavigationController(viewController);
            }

            TabBarViewController.ShowTabView(
                viewController,
                attribute);
        }
Ejemplo n.º 7
0
        public override void Close(IMvxViewModel toClose)
        {
            // check if there is a modal presented
            if (ModalViewControllers.Any() && CloseModalViewController(toClose))
            {
                return;
            }

            // if the current root is a TabBarViewController, delegate close responsibility to it
            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(toClose))
            {
                return;
            }

            // if the current root is a SplitViewController, delegate close responsibility to it
            if (SplitViewController != null && SplitViewController.CloseChildViewModel(toClose))
            {
                return;
            }

            // if the current root is a NavigationController, close it in the stack
            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, toClose))
            {
                return;
            }

            MvxTrace.Warning($"Could not close ViewModel type {toClose.GetType().Name}");
        }
Ejemplo n.º 8
0
        protected virtual bool CloseChildViewController(IMvxViewModel viewModel, MvxChildPresentationAttribute attribute)
        {
            // if there are modals presented
            if (ModalViewControllers.Any())
            {
                foreach (var modalNav in ModalViewControllers.Where(v => v is UINavigationController))
                {
                    if (TryCloseViewControllerInsideStack((UINavigationController)modalNav, viewModel))
                    {
                        return(true);
                    }
                }
            }

            //if the current root is a TabBarViewController, delegate close responsibility to it
            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(viewModel))
            {
                return(true);
            }

            if (SplitViewController != null && SplitViewController.CloseChildViewModel(viewModel))
            {
                return(true);
            }

            // if the current root is a NavigationController, close it in the stack
            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, viewModel))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 9
0
        public static void Prefix(ref TabBarViewController.TabBarItem[] items)
        {
            items = items.AddToArray(new TabBarViewController.TabBarItem("Japan Saber", () =>
            {
                Logger.Debug("Selected MyAnnotatedCollection");
                try
                {
                    var annotated = Resources.FindObjectsOfTypeAll <AnnotatedBeatmapLevelCollectionsViewController>().First();
                    annotated.SetData(AnnotatedBeatmapLevelCollections.ToArray(), 0, true);

                    foreach (var collection in AnnotatedBeatmapLevelCollections)
                    {
                        if (collection is IAsyncDataSource source)
                        {
                            if (!source.IsInitialLoaded && !source.IsInitialLoading)
                            {
                                source.GetDataAsync();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.IPALogger.Critical(ex);
                }
            }));
        }
        public override void Show(MvxViewModelRequest request)
        {
            var viewModelLoader = Mvx.Resolve <IMvxViewModelLoader>();
            var viewModel       = viewModelLoader.LoadViewModel(request, null);

            if (request.ViewModelType == typeof(FormsViewModel))
            {
                var page = new TestPage
                {
                    BindingContext = viewModel
                };
                var viewController = page.CreateViewController();
                MasterNavigationController.PushViewController(viewController, true);
                return;
            }

            if (request.ViewModelType == typeof(FormsTabViewModel))
            {
                var page = new TabPage()
                {
                    BindingContext = viewModel
                };
                var viewController = page.CreateViewController();
                var attribute      = new MvxTabPresentationAttribute()
                {
                    TabName = page.Title
                };
                TabBarViewController.ShowTabView(viewController, attribute);
                return;
            }
            base.Show(request);
        }
Ejemplo n.º 11
0
        protected virtual void ShowChildViewController(
            UIViewController viewController,
            MvxChildPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            if (viewController is IMvxSplitViewController)
            {
                throw new MvxException("A SplitViewController cannot be presented as a child. Consider using Root instead");
            }

            if (ModalNavigationController != null)
            {
                ModalNavigationController.PushViewController(viewController, attribute.Animated);
                return;
            }

            if (TabBarViewController != null && TabBarViewController.ShowChildView(viewController))
            {
                return;
            }

            if (MasterNavigationController != null)
            {
                MasterNavigationController.PushViewController(viewController, attribute.Animated);

                if (viewController is IMvxTabBarViewController)
                {
                    TabBarViewController = viewController as IMvxTabBarViewController;
                }

                return;
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current Root!");
        }
Ejemplo n.º 12
0
        protected virtual Task <bool> CloseTabViewController(IMvxViewModel viewModel, MvxTabPresentationAttribute attribute)
        {
            if (TabBarViewController != null && TabBarViewController.CloseTabViewModel(viewModel))
            {
                return(Task.FromResult(true));
            }

            return(Task.FromResult(false));
        }
Ejemplo n.º 13
0
        protected virtual ValueTask <bool> CloseTabViewController(IMvxViewModel viewModel, MvxTabPresentationAttribute?attribute)
        {
            if (TabBarViewController != null && TabBarViewController.CloseTabViewModel(viewModel))
            {
                return(new ValueTask <bool>(true));
            }

            return(new ValueTask <bool>(false));
        }
Ejemplo n.º 14
0
        protected virtual bool CloseTabViewController(IMvxViewModel viewModel, MvxTabPresentationAttribute attribute)
        {
            if (TabBarViewController != null && TabBarViewController.CloseTabViewModel(viewModel))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 15
0
        protected override Task <bool> ShowChildViewController(
            UIViewController viewController,
            MvxChildPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            if (viewController is IMvxSplitViewController)
            {
                throw new MvxException("A SplitViewController cannot be presented as a child. Consider using Root instead");
            }

            if (ModalViewControllers.Any())
            {
                if (ModalViewControllers.LastOrDefault() is UINavigationController modalNavController)
                {
                    PushViewControllerIntoStack(modalNavController, viewController, attribute);

                    return(Task.FromResult(true));
                }
                throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is currently a plain modal view presented!");
            }

            if (TabBarViewController != null)
            {
                if (request.PresentationValues != null &&
                    request.PresentationValues.ContainsKey(Presenter.NavigationModeKey))
                {
                    if (request.PresentationValues[Presenter.NavigationModeKey] == Presenter.ReplaceKey)
                    {
                        if (TabBarViewController is MainView mv)
                        {
                            mv.ReplaceTopChildViewModel(viewController);
                            return(Task.FromResult(true));
                        }
                    }
                }
                else
                {
                    return(Task.FromResult(TabBarViewController.ShowChildView(viewController)));
                }
            }

            if (MasterNavigationController != null)
            {
                PushViewControllerIntoStack(MasterNavigationController, viewController, attribute);
                return(Task.FromResult(true));
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current stack!");
        }
        protected virtual void ShowTabViewController(
            UIViewController viewController,
            bool needsNavigationController,
            string tabTitle,
            string tabIconName)
        {
            if (TabBarViewController == null)
            {
                throw new MvxException("You need a TabBarViewController to show a ViewModel as a Tab!");
            }

            if (string.IsNullOrEmpty(tabTitle) && string.IsNullOrEmpty(tabIconName))
            {
                throw new MvxException("You need to set at least an icon or a title when trying to show a ViewModel as a Tab!");
            }

            TabBarViewController.ShowTabView(viewController, needsNavigationController, tabTitle, tabIconName);
        }
Ejemplo n.º 17
0
        protected virtual void ShowTabViewController(
            UIViewController viewController,
            MvxTabPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            if (TabBarViewController == null)
            {
                throw new MvxException("Trying to show a tab without a TabBarViewController, this is not possible!");
            }

            if (attribute.WrapInNavigationController)
            {
                viewController = new MvxNavigationController(viewController);
            }

            TabBarViewController.ShowTabView(
                viewController,
                attribute.TabName,
                attribute.TabIconName,
                attribute.TabAccessibilityIdentifier);
        }
Ejemplo n.º 18
0
        public virtual MvxBasePresentationAttribute CreatePresentationAttribute(Type viewModelType, Type viewType)
        {
            if (MasterNavigationController == null &&
                (TabBarViewController == null ||
                 !TabBarViewController.CanShowChildView()))
            {
                MvxTrace.Trace($"PresentationAttribute nor MasterNavigationController found for {viewType.Name}. " +
                               $"Assuming Root presentation");
                return(new MvxRootPresentationAttribute()
                {
                    WrapInNavigationController = true, ViewType = viewType, ViewModelType = viewModelType
                });
            }

            MvxTrace.Trace($"PresentationAttribute not found for {viewType.Name}. " +
                           $"Assuming animated Child presentation");
            return(new MvxChildPresentationAttribute()
            {
                ViewType = viewType, ViewModelType = viewModelType
            });
        }
        protected virtual void Close(IMvxViewModel toClose)
        {
            // check if toClose is a modal ViewController
            if (Window.RootViewController.PresentedViewController != null)
            {
                UIViewController viewController;
                // the presented ViewController might be a NavigationController as well
                var navigationController = Window.RootViewController.PresentedViewController as UINavigationController;
                viewController = navigationController != null
                                                                        ? navigationController.TopViewController
                                                                        : Window.RootViewController.PresentedViewController;

                var mvxView = viewController.GetIMvxIosView();

                if (mvxView.ViewModel == toClose)
                {
                    Window.RootViewController.DismissViewController(true, null);
                    return;
                }
            }

            // check if ViewModel is shown inside TabBarViewController
            // if so, the TabBarViewController takes care of it
            if (TabBarViewController != null)
            {
                TabBarViewController.CloseChildViewModel(toClose);
                return;
            }

            // close ViewModel shown inside NavigationController
            if (NavigationController.TopViewController.GetIMvxIosView().ViewModel == toClose)
            {
                NavigationController.PopViewController(true);
            }
            else
            {
                ClosePreviousController(toClose);
            }
        }
Ejemplo n.º 20
0
        public override MvxBasePresentationAttribute CreatePresentationAttribute(Type viewModelType, Type viewType)
        {
            ValidateArguments(viewModelType, viewType);

            if (MasterNavigationController == null &&
                TabBarViewController?.CanShowChildView() != true)
            {
                MvxLog.Instance?.Trace(
                    $"PresentationAttribute nor MasterNavigationController found for {viewType.Name}. Assuming Root presentation");
                return(new MvxRootPresentationAttribute
                {
                    WrapInNavigationController = true, ViewType = viewType, ViewModelType = viewModelType
                });
            }

            MvxLog.Instance?.Trace(
                $"PresentationAttribute not found for {viewType.Name}. Assuming animated Child presentation");

            return(new MvxChildPresentationAttribute {
                ViewType = viewType, ViewModelType = viewModelType
            });
        }
        protected virtual void ShowChildViewController(UIViewController viewController)
        {
            // dismiss ModalViewController if shown
            Window.RootViewController?.DismissViewController(true, null);

            // if current RootViewController is a TabBarViewController, the TabBarViewController takes care of it
            if (TabBarViewController != null)
            {
                TabBarViewController?.ShowChildView(viewController);
                return;
            }

            // if current RootViewController is a NavigationController, push it
            if (NavigationController != null)
            {
                NavigationController.PushViewController(viewController, true);
                return;
            }

            // there is no Root, so let's start this way!
            Mvx.Trace(MvvmCross.Platform.Platform.MvxTraceLevel.Warning, $"Showing View type: {typeof(UIViewController).Name} as Root, but it's attributed as Child");
            ShowRootViewController(viewController);
        }
Ejemplo n.º 22
0
 static void Postfix(ref LevelFilteringNavigationController __instance, ref TabBarViewController ____tabBarViewController)
 {
     //      Logging.logger.Info("Set CustomLevelCollection");
     __instance.GetField("_customLevelsTabBarData")?.SetField("annotatedBeatmapLevelCollections", Loader.CustomBeatmapLevelPackCollectionSO?.beatmapLevelPacks);
 }
Ejemplo n.º 23
0
 static bool Prefix(ref LevelFilteringNavigationController __instance, ref TabBarViewController ____tabBarViewController)
 {
     __instance.GetField("_customLevelsTabBarData")?.SetField("annotatedBeatmapLevelCollections", Loader.CustomBeatmapLevelPackCollectionSO?.beatmapLevelPacks);
     return(false);
 }
Ejemplo n.º 24
0
        private void SelectSavedLevelPack()
        {
            string lastLevelPackString = PluginConfig.LastLevelPackID;
            int    separatorPos        = lastLevelPackString.IndexOf(PluginConfig.LastLevelPackIDSeparator);

            if (separatorPos < 0 || separatorPos + PluginConfig.LastLevelPackIDSeparator.Length >= lastLevelPackString.Length)
            {
                goto OnError;
            }

            string lastLevelPackCollectionTitle = lastLevelPackString.Substring(0, separatorPos);
            string lastLevelPackID = lastLevelPackString.Substring(separatorPos + PluginConfig.LastLevelPackIDSeparator.Length);

            TabBarViewController tabBarVC = LevelFilteringNavigationController.GetPrivateField <TabBarViewController>("_tabBarViewController");

            TabBarViewController.TabBarItem[] tabBarItems = tabBarVC.GetPrivateField <TabBarViewController.TabBarItem[]>("_items");
            var item = tabBarItems.FirstOrDefault(x => x.title == lastLevelPackCollectionTitle);

            if (item == null)
            {
                goto OnError;
            }

            int itemIndex = Array.IndexOf(tabBarItems, item);

            if (itemIndex < 0)
            {
                goto OnError;
            }

            var tabBarDatas = LevelFilteringNavigationController.GetPrivateField <object[]>("_tabBarDatas");

            if (itemIndex >= tabBarDatas.Length)
            {
                goto OnError;
            }

            var levelPacks = tabBarDatas[itemIndex].GetField <IAnnotatedBeatmapLevelCollection[]>("annotatedBeatmapLevelCollections");
            IAnnotatedBeatmapLevelCollection levelPack = levelPacks.FirstOrDefault(x => x.collectionName == lastLevelPackID || (x is IBeatmapLevelPack && ((IBeatmapLevelPack)x).packID == lastLevelPackID));

            if (levelPack == null)
            {
                goto OnError;
            }

            // this should trigger the LevelPackSelected() delegate and sort the level pack as well
            LevelFilteringNavigationController.SelectAnnotatedBeatmapLevelCollection(levelPack);

            // try to select last level as well
            string[] lastLevelData = PluginConfig.LastLevelID.Split(new string[] { PluginConfig.LastLevelIDSeparator }, StringSplitOptions.None);
            if (lastLevelData.Length != 3)
            {
                return;
            }

            string levelID = lastLevelData[0];

            IPreviewBeatmapLevel level = levelPack.beatmapLevelCollection.beatmapLevels.FirstOrDefault(x => x.levelID == levelID);

            if (level != null)
            {
                SelectLevel(level);
            }
            else
            {
                // could not find level with levelID
                // either song was deleted or is a WIP level and was changed
                // try using song name and level author as fallback
                string songName    = lastLevelData[1];
                string levelAuthor = lastLevelData[2];

                level = levelPack.beatmapLevelCollection.beatmapLevels.FirstOrDefault(x => x.songName == songName && x.levelAuthorName == levelAuthor);
                if (level != null)
                {
                    SelectLevel(level);
                }
            }

            return;

OnError:
            SongSortModule.ResetSortMode();
            ButtonPanel.instance.UpdateSortButtons();
        }
Ejemplo n.º 25
0
        private IEnumerator buttonClickCoroutine(string buttonName)
        {
            /*
             * foreach (Button b in Resources.FindObjectsOfTypeAll<Button>())
             * {
             *  Logger.log?.Debug($"Button.name={b.name}");
             * }
             */

            Logger.log?.Debug($"Time.time={Time.time}, WaitUntil={buttonName}");
            yield return(new WaitUntil(() => Resources.FindObjectsOfTypeAll <Button>().Any(x => x != null && x.name == buttonName)));

            Logger.log?.Debug($"Time.time={Time.time}, Found");
            Button button = Resources.FindObjectsOfTypeAll <Button>().Where(x => x != null && x.name == buttonName).First();

            // need some wait
            yield return(new WaitForSecondsRealtime(Configuration.PluginConfig.Instance.wait));

            // wait for SongCore
            GameObject songCoreLoader = GameObject.Find("SongCore Loader");

            if (songCoreLoader != null)
            {
                Logger.log?.Debug($"Time.time={Time.time}, SongCore Found");
                foreach (var monoBehaviour in songCoreLoader.GetComponents <MonoBehaviour>())
                {
                    if (monoBehaviour.GetType().Name == "Loader")
                    {
                        Logger.log?.Debug($"Time.time={Time.time}, SongCore Loader Found");

                        Logger.log?.Debug($"Time.time={Time.time}, WaitUntil AreSongsLoading");
                        yield return(new WaitUntil(() => AreSongsLoading(monoBehaviour) == false));

                        Logger.log?.Debug($"Time.time={Time.time}, SongsLoaded");

                        // need some wait for update screen
                        yield return(new WaitForSecondsRealtime(1f));

                        break;
                    }
                }
            }

            button.onClick.Invoke();

            if ((Configuration.PluginConfig.Instance.selectTab >= 0) && (Configuration.PluginConfig.Instance.selectTab <= 3))
            {
                // need some wait
                yield return(new WaitForSecondsRealtime(Configuration.PluginConfig.Instance.wait));

                LevelFilteringNavigationController levelFilteringNavigationController = Resources.FindObjectsOfTypeAll <LevelFilteringNavigationController>().First();
                TabBarViewController tabBarViewController = levelFilteringNavigationController?.GetField <TabBarViewController, LevelFilteringNavigationController>("_tabBarViewController");
                if (levelFilteringNavigationController != null && tabBarViewController != null)
                {
                    tabBarViewController.SelectItem(Configuration.PluginConfig.Instance.selectTab);
                    levelFilteringNavigationController.SwitchToPlaylists();
                }
            }

            Logger.log?.Debug($"Time.time={Time.time}, Done");
        }