Пример #1
0
        //Set the feed icon
        private async void btn_SetIcon_Clicked(object sender, EventArgs e)
        {
            try
            {
                Feeds SelectedItem = (Feeds)listview_Items.SelectedItem;
                if (SelectedItem != null)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Set custom icon");
                    messageAnswers.Add("Reset the icon");
                    messageAnswers.Add("Cancel");

                    string messageResult = await MessagePopup.Popup("Change the feed icon", "Would you like to set a custom feed icon for " + SelectedItem.feed_title + "?", messageAnswers);

                    if (messageResult == "Set custom icon")
                    {
                        Debug.WriteLine("Changing icon for feed: " + SelectedItem.feed_id + " / " + SelectedItem.feed_title);

                        PickOptions pickOptions = new PickOptions();
                        pickOptions.FileTypes = FilePickerFileType.Png;

                        FileResult pickResult = await FilePicker.PickAsync(pickOptions);

                        if (pickResult != null)
                        {
                            //Load feed icon
                            Stream imageStream = await pickResult.OpenReadAsync();

                            //Update feed icon
                            if (imageStream.CanSeek)
                            {
                                imageStream.Position = 0;
                            }
                            SelectedItem.feed_icon = ImageSource.FromStream(() => imageStream);

                            //Save feed icon
                            AVFiles.File_SaveStream(SelectedItem.feed_id + ".png", imageStream, true, true);
                        }
                    }
                    else if (messageResult == "Reset the icon")
                    {
                        //Delete the feed icon
                        AVFiles.File_Delete(SelectedItem.feed_id + ".png", true);

                        //Load default feed icon
                        SelectedItem.feed_icon = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");

                        //Reset the online status
                        OnlineUpdateFeeds = true;
                        ApiMessageError   = string.Empty;

                        List <string> messageAnswersReset = new List <string>();
                        messageAnswersReset.Add("Ok");

                        await MessagePopup.Popup("Feed icon reset", "The feed icon has been reset and will be refreshed on the next online feed update, you can refresh the feeds by clicking on the refresh icon above.", messageAnswersReset);
                    }
                }
            }
            catch { }
        }
Пример #2
0
        //Open item in browser
        private static async Task ListItemOpenBrowser(ListView SendListView, Items SelectedItem, ObservableCollection <Items> SelectedList, string CurrentPageName)
        {
            try
            {
                //Check internet connection
                if (Connectivity.NetworkAccess != NetworkAccess.Internet)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("No internet connection", "You currently don't have an internet connection available to open this item or link in your webbrowser.", messageAnswers);

                    return;
                }

                //Get the target uri
                Uri targetUri = new Uri(SelectedItem.item_link, UriKind.RelativeOrAbsolute);

                //Mark the item as read
                await ListItemMarkRead(true, SendListView, SelectedItem, SelectedList, CurrentPageName);

                //Open item in webbrowser
                await Browser.OpenAsync(targetUri, BrowserLaunchMode.SystemPreferred);
            }
            catch { }
        }
Пример #3
0
        //No account prompt
        private async Task NoAccountPrompt()
        {
            try
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Enter account");
                messageAnswers.Add("Register account");
                messageAnswers.Add("Exit application");

                string messageResult = await MessagePopup.Popup("No account is set", "Please set your account email and password to start using News Scroll.", messageAnswers);

                if (messageResult == "Enter account")
                {
                    //Focus on the text box to open keyboard
                    setting_ApiAccount.IsEnabled = false;
                    setting_ApiAccount.IsEnabled = true;
                    setting_ApiAccount.Focus();
                    return;
                }
                if (messageResult == "Register account")
                {
                    btn_RegisterAccount_Click(null, null);
                    return;
                }
                else if (messageResult == "Exit application")
                {
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
                    return;
                }
            }
            catch { }
        }
Пример #4
0
        private static async void vTimer_InternetCheck_Function()
        {
            try
            {
                bool currentOnlineStatus = Connectivity.NetworkAccess == NetworkAccess.Internet;

                //Check if media needs to load
                AppVariables.LoadMedia = true;
                if (!currentOnlineStatus && !(bool)AppSettingLoad("DisplayImagesOffline"))
                {
                    AppVariables.LoadMedia = false;
                }

                //Check if internet connection has changed
                if (currentOnlineStatus && !AppVariables.PreviousOnlineStatus)
                {
                    Debug.WriteLine("Connectivity changed, internet available: " + currentOnlineStatus);
                    AppVariables.PreviousOnlineStatus = currentOnlineStatus;

                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Internet now available", "It seems like you have an internet connection available, you can now refresh the feeds and items, your offline starred and read items will now be synced.", messageAnswers);
                    await SyncOfflineChanges(false, true);
                }
            }
            catch { }
        }
Пример #5
0
        private async Task DownloadFullItemContent(int RetryCount)
        {
            try
            {
                //Download the full item content
                string FullContent = await WebParser(vItemViewerItem.item_link, false, true);

                if (!string.IsNullOrWhiteSpace(FullContent))
                {
                    //Load item into the viewer
                    await LoadItem(FullContent);

                    //Update the button text
                    button_LoadFullItem.Text = "Load the original item";
                    iconItem.Source          = ImageSource.FromResource("NewsScroll.Assets.iconItemSumm.png");

                    //Scroll to the top
                    await Task.Delay(10);

                    await scrollviewer_NewsItem.ScrollToAsync(0, 0, false);
                }
                else
                {
                    if (RetryCount == 3)
                    {
                        //Check if internet is available
                        if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                        {
                            Debug.WriteLine("There is currently no full item content available.");

                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Open in browser");
                            messageAnswers.Add("Cancel");

                            string messageResult = await MessagePopup.Popup("No item content available", "There is currently no full item content available, would you like to open the item in the browser?", messageAnswers);

                            if (messageResult == "Open in browser")
                            {
                                await OpenBrowser(null, true);
                            }
                        }
                        else
                        {
                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Ok");

                            Debug.WriteLine("There is currently no full item content available. (No Internet)");
                            await MessagePopup.Popup("No item content available", "There is currently no full item content available but it might also be your internet connection, please check your internet connection and try again.", messageAnswers);
                        }
                    }
                    else
                    {
                        RetryCount++;
                        Debug.WriteLine("Retrying to download full item content: " + RetryCount);
                        await DownloadFullItemContent(RetryCount);
                    }
                }
            }
            catch { }
        }
Пример #6
0
        //Save the image
        private async void button_iconSave_Tap(object sender, EventArgs e)
        {
            try
            {
                string fileName    = Path.GetFileName(vImageLink);
                string localFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                string filePath    = Path.Combine(localFolder, fileName);

                //Download image
                Uri    imageUri    = new Uri(vImageLink);
                Stream imageStream = await dependencyAVImages.DownloadResizeImage(imageUri, 999999, 999999);

                //Save image
                AVFiles.File_SaveStream(filePath, imageStream, true, false);
            }
            catch
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Ok");

                await MessagePopup.Popup("Failed to save", "Failed to save the image, please check your internet connection and try again.", messageAnswers);

                Debug.WriteLine("Failed to save the image.");
            }
        }
Пример #7
0
        //Open item in browser
        private async Task OpenBrowser(Uri TargetUri, bool closePopup)
        {
            try
            {
                //Check internet connection
                if (Connectivity.NetworkAccess != NetworkAccess.Internet)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("No internet connection", "You currently don't have an internet connection available to open this item or link in your webbrowser.", messageAnswers);

                    return;
                }

                //Close the popup
                if (closePopup)
                {
                    await ClosePopup();
                }

                //Open item in webbrowser
                if (TargetUri != null)
                {
                    await Browser.OpenAsync(TargetUri, BrowserLaunchMode.SystemPreferred);
                }
                else
                {
                    await Browser.OpenAsync(new Uri(vItemViewerItem.item_link), BrowserLaunchMode.SystemPreferred);
                }
            }
            catch { }
        }
Пример #8
0
        private async Task LoadFullItem()
        {
            try
            {
                if (button_LoadFullItem.Text == "Load the original item")
                {
                    ProgressDisableUI("Loading the original item...");

                    //Load the original item content
                    string OriginalContent = vItemViewerItem.item_content_full;

                    //Load item into the viewer
                    await LoadItem(OriginalContent);

                    //Update the button text
                    button_LoadFullItem.Text = "Load the full item";
                    iconItem.Source          = ImageSource.FromResource("NewsScroll.Assets.iconItemFull.png");

                    //Scroll to the top
                    await Task.Delay(10);

                    await scrollviewer_NewsItem.ScrollToAsync(0, 0, false);
                }
                else
                {
                    //Check if internet is available
                    if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                    {
                        ProgressDisableUI("Loading the full item...");

                        int RetryCount = 0;
                        await DownloadFullItemContent(RetryCount);
                    }
                    else
                    {
                        List <string> messageAnswers = new List <string>();
                        messageAnswers.Add("Ok");

                        Debug.WriteLine("No network available to fully load this item.");
                        await MessagePopup.Popup("No internet connection", "You currently don't have an internet connection available to fully load this item.", messageAnswers);
                    }
                }

                ProgressEnableUI();
            }
            catch { }
        }
Пример #9
0
        //Clear Database Click
        async void ClearStoredItems_Click(object sender, EventArgs e)
        {
            try
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Clear database");
                messageAnswers.Add("Cancel");

                string messageResult = await MessagePopup.Popup("Clear database", "Do you want to clear all your stored offline feeds and items? All the feeds and items will need to be downloaded again.", messageAnswers);

                if (messageResult == "Clear database")
                {
                    await ClearDatabase();
                }
            }
            catch { }
        }
Пример #10
0
        //Open register account
        async void btn_RegisterAccount_Click(object sender, EventArgs e)
        {
            try
            {
                if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                {
                    await Browser.OpenAsync(new Uri("https://theoldreader.com/users/sign_up"), BrowserLaunchMode.SystemPreferred);
                }
                else
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("No internet connection", "You can't register an account when there is no internet connection available.", messageAnswers);
                }
            }
            catch { }
        }
Пример #11
0
        private async Task RefreshItems(bool Confirm)
        {
            try
            {
                string messageResult = string.Empty;
                if (Confirm)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Refresh news items");
                    messageAnswers.Add("Cancel");

                    messageResult = await MessagePopup.Popup("Refresh news items", "Do you want to refresh all the news items and scroll to the top?", messageAnswers);
                }

                if (messageResult == "Refresh news items")
                {
                    //Reset the online status
                    OnlineUpdateFeeds = true;
                    OnlineUpdateNews  = true;
                    ApiMessageError   = string.Empty;

                    //Load all the items
                    await LoadItems(true, false);
                }
                else if (!List_NewsItems.Any() && !(bool)AppSettingLoad("DisplayReadMarkedItems"))
                {
                    Feeds TempFeed = new Feeds();
                    TempFeed.feed_id = "1";

                    //Change the selection feed
                    ChangeSelectionFeed(TempFeed, false);

                    //Load all the items
                    await LoadItems(false, true);
                }
            }
            catch { }
        }
Пример #12
0
 //Show the popup
 public static async Task <string> Popup(string Question, string Description, List <string> Answers)
 {
     try
     {
         string messageResult = null;
         Device.BeginInvokeOnMainThread(async() =>
         {
             MessagePopup newPopup = new MessagePopup();
             App.NavigateToPage(newPopup, true, true);
             messageResult = await newPopup.WaitResult(Question, Description, Answers);
         });
         while (messageResult == null)
         {
             await Task.Delay(100);
         }
         return(messageResult);
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Failed to create message popup: " + ex.Message);
         return(string.Empty);
     }
 }
Пример #13
0
        private async Task RefreshItems()
        {
            try
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Refresh starred items");
                messageAnswers.Add("Cancel");

                string messageResult = await MessagePopup.Popup("Refresh starred items", "Do you want to refresh starred items and scroll to the top?", messageAnswers);

                if (messageResult == "Refresh starred items")
                {
                    //Reset the online status
                    OnlineUpdateFeeds   = true;
                    OnlineUpdateStarred = true;
                    ApiMessageError     = string.Empty;

                    //Load all the items
                    await LoadItems();
                }
            }
            catch { }
        }
Пример #14
0
        private async Task RefreshFeeds()
        {
            try
            {
                HideShowMenu(true);

                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Refresh feeds");
                messageAnswers.Add("Cancel");

                string messageResult = await MessagePopup.Popup("Refresh feeds", "Do you want to refresh the feeds and scroll to the top?", messageAnswers);

                if (messageResult == "Refresh feeds")
                {
                    //Reset the online status
                    OnlineUpdateFeeds = true;
                    ApiMessageError   = string.Empty;

                    //Load all the feeds
                    await LoadFeeds();
                }
            }
            catch { }
        }
Пример #15
0
        //Delete feeds from The Old Reader/Database
        async void btn_DeleteFeeds_Click(object sender, EventArgs e)
        {
            try
            {
                //Check for internet connection
                if (Connectivity.NetworkAccess != NetworkAccess.Internet)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("No internet connection", "Deleting a feed can only be done when there is an internet connection available.", messageAnswers);

                    return;
                }

                //Check for selected items
                if (listview_Items.SelectedItem == null)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("No feeds selected", "Please select some feeds that you want to delete first.", messageAnswers);

                    return;
                }
                else
                {
                    //Wait for busy application
                    await ApiUpdate.WaitForBusyApplication();

                    ProgressDisableUI("Deleting the selected feeds...", true);

                    try
                    {
                        Feeds SelectedItem = (Feeds)listview_Items.SelectedItem;
                        await DeleteFeed(SelectedItem.feed_id);

                        List <string> messageAnswers = new List <string>();
                        messageAnswers.Add("Ok");

                        await MessagePopup.Popup("Feeds have been deleted", "The feeds and it's items will disappear on the next refresh.", messageAnswers);
                    }
                    catch
                    {
                        List <string> messageAnswers = new List <string>();
                        messageAnswers.Add("Ok");

                        await MessagePopup.Popup("Failed to delete feeds", "Please check your account settings, internet connection and try again.", messageAnswers);
                    }

                    //Reset the online status
                    OnlineUpdateFeeds = true;
                    ApiMessageError   = string.Empty;

                    //Load all the feeds
                    await LoadFeeds();

                    ProgressEnableUI();
                }
            }
            catch { }
        }
Пример #16
0
        //Ignore feeds in database
        async void btn_IgnoreFeeds_Click(object sender, EventArgs e)
        {
            try
            {
                //Check for selected items
                if (listview_Items.SelectedItem == null)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("No feeds selected", "Please select some feeds that you want to un/ignore first.", messageAnswers);

                    return;
                }
                else
                {
                    try
                    {
                        //Wait for busy application
                        await ApiUpdate.WaitForBusyApplication();

                        ProgressDisableUI("Un/ignoring selected feeds...", true);

                        List <TableFeeds> TableEditFeeds = await vSQLConnection.Table <TableFeeds>().ToListAsync();

                        Feeds      SelectedItem = (Feeds)listview_Items.SelectedItem;
                        TableFeeds TableResult  = TableEditFeeds.Where(x => x.feed_id == SelectedItem.feed_id).FirstOrDefault();
                        if (SelectedItem.feed_ignore_status == true)
                        {
                            TableResult.feed_ignore_status  = false;
                            SelectedItem.feed_ignore_status = false;
                        }
                        else
                        {
                            TableResult.feed_ignore_status  = true;
                            SelectedItem.feed_ignore_status = true;
                        }

                        //Update the items in database
                        await vSQLConnection.UpdateAllAsync(TableEditFeeds);

                        //Reset the list selection
                        listview_Items.SelectedItem = -1;

                        List <string> messageAnswers = new List <string>();
                        messageAnswers.Add("Ok");

                        await MessagePopup.Popup("Feeds have been un/ignored", "Their items will be hidden or shown again on the next news item refresh.", messageAnswers);
                    }
                    catch
                    {
                        List <string> messageAnswers = new List <string>();
                        messageAnswers.Add("Ok");

                        await MessagePopup.Popup("Failed to un/ignore feeds", "Please try to un/ignored the feeds again.", messageAnswers);
                    }

                    ProgressEnableUI();
                }
            }
            catch { }
        }
Пример #17
0
        private static async Task ListView_DoubleTap(ListView SendListView, Items SelectedItem, ObservableCollection <Items> SelectedList)
        {
            try
            {
                //Set the action string text
                string ActionStarItem = "Un/star";
                if (SelectedItem.item_star_status == true)
                {
                    ActionStarItem = "Unstar";
                }
                else
                {
                    ActionStarItem = "Star";
                }

                //Set the action string text
                string ActionReadItem = "Un/read";
                if (SelectedItem.item_read_status == true)
                {
                    ActionReadItem = "Unread";
                }
                else
                {
                    ActionReadItem = "Read";
                }

                //Get and set the current page name
                string CurrentPageName = App.Current.MainPage.ToString();

                //Check if mark read till is enabled
                string actionMarkReadTill = string.Empty;
                if (CurrentPageName.EndsWith("NewsPage") && vNewsFeed.feed_id != "1")
                {
                    actionMarkReadTill = "Mark read till item";
                }

                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Open in browser");
                messageAnswers.Add("Share this item");
                messageAnswers.Add(ActionStarItem + " this item");
                messageAnswers.Add("Mark item as " + ActionReadItem.ToLower());
                if (!string.IsNullOrWhiteSpace(actionMarkReadTill))
                {
                    messageAnswers.Add(actionMarkReadTill);
                }
                messageAnswers.Add("Cancel");

                string messageResult = await MessagePopup.Popup("News item actions", "What would you like to do with this item?", messageAnswers);

                if (messageResult == "Open in browser")
                {
                    await ListItemOpenBrowser(SendListView, SelectedItem, SelectedList, CurrentPageName);
                }
                else if (messageResult == "Share this item")
                {
                    await ShareItem(SelectedItem);
                }
                else if (messageResult == ActionStarItem + " this item")
                {
                    if (CurrentPageName.EndsWith("StarredPage"))
                    {
                        bool MarkedAsStar = await MarkItemAsStarPrompt(SelectedItem, false, true, false, false, true);

                        //if (MarkedAsStar) { await EventUpdateTotalItemsCount(null, null, false, true); }
                    }
                    else
                    {
                        await MarkItemAsStarPrompt(SelectedItem, false, false, false, false, true);
                    }
                }
                else if (messageResult == "Mark item as " + ActionReadItem.ToLower())
                {
                    await ListItemMarkRead(false, SendListView, SelectedItem, SelectedList, CurrentPageName);
                }
                else if (messageResult == actionMarkReadTill)
                {
                    bool MarkedRead = await MarkReadTill(SelectedList, SelectedItem, true, false, true);

                    if (MarkedRead && CurrentPageName.EndsWith("NewsPage"))
                    {
                        //Check if there are any unread items
                        if (!SelectedList.Any(x => x.item_read_status == false))
                        {
                            await EventRefreshPageItems(true);
                        }
                    }
                }
            }
            catch { }
        }
Пример #18
0
        public static async Task <int> PageApiUpdate()
        {
            try
            {
                //Reset load variables
                AppVariables.CurrentTotalItemsCount = 0;
                AppVariables.CurrentFeedsLoaded     = 0;
                AppVariables.CurrentItemsLoaded     = 0;
                AppVariables.BusyApplication        = true;
                Debug.WriteLine("Started updating api (News: " + OnlineUpdateNews + " Starred: " + OnlineUpdateStarred + " Feeds: " + OnlineUpdateFeeds + ")");

                //Check if offline mode is enabled
                if (!ApiMessageError.Contains("Off"))
                {
                    //Check update success
                    bool UpdateStatus = true;

                    //Check the login status
                    if ((OnlineUpdateNews || OnlineUpdateStarred || OnlineUpdateFeeds) && !AppVariables.LoadSearch && !CheckLogin())
                    {
                        UpdateStatus = await Login(false, false);

                        if (UpdateStatus)
                        {
                            ApiMessageError = string.Empty;
                        }
                        else
                        {
                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Retry to login");
                            messageAnswers.Add("Go to account settings");
                            messageAnswers.Add("Switch to offline mode");

                            string messageResult = await MessagePopup.Popup("Failed to login", "Would you like to retry to login to The Old Reader or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                            if (messageResult == "Retry to login")
                            {
                                return(await PageApiUpdate());
                            }
                            else if (messageResult == "Go to account settings")
                            {
                                AppVariables.BusyApplication = false;
                                return(2);
                            }
                            else
                            {
                                ApiMessageError = "(Off) ";
                            }
                        }
                    }

                    //Download feeds from Api
                    if (UpdateStatus && AppVariables.LoadFeeds && OnlineUpdateFeeds && !ApiMessageError.Contains("Off"))
                    {
                        UpdateStatus = await Feeds(false, false);

                        if (UpdateStatus)
                        {
                            ApiMessageError   = string.Empty;
                            OnlineUpdateFeeds = false;
                        }
                        else
                        {
                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Retry downloading feeds");
                            messageAnswers.Add("Go to account settings");
                            messageAnswers.Add("Switch to offline mode");

                            string messageResult = await MessagePopup.Popup("Failed to load the feeds", "Would you like to retry loading the feeds or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                            if (messageResult == "Retry downloading feeds")
                            {
                                return(await PageApiUpdate());
                            }
                            else if (messageResult == "Go to account settings")
                            {
                                AppVariables.BusyApplication = false;
                                return(2);
                            }
                            else
                            {
                                ApiMessageError   = "(Off) ";
                                OnlineUpdateFeeds = true;
                            }
                        }
                    }

                    //Download news items from Api
                    if (UpdateStatus && AppVariables.LoadNews && OnlineUpdateNews)
                    {
                        //Remove older news items
                        await ItemsRemoveOld(false, false);

                        //Sync offline changed items
                        await SyncOfflineChanges(false, false);

                        //Download news items from Api
                        if (!ApiMessageError.Contains("Off"))
                        {
                            if (UpdateStatus)
                            {
                                UpdateStatus = await AllNewsItems(true, false, false, false);
                            }
                            if (!UpdateStatus)
                            {
                                List <string> messageAnswers = new List <string>();
                                messageAnswers.Add("Retry downloading items");
                                messageAnswers.Add("Switch to offline mode");

                                string messageResult = await MessagePopup.Popup("Failed to load the items", "Would you like to retry loading the items or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                                if (messageResult == "Retry downloading items")
                                {
                                    return(await PageApiUpdate());
                                }
                                else
                                {
                                    ApiMessageError  = "(Off) ";
                                    OnlineUpdateNews = true;
                                }
                            }
                        }

                        //Download read status from Api
                        if (!ApiMessageError.Contains("Off"))
                        {
                            if (UpdateStatus)
                            {
                                UpdateStatus = await ItemsRead(List_NewsItems, false, false);
                            }
                            if (!UpdateStatus)
                            {
                                List <string> messageAnswers = new List <string>();
                                messageAnswers.Add("Retry downloading read items");
                                messageAnswers.Add("Switch to offline mode");

                                string messageResult = await MessagePopup.Popup("Failed to load read items", "Would you like to retry loading read items or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                                if (messageResult == "Retry downloading read items")
                                {
                                    return(await PageApiUpdate());
                                }
                                else
                                {
                                    ApiMessageError  = "(Off) ";
                                    OnlineUpdateNews = true;
                                }
                            }
                        }

                        //Check if news items updated
                        if (UpdateStatus && !ApiMessageError.Contains("Off"))
                        {
                            ApiMessageError  = string.Empty;
                            OnlineUpdateNews = false;
                        }
                    }

                    //Download starred items from Api
                    if (UpdateStatus && AppVariables.LoadStarred && OnlineUpdateStarred && !ApiMessageError.Contains("Off"))
                    {
                        UpdateStatus = await ItemsStarred(true, false, false);

                        if (UpdateStatus)
                        {
                            ApiMessageError     = string.Empty;
                            OnlineUpdateStarred = false;
                        }
                        else
                        {
                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Retry downloading starred items");
                            messageAnswers.Add("Switch to offline mode");

                            string messageResult = await MessagePopup.Popup("Failed to load starred items", "Would you like to retry loading starred items or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                            if (messageResult == "Retry downloading starred items")
                            {
                                return(await PageApiUpdate());
                            }
                            else
                            {
                                ApiMessageError     = "(Off) ";
                                OnlineUpdateStarred = true;
                            }
                        }
                    }
                }

                Debug.WriteLine("Finished the update task.");
                AppVariables.BusyApplication = false;
                return(0);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to start update task: " + ex.Message);
                AppVariables.BusyApplication = false;
                return(1);
            }
        }
Пример #19
0
        public static async Task <bool> ListViewScroller(ListView TargetListView, int CurrentItemId, int PreviousItemId)
        {
            try
            {
                ObservableCollection <Items> SelectedList = (ObservableCollection <Items>)TargetListView.ItemsSource;
                int TargetListViewItems = SelectedList.Count;
                if (TargetListViewItems > 0)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Scroll to beginning");
                    messageAnswers.Add("Scroll to the middle");
                    messageAnswers.Add("Scroll to the end");
                    messageAnswers.Add("Scroll to unread item");
                    string stringReturnToPrevious = string.Empty;
                    if (PreviousItemId != 0 && TargetListViewItems > PreviousItemId)
                    {
                        stringReturnToPrevious = "Scroll back to " + PreviousItemId;
                        messageAnswers.Add(stringReturnToPrevious);
                    }
                    messageAnswers.Add("Cancel");

                    string messageResult = await MessagePopup.Popup("Item scroller", "Would you like to scroll in the items?", messageAnswers);

                    if (messageResult == "Scroll to beginning")
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollTo(SelectedList.FirstOrDefault(), ScrollToPosition.MakeVisible, false);
                        return(true);
                    }
                    else if (messageResult == "Scroll to the middle")
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollTo(SelectedList[TargetListViewItems / 2], ScrollToPosition.MakeVisible, false);
                        return(true);
                    }
                    else if (messageResult == "Scroll to the end")
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollTo(SelectedList.LastOrDefault(), ScrollToPosition.MakeVisible, false);
                        return(true);
                    }
                    else if (messageResult == "Scroll to unread item")
                    {
                        await Task.Delay(10);

                        Items scrollItem = SelectedList.Where(x => x.item_read_status == false).FirstOrDefault();
                        if (scrollItem != null)
                        {
                            TargetListView.ScrollTo(scrollItem, ScrollToPosition.MakeVisible, false);
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (messageResult == stringReturnToPrevious)
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollTo(SelectedList[PreviousItemId], ScrollToPosition.MakeVisible, false);
                        return(true);
                    }
                }
            }
            catch { }
            return(false);
        }
Пример #20
0
        //Add feed to the api
        private async Task AddFeedToApi()
        {
            try
            {
                //Check if user is logged in
                if (!CheckLogin())
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Not logged in", "Adding a feed can only be done when you are logged in.", messageAnswers);

                    return;
                }

                //Check for internet connection
                if (Connectivity.NetworkAccess != NetworkAccess.Internet)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("No internet connection", "Adding a feed can only be done when there is an internet connection available.", messageAnswers);

                    return;
                }

                //Remove ending / characters from the url
                txtbox_AddFeed.Text = AVFunctions.StringRemoveEnd(txtbox_AddFeed.Text, "/");

                //Check if there is an url entered
                if (string.IsNullOrWhiteSpace(txtbox_AddFeed.Text))
                {
                    //Focus on the text box to open keyboard
                    txtbox_AddFeed.IsEnabled = false;
                    txtbox_AddFeed.IsEnabled = true;
                    txtbox_AddFeed.Focus();
                    return;
                }

                //Validate the url entered
                if (!Regex.IsMatch(txtbox_AddFeed.Text, @"^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$"))
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Invalid feed link", "The entered feed link is invalid or does not contain a feed, please check your link and try again.", messageAnswers);

                    //Focus on the text box to open keyboard
                    txtbox_AddFeed.IsEnabled = false;
                    txtbox_AddFeed.IsEnabled = true;
                    txtbox_AddFeed.Focus();
                    return;
                }

                ProgressDisableUI("Adding feed: " + txtbox_AddFeed.Text, true);

                if (await AddFeed(txtbox_AddFeed.Text))
                {
                    //Reset the online status
                    OnlineUpdateFeeds   = true;
                    OnlineUpdateNews    = true;
                    OnlineUpdateStarred = true;
                    ApiMessageError     = string.Empty;

                    //Reset the last update setting
                    await AppSettingSave("LastItemsUpdate", "Never");

                    //Reset the textbox entry
                    txtbox_AddFeed.Text = string.Empty;

                    //Load all the feeds
                    await LoadFeeds();
                }
                else
                {
                    //Focus on the text box to open keyboard
                    txtbox_AddFeed.IsEnabled = false;
                    txtbox_AddFeed.IsEnabled = true;
                    txtbox_AddFeed.Focus();
                }

                ProgressEnableUI();
            }
            catch { }
        }