示例#1
0
        public MainPage(InMemoryService services)
        {
            // setting service to private var
            Services = services;
            InitializeComponent();

            // stack layout for sure as content layout
            var contentLayout = new StackLayout();

            // need action / title bar
            Title = "HsH2Brain";


            // add a new frame for each question set
            foreach (var questionSet in Services.QuestionSets)
            {
                contentLayout.Children.Add(CreateSetCard(questionSet));
            }

            if (Services.QuestionSets.Count == 0)
            {
                contentLayout.Children.Add(CreateEmptyCard());
            }

            // wrap everything in a scroll view and make it pretty ╰(*°▽°*)╯
            Content = new ScrollView
            {
                Content         = contentLayout,
                BackgroundColor = Color.LightBlue,
                Padding         = 10
            };
        }
        public UnitOfWork()
        {
            var storagePath     = AppDomain.CurrentDomain.BaseDirectory;
            var inMemoryService = new InMemoryService();

            _fileManager = new FileManager();
            var ingredientList = _fileManager.ResolveEntitiesFile(Path.Combine(storagePath, _fileManager.IngredientsFile), inMemoryService?.GetAllIngredients());
            var recipeList     = _fileManager.ResolveEntitiesFile(Path.Combine(storagePath, _fileManager.RecipesFile), inMemoryService?.GetAllRecipes());
            var categoryList   = _fileManager.ResolveEntitiesFile(Path.Combine(storagePath, _fileManager.CategoriesFile), inMemoryService?.GetAllCategories());

            RecipeRepository     = new RecipeRepository(recipeList, _fileManager.IngredientsFile);
            CategoryRepository   = new CategoryRepository(categoryList, _fileManager.RecipesFile);
            IngredientRepository = new IngredientRepository(ingredientList, _fileManager.CategoriesFile);
        }
示例#3
0
        public App()
        {
            // default
            InitializeComponent();

            // inject IMS from the very top (giving down to, might be replaced with a singleton in the future)
            Services    = new InMemoryService();
            SyncService = new SyncService(Services);

            // load data
            Services.Load();

            // init mainpage
            MainPage = new NavigationPage();

            // add login/logout button
            if (Services.DeviceUser == null)
            {
                SyncButton = new ToolbarItem
                {
                    Text = "Login"
                };
            }
            else
            {
                SyncButton = new ToolbarItem
                {
                    Text = "Sync"
                };
            }

            SyncButton.Clicked += StartSync;

            MainPage.ToolbarItems.Add(SyncButton);

            MainPage.Navigation.PushAsync(new MainPage(Services));
        }
示例#4
0
        public QuestionPage(InMemoryService services, Guid setId)
        {
            // Load InMemoryService and check if questionset is valid
            Services           = services;
            CurrentQuestionSet = Services.QuestionSets.SingleOrDefault(c => c.Id == setId);
            if (CurrentQuestionSet?.Questions == null || CurrentQuestionSet.Questions.Count < 1)
            {
                CrossToastPopUp.Current.ShowToastMessage("Das ausgewählte Set ist ungültig");
                Navigation.PopAsync();
            }

            // let's pick the first question, doesn't matter which one, but should be in the very first filled bucket
            CurrentQuestion = CurrentQuestionSet?.Questions?.OrderBy(c => c.Bucket).ThenBy(c => Guid.NewGuid()).First();

            // prepare stacklayout for view
            var stackLayout = new StackLayout
            {
                BackgroundColor = Color.LightBlue,
            };

            // Frame with question content // this is flipable
            var questionFrameFront = new Frame
            {
                BackgroundColor = Color.LightYellow,
                VerticalOptions = LayoutOptions.FillAndExpand,
                CornerRadius    = 3
            };

            TextLabel = new Label
            {
                Text     = CurrentQuestion?.Question,
                FontSize = 24
            };

            questionFrameFront.Content = TextLabel;

            // add flash card within scrollview
            stackLayout.Children.Add(
                new ScrollView
            {
                Content           = questionFrameFront,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding           = 5
            }
                );

            // add stats bar
            var statsBar = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Padding     = 5
            };

            WrongLabel = new Label
            {
                FontSize          = 14,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            CorrectLabel = new Label
            {
                FontSize          = 14,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            BucketLabel = new Label
            {
                FontSize          = 14,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            UpdateStatsBar();

            statsBar.Children.Add(WrongLabel);
            statsBar.Children.Add(CorrectLabel);
            statsBar.Children.Add(BucketLabel);
            stackLayout.Children.Add(statsBar);

            // add toolbar
            var bottomMenu = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Padding     = 5
            };

            // add a "Richtig"-Button
            var correctButton = new Button
            {
                Text              = "Richtig",
                CornerRadius      = 5,
                BackgroundColor   = Color.ForestGreen,
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            correctButton.Clicked += HandleCorrect;
            bottomMenu.Children.Add(correctButton);

            // add a "Lösung"-Button
            var solutionButton = new Button
            {
                Text              = "Karte drehen",
                CornerRadius      = 5,
                BackgroundColor   = Color.Blue,
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            solutionButton.Clicked += HandleSolution;
            bottomMenu.Children.Add(solutionButton);

            // Add a "Falsch"-Button
            var wrongButton = new Button
            {
                Text              = "Falsch",
                CornerRadius      = 5,
                BackgroundColor   = Color.PaleVioletRed,
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            wrongButton.Clicked += HandleWrong;
            bottomMenu.Children.Add(wrongButton);

            // wrap everything up and set content
            stackLayout.Children.Add(bottomMenu);
            Content = stackLayout;
        }