Esempio n. 1
0
        private void GetFavoriteForums()
        {
            var forumEntities = ForumsDatabase.GetFavoriteForums();
            var favorites     = RemoveCurrentFavoritesFromList(forumEntities);

            _favoritesEntity = new Category
            {
                Name      = "Favorites",
                Location  = string.Format(Awful.Parser.Core.EndPoints.ForumPage, "forumid=48"),
                ForumList = forumEntities
            };
            if (favorites == null)
            {
                if (forumEntities.Any())
                {
                    ForumGroupList.Insert(0, _favoritesEntity);
                }
            }
            else
            {
                if (ForumGroupList.First().Name == _favoritesEntity.Name)
                {
                    ForumGroupList.RemoveAt(0);
                }
                if (forumEntities.Any())
                {
                    ForumGroupList.Insert(0, _favoritesEntity);
                }
            }
        }
        public async Task Refresh()
        {
            IsLoading = true;
            string error = "";

            try
            {
                var bookmarkResult = await _threadManager.GetAllBookmarks();

                BookmarkedThreads = new ObservableCollection <Thread>();
                foreach (var bookmark in bookmarkResult)
                {
                    BookmarkedThreads.Add(bookmark);
                }
                await ApplicationData.Current.LocalSettings.SaveAsync(RefreshKey, DateTime.UtcNow);

                await ForumsDatabase.RefreshBookmarkedThreads(BookmarkedThreads.ToList());
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            if (!string.IsNullOrEmpty(error))
            {
                await ResultChecker.SendMessageDialogAsync($"Failed to get Bookmarks (Refresh): {error}", false);
            }
            IsLoading = false;
        }
        public async Task LoadInitialList()
        {
            IsLoading = true;
            string error = "";

            try
            {
                var bookmarks = await ForumsDatabase.GetBookmarkedThreadsFromDb();

                if (bookmarks != null && bookmarks.Any())
                {
                    BookmarkedThreads = bookmarks.OrderBy(node => node.OrderNumber).ToObservableCollection();
                }
                string refreshTime = await ApplicationData.Current.LocalSettings.ReadAsync <string>(RefreshKey);

                if ((!BookmarkedThreads.Any() || (!string.IsNullOrEmpty(refreshTime) && DateTime.Parse(refreshTime) > (DateTime.UtcNow.AddHours(1.00)))))
                {
                    await Refresh();
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            if (!string.IsNullOrEmpty(error))
            {
                await ResultChecker.SendMessageDialogAsync($"Failed to get Bookmarks (Load Inital List): {error}", false);
            }
            IsLoading = false;
        }
Esempio n. 4
0
        public async Task AddOrRemoveFavorite(Forum forum)
        {
            try
            {
                var result = await ForumsDatabase.UpdateForumBookmark(forum);

                GetFavoriteForums();
            }
            catch (Exception e)
            {
                await ResultChecker.SendMessageDialogAsync($"Failed to add or remove favorite: {e.Message}", false);
            }
        }
Esempio n. 5
0
        public async Task AddRemoveNotification(Thread thread)
        {
            string error = "";

            try
            {
                if (!thread.IsBookmark)
                {
                    return;
                }
                thread.IsNotified = !thread.IsNotified;
                await ForumsDatabase.AddRemoveNotification(thread.ThreadId, thread.IsNotified);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
        }
Esempio n. 6
0
        private async Task GetMainPageForumsAsync(bool forceRefresh = false)
        {
            var forumCategoryEntities = ForumsDatabase.GetMainForumCategories();

            if (forumCategoryEntities.Any() && !forceRefresh)
            {
                AddForumCategoryToPage(forumCategoryEntities);
                return;
            }
            else
            {
                forumCategoryEntities = await LoadForumsFromSite();
            }
            ForumGroupList.Clear();
            foreach (var forumCategoryEntity in forumCategoryEntities)
            {
                ForumGroupList.Add(forumCategoryEntity);
            }
            OnPropertyChanged("ForumGroupList");
            await ForumsDatabase.SaveForumList(ForumGroupList.ToList());
        }