Ejemplo n.º 1
0
        private static async Task LoadJsonModelIntoGeneratedJsonSchemaView(
            ViewStack viewStack, ModelToJsonSchema schemaGenerator, JsonSchema schema, string jsonModel)
        {
            JObject          model         = JsonReader.GetReader().Read <JObject>(jsonModel);
            JsonSchemaToView viewGenerator = new JsonSchemaToView(schemaGenerator);
            GameObject       generatedView = await viewGenerator.ToView(schema);

            viewStack.ShowView(generatedView);

            var presenter = new JsonSchemaPresenter(viewGenerator);

            presenter.targetView = generatedView;

            Log.d("Model BEFORE changes: " + model.ToPrettyString());
            var changedModel = await presenter.LoadModelIntoView(model.DeepClone() as JObject);

            await JsonSchemaPresenter.ChangesSavedViaConfirmButton(generatedView);

            Log.d("Model AFTER changes: " + changedModel.ToPrettyString());

            viewStack.SwitchBackToLastView(generatedView);
            var changedFields = MergeJson.GetDiff(model, changedModel);

            Log.d("Fields changed: " + changedFields?.ToPrettyString());
        }
Ejemplo n.º 2
0
        public static async Task ShowIn(ViewStack viewStack)
        {
            var model     = new MyModel();
            var presenter = new MyPresenter();

            presenter.targetView = viewStack.ShowView("7GUIs_Task4_Timer");
            await presenter.LoadModelIntoView(model);
        }
Ejemplo n.º 3
0
        private static async Task LoadModelIntoGeneratedView(ViewStack viewStack, ModelToJsonSchema schemaGenerator, JsonSchema schema)
        {
            MyUserModel model = NewExampleUserInstance();
            {
                await Dialog.ShowInfoDialog("Manually connecting the model instance to the view", "First an example to connect the " +
                                            "model to a generated view via a manual presenter 'MyManualPresenter1'", "Show manual presenter example");

                var        viewGenerator = new JsonSchemaToView(schemaGenerator);
                GameObject generatedView = await viewGenerator.ToView(schema);

                viewStack.ShowView(generatedView);

                var presenter = new MyManualPresenter1();
                presenter.targetView = generatedView;

                Log.d("Model BEFORE changes: " + JsonWriter.AsPrettyString(model));
                await presenter.LoadModelIntoView(model);

                viewStack.SwitchBackToLastView(generatedView);
                Log.d("Model AFTER changes: " + JsonWriter.AsPrettyString(model));
            }
            {
                await Dialog.ShowInfoDialog("Using JsonSchemaPresenter to autmatically connect the model instance and view",
                                            "The second option is to use a generic JObjectPresenter to connect the model to the generated view",
                                            "Show JsonSchemaPresenter example");

                var        viewGenerator = new JsonSchemaToView(schemaGenerator);
                GameObject generatedView = await viewGenerator.ToView(schema);

                viewStack.ShowView(generatedView);

                var presenter = new JsonSchemaPresenter(viewGenerator);
                presenter.targetView = generatedView;

                Log.d("Model BEFORE changes: " + JsonWriter.AsPrettyString(model));
                MyUserModel changedModel = await presenter.LoadViaJsonIntoView(model);

                viewStack.SwitchBackToLastView(generatedView);

                Log.d("Model AFTER changes: " + JsonWriter.AsPrettyString(changedModel));
                var changedFields = MergeJson.GetDiff(model, changedModel);
                Log.d("Fields changed: " + changedFields?.ToPrettyString());
            }
        }
Ejemplo n.º 4
0
        public static async Task ShowIn(ViewStack viewStack)
        {
            TestDataStore();

            DataStore <MyModel> store     = NewDataStore();
            MyPresenter         presenter = new MyPresenter();

            presenter.targetView = viewStack.ShowView("7GUIs_Task6_CircleDrawer");
            await presenter.LoadModelIntoView(store);
        }
        public static async Task ShowIn(ViewStack viewStack)
        {
            var model = new MyModel()
            {
                degreeInCelsius = 0
            };
            var presenter = new MyPresenter();

            presenter.targetView = viewStack.ShowView("7GUIs_Task2_TemperatureConverter");
            await presenter.LoadModelIntoView(model);
        }
Ejemplo n.º 6
0
        public static async Task ShowIn(ViewStack viewStack)
        {
            MyModel model = new MyModel(null, ImmutableList <MyUser> .Empty);
            Middleware <MyModel>      exampleMiddleware = Middlewares.NewLoggingMiddleware <MyModel>();
            UndoRedoReducer <MyModel> undoLogic         = new UndoRedoReducer <MyModel>();
            DataStore <MyModel>       store             = new DataStore <MyModel>(undoLogic.Wrap(MyReducer), model, exampleMiddleware);

            MyPresenter presenter = new MyPresenter();

            presenter.targetView = viewStack.ShowView("7GUIs_Task5_CRUD");
            await presenter.LoadModelIntoView(store);
        }
Ejemplo n.º 7
0
        public static async Task <ActionMenu.Entry> ShowActionMenu(this ViewStack self, ActionMenu menu, string menuPrefabName = ActionMenu.DEFAULT_MENU)
        {
            var eventName = "ShowActionMenu " + menu.menuId;
            var timing    = Log.MethodEntered(eventName);
            var menuUiGo  = self.ShowView(menuPrefabName);
            var presenter = new ActionMenu.Presenter();

            presenter.targetView = menuUiGo;
            try {
                var selectedEntry = (await presenter.LoadModelIntoView(menu)).clickedEntry;
                menuUiGo.Destroy(); // Close the menu UI again
                EventBus.instance.Publish(EventConsts.catMethod, eventName + " done: " + selectedEntry.name);
                Log.MethodDone(timing);
                return(selectedEntry);
            }
            catch (TaskCanceledException) { // If the user canceled the action selection:
                menuUiGo.Destroy();         // Close the menu UI again
                EventBus.instance.Publish(EventConsts.catMethod, eventName + " canceled");
                Log.MethodDone(timing);
                return(null);
            }
        }
Ejemplo n.º 8
0
        public static async Task ShowIn(ViewStack viewStack)
        {
            // Call model unit tests manually before the UI is shown:
            CellsModelTests.TestFromAndToRowName();
            CellsModelTests.TestDataStoreTransitiveChanges();

            CellsModel model = new CellsModel(ImmutableDictionary <CellPos, Cell> .Empty);
            Middleware <CellsModel>      logging   = Middlewares.NewLoggingMiddleware <CellsModel>();
            UndoRedoReducer <CellsModel> undoLogic = new UndoRedoReducer <CellsModel>();
            DataStore <CellsModel>       store     = new DataStore <CellsModel>(undoLogic.Wrap(CellsReducers.MainReducer), model, logging);

            MyPresenter presenter = new MyPresenter();

            presenter.targetView = viewStack.ShowView("7GUIs_Task7_Cells");
            await presenter.LoadModelIntoView(store);

            await TaskV2.Delay(2000);

            Toast.Show("Now simulating some table model changes..");
            // Simulate changes in the model to check if the UI updates correctly:
            CellsModelTests.SimulateSomeChangesInModel(store);
        }
Ejemplo n.º 9
0
        public static IEnumerator RunTest <T>(ViewStack viewStack, string prefabName) where T : UnitTestMono
        {
            var ui = viewStack.ShowView(prefabName);

            yield return(RunTest <T>(ui));
        }