示例#1
0
        private void DisplayArticles()
        {
            MaterialDialog dialog = null;

            MaterialDialog.Builder progress = new MaterialDialog.Builder(Activity);
            progress.SetContent("Loading articles");
            progress.SetCancelable(false);
            progress.SetProgress(true, 0);

            ThreadPool.QueueUserWorkItem((o) =>
            {
                Activity.RunOnUiThread(() => dialog = progress.Show());

                if (primaryArticles.Count <= 0 || secondaryArticles.Count <= 0)
                {
                    LoadArticlesFromStorehouses();
                }

                List <string> content = new List <string>();

                content.Add(GetArticle("primary"));
                content.Add(GetArticle("secondary"));

                LoadWebViews(content);

                Activity.RunOnUiThread(() => dialog.Dismiss());
            });

            //Task.Factory.StartNew<List<string>>(() =>
            //{
            //    List<string> content = new List<string>();

            //    content.Add(GetArticle("primary"));
            //    content.Add(GetArticle("secondary"));

            //    return content;
            //}).ContinueWith(antecendent => LoadWebViews(antecendent.Result));

            ThreadPool.QueueUserWorkItem((o) => App.STATE.SelectedArticle = SelectedArticle);
            ThreadPool.QueueUserWorkItem((o) => App.STATE.SaveUserPreferences());
        }
 public virtual Builder SetCancelable(bool cancelable)
 {
     builder.SetCancelable(cancelable);
     return(this);
 }
        public void BuildStorehouseWorker()
        {
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += (object sender, DoWorkEventArgs e) =>
            {
                MaterialDialog.Builder progress = new MaterialDialog.Builder(this);
                progress.SetTitle("Finalizing Storehouse");
                progress.SetContent("Please be patient");
                progress.SetCancelable(false);
                progress.SetProgress(true, 3);

                MaterialDialog dialog = null;

                RunOnUiThread(() =>
                {
                    dialog = progress.Show();
                });

                RunOnUiThread(() =>
                {
                    dialog.SetContent("Building English library");
                });
                App.FUNCTIONS.ExtractDatabase("english.db", this, MAIN_EXPANSION_FILE_VERSION);
                RunOnUiThread(() =>
                {
                    dialog.SetContent("Building Chinese library");
                });
                App.FUNCTIONS.ExtractDatabase("chinese.db", this, MAIN_EXPANSION_FILE_VERSION);
                RunOnUiThread(() =>
                {
                    dialog.SetContent("Building Pinyin library");
                });
                App.FUNCTIONS.ExtractDatabase("pinyin.db", this, MAIN_EXPANSION_FILE_VERSION);

                List <Library> libraries = new List <Library>();
                libraries.Add(Library.Bible);
                libraries.Add(Library.Insight);
                libraries.Add(Library.DailyText);
                libraries.Add(Library.Publications);

                App.STATE.Libraries      = libraries;
                App.STATE.CurrentLibrary = libraries.First();

                App.STATE.SeekBarTextSize = Resources.GetInteger(Resource.Integer.webview_base_font_size);

                // English
                App.STATE.PrimaryLanguage = App.FUNCTIONS.GetAvailableLanguages(this)[0];
                // Chinese
                App.STATE.SecondaryLanguage = App.FUNCTIONS.GetAvailableLanguages(this)[1];
                // Pinyin
                App.STATE.PinyinLanguage = App.FUNCTIONS.GetAvailableLanguages(this)[2];
                // Set current language first to English
                App.STATE.Language = App.STATE.PrimaryLanguage.EnglishName;

                App.STATE.SaveUserPreferences();
                preferences.Edit().PutInt("MainExpansionFileVersion", MAIN_EXPANSION_FILE_VERSION).Commit();

                RunOnUiThread(() =>
                {
                    Toast.MakeText(this, "Set up complete. Have fun!", ToastLength.Long).Show();
                });

                dialog.Dismiss();

                StartApplication();
            };

            worker.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) =>
            {
                Console.WriteLine("WORKER COMPLETE!");
            };
        }