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

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

                JObject WebJObject = JObject.Parse(PostHttp);
                if (WebJObject["numResults"].ToString() == "0")
                {
                    await new MessagePopup().OpenPopup("Invalid feed link", "The entered feed link is invalid or does not contain a feed, please check your link and try again.", "Ok", "", "", "", "", false);
                    //System.Diagnostics.Debug.WriteLine(WebJObject["error"].ToString());
                    return(false);
                }
                else
                {
                    await new MessagePopup().OpenPopup("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 new MessagePopup().OpenPopup("Failed to add feed", "Please check your account settings, internet connection and try again.", "Ok", "", "", "", "", false);
                return(false);
            }
        }
Example #2
0
        //Download all available games
        public async Task <IEnumerable <ApiIGDBGames> > ApiIGDB_DownloadGames(string gameName)
        {
            try
            {
                Debug.WriteLine("Downloading games for: " + gameName);

                //Authenticate with Twitch
                string authAccessToken = await ApiTwitch_Authenticate();

                if (string.IsNullOrWhiteSpace(authAccessToken))
                {
                    return(null);
                }

                //Set request headers
                string[]   requestAccept        = new[] { "Accept", "application/json" };
                string[]   requestClientID      = new[] { "Client-ID", vApiIGDBClientID };
                string[]   requestAuthorization = new[] { "Authorization", "Bearer " + authAccessToken };
                string[][] requestHeaders       = new string[][] { requestAccept, requestClientID, requestAuthorization };

                //Create request uri
                Uri requestUri = new Uri("https://api.igdb.com/v4/games");

                //Create request body
                string        requestBodyString        = "fields *; limit 100; search \"" + gameName + "\";";
                StringContent requestBodyStringContent = new StringContent(requestBodyString, Encoding.UTF8, "application/text");

                //Download available games
                string resultSearch = await AVDownloader.SendPostRequestAsync(5000, "CtrlUI", requestHeaders, requestUri, requestBodyStringContent);

                if (string.IsNullOrWhiteSpace(resultSearch))
                {
                    Debug.WriteLine("Failed downloading games.");
                    return(null);
                }

                //Check if status is set
                if (resultSearch.Contains("\"status\"") && resultSearch.Contains("\"type\""))
                {
                    Debug.WriteLine("Received invalid games data.");
                    return(null);
                }

                //Return games sorted
                return(JsonConvert.DeserializeObject <IEnumerable <ApiIGDBGames> >(resultSearch).OrderBy(x => x.name));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed downloading games: " + ex.Message);
                return(null);
            }
        }
Example #3
0
        //Download platform version id information
        public async Task <ApiIGDBPlatformVersions[]> ApiIGDBDownloadPlatformVersions(string platformId)
        {
            try
            {
                Debug.WriteLine("Downloading platform versions for: " + platformId);

                //Authenticate with Twitch
                string authAccessToken = await Api_Twitch_Authenticate();

                if (string.IsNullOrWhiteSpace(authAccessToken))
                {
                    return(null);
                }

                //Set request headers
                string[]   requestAccept        = new[] { "Accept", "application/json" };
                string[]   requestClientID      = new[] { "Client-ID", vApiIGDBClientID };
                string[]   requestAuthorization = new[] { "Authorization", "Bearer " + authAccessToken };
                string[][] requestHeaders       = new string[][] { requestAccept, requestClientID, requestAuthorization };

                //Create request uri
                Uri requestUri = new Uri("https://api.igdb.com/v4/platform_versions");

                //Create request body
                string        requestBodyString        = "fields *; limit 100; where id = " + platformId + ";";
                StringContent requestBodyStringContent = new StringContent(requestBodyString, Encoding.UTF8, "application/text");

                //Download available platform versions
                string resultSearch = await AVDownloader.SendPostRequestAsync(5000, "CtrlUI", requestHeaders, requestUri, requestBodyStringContent);

                if (string.IsNullOrWhiteSpace(resultSearch))
                {
                    Debug.WriteLine("Failed downloading platform versions.");
                    return(null);
                }

                //Check if status is set
                if (resultSearch.Contains("\"status\"") && resultSearch.Contains("\"type\""))
                {
                    Debug.WriteLine("Received invalid platform versions data.");
                    return(null);
                }

                //Return platform versions
                return(JsonConvert.DeserializeObject <ApiIGDBPlatformVersions[]>(resultSearch));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed downloading platform versions: " + ex.Message);
                return(null);
            }
        }
Example #4
0
        //Download image id information
        public async Task <string> Api_Twitch_Authenticate()
        {
            try
            {
                //Check if auth token is cached
                if (vApiIGDBTokenExpire != null && DateTime.Now < vApiIGDBTokenExpire)
                {
                    Debug.WriteLine("Returning auth cache from Twitch.");
                    return(vApiIGDBTokenCache);
                }

                Debug.WriteLine("Authenticating with Twitch.");

                //Set request headers
                string[]   requestAccept  = new[] { "Accept", "application/json" };
                string[][] requestHeaders = new string[][] { requestAccept };

                //Create request uri
                Uri requestUri = new Uri("https://id.twitch.tv/oauth2/token?client_id=" + vApiIGDBClientID + "&client_secret=" + vApiIGDBAuthorization + "&grant_type=client_credentials");

                //Authenticate with Twitch
                string resultAuth = await AVDownloader.SendPostRequestAsync(5000, "CtrlUI", requestHeaders, requestUri, null);

                if (string.IsNullOrWhiteSpace(resultAuth))
                {
                    Debug.WriteLine("Failed authenticating with Twitch, no connection.");
                    return(string.Empty);
                }

                //Deserialize json string
                ApiTwitchOauth2 jsonAuth = JsonConvert.DeserializeObject <ApiTwitchOauth2>(resultAuth);

                //Check if authenticated
                if (!string.IsNullOrWhiteSpace(jsonAuth.access_token))
                {
                    vApiIGDBTokenCache  = jsonAuth.access_token;
                    vApiIGDBTokenExpire = DateTime.Now.AddSeconds(jsonAuth.expires_in).AddSeconds(-30);
                    return(vApiIGDBTokenCache);
                }
                else
                {
                    Debug.WriteLine("Failed authenticating with Twitch: " + jsonAuth.message);
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed authenticating with Twitch: " + ex.Message);
                return(string.Empty);
            }
        }
Example #5
0
        static public async Task <bool> MultiItems(string DownloadItemIds, bool Preload, bool IgnoreDate, bool Silent, bool EnableUI)
        {
            try
            {
                string     DownloadItems = DownloadItemIds.Replace(" ", String.Empty).Replace("tag:google.com,2005:reader/item/", String.Empty);
                string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };

                HttpStringContent PostContent = new HttpStringContent(DownloadItems, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                Uri PostUri = new Uri(ApiConnectionUrl + "stream/items/contents?output=json");
                HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(20000, "News Scroll", RequestHeader, PostUri, PostContent);

                return(await DownloadToTableItemList(Preload, IgnoreDate, PostHttp.Content.ToString(), Silent, EnableUI));
            }
            catch { return(false); }
        }
Example #6
0
        static public async Task <bool> DeleteFeed(string FeedId)
        {
            try
            {
                string[][]          RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                HttpStringContent   PostContent   = new HttpStringContent("ac=unsubscribe&s=feed/" + FeedId, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                HttpResponseMessage PostHttp      = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/edit"), PostContent);

                if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                {
                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    //Clear feed from database
                    await SQLConnection.ExecuteAsync("DELETE FROM TableFeeds WHERE feed_id = ('" + FeedId + "')");

                    //Clear items from database
                    await SQLConnection.ExecuteAsync("DELETE FROM TableItems WHERE item_feed_id = ('" + FeedId + "') AND item_star_status = ('0')");

                    //Delete the feed icon
                    IStorageItem LocalFile = await ApplicationData.Current.LocalFolder.TryGetItemAsync(FeedId + ".png");

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

                    Debug.WriteLine("Deleted the feed and items off: " + FeedId);
                    return(true);
                }
                else
                {
                    Debug.WriteLine("Failed to delete feed: " + FeedId + " / server error.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to delete feed: " + FeedId + " / " + ex.Message);
                return(false);
            }
        }
Example #7
0
        //Download igdb genres
        public async Task ApiIGDBDownloadGenres()
        {
            try
            {
                Debug.WriteLine("Downloading IGDB genres.");

                //Authenticate with Twitch
                string authAccessToken = await Api_Twitch_Authenticate();

                if (string.IsNullOrWhiteSpace(authAccessToken))
                {
                    return;
                }

                //Set request headers
                string[]   requestAccept        = new[] { "Accept", "application/json" };
                string[]   requestClientID      = new[] { "Client-ID", vApiIGDBClientID };
                string[]   requestAuthorization = new[] { "Authorization", "Bearer " + authAccessToken };
                string[][] requestHeaders       = new string[][] { requestAccept, requestClientID, requestAuthorization };

                //Create request uri
                Uri requestUri = new Uri("https://api.igdb.com/v4/genres");

                //Create request body
                string        requestBodyString        = "fields *; limit 500; sort id asc;";
                StringContent requestBodyStringContent = new StringContent(requestBodyString, Encoding.UTF8, "application/text");

                //Download igdb genres
                string resultSearch = await AVDownloader.SendPostRequestAsync(5000, "CtrlUI", requestHeaders, requestUri, requestBodyStringContent);

                if (string.IsNullOrWhiteSpace(resultSearch))
                {
                    Debug.WriteLine("Failed downloading IGDB genres.");
                    return;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed downloading IGDB genres: " + ex.Message);
                return;
            }
        }
Example #8
0
        //Login to the api
        static public async Task <bool> Login(bool Silent, bool EnableUI)
        {
            try
            {
                if (!Silent)
                {
                    EventProgressDisableUI("Logging into The Old Reader...", true);
                }
                Debug.WriteLine("Logging into The Old Reader.");

                string        PostString  = "client=NewsScroll&accountType=HOSTED_OR_GOOGLE&service=reader&output=json&Email=" + WebUtility.HtmlEncode(AppSettingLoad("ApiAccount").ToString()) + "&Passwd=" + WebUtility.HtmlEncode(AppSettingLoad("ApiPassword").ToString());
                StringContent PostContent = new StringContent(PostString, Encoding.UTF8, "application/x-www-form-urlencoded");
                Uri           PostUri     = new Uri(ApiConnectionUrl + "accounts/ClientLogin");

                string PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", null, PostUri, PostContent);

                JObject WebJObject = JObject.Parse(PostHttp);
                if (WebJObject["Auth"] != null)
                {
                    ApiMessageError = string.Empty;
                    await AppSettingSave("ConnectApiAuth", WebJObject["Auth"].ToString());

                    if (EnableUI)
                    {
                        EventProgressEnableUI();
                    }
                    return(true);
                }
                else
                {
                    EventProgressEnableUI();
                    return(false);
                }
            }
            catch
            {
                EventProgressEnableUI();
                return(false);
            }
        }
Example #9
0
        //Mark item as un/read from string list
        static public async Task <bool> MarkItemReadStringList(List <string> MarkIds, bool MarkType)
        {
            try
            {
                //Add items to post string
                string PostStringItemIds = string.Empty;
                foreach (string ItemId in MarkIds)
                {
                    PostStringItemIds += "&i=" + ItemId;
                }

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

                StringContent PostContent;
                if (MarkType)
                {
                    PostContent = new StringContent("a=user/-/state/com.google/read" + PostStringItemIds, Encoding.UTF8, "application/x-www-form-urlencoded");
                }
                else
                {
                    PostContent = new StringContent("r=user/-/state/com.google/read" + PostStringItemIds, Encoding.UTF8, "application/x-www-form-urlencoded");
                }
                Uri PostUri = new Uri(ApiConnectionUrl + "edit-tag");

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

                if (PostHttp != null && (PostHttp == "OK" || PostHttp.Contains("<error>Not found</error>")))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Example #10
0
        //Login to the api
        static public async Task <bool> Login(bool Silent, bool EnableUI)
        {
            try
            {
                if (!Silent)
                {
                    await EventProgressDisableUI("Logging into The Old Reader...", true);
                }
                Debug.WriteLine("Logging into The Old Reader.");

                HttpStringContent   PostContent = new HttpStringContent("client=NewsScroll&accountType=HOSTED_OR_GOOGLE&service=reader&output=json&Email=" + WebUtility.HtmlEncode(AppVariables.ApplicationSettings["ApiAccount"].ToString()) + "&Passwd=" + WebUtility.HtmlEncode(AppVariables.ApplicationSettings["ApiPassword"].ToString()), Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                HttpResponseMessage PostHttp    = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", null, new Uri(ApiConnectionUrl + "accounts/ClientLogin"), PostContent);

                JObject WebJObject = JObject.Parse(PostHttp.Content.ToString());
                if (WebJObject["Auth"] != null)
                {
                    ApiMessageError = String.Empty;
                    AppVariables.ApplicationSettings["ConnectApiAuth"] = WebJObject["Auth"].ToString();

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

                    return(false);
                }
            }
            catch
            {
                await EventProgressEnableUI();

                return(false);
            }
        }
Example #11
0
        static public async Task <bool> DeleteFeed(string FeedId)
        {
            try
            {
                string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } };

                string        PostString  = "ac=unsubscribe&s=feed/" + FeedId;
                StringContent PostContent = new StringContent(PostString, Encoding.UTF8, "application/x-www-form-urlencoded");
                Uri           PostUri     = new Uri(ApiConnectionUrl + "subscription/edit");

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

                if (PostHttp != null && (PostHttp == "OK" || PostHttp.Contains("<error>Not found</error>")))
                {
                    //Clear feed from database
                    await vSQLConnection.ExecuteAsync("DELETE FROM TableFeeds WHERE feed_id = ('" + FeedId + "')");

                    //Clear items from database
                    await vSQLConnection.ExecuteAsync("DELETE FROM TableItems WHERE item_feed_id = ('" + FeedId + "') AND item_star_status = ('0')");

                    //Delete the feed icon
                    AVFiles.File_Delete(FeedId + ".png", true);

                    Debug.WriteLine("Deleted the feed and items off: " + FeedId);
                    return(true);
                }
                else
                {
                    Debug.WriteLine("Failed to delete feed: " + FeedId + " / server error.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to delete feed: " + FeedId + " / " + ex.Message);
                return(false);
            }
        }
Example #12
0
        //Mark item as un/read from string list
        static public async Task <bool> MarkItemReadStringList(List <String> MarkIds, bool MarkType)
        {
            try
            {
                //Add items to post string
                string PostStringItemIds = String.Empty;
                foreach (String ItemId in MarkIds)
                {
                    PostStringItemIds += "&i=" + ItemId;
                }

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

                HttpStringContent PostContent;
                if (MarkType)
                {
                    PostContent = new HttpStringContent("a=user/-/state/com.google/read" + PostStringItemIds, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                }
                else
                {
                    PostContent = new HttpStringContent("r=user/-/state/com.google/read" + PostStringItemIds, 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>")))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch { return(false); }
        }
Example #13
0
        private static async Task <bool> MarkStarSingle(Items ListItem, bool RemoveFromList, string ActionType, bool Silent)
        {
            try
            {
                bool   MarkStatus = false;
                string ItemId     = ListItem.item_id;

                //Check if internet is available
                if (!AppVariables.InternetAccess || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Off " + ActionType.ToLower() + "ring the item...", true);
                    }
                    System.Diagnostics.Debug.WriteLine("Off " + ActionType.ToLower() + "ring the item...");

                    await AddOfflineSync(ItemId, ActionType);

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI(ActionType + "ring the item...", true);
                    }
                    System.Diagnostics.Debug.WriteLine(ActionType + "ring the item...");

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

                    StringContent PostContent;
                    if (ActionType == "Star")
                    {
                        PostContent = new StringContent("i=" + ItemId + "&a=user/-/state/com.google/starred", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }
                    else
                    {
                        PostContent = new StringContent("i=" + ItemId + "&r=user/-/state/com.google/starred", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }

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

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

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

                    if (TableEditItems != null)
                    {
                        if (ActionType == "Star")
                        {
                            TableEditItems.item_star_status = true;
                            ListItem.item_star_status       = Visibility.Visible;
                        }
                        else
                        {
                            TableEditItems.item_star_status = false;
                            ListItem.item_star_status       = Visibility.Collapsed;
                            if (RemoveFromList)
                            {
                                List_StarredItems.Remove(ListItem);
                            }
                        }
                    }

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

                return(MarkStatus);
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Failed to un/star item.");
                return(false);
            }
        }
Example #14
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 #15
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 #16
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 #17
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 (Connectivity.NetworkAccess != NetworkAccess.Internet || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        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)
                    {
                        EventProgressDisableUI("Marking item as " + ActionType.ToLower() + "...", true);
                    }
                    Debug.WriteLine("Marking item as " + ActionType.ToLower() + "...");

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

                    StringContent PostContent;
                    if (ActionType == "Read")
                    {
                        PostContent = new StringContent("i=" + ItemId + "&a=user/-/state/com.google/read", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }
                    else
                    {
                        PostContent = new StringContent("i=" + ItemId + "&r=user/-/state/com.google/read", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }
                    Uri PostUri = new Uri(ApiConnectionUrl + "edit-tag");

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

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

                if (MarkStatus)
                {
                    //Get the current page name
                    string currentPage = App.Current.MainPage.ToString();

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

                    if (TableEditItems != null)
                    {
                        if (ActionType == "Read")
                        {
                            TableEditItems.item_read_status = true;
                            ListItem.item_read_status       = true;
                            ListItem.item_read_icon         = ImageSource.FromResource("NewsScroll.Assets.iconRead-Dark.png");
                        }
                        else
                        {
                            TableEditItems.item_read_status = false;
                            ListItem.item_read_status       = false;
                            ListItem.item_read_icon         = null;
                        }
                    }

                    //Update the items in database
                    await vSQLConnection.UpdateAsync(TableEditItems);
                }
                else
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Failed to mark item " + ActionType.ToLower(), "Please check your internet connection and try again.", messageAnswers);

                    EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                Debug.WriteLine("Failed to un/read item.");
                return(false);
            }
        }
Example #18
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())
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Not logged in", "Marking all items read can only be done when you are logged in.", messageAnswers);

                    return(false);
                }

                if (Confirm)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Mark all items read");
                    messageAnswers.Add("Cancel");

                    string messageResult = await MessagePopup.Popup("Mark all items read", "Do you want to mark all items for every feed as read?", messageAnswers);

                    if (messageResult == "Cancel")
                    {
                        return(false);
                    }
                }

                bool MarkStatus = false;

                //Check if internet is available
                if (Connectivity.NetworkAccess != NetworkAccess.Internet || ApiMessageError.StartsWith("(Off)"))
                {
                    EventProgressDisableUI("Off marking all items as read...", true);
                    Debug.WriteLine("Off marking all items as read...");

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

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

                    //Date time variables
                    long UnixTimeTicks = 0;
                    if (AppSettingLoad("LastItemsUpdate").ToString() != "Never")
                    {
                        UnixTimeTicks = (Convert.ToDateTime(AppSettingLoad("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=" + AppSettingLoad("ConnectApiAuth").ToString() } };
                    StringContent PostContent   = new StringContent("s=user/-/state/com.google/reading-list&ts=" + UnixTimeTicks, Encoding.UTF8, "application/x-www-form-urlencoded");
                    Uri           PostUri       = new Uri(ApiConnectionUrl + "mark-all-as-read");

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

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

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

                    //Update items in database
                    await vSQLConnection.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 == false).ToList();
                    foreach (Items NewsItem in ListItems)
                    {
                        //Mark the item as read
                        NewsItem.item_read_status = true;
                        NewsItem.item_read_icon   = ImageSource.FromResource("NewsScroll.Assets.iconRead-Dark.png");
                    }

                    EventProgressEnableUI();
                }
                else
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Failed to mark all items read", "Please check your internet connection and try again.", messageAnswers);

                    EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Ok");

                await MessagePopup.Popup("Failed to mark all items read", "Please check your internet connection and try again.", messageAnswers);

                EventProgressEnableUI();
                return(false);
            }
        }
Example #19
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)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Mark read till item");
                    messageAnswers.Add("Cancel");

                    string messageResult = await MessagePopup.Popup("Mark items read till item", "Do you want to mark all items for the selected feed till this item as read?", messageAnswers);

                    if (messageResult == "Cancel")
                    {
                        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 == false).ToList();

                //Check if internet is available
                if (Connectivity.NetworkAccess != NetworkAccess.Internet || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        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)
                    {
                        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=" + AppSettingLoad("ConnectApiAuth").ToString() } };
                    StringContent PostContent   = new StringContent("a=user/-/state/com.google/read" + PostStringItemIds, Encoding.UTF8, "application/x-www-form-urlencoded");
                    Uri           PostUri       = new Uri(ApiConnectionUrl + "edit-tag");

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

                    if (PostHttp != null && (PostHttp == "OK" || PostHttp.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;
                        }
                    }

                    SqlStringItemIds = AVFunctions.StringRemoveEnd(SqlStringItemIds, ",");
                    await vSQLConnection.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
                        NewsItem.item_read_status = true;
                        NewsItem.item_read_icon   = ImageSource.FromResource("NewsScroll.Assets.iconRead-Dark.png");

                        //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)
                    {
                        EventProgressEnableUI();
                    }
                }
                else
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Failed to mark items read", "Please check your internet connection and try again.", messageAnswers);

                    EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Ok");

                await MessagePopup.Popup("Failed to mark items read", "Please check your internet connection and try again.", messageAnswers);

                EventProgressEnableUI();
                return(false);
            }
        }