Esempio n. 1
0
        private async Task GetUserConfirmation()
        {
            await dialog.ShowAsync();

            if (dialog.IsLeftButtonClick())
            {
                isCancel  = false;
                isReplace = true;
            }
            else if (dialog.IsMiddleButtonClick())
            {
                isCancel  = false;
                isReplace = false;
            }
            else
            {
                isCancel = true;
            }

            isNotAksAgain = dialog.IsNotAskAgain();

            await dialog.WaitForDialogClosed();

            progressDialog.ShowInDeterminateStateNoStopAsync("Insert media files");
        }
        private async void OkButtonClick(object sender, RoutedEventArgs e)
        {
            string deckName = Utils.GetValidName(deckNameTextBox.Text);
            string noteName = Utils.GetValidName(noteTypeNameTextBox.Text);

            bool isValid = await CheckDeckAndNoteName(deckName, noteName);

            if (!isValid)
            {
                return;
            }

            isOkPress = true;
            isError   = false;
            addDeckFlyout.Hide();
            long?deckId = collection.Deck.AddOrResuedDeck(deckName, true);

            if (deckId == null)
            {
                await UIHelper.ShowMessageDialog("Unexpected error!");

                return;
            }

            long           modelCopyFromID = modelView.GetSelectedModelId();
            ProgressDialog dialog          = new ProgressDialog();

            dialog.ProgressBarLabel = "";
            dialog.ShowInDeterminateStateNoStopAsync("Add new deck");

            var task = Task.Run(async() =>
            {
                var deckJson = collection.Deck.Get(deckId);
                JsonObject model;
                if (!String.IsNullOrWhiteSpace(noteName))
                {
                    var modelCloneFrom = collection.Models.Get(modelCopyFromID);
                    model         = collection.Models.Copy(modelCloneFrom);
                    model["name"] = JsonValue.CreateStringValue(noteName);
                }
                else
                {
                    model = collection.Models.Get(modelCopyFromID);
                }
                deckJson["mid"] = model["id"];
                model["did"]    = JsonValue.CreateNumberValue((long)deckId);
                collection.Models.Save(model);
                collection.Deck.Save(deckJson);
                collection.SaveAndCommit();

                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    dialog.Hide();
                    NewDeckCreatedEvent?.Invoke((long)deckId);
                });
            });
        }
Esempio n. 3
0
 private void PrepareProgessDialog()
 {
     if (progressDialog == null)
     {
         progressDialog = new ProgressDialog();
         progressDialog.ProgressBarLabel = "Extracting...";
         progressDialog.ShowInDeterminateStateNoStopAsync("Insert media files");
         progressDialog.Closed += ProgressDialogClosed;
         progressDialog.Opened += ProgressDialogOpened;
     }
 }
Esempio n. 4
0
        private async Task CreateCustomStudy()
        {
            var deck = collection.Deck.Current();

            if (HandleNotCreatingDynamicDeckCases(deck))
            {
                return;
            }

            //Not like in java and python ver, we do nothing if no cards are available
            if (studyOption != CustomStudyOption.CramMode)
            {
                var max = int.Parse(chosenLabelValue.Text);
                if (max == 0)
                {
                    return;
                }
            }

            customStudyFlyout.IsOpen = false;
            JsonObject dynamicDeck;
            long       dynamicDeckId;
            var        currentCustomDeck = collection.Deck.GetDeckByName(DEFAULT_DYN_DECKNAME);

            if (currentCustomDeck != null)
            {
                dynamicDeckId = (long)JsonHelper.GetNameNumber(currentCustomDeck, "id");
                bool isDyn = collection.Deck.IsDyn(dynamicDeckId);
                if (!isDyn)
                {
                    await UIHelper.ShowMessageDialog("Please rename the deck named \"" + DEFAULT_DYN_DECKNAME + "\" to another name first.");

                    return;
                }
                else
                {
                    collection.Sched.EmptyDyn(dynamicDeckId);
                    dynamicDeck = currentCustomDeck;
                    collection.Deck.Select(dynamicDeckId);
                }
            }
            else
            {
                dynamicDeckId = collection.Deck.NewDynamicDeck(DEFAULT_DYN_DECKNAME);
                dynamicDeck   = collection.Deck.Get(dynamicDeckId);
            }
            ProgressDialog dialog = new ProgressDialog();

            dialog.ProgressBarLabel = "Buidling custom study deck...";
            dialog.ShowInDeterminateStateNoStopAsync("Custom Study");

            CreateDynamicDeckConfigs(dynamicDeck, deck);

            var task = Task.Run(async() =>
            {
                var cards = collection.Sched.RebuildDyn();
                collection.SaveAndCommitAsync();

                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    if (cards == null || cards.Count == 0)
                    {
                        await UIHelper.ShowMessageDialog(UIConst.WARN_CUSTOM_STUDY_NOCARDS_MATCH);
                    }

                    CustomStudyCreateEvent?.Invoke(studyOption, currentDeckId, dynamicDeckId);
                    dialog.Hide();
                });
            });
        }