예제 #1
0
        public App()
        {
            InitializeComponent();

            Load();

            WordbookImpressLibrary.Storage.TranslateStorage.TrueFalseTranslation
                = new System.Collections.Generic.Dictionary <string, string>()
                {
                { "true", Resx.AppResources.WordTrue },
                { "false", Resx.AppResources.WordFalse },
                };

            {
                var page = new MasterDetailPage()
                {
                    Master = new Views.MasterPage(),
                    Detail = new NavigationPage(new Views.WordbooksPage())
                    {
                        Title = "’PŒê’ "
                    }
                };
                if (WordbookImpressLibrary.Storage.TutorialStorage.TutorialCompleted)
                {
                    MainPage = page;
                }
                else
                {
                    var model = Views.TutorialsPage.GetTutorial();
                    model.OnFinishAction = () =>
                    {
                        WordbookImpressLibrary.Storage.TutorialStorage.SetTutorialCompleted(true);
                        MainPage = page;
                    };
                    MainPage = new Views.TutorialsPage(model);
                }
            }
        }
예제 #2
0
        public ConfigPage()
        {
            InitializeComponent();

            SaveOnDisappearing = true;

            var licenseChildren = GetLicenseChildren(Navigation);

            var storage = WordbookImpressLibrary.Storage.ConfigStorage.Content;

            Items = new ObservableCollection <SettingItems>
            {
                new SettingItems(AppResources.SettingQuizTitle)
                {
                    new SettingItem(AppResources.SettingQuizChoiceTitle, (w) => String.Format(AppResources.SettingQuizChoiceDetail, storage.ChoiceCount))
                    {
                        Action = async(s) => {
                            storage.ChoiceCount = await GetByActionSheet <int>(AppResources.SettingQuizChoiceMessage
                                                                               , new int[] { 2, 3, 4, 5, 6, 7, 8 }.ToDictionary(a => String.Format(AppResources.SettingQuizChoiceChoice, a))
                                                                               , storage.ChoiceCount, false, (a) => (a is int) && (int)a >= 2);
                        }
                    },
                },
                new SettingItems(AppResources.SettingQuizConditionTitle)
                {
                    new SettingItem(AppResources.SettingQuizConditionRememberedTitle, (w) => storage.SkipChecked?AppResources.SettingQuizConditionRememberedDetailTrue:AppResources.SettingQuizConditionRememberedDetailFalse, !storage.SkipChecked)
                    {
                        Action = (s) => { storage.SkipChecked = !s.BoolValue; return(Task.CompletedTask); }
                    },
                    new SettingItem(AppResources.SettingQuizConditionCorrectCountTitle, (w) => storage.SkipMinCorrect == int.MaxValue?AppResources.SettingQuizConditionCorrectCountDetailTrue: String.Format(AppResources.SettingQuizConditionCorrectCountDetailFalse, storage.SkipMinCorrect))
                    {
                        Action = async(s) => {
                            storage.SkipMinCorrect = await GetByActionSheet <int>(AppResources.SettingQuizConditionCorrectCountMessage
                                                                                  , new Dictionary <string, int> {
                                { AppResources.SettingQuizConditionWordNotSkip, int.MaxValue }
                            }.Union(new int[] { 1, 2, 3, 5, 10 }.Select(a => new KeyValuePair <string, int>(String.Format(AppResources.SettingQuizConditionCorrectCountChoice, a), a))).ToDictionary(a => a.Key, b => b.Value)
                                                                                  , storage.SkipMinCorrect, true, (a) => (a is int) && (int)a >= 1);
                        }
                    },
                    new SettingItem(AppResources.SettingQuizConditionCorrectRateTitle, (w) => storage.SkipMinRate == 2 || storage.SkipMinRateMinTotal == int.MaxValue ? AppResources.SettingQuizConditionCorrectRateDetailTrue:
                                    String.Format(AppResources.SettingQuizConditionCorrectRateDetailFalse, storage.SkipMinRateMinTotal, storage.SkipMinRate * 100)
                                    )
                    {
                        Children = new ObservableCollection <SettingItems>()
                        {
                            new SettingItems(AppResources.WordCommentary)
                            {
                                new SettingItem(AppResources.WordExplanation, (w) => AppResources.SettingQuizConditionCorrectRatePageExplanationExplanationMessage)
                                {
                                    Action = async(s) =>
                                    {
                                        await DisplayAlert(AppResources.WordExplanation, AppResources.SettingQuizConditionCorrectRatePageExplanationExplanationAlert, AppResources.AlertConfirmed);
                                    }
                                }
                            },
                            new SettingItems(AppResources.SettingQuizConditionCorrectRatePageRequirementTitle)
                            {
                                new SettingItem(AppResources.WordCorrectRate, (w) => storage.SkipMinRate == 2?AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectRateDetailTrue:String.Format(AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectRateDetailFalse, Math.Floor(storage.SkipMinRate * 100)))
                                {
                                    Action = async(s) => {
                                        storage.SkipMinRate = await GetByActionSheet <double>(AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectRateChoiceMessage
                                                                                              , new Dictionary <string, double> {
                                            { AppResources.SettingQuizConditionWordNotSkip, 2 }
                                        }.Union(new double[] { 0.5, 0.6, 0.75, 0.9, 1.0 }.ToDictionary(a => String.Format(AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectRateChoice, Math.Floor(a * 100)))).ToDictionary(a => a.Key, a => a.Value)
                                                                                              , storage.SkipMinRate, true, (a) => (a is double) && (((double)a > 0 && (double)a <= 1) || (double)a == 2), new PercentageValueConverter());
                                    }
                                }
                                , new SettingItem(AppResources.WordCorrectCount, (w) => storage.SkipMinRateMinTotal == int.MaxValue?AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectCountDetailTrue:String.Format(AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectCountDetailFalse, storage.SkipMinRateMinTotal))
                                {
                                    Action = async(s) => {
                                        storage.SkipMinRateMinTotal = await GetByActionSheet <int>(AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectCountChoiceMessage
                                                                                                   , new Dictionary <string, int> {
                                            { AppResources.SettingQuizConditionWordNotSkip, int.MaxValue }
                                        }.Union(new int[] { 3, 5, 10, 20, 50 }.ToDictionary(a => String.Format(AppResources.SettingQuizConditionCorrectRatePageRequirementCorrectCountChoice, a))).ToDictionary(a => a.Key, a => a.Value)
                                                                                                   , storage.SkipMinRateMinTotal, true, (a) => (a is int) && (int)a >= 1);
                                    }
                                }
                            }
                        }
                    },
                    new SettingItem(AppResources.SettingQuizConditionIgnoreTimeSpanTitle, (w) => storage.SkipVoidTicks == -1?AppResources.SettingQuizConditionIgnoreTimeSpanDetailTrue: String.Format(AppResources.SettingQuizConditionIgnoreTimeSpanDetailFalse, ValueConverters.TimeSpanFormatValueConverter.FormatTimeSpan(new TimeSpan(storage.SkipVoidTicks), AppResources.SettingQuizConditionIgnoreTimeSpanTimeSpanFormat)))
                    {
                        Action = async(s) =>
                        {
                            storage.SkipVoidTicks = await GetByActionSheet <long>(AppResources.SettingQuizConditionIgnoreTimeSpanChoiceMessage,
                                                                                  new Dictionary <string, long> {
                                { AppResources.SettingQuizConditionIgnoreTimeSpanChoiceNever, -1 }
                            }.Union(new TimeSpan[] { TimeSpan.FromMinutes(10), TimeSpan.FromHours(1), TimeSpan.FromDays(1), TimeSpan.FromDays(7) }.ToDictionary(a => ValueConverters.TimeSpanFormatValueConverter.FormatTimeSpan(a, AppResources.SettingQuizConditionIgnoreTimeSpanTimeSpanFormat), a => a.Ticks)).ToDictionary(a => a.Key, a => a.Value)
                                                                                  , storage.SkipVoidTicks, true, (a) => (a is long) && ((long)a >= TimeSpan.FromSeconds(1).Ticks || (long)a == -1), new TimeSpanTicksValueConverter(), Keyboard.Plain);
                        }
                    }
                },
                new SettingItems(AppResources.SettingStatisticsTitle)
                {
                    new SettingItem(AppResources.SettingStatisticsDailyQuestionTitle, (w) => String.Format(AppResources.SettingStatisticsDailyQuestionDetail, +storage.MaxDailyTestCount))
                    {
                        Action = async(s) =>
                        {
                            storage.MaxDailyTestCount = await GetByActionSheet <int>(AppResources.SettingStatisticsDailyQuestionChoiceMessage,
                                                                                     new int[] { 10, 50, 100, 500 }.ToDictionary(a => String.Format(AppResources.SettingStatisticsDailyQuestionChoice, a), a => a)
                                                                                     , storage.MaxDailyTestCount);
                        }
                    },
                    new SettingItem(AppResources.SettingStatisticsZeroAnswerTitle, (w) => storage.ShowStatisticsZeroAnswer?AppResources.SettingStatisticsZeroAnswerDetailTrue:AppResources.SettingStatisticsZeroAnswerDetailFalse, storage.ShowStatisticsZeroAnswer)
                    {
                        Action = (s) =>
                        {
                            storage.ShowStatisticsZeroAnswer = s.BoolValue;
                            return(Task.CompletedTask);
                        }
                    },
                    new SettingItem(AppResources.SettingStatisticsAmazonAssociateIdTitle, AppResources.SettingStatisticsAmazonAssociateIdDetail)
                    {
                        Action = async(s) => {
                            var dic = new Dictionary <string, string>();
                            dic.Add(AppResources.SettingStatisticsAmazonAssociateIdChoiceProgrammer, WordbookImpressLibrary.APIKeys.AmazonAssociateTag);
                            if (!string.IsNullOrWhiteSpace(storage.CustomAmazonAssociateTag) && storage.CustomAmazonAssociateTag != WordbookImpressLibrary.APIKeys.AmazonAssociateTag)
                            {
                                dic.Add(storage.CustomAmazonAssociateTag, storage.CustomAmazonAssociateTag);
                            }
                            storage.CustomAmazonAssociateTag = await GetByActionSheet <string>(AppResources.SettingStatisticsAmazonAssociateIdChoiceMessage, dic, storage.CustomAmazonAssociateTag, false);
                        }
                    },
                },
                new SettingItems(AppResources.SettingStoreTitle)
                {
                    new SettingItem(AppResources.SettingStorePreferPrintedTitle, (w) => storage.StorePreferPrintedBook?AppResources.SettingStorePreferPrintedDetailTrue:AppResources.SettingStorePreferPrintedDetailFalse, storage.StorePreferPrintedBook)
                    {
                        Action = (s) =>
                        {
                            storage.StorePreferPrintedBook = s.BoolValue;
                            return(Task.CompletedTask);
                        }
                    },
                    new SettingItem(AppResources.SettingStoreStoreTitle, AppResources.SettingStoreStoreDetail)
                    {
                        Action = async(s) =>
                        {
                            storage.StoreOpenBookLink = await GetByActionSheet <string>(AppResources.SettingStoreStoreChoiceMessage,
                                                                                        AppResources.SettingStoreStoreChoiceChoices
                                                                                        .Split(new[] { "\n\n" }, StringSplitOptions.None)
                                                                                        .ToDictionary(a => a.Split(new[] { '\n' }, 2)[0], a => a.Split(new[] { '\n' }, 2)[1])
                                                                                        , storage.StoreOpenBookLink);
                        }
                    },
                    new SettingItem(AppResources.SettingStoreEnableImpressTitle, (w) => storage.EnableImpressBookFeature?AppResources.SettingStoreEnableImpressDetailTrue:AppResources.SettingStoreEnableImpressDetailFalse, storage.EnableImpressBookFeature)
                    {
                        Action = (s) =>
                        {
                            storage.EnableImpressBookFeature = s.BoolValue;
                            return(Task.CompletedTask);
                        }
                    },
                },
#if DEBUG
                new SettingItems(AppResources.SettingDebugTitle)
                {
                    new SettingItem(AppResources.SettingDebugInitTutorialTitle, AppResources.SettingDebugInitTutorialDetail)
                    {
                        Action = async(s) =>
                        {
                            WordbookImpressLibrary.Storage.TutorialStorage.SetTutorialCompleted(false);
                            await DisplayAlert(AppResources.SettingDebugInitTutorialAlertTitle, String.Format(AppResources.SettingDebugInitTutorialAlertMessage, WordbookImpressLibrary.Storage.TutorialStorage.Path), AppResources.AlertConfirmed);
                        }
                    },
                    new SettingItem(AppResources.SettingDebugDemoCalendarTitle, AppResources.SettingDebugDemoCalendarDetail, storage.DemoModeCalendar)
                    {
                        Action = (s) =>
                        {
                            storage.DemoModeCalendar = s.BoolValue; return(Task.CompletedTask);
                        }
                    },
                },
#endif
                new SettingItems(AppResources.SettingInitTitle)
                {
                    new SettingItem(AppResources.SettingInitWordbookName, AppResources.SettingInitWordbookDetail)
                    {
                        Action = async(s) =>
                        {
                            if (await DisplayAlert(AppResources.WordWarning, String.Format(AppResources.SettingInitConfirmation, AppResources.SettingInitWordbookName.ToLower()), AppResources.AlertYes, AppResources.AlertNo))
                            {
                                WordbookImpressLibrary.Storage.WordbooksImpressStorage.Init();
                            }
                        }
                    },
                    new SettingItem(AppResources.SettingInitAuthName, AppResources.SettingInitAuthDetail)
                    {
                        Action = async(s) =>
                        {
                            if (await DisplayAlert(AppResources.WordWarning, String.Format(AppResources.SettingInitConfirmation, AppResources.SettingInitAuthName.ToLower()), AppResources.AlertYes, AppResources.AlertNo))
                            {
                                WordbookImpressLibrary.Storage.WordbooksImpressInfoStorage.Init();
                            }
                        }
                    },
                    new SettingItem(AppResources.SettingInitStoreStatisticsName, AppResources.SettingInitStoreStatisticsDetail)
                    {
                        Action = async(s) =>
                        {
                            if (await DisplayAlert(AppResources.WordWarning, String.Format(AppResources.SettingInitConfirmation, AppResources.SettingInitStoreStatisticsName.ToLower()), AppResources.AlertYes, AppResources.AlertNo))
                            {
                                WordbookImpressLibrary.Storage.PurchaseHistoryStorage.Init();
                            }
                        }
                    },
                    new SettingItem(AppResources.SettingInitStatisticsName, AppResources.SettingInitStatisticsDetail)
                    {
                        Action = async(s) =>
                        {
                            if (await DisplayAlert(AppResources.WordWarning, String.Format(AppResources.SettingInitConfirmation, AppResources.SettingInitStatisticsName.ToLower()), AppResources.AlertYes, AppResources.AlertNo))
                            {
                                WordbookImpressLibrary.Storage.WordbooksImpressInfoStorage.Init();
                            }
                        }
                    },
                },
                new SettingItems(AppResources.SettingSupportTitle)
                {
                    new SettingItem(AppResources.SettingSupportTutorialTitle, AppResources.SettingSupportTutorialDetail)
                    {
                        Action = async(s) =>
                        {
                            var page = new TutorialsPage();
                            NavigationPage.SetHasNavigationBar(page, false);
                            await Navigation.PushAsync(page);
                        },
                    },
                    new SettingItem(AppResources.SettingSupportWikiTitle, AppResources.SettingSupportWikiDetail)
                    {
                        Action = (s) => { try{ Device.OpenUri(new Uri(AppResources.ProfileAppWikiUrl)); }catch { } return(Task.CompletedTask); }
                    },
                },
                new SettingItems(String.Format(AppResources.SettingAboutTitle, nameof(WordbookImpressApp)))
                {
                    new SettingItem(AppResources.SettingAboutLicenseOSSTitle, AppResources.SettingAboutLicenseOSSDetail)
                    {
                        Children = licenseChildren
                    },
                    new SettingItem(AppResources.SettingAboutLicenseAppTitle, AppResources.SettingAboutLicenseAppDetail)
                    {
                        Action = async(a) =>
                        {
                            await Navigation.PushAsync(new LicenseInfoPage(new WordbookImpressLibrary.Models.License.NormalLicense()
                            {
                                LicenseText = await Storage.LicenseStorage.LoadLicenseText(nameof(WordbookImpressApp))
                                , Name = nameof(WordbookImpressApp)
                                , ProjectName = nameof(WordbookImpressApp)
                                , LicenseUrl = AppResources.ProfileAppLicenseUrl
                            }));
                        }
                    },
                    new SettingItem(AppResources.SettingAboutProjectPage, AppResources.ProfileAppProjectUrl, null)
                    {
                        Action = (w) => { try{ Device.OpenUri(new Uri(AppResources.ProfileAppProjectUrl)); }catch { } return(Task.CompletedTask); }
                    },
                },
            };

            MyListView.ItemsSource = Items;
        }