Ejemplo n.º 1
0
        /// <summary>
        /// Will save a draft of what the user currently has.
        /// </summary>
        private async Task SaveDraft()
        {
            // If we have nothing to save don't
            if (!HasInfoToDraft())
            {
                return;
            }

            // Make the data
            PostSubmissionDraftData data = new PostSubmissionDraftData()
            {
                Title      = ui_postTitleTextBox.Text,
                UrlOrText  = ui_postUrlTextBox.Text,
                isSelfText = ui_isSelfPostCheckBox.IsChecked.Value,
                Subreddit  = ui_subredditSuggestBox.Text
            };

            // Save the data
            bool success = await App.BaconMan.DraftMan.SavePostSubmissionDraft(data);

            // Print the last save time
            if (success)
            {
                ui_lastDraftSaveTime.Text = "Saved at " + DateTime.Now.ToString("hh:mm:ss");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Will check for an existing draft and will restore if the users wants.
        /// </summary>
        private async void CheckForAndPromptForDraft()
        {
            // If we already have info on the screen don't replace it.
            if (HasInfoToDraft())
            {
                return;
            }

            // See if we have something to restore
            if (await App.BaconMan.DraftMan.HasPostSubmitDraft())
            {
                // Make a message to show the user
                bool          restoreDraft = true;
                MessageDialog message      = new MessageDialog("It looks like you have draft of a submission, would you like to restore it?", "Draft Restore");
                message.Commands.Add(new UICommand(
                                         "Restore Draft",
                                         (IUICommand command) => { restoreDraft = true; }));
                message.Commands.Add(new UICommand(
                                         "Discard Draft",
                                         (IUICommand command) => { restoreDraft = false; }));
                message.DefaultCommandIndex = 0;
                message.CancelCommandIndex  = 1;

                // Show the dialog
                await message.ShowAsync();

                if (restoreDraft)
                {
                    // Get the data
                    PostSubmissionDraftData data = await App.BaconMan.DraftMan.GetPostSubmissionDraft();

                    if (data != null)
                    {
                        // Restore it
                        ui_postTitleTextBox.Text        = data.Title;
                        ui_postUrlTextBox.Text          = data.UrlOrText;
                        ui_isSelfPostCheckBox.IsChecked = data.isSelfText;
                        ui_subredditSuggestBox.Text     = data.Subreddit;

                        // If we are self text open the box
                        if (ui_isSelfPostCheckBox.IsChecked.Value)
                        {
                            IsSelfPostCheckBox_Click(null, null);
                        }
                    }
                }
                else
                {
                    // Delete the data.
                    ClearDraft();
                }
            }
        }