Esempio n. 1
0
        /// <summary>
        /// Function to add user interest in MainFeed
        /// </summary>
        /// <param name="interest">Takes in an interest</param>
        public async Task AddUserInterest(Interest interest)
        {
            try
            {
                var addableTabItem = new Tab {
                    Title = interest.Title, ArticlePage = 1
                };
                var articles = await NewsApiHelper.SearchArticles(new string[] { interest.Title.ToLower() });

                addableTabItem.Articles.AddRange(articles);
                addableTabItem.IsBusy = false;

                MainFeedViewModel.Instance.TabItems.Insert(MainFeedViewModel.Instance.TabItems.IndexOf(MainFeedViewModel.Instance.TabItems.LastOrDefault()) + 1, addableTabItem);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Method to search articles depending on Interest Key words
        /// </summary>
        /// <param name="tab">Takes in a Tab Item</param>
        /// <param name="isRefreshing">True if page is being refreshed</param>
        async Task SearchArticles(Tab tab, bool isRefreshing = false)
        {
            tab.HasError = false;

            try
            {
                if (tab.Articles.Count == 0)
                {
                    tab.IsBusy = true;

                    var articles = await NewsApiHelper.SearchArticles(new string[] { tab.Title.ToLower() }, page : tab.ArticlePage);

                    tab.Articles.AddRange(articles);

                    tab.IsBusy = false;
                }
                else if (isRefreshing)
                {
                    tab.IsRefreshing = true;

                    var articles = await NewsApiHelper.SearchArticles(new string[] { tab.Title.ToLower() }, page : tab.ArticlePage);

                    tab.Articles.ReplaceRange(articles);

                    tab.IsRefreshing = false;
                }

                if (tab.Articles.Count == 0)
                {
                    tab.IsRefreshing = false;
                    tab.IsBusy       = false;
                    tab.HasError     = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                tab.IsRefreshing = false;
                tab.IsBusy       = false;
                tab.HasError     = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves users Interests in the database and locally
        /// </summary>
        /// <param name="interest"></param>
        public async Task AddUserInterest(Interest interest)
        {
            try
            {
                interest.Title = interest.Title.ToLower();

                var userInterestsList = DatabaseHelper.GetSavedInterestsList();

                if (userInterestsList == null)
                {
                    userInterestsList = new List <Interest>();
                }

                userInterestsList.Add(interest);

                string userInterestsJson = JsonConvert.SerializeObject(userInterestsList);
                Settings.AddSetting(Settings.AppPrefrences.Interests, userInterestsJson);

                var addableTabItem = new Tab {
                    Title = interest.Title, ArticlePage = 1
                };
                var articles = await NewsApiHelper.SearchArticles(new string[] { interest.Title.ToLower() });

                addableTabItem.Articles.AddRange(articles);
                addableTabItem.IsBusy = false;

                MainFeedViewModel.Instance.TabItems.Insert(MainFeedViewModel.Instance.TabItems.IndexOf(MainFeedViewModel.Instance.TabItems.LastOrDefault()) + 1, addableTabItem);

                string isloggedIn = Settings.GetSetting(Settings.AppPrefrences.IsLoggedIn);

                if (isloggedIn != null || isloggedIn != "False")
                {
                    await DatabaseHelper.UpdateUserInterests(userInterestsList).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }