Example #1
0
        static public async Task <bool> AddFeed(string FeedLink)
        {
            try
            {
                string[][]        RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                HttpStringContent PostContent   = new HttpStringContent("quickadd=" + WebUtility.HtmlEncode(FeedLink), Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                Uri PostUri = new Uri(ApiConnectionUrl + "subscription/quickadd");

                HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(10000, "News Scroll", RequestHeader, PostUri, PostContent);

                JObject WebJObject = JObject.Parse(PostHttp.Content.ToString());
                if (WebJObject["numResults"].ToString() == "0")
                {
                    await AVMessageBox.Popup("Invalid feed link", "The entered feed link is invalid or does not contain a feed, please check your link and try again.", "Ok", "", "", "", "", false);

                    //Debug.WriteLine(WebJObject["error"].ToString());
                    return(false);
                }
                else
                {
                    await AVMessageBox.Popup("Feed has been added", "Your new feed has been added to your account, and will appear on the next feed refresh.", "Ok", "", "", "", "", false);

                    return(true);
                }
            }
            catch
            {
                await AVMessageBox.Popup("Failed to add feed", "Please check your account settings, internet connection and try again.", "Ok", "", "", "", "", false);

                return(false);
            }
        }
Example #2
0
        //Open item in browser
        private static async Task ListItemOpenBrowser(ListView SendListView, Items SelectedItem, ObservableCollection <Items> SelectedList, string CurrentPageName)
        {
            try
            {
                int MsgBoxResult = 0;

                //Check internet connection
                if (!NetworkInterface.GetIsNetworkAvailable())
                {
                    await AVMessageBox.Popup("No internet connection", "You currently don't have an internet connection available to open this item or link in the webviewer or your webbrowser.", "Ok", "", "", "", "", false);

                    return;
                }

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

                //Check webbrowser only links
                if (targetUri != null)
                {
                    string TargetString = targetUri.ToString();
                    if (!TargetString.StartsWith("http"))
                    {
                        MsgBoxResult = 2;
                    }
                }

                if (MsgBoxResult != 2)
                {
                    string LowMemoryWarning = string.Empty;
                    if (AVFunctions.DevMemoryAvailableMB() < 200)
                    {
                        LowMemoryWarning = "\n\n* Your device is currently low on available memory and may cause issues when you open this link or item in the webviewer.";
                    }
                    MsgBoxResult = await AVMessageBox.Popup("Open this item or link", "Do you want to open this item or link in the webviewer or your webbrowser?" + LowMemoryWarning, "Webviewer (In-app)", "Webbrowser (Device)", "", "", "", true);
                }

                if (MsgBoxResult == 1)
                {
                    //Open item in webviewer
                    WebViewer webViewer = new WebViewer();
                    await webViewer.OpenPopup(targetUri, SelectedItem);

                    //Mark the item as read
                    await ListItemMarkRead(true, SendListView, SelectedItem, SelectedList, CurrentPageName);
                }
                else if (MsgBoxResult == 2)
                {
                    //Mark the item as read
                    await ListItemMarkRead(true, SendListView, SelectedItem, SelectedList, CurrentPageName);

                    //Open item in webbrowser
                    await Launcher.LaunchUriAsync(targetUri);
                }
            }
            catch { }
        }
Example #3
0
        //Ignore feeds in database
        async void btn_IgnoreFeeds_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Check for selected items
                if (ListView_Items.SelectedItems.Count == 0)
                {
                    await AVMessageBox.Popup("No feeds selected", "Please select some feeds that you want to un/ignore first.", "Ok", "", "", "", "", false);

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

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

                        //Wait for busy database
                        await ApiUpdate.WaitForBusyDatabase();

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

                        foreach (Feeds SelectedItem in ListView_Items.SelectedItems)
                        {
                            TableFeeds TableResult = TableEditFeeds.Where(x => x.feed_id == SelectedItem.feed_id).FirstOrDefault();
                            if (SelectedItem.feed_ignore_status == Visibility.Visible)
                            {
                                TableResult.feed_ignore_status  = false;
                                SelectedItem.feed_ignore_status = Visibility.Collapsed;
                            }
                            else
                            {
                                TableResult.feed_ignore_status  = true;
                                SelectedItem.feed_ignore_status = Visibility.Visible;
                            }
                        }

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

                        //Reset the list selection
                        ListView_Items.SelectedIndex = -1;
                        await AVMessageBox.Popup("Feeds have been un/ignored", "Their items will be hidden or shown again on the next news item refresh.", "Ok", "", "", "", "", false);
                    }
                    catch
                    {
                        await AVMessageBox.Popup("Failed to un/ignore feeds", "Please try to un/ignored the feeds again.", "Ok", "", "", "", "", false);
                    }

                    await ProgressEnableUI();
                }
            }
            catch { }
        }
Example #4
0
        private async Task DownloadFullItemContent(int RetryCount)
        {
            try
            {
                //Download the full item content
                string FullContent = await WebParser(vCurrentWebSource.item_link, false, true);

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

                    //Update the button text
                    button_LoadFullItem.Content = "Load the original item";
                    ToolTipService.SetToolTip(iconItem, "Load the original item");
                    iconImageItem.Source = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconItemSumm.png", false);

                    PreviousScrollOffset = -1;

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

                    scrollviewer_NewsItem.ChangeView(null, 0, null);
                }
                else
                {
                    if (RetryCount == 3)
                    {
                        //Check if internet is available
                        if (NetworkInterface.GetIsNetworkAvailable())
                        {
                            Debug.WriteLine("There is currently no full item content available.");
                            int MsgBoxResult = await AVMessageBox.Popup("No item content available", "There is currently no full item content available, would you like to open the item in the browser?", "Open in browser", "", "", "", "", true);

                            if (MsgBoxResult == 1)
                            {
                                await OpenBrowser(null, true);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("There is currently no full item content available. (No Internet)");
                            await AVMessageBox.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.", "Ok", "", "", "", "", false);
                        }
                    }
                    else
                    {
                        RetryCount++;
                        Debug.WriteLine("Retrying to download full item content: " + RetryCount);
                        await DownloadFullItemContent(RetryCount);
                    }
                }
            }
            catch { }
        }
Example #5
0
        //Clear Database Click
        async void ClearStoredItems_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Int32 MessageBoxResult = await AVMessageBox.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.", "Clear database", "", "", "", "", true);

                if (MessageBoxResult == 1)
                {
                    await ClearDatabase();
                }
            }
            catch { }
        }
Example #6
0
        //Application close prompt
        public async Task Application_Exit_Prompt()
        {
            try
            {
                int messageResult = await AVMessageBox.MessageBoxPopup(this, "Do you really want to close DirectXInput?", "This will disconnect all your currently connected controllers.", "Close application", "Cancel", "", "");

                if (messageResult == 1)
                {
                    await Application_Exit();
                }
            }
            catch { }
        }
Example #7
0
        //Delete feeds from The Old Reader/Database
        async void btn_DeleteFeeds_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Check for internet connection
                if (!NetworkInterface.GetIsNetworkAvailable())
                {
                    await AVMessageBox.Popup("No internet connection", "Deleting a feed can only be done when there is an internet connection available.", "Ok", "", "", "", "", false);

                    return;
                }

                //Check for selected items
                if (ListView_Items.SelectedItems.Count == 0)
                {
                    await AVMessageBox.Popup("No feeds selected", "Please select some feeds that you want to delete first.", "Ok", "", "", "", "", false);

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

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

                    try
                    {
                        foreach (Feeds SelectedItem in ListView_Items.SelectedItems)
                        {
                            await DeleteFeed(SelectedItem.feed_id);
                        }
                        await AVMessageBox.Popup("Feeds have been deleted", "The feeds and it's items will disappear on the next refresh.", "Ok", "", "", "", "", false);
                    }
                    catch
                    {
                        await AVMessageBox.Popup("Failed to delete feeds", "Please check your account settings, internet connection and try again.", "Ok", "", "", "", "", false);
                    }

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

                    //Load all the feeds
                    await LoadFeeds();

                    await ProgressEnableUI();
                }
            }
            catch { }
        }
Example #8
0
 //Open register account
 async void btn_RegisterAccount_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (NetworkInterface.GetIsNetworkAvailable())
         {
             await Launcher.LaunchUriAsync(new Uri("https://theoldreader.com/users/sign_up"));
         }
         else
         {
             await AVMessageBox.Popup("No internet connection", "You can't register an account when there is no internet connection available.", "Ok", "", "", "", "", false);
         }
     }
     catch { }
 }
Example #9
0
        private async Task LoadFullItem()
        {
            try
            {
                if (button_LoadFullItem.Content.ToString() == "Load the original item")
                {
                    ProgressDisableUI("Loading the original item...");

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

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

                    //Update the button text
                    button_LoadFullItem.Content = "Load the full item";
                    ToolTipService.SetToolTip(iconItem, "Load the full item");
                    iconImageItem.Source = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconItemFull.png", false);

                    PreviousScrollOffset = -1;

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

                    scrollviewer_NewsItem.ChangeView(null, 0, null);
                }
                else
                {
                    //Check if internet is available
                    if (NetworkInterface.GetIsNetworkAvailable())
                    {
                        ProgressDisableUI("Loading the full item...");

                        int RetryCount = 0;
                        await DownloadFullItemContent(RetryCount);
                    }
                    else
                    {
                        Debug.WriteLine("No network available to fully load this item.");
                        await AVMessageBox.Popup("No internet connection", "You currently don't have an internet connection available to fully load this item.", "Ok", "", "", "", "", false);
                    }
                }

                ProgressEnableUI();
            }
            catch { }
        }
Example #10
0
        private static async void CheckInternetConnection(object sender)
        {
            try
            {
                bool CurrentOnlineStatus = NetworkInterface.GetIsNetworkAvailable();

                //Check if internet connection has changed
                if (CurrentOnlineStatus && !AppVariables.PreviousOnlineStatus)
                {
                    await AVMessageBox.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.", "Ok", "", "", "", "", false);
                    await SyncOfflineChanges(false, true);
                }

                AppVariables.PreviousOnlineStatus = CurrentOnlineStatus;
            }
            catch { }
        }
Example #11
0
        async void iconBrowser_Tap(object sender, RoutedEventArgs e)
        {
            try
            {
                await HideShowMenu(true);

                Int32 MsgBoxResult = await AVMessageBox.Popup("Open this item or link", "Do you want to open this item or link in your webbrowser?", "Open in webbrowser", "", "", "", "", true);

                if (MsgBoxResult == 1)
                {
                    ClosePopup();
                    //Open item in webbrowser
                    await Launcher.LaunchUriAsync(new Uri(vCurrentWebSource.item_link, UriKind.RelativeOrAbsolute));
                }
            }
            catch { }
        }
Example #12
0
        private async void button_StatusCurrentItem_Tapped(object sender, RoutedEventArgs e)
        {
            try
            {
                string ReturnToPrevious = string.Empty;
                if (PreviousScrollOffset != -1)
                {
                    ReturnToPrevious = "Scroll to previous";
                }

                int MsgBoxResult = await AVMessageBox.Popup("View scroller", "Would you like to scroll in the itemviewer?", "Scroll to beginning", "Scroll to the middle", "Scroll to the end", ReturnToPrevious, "", true);

                if (MsgBoxResult == 1)
                {
                    await Task.Delay(10);

                    PreviousScrollOffset = scrollviewer_NewsItem.VerticalOffset;
                    scrollviewer_NewsItem.ChangeView(null, 0, null);
                }
                else if (MsgBoxResult == 2)
                {
                    await Task.Delay(10);

                    PreviousScrollOffset = scrollviewer_NewsItem.VerticalOffset;
                    scrollviewer_NewsItem.ChangeView(null, scrollviewer_NewsItem.ScrollableHeight / 2, null);
                }
                else if (MsgBoxResult == 3)
                {
                    await Task.Delay(10);

                    PreviousScrollOffset = scrollviewer_NewsItem.VerticalOffset;
                    scrollviewer_NewsItem.ChangeView(null, scrollviewer_NewsItem.ScrollableHeight, null);
                }
                else if (MsgBoxResult == 4)
                {
                    await Task.Delay(10);

                    double CurrentOffset = scrollviewer_NewsItem.VerticalOffset;
                    scrollviewer_NewsItem.ChangeView(null, PreviousScrollOffset, null);
                    PreviousScrollOffset = CurrentOffset;
                }
            }
            catch { }
        }
Example #13
0
        private async Task RefreshItems()
        {
            try
            {
                Int32 MsgBoxResult = await AVMessageBox.Popup("Refresh starred items", "Do you want to refresh starred items and scroll to the top?", "Refresh starred items", "", "", "", "", true);

                if (MsgBoxResult == 1)
                {
                    //Reset the online status
                    OnlineUpdateFeeds   = true;
                    OnlineUpdateStarred = true;
                    ApiMessageError     = String.Empty;

                    //Load all the items
                    await LoadItems();
                }
            }
            catch { }
        }
Example #14
0
        //Mark item as star
        static public async Task <bool> MarkItemAsStarPrompt(Items ListItem, bool Confirm, bool RemoveFromList, bool ForceStar, bool Silent, bool EnableUI)
        {
            string ActionType = "Un/star";

            try
            {
                //Set the action string text
                if (ForceStar || ListItem.item_star_status == Visibility.Collapsed)
                {
                    ActionType = "Star";
                }
                else
                {
                    ActionType = "Unstar";
                }

                if (Confirm)
                {
                    Int32 MsgBoxResult = await AVMessageBox.Popup(ActionType + " item", "Do you want to " + ActionType.ToLower() + " this item?", ActionType + " item", "", "", "", "", true);

                    if (MsgBoxResult == 0)
                    {
                        return(false);
                    }
                }

                await MarkStarSingle(ListItem, RemoveFromList, ActionType, Silent);

                if (EnableUI)
                {
                    await EventProgressEnableUI();
                }
                return(true);
            }
            catch
            {
                await AVMessageBox.Popup("Failed to " + ActionType.ToLower() + " item", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                await EventProgressEnableUI();

                return(false);
            }
        }
Example #15
0
        //Mark item as read
        static public async Task <bool> MarkItemAsReadPrompt(ObservableCollection <Items> UpdateList, Items ListItem, bool Confirm, bool ForceRead, bool Silent)
        {
            string ActionType = "Un/read";

            try
            {
                //Set the action string text
                if (ForceRead || ListItem.item_read_status == Visibility.Collapsed)
                {
                    ActionType = "Read";
                }
                else
                {
                    ActionType = "Unread";
                }

                if (Confirm)
                {
                    Int32 MsgBoxResult = await AVMessageBox.Popup("Mark item " + ActionType.ToLower(), "Do you want to mark this item as " + ActionType.ToLower() + "?", "Mark item " + ActionType.ToLower(), "", "", "", "", true);

                    if (MsgBoxResult == 0)
                    {
                        return(false);
                    }
                }

                await MarkReadSingle(UpdateList, ListItem, ActionType, Silent);

                if (!Silent)
                {
                    await EventProgressEnableUI();
                }
                return(true);
            }
            catch
            {
                await AVMessageBox.Popup("Failed to mark item " + ActionType.ToLower(), "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                await EventProgressEnableUI();

                return(false);
            }
        }
Example #16
0
        private async Task RefreshFeeds()
        {
            try
            {
                HideShowMenu(true);

                Int32 MsgBoxResult = await AVMessageBox.Popup("Refresh feeds", "Do you want to refresh the feeds and scroll to the top?", "Refresh feeds", "", "", "", "", true);

                if (MsgBoxResult == 1)
                {
                    //Reset the online status
                    OnlineUpdateFeeds = true;
                    ApiMessageError   = String.Empty;

                    //Load all the feeds
                    await LoadFeeds();
                }
            }
            catch { }
        }
Example #17
0
        //Install the required drivers message popup
        async Task Message_InstallDrivers()
        {
            try
            {
                int messageResult = await AVMessageBox.MessageBoxPopup(this, "Drivers not installed", "Welcome to DirectXInput, it seems like you have not yet installed the required drivers to use this application, please make sure that you have installed the required drivers.\n\nDirectXInput will be closed during the installation of the required drivers.\n\nIf you just installed the drivers and this message shows up restart your PC.", "Install the drivers", "Close application", "", "");

                if (messageResult == 1)
                {
                    if (!CheckRunningProcessByNameOrTitle("DriverInstaller", false))
                    {
                        await ProcessLauncherWin32Async("DriverInstaller.exe", "", "", false, false);
                        await Application_Exit();
                    }
                }
                else
                {
                    await Application_Exit();
                }
            }
            catch { }
        }
Example #18
0
        //Remove the controller from the list
        async void Btn_RemoveController_Click(object sender, RoutedEventArgs args)
        {
            try
            {
                ControllerStatus activeController = vActiveController();
                if (activeController != null)
                {
                    int messageResult = await AVMessageBox.MessageBoxPopup(this, "Do you really want to remove this controller?", "This will reset the active controller to it's defaults and disconnect it.", "Remove controller profile", "Cancel", "", "");

                    if (messageResult == 1)
                    {
                        Debug.WriteLine("Removed the controller: " + activeController.Details.DisplayName);

                        NotificationDetails notificationDetails = new NotificationDetails();
                        notificationDetails.Icon = "Controller";
                        notificationDetails.Text = "Removed controller";
                        App.vWindowOverlay.Notification_Show_Status(notificationDetails);

                        AVActions.ActionDispatcherInvoke(delegate
                        {
                            txt_Controller_Information.Text = "Removed the controller: " + activeController.Details.DisplayName;
                        });

                        vDirectControllersProfile.Remove(activeController.Details.Profile);
                        await StopControllerAsync(activeController, "removed");

                        //Save changes to Json file
                        JsonSaveObject(vDirectControllersProfile, "DirectControllersProfile");
                    }
                }
                else
                {
                    NotificationDetails notificationDetails = new NotificationDetails();
                    notificationDetails.Icon = "Controller";
                    notificationDetails.Text = "No controller connected";
                    App.vWindowOverlay.Notification_Show_Status(notificationDetails);
                }
            }
            catch { }
        }
Example #19
0
        private static async Task <bool> MarkReadSingle(ObservableCollection <Items> UpdateList, Items ListItem, string ActionType, bool Silent)
        {
            try
            {
                bool   MarkStatus = false;
                string ItemId     = ListItem.item_id;

                //Check if internet is available
                if (!NetworkInterface.GetIsNetworkAvailable() || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Off marking item as " + ActionType.ToLower() + "...", true);
                    }
                    Debug.WriteLine("Off marking item as " + ActionType.ToLower() + "...");

                    await AddOfflineSync(ItemId, ActionType);

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Marking item as " + ActionType.ToLower() + "...", true);
                    }
                    Debug.WriteLine("Marking item as " + ActionType.ToLower() + "...");

                    string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };

                    HttpStringContent PostContent;
                    if (ActionType == "Read")
                    {
                        PostContent = new HttpStringContent("i=" + ItemId + "&a=user/-/state/com.google/read", Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                    }
                    else
                    {
                        PostContent = new HttpStringContent("i=" + ItemId + "&r=user/-/state/com.google/read", Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                    }

                    HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "edit-tag"), PostContent);

                    if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    //Mark item in database and list
                    TableItems TableEditItems = await SQLConnection.Table <TableItems>().Where(x => x.item_id == ItemId).FirstOrDefaultAsync();

                    if (TableEditItems != null)
                    {
                        if (ActionType == "Read")
                        {
                            TableEditItems.item_read_status = true;
                            ListItem.item_read_status       = Visibility.Visible; //Updates itemviewer
                            if (App.vApplicationFrame.SourcePageType.ToString().EndsWith("NewsPage") && NewsPage.vCurrentLoadingFeedFolder.feed_id != "1" && (bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                            {
                                UpdateList.Remove(ListItem);
                            }
                        }
                        else
                        {
                            TableEditItems.item_read_status = false;
                            ListItem.item_read_status       = Visibility.Collapsed; //Updates itemviewer
                            if (App.vApplicationFrame.SourcePageType.ToString().EndsWith("NewsPage") && NewsPage.vCurrentLoadingFeedFolder.feed_id == "1" && (bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                            {
                                UpdateList.Remove(ListItem);
                            }
                        }
                    }

                    //Update the items in database
                    await SQLConnection.UpdateAsync(TableEditItems);
                }
                else
                {
                    await AVMessageBox.Popup("Failed to mark item " + ActionType.ToLower(), "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                    await EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                Debug.WriteLine("Failed to un/read item.");
                return(false);
            }
        }
Example #20
0
        //Mark all items as read
        public static async Task <bool> MarkReadAll(ObservableCollection <Items> UpdateList, bool Confirm)
        {
            try
            {
                //Check if user is logged in
                if (!CheckLogin())
                {
                    await AVMessageBox.Popup("Not logged in", "Marking all items read can only be done when you are logged in.", "Ok", "", "", "", "", false);

                    return(false);
                }

                if (Confirm)
                {
                    Int32 MsgBoxResult = await AVMessageBox.Popup("Mark all items read", "Do you want to mark all items for every feed as read?", "Mark all items read", "", "", "", "", true);

                    if (MsgBoxResult == 0)
                    {
                        return(false);
                    }
                }

                bool MarkStatus = false;

                //Check if internet is available
                if (!NetworkInterface.GetIsNetworkAvailable() || ApiMessageError.StartsWith("(Off)"))
                {
                    await EventProgressDisableUI("Off marking all items as read...", true);

                    Debug.WriteLine("Off marking all items as read...");

                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    List <String> UnreadItemList = (await SQLConnection.Table <TableItems>().Where(x => !x.item_read_status).ToListAsync()).Select(x => x.item_id).ToList();
                    await AddOfflineSync(UnreadItemList, "Read");

                    MarkStatus = true;
                }
                else
                {
                    await EventProgressDisableUI("Marking all items as read...", true);

                    Debug.WriteLine("Marking all items as read...");

                    //Date time variables
                    Int64 UnixTimeTicks = 0;
                    if (AppVariables.ApplicationSettings["LastItemsUpdate"].ToString() != "Never")
                    {
                        UnixTimeTicks = (Convert.ToDateTime(AppVariables.ApplicationSettings["LastItemsUpdate"], AppVariables.CultureInfoEnglish).Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10; //Nanoseconds
                    }

                    //Mark all items as read on api server
                    string[][]        RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                    HttpStringContent PostContent   = new HttpStringContent("s=user/-/state/com.google/reading-list&ts=" + UnixTimeTicks, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");

                    HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "mark-all-as-read"), PostContent);

                    if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    Debug.WriteLine("Marked all items as read on the server or offline sync list.");

                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    //Update items in database
                    await SQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('1') WHERE item_read_status = ('0')");

                    //Update current items list
                    List <Items> ListItems = UpdateList.Where(x => x.item_read_status == Visibility.Collapsed).ToList();
                    foreach (Items NewsItem in ListItems)
                    {
                        if ((bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                        {
                            UpdateList.Remove(NewsItem);
                        }
                        else
                        {
                            NewsItem.item_read_status = Visibility.Visible;
                        }
                    }

                    await EventProgressEnableUI();
                }
                else
                {
                    await AVMessageBox.Popup("Failed to mark all items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                    await EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                await AVMessageBox.Popup("Failed to mark all items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                await EventProgressEnableUI();

                return(false);
            }
        }
Example #21
0
        //Mark items till as read
        public static async Task <bool> MarkReadTill(ObservableCollection <Items> UpdateList, Items EndItem, bool Confirm, bool Silent, bool EnableUI)
        {
            try
            {
                if (Confirm)
                {
                    Int32 MsgBoxResult = await AVMessageBox.Popup("Mark items read till item", "Do you want to mark all items for the selected feed till this item as read?", "Mark read till item", "", "", "", "", true);

                    if (MsgBoxResult == 0)
                    {
                        return(false);
                    }
                }

                bool   MarkStatus = false;
                string EndItemId  = EndItem.item_id;

                //Check the selected items
                List <Items> TableEditItems = UpdateList.Where(x => x.item_id == EndItemId || x.item_read_status == Visibility.Collapsed).ToList();

                //Check if internet is available
                if (!NetworkInterface.GetIsNetworkAvailable() || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Off marking read till item...", true);
                    }
                    Debug.WriteLine("Off marking read till item...");

                    //Add items to string list
                    List <String> ReadItemIds = new List <String>();
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        ReadItemIds.Add(NewsItemId);

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the string list.");
                            break;
                        }
                    }

                    await AddOfflineSync(ReadItemIds, "Read");

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Marking read till item...", true);
                    }
                    Debug.WriteLine("Marking read till item...");

                    //Add items to post string
                    string PostStringItemIds = String.Empty;
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        PostStringItemIds += "&i=" + NewsItemId;

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the post string.");
                            break;
                        }
                    }

                    string[][]        RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                    HttpStringContent PostContent   = new HttpStringContent("a=user/-/state/com.google/read" + PostStringItemIds, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");

                    HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "edit-tag"), PostContent);

                    if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    Debug.WriteLine("Marked items till this item as read on the server or offline sync list.");

                    //Add items to post string
                    string SqlStringItemIds = String.Empty;
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        SqlStringItemIds += "'" + NewsItemId + "',";

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the sql string.");
                            break;
                        }
                    }

                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    SqlStringItemIds = AVFunctions.StringRemoveEnd(SqlStringItemIds, ",");
                    await SQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('1') WHERE item_id IN (" + SqlStringItemIds + ") AND item_read_status = ('0')");

                    //Update current items list
                    foreach (Items NewsItem in UpdateList.ToList())
                    {
                        //Mark the item as read or remove it from list
                        if ((bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                        {
                            UpdateList.Remove(NewsItem);
                        }
                        else
                        {
                            NewsItem.item_read_status = Visibility.Visible;
                        }

                        //Check if the end item has been reached
                        if (EndItemId == NewsItem.item_id)
                        {
                            Debug.WriteLine("Marked items till this item as read in the list and database.");
                            break;
                        }
                    }

                    if (EnableUI)
                    {
                        await EventProgressEnableUI();
                    }
                }
                else
                {
                    await AVMessageBox.Popup("Failed to mark items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                    await EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                await AVMessageBox.Popup("Failed to mark items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                await EventProgressEnableUI();

                return(false);
            }
        }
Example #22
0
        //Update the feed icon
        private async void UpdateFeedIcon(object sender, RightTappedRoutedEventArgs e)
        {
            try
            {
                ListView SendListView = sender as ListView;
                Feeds    SelectedItem = ((e.OriginalSource as FrameworkElement).DataContext) as Feeds;
                if (SelectedItem != null)
                {
                    Int32 MsgBoxResult = await AVMessageBox.Popup("Change the feed icon", "Would you like to set a custom feed icon for " + SelectedItem.feed_title + "?", "Set custom icon", "Reset the icon", "", "", "", true);

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

                        FileOpenPicker FileOpenPicker = new FileOpenPicker();
                        FileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
                        FileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                        FileOpenPicker.FileTypeFilter.Add(".png");

                        //Save and replace feed icon locally
                        StorageFile StorageFile = await FileOpenPicker.PickSingleFileAsync();

                        if (StorageFile != null)
                        {
                            await StorageFile.CopyAndReplaceAsync(await ApplicationData.Current.LocalFolder.CreateFileAsync(SelectedItem.feed_id + ".png", CreationCollisionOption.ReplaceExisting));

                            //Load the feed icon
                            BitmapImage FeedIcon = null;
                            if (SelectedItem.feed_id.StartsWith("user/"))
                            {
                                FeedIcon = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconUser-Dark.png", false);
                            }
                            else
                            {
                                FeedIcon = await AVImage.LoadBitmapImage("ms-appdata:///local/" + SelectedItem.feed_id + ".png", false);
                            }
                            if (FeedIcon == null)
                            {
                                FeedIcon = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconRSS-Dark.png", false);
                            }

                            SelectedItem.feed_icon = FeedIcon;
                        }
                    }
                    else if (MsgBoxResult == 2)
                    {
                        //Delete the feed icon
                        IStorageItem LocalFile = await ApplicationData.Current.LocalFolder.TryGetItemAsync(SelectedItem.feed_id + ".png");

                        if (LocalFile != null)
                        {
                            try { await LocalFile.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch { }
                        }

                        //Load default feed icon
                        SelectedItem.feed_icon = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconRSS-Dark.png", false);

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

                        await AVMessageBox.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.", "Ok", "", "", "", "", false);
                    }
                }
            }
            catch { }
        }
Example #23
0
        //Add feed to the api
        private async Task AddFeedToApi()
        {
            try
            {
                //Check if user is logged in
                if (!CheckLogin())
                {
                    await AVMessageBox.Popup("Not logged in", "Adding a feed can only be done when you are logged in.", "Ok", "", "", "", "", false);

                    return;
                }

                //Check for internet connection
                if (!NetworkInterface.GetIsNetworkAvailable())
                {
                    await AVMessageBox.Popup("No internet connection", "Adding a feed can only be done when there is an internet connection available.", "Ok", "", "", "", "", false);

                    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(FocusState.Programmatic);
                    return;
                }

                //Validate the url entered
                if (!Regex.IsMatch(txtbox_AddFeed.Text, @"^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$"))
                {
                    await AVMessageBox.Popup("Invalid feed link", "The entered feed link is invalid or does not contain a feed, please check your link and try again.", "Ok", "", "", "", "", false);

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

                await 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
                    AppVariables.ApplicationSettings["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(FocusState.Programmatic);
                }

                await ProgressEnableUI();
            }
            catch { }
        }
Example #24
0
        public static async Task <bool> ListViewScroller(ListView TargetListView, Int32 CurrentItemId, Int32 PreviousItemId)
        {
            try
            {
                Int32 TargetListViewItems = TargetListView.Items.Count();
                if (TargetListViewItems > 0)
                {
                    string ReturnToPrevious = String.Empty;
                    if (PreviousItemId != 0 && TargetListViewItems > PreviousItemId)
                    {
                        ReturnToPrevious = "Scroll back to " + PreviousItemId;
                    }

                    Int32 MsgBoxResult = await AVMessageBox.Popup("Item scroller", "Would you like to scroll in the items?", "Scroll to beginning", "Scroll to the middle", "Scroll to the end", "Scroll to unread item", ReturnToPrevious, true);

                    if (MsgBoxResult == 1)
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollIntoView(TargetListView.Items.FirstOrDefault());
                        return(true);
                    }
                    else if (MsgBoxResult == 2)
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollIntoView(TargetListView.Items[(TargetListView.Items.Count / 2)]);
                        return(true);
                    }
                    else if (MsgBoxResult == 3)
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollIntoView(TargetListView.Items.LastOrDefault());
                        return(true);
                    }
                    else if (MsgBoxResult == 4)
                    {
                        await Task.Delay(10);

                        IEnumerable <Items> itemsList = TargetListView.Items.OfType <Items>();
                        Items scrollItem = itemsList.Where(x => x.item_read_status == Visibility.Collapsed).FirstOrDefault();
                        if (scrollItem != null)
                        {
                            TargetListView.ScrollIntoView(scrollItem);
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (MsgBoxResult == 5)
                    {
                        await Task.Delay(10);

                        TargetListView.ScrollIntoView(TargetListView.Items[PreviousItemId]);
                        return(true);
                    }
                }
            }
            catch { }
            return(false);
        }
Example #25
0
        public static async void ListView_Items_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            try
            {
                ListView SendListView = sender as ListView;
                Items    SelectedItem = ((e.OriginalSource as FrameworkElement).DataContext) as Items;
                ObservableCollection <Items> SelectedList = (ObservableCollection <Items>)SendListView.ItemsSource;
                if (SelectedItem != null)
                {
                    //Set the action string text
                    string ActionStarItem = "Un/star";
                    if (SelectedItem.item_star_status == Visibility.Visible)
                    {
                        ActionStarItem = "Unstar";
                    }
                    else
                    {
                        ActionStarItem = "Star";
                    }

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

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

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

                    int MsgBoxResult = await AVMessageBox.Popup("News item actions", "What would you like to do with this item?", "Open in browser", "Share this item", ActionStarItem + " this item", "Mark item as " + ActionReadItem.ToLower(), ActionMarkReadTill, true);

                    if (MsgBoxResult == 1)
                    {
                        await ListItemOpenBrowser(SendListView, SelectedItem, SelectedList, CurrentPageName);
                    }
                    else if (MsgBoxResult == 2)
                    {
                        ShareItem(SelectedItem);
                    }
                    else if (MsgBoxResult == 3)
                    {
                        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 (MsgBoxResult == 4)
                    {
                        await ListItemMarkRead(false, SendListView, SelectedItem, SelectedList, CurrentPageName);
                    }
                    else if (MsgBoxResult == 5)
                    {
                        bool MarkedRead = await MarkReadTill(SelectedList, SelectedItem, true, false, true);

                        if (MarkedRead && CurrentPageName.EndsWith("NewsPage"))
                        {
                            if ((bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                            {
                                if (SendListView.Items.Any())
                                {
                                    //Scroll to the ListView top
                                    await Task.Delay(10);

                                    SendListView.ScrollIntoView(SendListView.Items.First());

                                    //Update the header and selection feeds
                                    await EventUpdateTotalItemsCount(null, null, false, true);
                                }
                                else
                                {
                                    await EventRefreshPageItems(true);
                                }
                            }
                            else
                            {
                                if (!SelectedList.Any(x => x.item_read_status == Visibility.Collapsed))
                                {
                                    await EventRefreshPageItems(true);
                                }
                            }
                        }
                    }

                    //Reset the item selection
                    SendListView.SelectedIndex = -1;
                }
            }
            catch { }
        }
Example #26
0
        //Open item in browser
        private async Task OpenBrowser(Uri TargetUri, bool closePopup)
        {
            try
            {
                int MsgBoxResult = 0;

                //Check internet connection
                if (!NetworkInterface.GetIsNetworkAvailable())
                {
                    await AVMessageBox.Popup("No internet connection", "You currently don't have an internet connection available to open this item or link in the webviewer or your webbrowser.", "Ok", "", "", "", "", false);

                    return;
                }

                //Check webbrowser only links
                if (TargetUri != null)
                {
                    string TargetString = TargetUri.ToString();
                    if (!TargetString.StartsWith("http"))
                    {
                        MsgBoxResult = 2;
                    }
                }

                if (MsgBoxResult != 2)
                {
                    string LowMemoryWarning = string.Empty;
                    if (AVFunctions.DevMemoryAvailableMB() < 200)
                    {
                        LowMemoryWarning = "\n\n* Your device is currently low on available memory and may cause issues when you open this link or item in the webviewer.";
                    }
                    MsgBoxResult = await AVMessageBox.Popup("Open this item or link", "Do you want to open this item or link in the webviewer or your webbrowser?" + LowMemoryWarning, "Webviewer (In-app)", "Webbrowser (Device)", "", "", "", true);
                }

                if (MsgBoxResult == 1)
                {
                    if (closePopup)
                    {
                        ClosePopup();
                    }
                    //Open item in webviewer
                    WebViewer webViewer = new WebViewer();
                    await webViewer.OpenPopup(TargetUri, vCurrentWebSource);
                }
                else if (MsgBoxResult == 2)
                {
                    if (closePopup)
                    {
                        ClosePopup();
                    }
                    //Open item in webbrowser
                    if (TargetUri != null)
                    {
                        await Launcher.LaunchUriAsync(TargetUri);
                    }
                    else
                    {
                        await Launcher.LaunchUriAsync(new Uri(vCurrentWebSource.item_link, UriKind.RelativeOrAbsolute));
                    }
                }
            }
            catch { }
        }
Example #27
0
        //Save the image
        private async void button_iconSave_Tap(object sender, RoutedEventArgs e)
        {
            try
            {
                if (vBitmapImage != null && vBitmapImage.PixelHeight > 0)
                {
                    //Get the url path
                    string UrlPath = String.Empty;
                    try { UrlPath = vBitmapImage.UriSource.AbsolutePath; } catch { }
                    if (String.IsNullOrWhiteSpace(UrlPath))
                    {
                        UrlPath = vBitmapImage.UriSource.ToString();
                    }

                    //Get the file name
                    string FileName = "Unknown";
                    try { FileName = Path.GetFileNameWithoutExtension(UrlPath); } catch { }
                    if (String.IsNullOrWhiteSpace(FileName))
                    {
                        FileName = "Unknown";
                    }

                    //Check if network is available
                    bool IsNetworkAvailable = NetworkInterface.GetIsNetworkAvailable();

                    //Get the file extension
                    string FileExtensionFile    = ".jpg";
                    string FileExtensionDisplay = "JPG";
                    if (IsNetworkAvailable)
                    {
                        try { FileExtensionFile = Path.GetExtension(UrlPath).ToLower(); } catch { }
                        if (String.IsNullOrWhiteSpace(FileExtensionFile))
                        {
                            FileExtensionFile = ".jpg";
                        }
                        FileExtensionDisplay = FileExtensionFile.ToUpper().Replace(".", String.Empty);
                    }
                    else
                    {
                        Int32 MessageResult = await AVMessageBox.Popup("Offline saving", "Saving images while in offline mode may save the image in a lower quality and animations will be saved as a static image.", "Save image", "", "", "", "", true);

                        if (MessageResult == 0)
                        {
                            return;
                        }
                    }

                    FileSavePicker FileSavePicker = new FileSavePicker();
                    FileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                    FileSavePicker.FileTypeChoices.Add(FileExtensionDisplay, new List <string>()
                    {
                        FileExtensionFile
                    });
                    FileSavePicker.SuggestedFileName = FileName;

                    StorageFile NewFile = await FileSavePicker.PickSaveFileAsync();

                    if (NewFile != null)
                    {
                        //Download the bitmapimage source uri
                        if (IsNetworkAvailable)
                        {
                            Debug.WriteLine("Saving online image...");

                            IBuffer ImageBuffer = await AVDownloader.DownloadBufferAsync(10000, "News Scroll", vBitmapImage.UriSource);

                            if (ImageBuffer != null)
                            {
                                await FileIO.WriteBufferAsync(NewFile, ImageBuffer);
                            }
                            else
                            {
                                await AVMessageBox.Popup("Failed to save", "Failed to save the image, please check your internet connection and try again.", "Ok", "", "", "", "", false);

                                Debug.WriteLine("Failed to download the image.");
                            }
                        }
                        //Capture the image displayed in xaml
                        else
                        {
                            Debug.WriteLine("Saving offline image...");

                            ////Set the image size temporarily to bitmap size
                            //Double PreviousWidth = image_ImageViewer.ActualWidth;
                            //Double PreviousHeight = image_ImageViewer.ActualHeight;
                            //image_ImageViewer.Width = vBitmapImage.PixelWidth;
                            //image_ImageViewer.Height = vBitmapImage.PixelHeight;

                            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                            await renderTargetBitmap.RenderAsync(image_source);

                            IBuffer PixelBuffer = await renderTargetBitmap.GetPixelsAsync();

                            using (IRandomAccessStream fileStream = await NewFile.OpenAsync(FileAccessMode.ReadWrite))
                            {
                                BitmapEncoder bitmapEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, fileStream);

                                bitmapEncoder.SetPixelData(
                                    BitmapPixelFormat.Bgra8,
                                    BitmapAlphaMode.Ignore,
                                    (uint)renderTargetBitmap.PixelWidth,
                                    (uint)renderTargetBitmap.PixelHeight,
                                    DisplayInformation.GetForCurrentView().LogicalDpi,
                                    DisplayInformation.GetForCurrentView().LogicalDpi,
                                    PixelBuffer.ToArray());
                                await bitmapEncoder.FlushAsync();
                            }

                            //Debug.WriteLine("From: " + image_ImageViewer.Width + " setting back: " + PreviousWidth);
                            //image_ImageViewer.Width = PreviousWidth;
                            //image_ImageViewer.Height = PreviousHeight;
                        }
                    }
                }
            }
            catch
            {
                await AVMessageBox.Popup("Failed to save", "Failed to save the image, please check your internet connection and try again.", "Ok", "", "", "", "", false);

                Debug.WriteLine("Failed to save the image.");
            }
        }
Example #28
0
        public static async Task <Int32> PageApiUpdate()
        {
            return(await Task.Run(async() =>
            {
                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
                            {
                                Int32 MessageResult = await AVMessageBox.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.", "Retry to login", "Go to account settings", "Switch to offline mode", "", "", false);
                                if (MessageResult == 1)
                                {
                                    return await PageApiUpdate();
                                }
                                else if (MessageResult == 2)
                                {
                                    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
                            {
                                Int32 MessageResult = await AVMessageBox.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.", "Retry downloading feeds", "Go to account settings", "Switch to offline mode", "", "", false);
                                if (MessageResult == 1)
                                {
                                    return await PageApiUpdate();
                                }
                                else if (MessageResult == 2)
                                {
                                    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)
                                {
                                    Int32 MessageResult = await AVMessageBox.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.", "Retry downloading items", "Switch to offline mode", "", "", "", false);
                                    if (MessageResult == 1)
                                    {
                                        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)
                                {
                                    Int32 MessageResult = await AVMessageBox.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.", "Retry downloading read items", "Switch to offline mode", "", "", "", false);
                                    if (MessageResult == 1)
                                    {
                                        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
                            {
                                Int32 MessageResult = await AVMessageBox.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.", "Retry downloading starred items", "Switch to offline mode", "", "", "", false);
                                if (MessageResult == 1)
                                {
                                    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;
                }
            }));
        }