Example #1
0
        public override void Initialize()
        {
            CreatableTypes()
            .EndingWith("Service")
            .AsInterfaces()
            .RegisterAsLazySingleton();

            Mvx.IoCProvider.RegisterSingleton(() => UserDialogs.Instance);
            RegisterAppStart <MainViewModel>();
            DataBase.SetupConnection();
            Task.Run(async() =>
            {
                await DatabaseImages.UpdateData();
                await DatabaseWords.UpdateData();
            });

            var assemblyConfig = new AssemblyContentConfig(GetType().GetTypeInfo().Assembly)
            {
                ResourceFolder = "Locales",
                ParserConfig   = new ParserConfig
                {
                    ThrowWhenKeyNotFound = true
                }
            };

            var textProvider = new MvxYamlTextProvider(assemblyConfig);

            Mvx.IoCProvider.RegisterSingleton <IMvxTextProvider>(textProvider);
            Mvx.IoCProvider.RegisterSingleton <IMvxLocalizationProvider>(textProvider);
        }
Example #2
0
        private async Task Blitz(bool isImage)
        {
            Settings.TypeOfRepetition = TypeOfRepetitions.FourOptions;
            if (isImage)
            {
                var database = await DatabaseImages.GetDataNotLearned();

                if (database.Count == 0)
                {
                    Mvx.IoCProvider.Resolve <IMessageCore>().Toast(this["RepeatedAllImages"]);
                }
                else
                {
                    await NavigationService.Navigate <BlitzPollViewModel, List <DatabaseImages> >(database);
                }
            }
            else
            {
                var database = await DatabaseWords.GetDataNotLearned();

                if (database.Count == 0)
                {
                    Mvx.IoCProvider.Resolve <IMessageCore>().Toast(this["RepeatedAllWords"]);
                }
                else
                {
                    await NavigationService.Navigate <Languages.BlitzPollViewModel, List <DatabaseWords> >(database);
                }
            }
        }
Example #3
0
        private async Task NavigateToLearn()
        {
            if (DatabaseImages.DatabaseIsContain($"{DataBase.TableName}"))
            {
                var database = await DatabaseImages.GetDataNotLearned();

                if (database.Count == 0)
                {
                    Mvx.IoCProvider.Resolve <IMessageCore>().Toast(this["RepeatedAllImages"]);
                }
                else
                {
                    await NavigationService.Navigate <LearnViewModel, List <DatabaseImages> >(database);
                }
            }
            else
            {
                var database = await DatabaseWords.GetDataNotLearned();

                if (database.Count == 0)
                {
                    Mvx.IoCProvider.Resolve <IMessageCore>().Toast(this["RepeatedAllWords"]);
                }
                else
                {
                    await NavigationService.Navigate <Languages.LearnViewModel, List <DatabaseWords> >(database);
                }
            }
        }
Example #4
0
        public static async Task AddColumn()
        {
            foreach (var tableName in Enum.GetNames(typeof(TableNamesLanguage)))
            {
                if (!DatabaseWords.ContainColumn("Transcription",
                                                 await DataBase.Languages.GetTableInfoAsync(tableName)))
                {
                    await DataBase.Languages.ExecuteAsync($"ALTER TABLE {tableName} ADD COLUMN Transcription string");

                    if (tableName != $"{TableNamesLanguage.My_Directly}")
                    {
                        using (var reader =
                                   new StreamReader(Application.Context.Assets.Open($"Database/{tableName}.txt")))
                        {
                            string strLine;
                            while ((strLine = reader.ReadLine()) != null)
                            {
                                var list    = strLine.Split('|');
                                var changes = await DataBase.Languages.ExecuteAsync(
                                    $"UPDATE {tableName} SET Word = ?, Transcription = ? WHERE Word = ?",
                                    list[0].ToLower().Trim(), list[2].Trim(), list[0].ToLower().Trim())
                                              + await DataBase.Languages.ExecuteAsync(
                                    $"UPDATE {tableName} SET Word = ?, Transcription = ? WHERE Word = ?",
                                    list[0].ToLower().Trim(), list[2].Trim(),
                                    list[0].ToLower().Trim() + " ")
                                              + await DataBase.Languages.ExecuteAsync(
                                    $"UPDATE {tableName} SET Word = ?, Transcription = ? WHERE Word = ?",
                                    list[0].ToLower().Trim(), list[2].Trim(),
                                    list[0].ToLower().Trim() + "  ");

                                if (changes == 0)
                                {
                                    await DataBase.Languages.ExecuteAsync(
                                        $"INSERT INTO {tableName} (Word, TranslationWord, Transcription, NumberLearn, DateRecurrence) VALUES (?, ?, ?, ?, ?)",
                                        list[0].ToLower().Trim(), list[1].ToLower().Trim(), list[2].Trim(),
                                        Settings.StandardNumberOfRepeats, DateTime.Now);
                                }

                                if (changes > 1) // из-за старых таблиц
                                {
                                    await DataBase.Languages.ExecuteAsync($"DELETE FROM {tableName} WHERE Word = ?",
                                                                          list[0].ToLower().Trim());

                                    await DataBase.Languages.ExecuteAsync(
                                        $"INSERT INTO {tableName} (Word, TranslationWord, Transcription, NumberLearn, DateRecurrence) VALUES (?, ?, ?, ?, ?)",
                                        list[0].ToLower().Trim(), list[1].ToLower().Trim(), list[2].Trim(),
                                        Settings.StandardNumberOfRepeats, DateTime.Now);
                                }
                            }

                            await DataBase.Languages.ExecuteAsync(
                                $"DELETE FROM {tableName} WHERE Transcription IS NULL OR trim(Transcription) = ''");
                        }
                    }
                }
            }
        }
        public override void OnCreateOptionsMenu(IMenu menu, MenuInflater inflater)
        {
            inflater.Inflate(Resource.Menu.search, menu);
            var _searchView = menu.FindItem(Resource.Id.action_search).ActionView.JavaCast <AndroidX.AppCompat.Widget.SearchView>();

            menu.FindItem(Resource.Id.HideStudied).SetChecked(ViewModel.HideStudied);

            menu.FindItem(Resource.Id.ABC).SetTitle(ViewModel.TextSortAlphabetically);
            menu.FindItem(Resource.Id.HideStudied).SetTitle(ViewModel.TextHideStudied);
            menu.FindItem(Resource.Id.increase).SetTitle(ViewModel.TextSortAscending);
            menu.FindItem(Resource.Id.decrease).SetTitle(ViewModel.TextSortDescending);

            _searchView.QueryTextChange += (sender, e) =>
            {
                var searchWord = e.NewText.ToLower().Trim();
                if (searchWord == "")
                {
                    DictionaryWords.Adapter = new CustomAdapterWord(ParentActivity,
                                                                    ViewModel.HideStudied
                            ? ViewModel.Database.FindAll(column => column.NumberLearn != 0)
                            : ViewModel.Database);
                }
                else
                {
                    var date = ViewModel.Database.FindAll(column =>
                                                          column.Word.ToLower().Contains(searchWord) ||
                                                          column.TranslationWord.ToLower().Contains(searchWord));

                    DictionaryWords.Adapter = new CustomAdapterWord(ParentActivity, date);
                }
            };

            DictionaryWords.ItemClick += (s, args) =>
            {
                var word  = DictionaryWords.Adapter.GetItem(args.Position);
                var words = new DatabaseWords();
                words = ViewModel.Database[ViewModel.Database.FindIndex(obj => obj.Word == $"{word}")];
                var alert = new AlertDialog.Builder(ParentActivity);

                alert.SetTitle("");
                alert.SetMessage($"{ViewModel.TextDelete} {$"{word}"}?");
                alert.SetPositiveButton(ViewModel.TextCancel, delegate { alert.Dispose(); });
                alert.SetNeutralButton(ViewModel.TextOk, delegate
                {
                    ViewModel.Database.Remove(words);
                    DictionaryWords.Adapter = new CustomAdapterWord(ParentActivity,
                                                                    ViewModel.HideStudied
                            ? ViewModel.Database.FindAll(obj => obj.NumberLearn != 0)
                            : ViewModel.Database);
                    DatabaseWords.Delete($"{word}").ConfigureAwait(false);
                    Toast.MakeText(ParentActivity, ViewModel.ErrorWordDelete, ToastLength.Short).Show();
                });
                alert.Show();
            };
        }