示例#1
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 { }
        }
示例#2
0
        static public async Task <bool> Feeds(bool Silent, bool EnableUI)
        {
            try
            {
                if (!Silent)
                {
                    await EventProgressDisableUI("Downloading latest feeds...", true);
                }
                System.Diagnostics.Debug.WriteLine("Downloading latest feeds...");

                string[][] RequestHeader  = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                string     DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/list?output=json"));

                JObject WebJObject = JObject.Parse(DownloadString);
                if (WebJObject["subscriptions"] != null && WebJObject["subscriptions"].HasValues)
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Processing " + WebJObject["subscriptions"].Count() + " feeds...", true);
                    }
                    System.Diagnostics.Debug.WriteLine("Processing " + WebJObject["subscriptions"].Count() + " feeds...");

                    List <string> ApiFeedIdList = new List <string>();
                    IReadOnlyList <IStorageItem> LocalFileList = await ApplicationData.Current.LocalFolder.GetItemsAsync();

                    List <TableFeeds> TableUpdatedFeeds = new List <TableFeeds>();
                    List <TableFeeds> TableCurrentFeeds = await SQLConnection.Table <TableFeeds>().ToListAsync();

                    foreach (JToken JTokenRoot in WebJObject["subscriptions"])
                    {
                        string FeedId    = JTokenRoot["sortid"].ToString();
                        string FeedTitle = JTokenRoot["title"].ToString();

                        string HtmlUrl = WebUtility.HtmlDecode(JTokenRoot["htmlUrl"].ToString());
                        HtmlUrl = WebUtility.UrlDecode(HtmlUrl);

                        Uri FullUrl = new Uri(HtmlUrl);
                        ApiFeedIdList.Add(FeedId);

                        TableFeeds TableResult = TableCurrentFeeds.Where(x => x.feed_id == FeedId).FirstOrDefault();
                        if (TableResult == null)
                        {
                            //System.Diagnostics.Debug.WriteLine("Adding feed: " + FeedTitle);

                            TableFeeds AddFeed = new TableFeeds();
                            AddFeed.feed_id    = FeedId;
                            AddFeed.feed_title = FeedTitle;
                            AddFeed.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            AddFeed.feed_ignore_status = false;
                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                AddFeed.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(AddFeed);
                        }
                        else
                        {
                            //System.Diagnostics.Debug.WriteLine("Updating feed: " + FeedTitle);

                            TableResult.feed_title = FeedTitle;
                            TableResult.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                TableResult.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(TableResult);
                        }

                        //Check and download feed logo
                        if (!LocalFileList.Any(x => x.Name == FeedId + ".png"))
                        {
                            try
                            {
                                if (!Silent)
                                {
                                    await EventProgressDisableUI("Downloading " + FeedTitle + " icon...", true);
                                }

                                Uri    IconUrl      = new Uri("https://s2.googleusercontent.com/s2/favicons?domain=" + FullUrl.Host);
                                byte[] HttpFeedIcon = await AVDownloader.DownloadByteAsync(3000, "News Scroll", null, IconUrl);

                                if (HttpFeedIcon != null && HttpFeedIcon.Length > 75)
                                {
                                    await AVFile.SaveBytes(FeedId + ".png", HttpFeedIcon);

                                    System.Diagnostics.Debug.WriteLine("Downloaded transparent logo: " + HttpFeedIcon.Length + "bytes/" + IconUrl);
                                }
                                else
                                {
                                    System.Diagnostics.Debug.WriteLine("No logo found for: " + IconUrl);
                                }
                            }
                            catch { }
                        }
                    }

                    //Update the feeds in database
                    if (TableUpdatedFeeds.Any())
                    {
                        await SQLConnection.InsertAllAsync(TableUpdatedFeeds, "OR REPLACE");
                    }

                    //Delete removed feeds from the database
                    List <string> DeletedFeeds = TableCurrentFeeds.Select(x => x.feed_id).Except(ApiFeedIdList).ToList();
                    System.Diagnostics.Debug.WriteLine("Found deleted feeds: " + DeletedFeeds.Count());
                    foreach (string DeleteFeedId in DeletedFeeds)
                    {
                        await DeleteFeed(DeleteFeedId);
                    }
                }

                if (EnableUI)
                {
                    await EventProgressEnableUI();
                }
                return(true);
            }
            catch
            {
                await EventProgressEnableUI();

                return(false);
            }
        }
示例#3
0
        public static async Task <bool> ProcessTableItemsToList(ObservableCollection <Items> AddList, List <TableItems> LoadTableItems, bool AddFromTop, bool HideReadStatus, bool HideStarStatus)
        {
            try
            {
                List <TableFeeds> FeedList = await vSQLConnection.Table <TableFeeds>().ToListAsync();

                foreach (TableItems LoadTable in LoadTableItems)
                {
                    //Load and check item id
                    string ItemId = LoadTable.item_id;
                    if (!AddList.Any(x => x.item_id == ItemId))
                    {
                        //Load feed id and title
                        string FeedId    = LoadTable.item_feed_id;
                        string FeedTitle = "Unknown feed";

                        TableFeeds TableResult = FeedList.Where(x => x.feed_id == FeedId).FirstOrDefault();
                        if (TableResult == null)
                        {
                            //Debug.WriteLine("Feed not found: " + FeedId);
                            if (LoadTable.item_feed_title != null && !string.IsNullOrWhiteSpace(LoadTable.item_feed_title))
                            {
                                Debug.WriteLine("Backup feed title: " + LoadTable.item_feed_title);
                                FeedTitle = LoadTable.item_feed_title;
                            }
                            else if (FeedId.StartsWith("user/"))
                            {
                                Debug.WriteLine("Detected an user feed.");
                                FeedTitle = "User feed";
                            }
                        }
                        else
                        {
                            //Set the feed item title
                            FeedTitle = TableResult.feed_title;
                        }

                        //Load item image
                        bool   ItemImageVisibility = false;
                        string ItemImageLink       = LoadTable.item_image;
                        if (!string.IsNullOrWhiteSpace(ItemImageLink) && AppVariables.LoadMedia)
                        {
                            ItemImageVisibility = true;
                        }

                        //Set the date time string
                        DateTime convertedDate    = DateTime.SpecifyKind(LoadTable.item_datetime, DateTimeKind.Utc).ToLocalTime();
                        string   DateAuthorString = convertedDate.ToString(AppVariables.CultureInfoLocal.DateTimeFormat.LongDatePattern, AppVariables.CultureInfoLocal.DateTimeFormat) + ", " + convertedDate.ToString(AppVariables.CultureInfoLocal.DateTimeFormat.ShortTimePattern, AppVariables.CultureInfoLocal.DateTimeFormat);

                        //Add the author to date time
                        if ((bool)AppSettingLoad("DisplayItemsAuthor") && !string.IsNullOrWhiteSpace(LoadTable.item_author))
                        {
                            DateAuthorString += " by " + LoadTable.item_author;
                        }

                        //Check item read or star status
                        bool ReadVisibility = false;
                        if (!HideReadStatus)
                        {
                            ReadVisibility = LoadTable.item_read_status ? true : false;
                        }
                        bool StarredVisibility = false;
                        if (!HideStarStatus)
                        {
                            StarredVisibility = LoadTable.item_star_status ? true : false;
                        }

                        //Load item content
                        string item_content = string.Empty;
                        if ((bool)AppSettingLoad("ContentCutting"))
                        {
                            item_content = AVFunctions.StringCut(LoadTable.item_content, Convert.ToInt32(AppSettingLoad("ContentCuttingLength")), "...");
                        }
                        else
                        {
                            item_content = AVFunctions.StringCut(LoadTable.item_content, AppVariables.MaximumItemTextLength, "...");
                        }

                        //Add item to the ListView
                        Items NewItem = new Items()
                        {
                            feed_id = FeedId, feed_title = FeedTitle, item_id = ItemId, item_read_status = ReadVisibility, item_star_status = StarredVisibility, item_title = LoadTable.item_title, item_image_visibility = ItemImageVisibility, item_image_link = ItemImageLink, item_content = item_content, item_link = LoadTable.item_link, item_datestring = DateAuthorString, item_datetime = LoadTable.item_datetime
                        };
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            try
                            {
                                if (AddFromTop)
                                {
                                    AddList.Insert(0, NewItem);
                                }
                                else
                                {
                                    AddList.Add(NewItem);
                                }
                            }
                            catch { }
                        });

                        //Update the added item count
                        AppVariables.CurrentItemsLoaded++;

                        //Request information update
                        if (AppVariables.CurrentItemsLoaded == 1)
                        {
                            EventHideProgressionStatus();
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed processing multiple items from database: " + ex.Message);
                return(false);
            }
        }
示例#4
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 { }
        }
示例#5
0
        public static async Task <bool> ProcessTableItemsToList(ObservableCollection <Items> AddList, List <TableItems> LoadTableItems, bool AddFromTop, bool HideReadStatus, bool HideStarStatus)
        {
            try
            {
                //Check if media needs to load
                AppVariables.LoadMedia = true;
                if (!NetworkInterface.GetIsNetworkAvailable() && !(bool)AppVariables.ApplicationSettings["DisplayImagesOffline"])
                {
                    AppVariables.LoadMedia = false;
                }

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

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

                foreach (TableItems LoadTable in LoadTableItems)
                {
                    //Load and check item id
                    string ItemId = LoadTable.item_id;
                    if (!AddList.Any(x => x.item_id == ItemId))
                    {
                        //Load feed id and title
                        string FeedId    = LoadTable.item_feed_id;
                        string FeedTitle = "Unknown feed";

                        TableFeeds TableResult = FeedList.Where(x => x.feed_id == FeedId).FirstOrDefault();
                        if (TableResult == null)
                        {
                            //Debug.WriteLine("Feed not found: " + FeedId);
                            if (LoadTable.item_feed_title != null && !String.IsNullOrWhiteSpace(LoadTable.item_feed_title))
                            {
                                Debug.WriteLine("Backup feed title: " + LoadTable.item_feed_title);
                                FeedTitle = LoadTable.item_feed_title;
                            }
                            else if (FeedId.StartsWith("user/"))
                            {
                                Debug.WriteLine("Detected an user feed.");
                                FeedTitle = "User feed";
                            }
                        }
                        else
                        {
                            //Set the feed item title
                            FeedTitle = TableResult.feed_title;
                        }

                        //Load item image
                        BitmapImage ItemImage           = null;
                        Visibility  ItemImageVisibility = Visibility.Collapsed;
                        string      ItemImageLink       = LoadTable.item_image;
                        if (!String.IsNullOrWhiteSpace(ItemImageLink) && AppVariables.LoadMedia)
                        {
                            ItemImageVisibility = Visibility.Visible;
                            if (AppVariables.CurrentItemsLoaded < AppVariables.ContentToScrollLoad)
                            {
                                ItemImage = await AVImage.LoadBitmapImage(ItemImageLink, false);
                            }
                        }

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

                        //Set the date time string
                        DateTime convertedDate    = DateTime.SpecifyKind(LoadTable.item_datetime, DateTimeKind.Utc).ToLocalTime();
                        string   DateAuthorString = convertedDate.ToString(AppVariables.CultureInfoFormat.LongDatePattern, AppVariables.CultureInfoFormat) + ", " + convertedDate.ToString(AppVariables.CultureInfoFormat.ShortTimePattern, AppVariables.CultureInfoFormat);

                        //Add the author to date time
                        if ((bool)AppVariables.ApplicationSettings["DisplayItemsAuthor"] && !String.IsNullOrWhiteSpace(LoadTable.item_author))
                        {
                            DateAuthorString += " by " + LoadTable.item_author;
                        }

                        //Check item read or star status
                        Visibility ReadVisibility = Visibility.Collapsed;
                        if (!HideReadStatus)
                        {
                            ReadVisibility = LoadTable.item_read_status ? Visibility.Visible : Visibility.Collapsed;
                        }
                        Visibility StarredVisibility = Visibility.Collapsed;
                        if (!HideStarStatus)
                        {
                            StarredVisibility = LoadTable.item_star_status ? Visibility.Visible : Visibility.Collapsed;
                        }

                        //Load item content
                        string item_content = String.Empty;
                        if ((bool)AppVariables.ApplicationSettings["ContentCutting"])
                        {
                            item_content = AVFunctions.StringCut(LoadTable.item_content, Convert.ToInt32(AppVariables.ApplicationSettings["ContentCuttingLength"]), "...");
                        }
                        else
                        {
                            item_content = AVFunctions.StringCut(LoadTable.item_content, AppVariables.MaximumItemTextLength, "...");
                        }

                        //Add item to the ListView
                        Items NewItem = new Items()
                        {
                            feed_id = FeedId, feed_title = FeedTitle, feed_icon = FeedIcon, item_id = ItemId, item_read_status = ReadVisibility, item_star_status = StarredVisibility, item_title = LoadTable.item_title, item_image = ItemImage, item_image_visibility = ItemImageVisibility, item_image_link = ItemImageLink, item_content = item_content, item_link = LoadTable.item_link, item_datestring = DateAuthorString, item_datetime = LoadTable.item_datetime
                        };
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            try
                            {
                                if (AddFromTop)
                                {
                                    AddList.Insert(0, NewItem);
                                }
                                else
                                {
                                    AddList.Add(NewItem);
                                }
                            }
                            catch { }
                        });

                        //Update the added item count
                        AppVariables.CurrentItemsLoaded++;

                        //Request information update
                        if (AppVariables.CurrentItemsLoaded == 1)
                        {
                            await EventHideProgressionStatus();
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed processing multiple items from database: " + ex.Message);
                return(false);
            }
        }