Esempio n. 1
0
        public void FavButtonCheck(RSSTable RSS) //Checks if the user has already favorited the article, and sets the favoritesbutton if so.
        {
            if (App.LoggedinUser != null)
            {
                int j   = 0;
                var FAL = App.database.GetFavorites(App.LoggedinUser.ID);

                if (FAL != null)
                {
                    Console.WriteLine("Favorites Gotten: " + FAL.Count());
                    foreach (var FA in FAL)
                    {
                        if (RSS.ID == FA.ID)
                        {
                            Favorited = true;
                        }
                    }
                }
                if (Favorited)
                {
                    FavIcon.Source = "Icon_Heart_Full";
                }
                else
                {
                    FavIcon.Source = "Icon_Heart_red";
                }
            }
        }
Esempio n. 2
0
        // Fetches the RSS object of an article from the database and uses it to load in a news page.
        async void LoadNews(object sender, EventArgs e)
        {
            bool LoadFailure = false;
            var  Header      = (Button)sender;

            Header.IsEnabled = false;
            var id = Int32.Parse(Header.ClassId);

            await System.Threading.Tasks.Task.Run(async() =>
            {
                var NP = new ContentPage();

                bool OK = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    //IsBusy = true;

                    LoadingPopUp x = new LoadingPopUp();
                    x.loadingAnimation.Play();
                    await Navigation.PushAsync(x);
                });

                var RSSTable = App.database.GetServerRSS(id);
                if (RSSTable != null)
                {
                    RSSTable RSS = RSSTable.First();
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        NP = new NewsPage(RSS, argc);
                        OK = true;
                    });
                }
                else
                {
                    LoadFailure = true;
                }

                await System.Threading.Tasks.Task.Delay(10);
                Device.BeginInvokeOnMainThread(async() =>
                {
                    Console.WriteLine("Initiering Klar");

                    await Navigation.PopAsync();
                    if (OK)
                    {
                        await Navigation.PushAsync(NP);
                    }
                });
            });

            Header.IsEnabled = true;
            if (LoadFailure)
            {
                await DisplayAlert("Article Load Failure", "Artikeln misslyckades att laddas in, vänligen försök igen.", "OK");
            }
        }
Esempio n. 3
0
        //The visuals are set up. If the user is logged in, interactions such as coin collecting, history and favorite checks are performed.
        public NewsPage(RSSTable RSS, int argc)
        {
            InitializeComponent();

            rssTable = RSS;
            BackGroundReactionTimerFavorites.BackgroundColor = App.MC;
            red   = 255 + (int)App.MC.R * 2;
            green = 255 + (int)App.MC.G * 2;
            blue  = 255 + (int)App.MC.B * 2;
            FavIcon.BackgroundColor = App.MC;

            if (App.LoggedinUser != null && argc == 0) // If the User is logged in and article is opened normally
            {
                bool read    = false;
                var  History = App.database.GetAllHistory(App.LoggedinUser.ID); //Fetch history from server to check if article is read.

                if (History == null)
                {
                    read = true;
                }
                else
                {
                    foreach (HistoryTable HT in History)
                    {
                        if (RSS.ID == HT.Article)
                        {
                            read = true;
                            break;
                        }
                    }
                }

                if (read)
                {
                    TimerButton.IsEnabled = false;
                    TimerIcon.Source      = "Icon_Coin.png";
                    TimerButton.Text      = "";
                    TimerButton.IsVisible = false;
                    Read = true;
                    NewsPageView.BackgroundColor = App.MC;
                    TimerButton.BackgroundColor  = App.MC;
                    TimerButton.TextColor        = Color.White;
                }
                else
                {
                    NewsPageView.BackgroundColor = Color.White;
                    TimerButton.TextColor        = Color.White;
                    Timer = new System.Timers.Timer
                    {
                        Interval = 20
                    };
                    Timer.Elapsed += OnTimedEvent;
                    Timer.Enabled  = true;
                }
            }
            else
            {
                NewsPageView.BackgroundColor = Color.FromRgb(248, 248, 248);
            }

            if (argc == 1) // If article is loaded through History
            {
                TimerButton.IsVisible = false;
                TimerIcon.IsVisible   = false;
                FavIcon.IsVisible     = false;
            }

            if (argc == 2) // If article is loaded through Favorites
            {
                TimerButton.IsVisible = false;
                TimerIcon.IsVisible   = false;
                Favorited             = true;
            }
            LoadNews(RSS);
            FavButtonCheck(RSS);
            ReactionCheck();
        }
Esempio n. 4
0
        //The article is loaded in, and the article text, date, author, tags, reactions, and comment sections are defined, modified, and added to the page.
        void LoadNews(RSSTable RSS)
        {
            ArticleNR    = RSS.ID;
            Rubrik.Text  = RSS.Title.Replace("*", "-").Replace(""", "'");
            Ingress.Text = RSS.Description.Replace("*", "-").Replace(""", "'");
            string datePub = RSS.PubDate.ToString();

            for (int i = 0; i < 3; i++)
            {
                datePub = datePub.Remove(datePub.Length - 1);
            }
            Top.Text = datePub + "   " + RSS.Source;
            if (RSS.Author == "Ingen Byline")
            {
                Author.Text = "";
            }
            else
            {
                Author.TextColor = Color.FromHex("#649FD4");
                Author.Text      = "Av: " + RSS.Author;
            }

            Location.TextColor = Color.FromHex("#649FD4");
            switch (RSS.Tag)
            {
            case "Skövde":
                Location.Text = "Plats: Skövde";
                break;

            case "Tibro":
                Location.Text = "Plats: Tibro";
                break;

            case "Falköping":
                Location.Text = "Plats: Falköping";
                break;

            case "Karlsborg":
                Location.Text = "Plats: Karlsborg";
                break;
            }
            switch (RSS.Category)
            {
            case "Skövde":
                Location.Text = "Plats: Skövde";
                break;

            case "Tibro":
                Location.Text = "Plats: Tibro";
                break;

            case "Falköping":
                Location.Text = "Plats: Falköping";
                break;

            case "Karlsborg":
                Location.Text = "Plats: Karlsborg";
                break;
            }

            Title = RSS.Category;

            if (RSS.Tag.Length > 20)
            {
                //Tags.Text = "";
            }
            else if (RSS.Tag != "")
            {
                //Tags.Text = "Tags: " + RSS.Tag + "  ";
            }
            else
            {
                //Tags.Text = "";
            }

            var TGR = new TapGestureRecognizer
            {
                NumberOfTapsRequired = 1
            };

            TGR.Tapped += (s, e) => {
                IsEnabled = false;
                IsEnabled = true;
            };
            Author.GestureRecognizers.Add(TGR);

            ArticleImage.Source = RSS.ImgSource;


            var Order     = JsonConvert.DeserializeObject <List <int> >(RSS.Ordning);
            var Text      = JsonConvert.DeserializeObject <List <string> >(RSS.Text);
            var Images    = JsonConvert.DeserializeObject <List <string> >(RSS.Images);
            var ImageText = JsonConvert.DeserializeObject <List <string> >(RSS.Imagetext);

            int Count      = 0;
            int TextCount  = 0;
            int ImageCount = 0;

            var Reactions = App.database.GetReactionsFromArticle(RSS.ID);

            foreach (ReactionTable Reaction in Reactions)
            {
                if (Reaction.User == App.LoggedinUser.ID)
                {
                    Reacted = true;
                    CR      = Reaction;
                    break;
                }
            }

            var ReactionBackground = new BoxView
            {
                CornerRadius      = 0,
                Margin            = 0,
                BackgroundColor   = App.MC,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
            };

            //Reaction buttons
            var ReactionButton = new Button
            {
                CornerRadius      = 0,
                BorderWidth       = 0,
                Margin            = 0,
                BackgroundColor   = Color.Transparent,
                BorderColor       = Color.LightGray,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Text      = "",
                FontSize  = 20,
                TextColor = Color.LightGray,
            };

            ReactionButton.Clicked += ReactionButtonClicked;
            ReactionImage           = new Image
            {
                Source            = "reactions_gray",
                Margin            = 0,
                BackgroundColor   = Color.Transparent,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                WidthRequest      = 50,
                HeightRequest     = 50,
            };
            var ReactionBar1 = new BoxView
            {
                CornerRadius      = 1,
                Margin            = 5,
                BackgroundColor   = Color.Red,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.End,
                WidthRequest      = Application.Current.MainPage.Width / 2 * 1f,
                HeightRequest     = 5,
            };
            var ReactionBar2 = new BoxView
            {
                CornerRadius      = 1,
                Margin            = 5,
                BackgroundColor   = Color.Blue,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.End,
                WidthRequest      = Application.Current.MainPage.Width / 2 * 0.4f,
                HeightRequest     = 5,
            };
            var ReactionBar3 = new BoxView
            {
                CornerRadius      = 1,
                Margin            = 0,
                BackgroundColor   = Color.Yellow,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.End,
                WidthRequest      = Application.Current.MainPage.Width / 2 * 0.1f,
                HeightRequest     = 5,
            };

            ReactionsOthers1 = new Image
            {
                Source            = "reactions_4",
                Margin            = 10,
                BackgroundColor   = Color.Transparent,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Center,
                WidthRequest      = 30,
                HeightRequest     = 30,
            };
            var ReactionsOthers2 = new Image
            {
                Source            = "reactions_2",
                Margin            = 10,
                BackgroundColor   = Color.Transparent,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                WidthRequest      = 30,
                HeightRequest     = 30,
            };
            var ReactionsOthers3 = new Image
            {
                Source            = "reactions_0",
                Margin            = 10,
                BackgroundColor   = Color.Transparent,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Center,
                WidthRequest      = 30,
                HeightRequest     = 30,
            };

            ReactionsOthersText = new Label
            {
                Text              = Reactions.Count.ToString(),
                TextColor         = Color.Black,
                FontSize          = 20,
                Margin            = 0,
                BackgroundColor   = Color.Transparent,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
            };

            foreach (int Type in Order) //For loop that decided which order the images and the body text will be arranged in
            {
                if (Type == 0)          //If Text
                {
                    ArticleGrid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });



                    var Label = new Label
                    {
                        Text = Text[TextCount].Replace("*", "-").Replace("&quot;", "'"),
                        HorizontalTextAlignment = TextAlignment.Start,
                        VerticalTextAlignment   = TextAlignment.Start,
                        FontSize  = 16,
                        TextColor = Color.Black,
                        Margin    = new Thickness(0, 0, 5, 10)
                    };
                    ArticleGrid.Children.Add(Label, 1, 4, Row, Row + 1);
                    Row++;
                    Count++;
                    TextCount++;
                }
                else if (Type == 1) //If Image
                {
                    var IMGText = new Label
                    {
                        Text = ImageText[ImageCount].Replace("*", "-"),
                        HorizontalOptions       = LayoutOptions.Start,
                        VerticalOptions         = LayoutOptions.Start,
                        HorizontalTextAlignment = TextAlignment.Start,
                        VerticalTextAlignment   = TextAlignment.Start,
                        FontSize  = 14,
                        TextColor = Color.Gray,
                        Margin    = new Thickness(0, 10, 0, 20)
                    };

                    if (Topimg == true)
                    {
                        Image img = new Image {
                            Source = Images[ImageCount]
                        };


                        ArticleImage.Source        = Images[ImageCount];
                        ArticleImage.HeightRequest = img.Height;
                        ArticleImage.WidthRequest  = 300;
                        ArticleGrid.Children.Add(IMGText, 1, 4, 5, 6);
                        Topimg = false;
                    }
                    else
                    {
                        var Image = new Image
                        {
                            WidthRequest  = 200,
                            HeightRequest = 300,
                            Aspect        = Aspect.AspectFill,
                            Margin        = 5,
                        };

                        ArticleGrid.RowDefinitions.Add(new RowDefinition {
                            Height = GridLength.Auto
                        });
                        ArticleGrid.RowDefinitions.Add(new RowDefinition {
                            Height = GridLength.Auto
                        });
                        ArticleGrid.RowDefinitions.Add(new RowDefinition {
                            Height = GridLength.Auto
                        });
                        Image.Source = Images[ImageCount];
                        ArticleGrid.Children.Add(Image, 0, 5, Row, Row + 1);
                        ArticleGrid.Children.Add(IMGText, 1, 4, Row + 1, Row + 2);
                        Row++;
                        Row++;
                        Row++;
                    }
                    Count++;
                    ImageCount++;
                }
            }
            string[] Categories = RSS.Category.Split(new[] { ", " }, StringSplitOptions.None);
            string[] Tags       = RSS.Tag.Split(new[] { ", " }, StringSplitOptions.None);

            int TagRow = 0;

            foreach (String Category in Categories) //Display all the articles categories
            {
                var Box = new Button
                {
                    CornerRadius      = 10,
                    Margin            = 2,
                    BackgroundColor   = Color.Transparent,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    ClassId           = Category,
                };
                Box.Clicked += CategoryButtonClicked;

                var EmptyAddedBox = new Image
                {
                    Source            = "Icon_Heart_red",
                    Margin            = 10,
                    BackgroundColor   = Color.Transparent,
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    ClassId           = Category,
                    WidthRequest      = 30,
                    HeightRequest     = 30,
                };

                var AddedBox = new Image
                {
                    Source            = "Icon_Heart_Full",
                    Margin            = 10,
                    BackgroundColor   = Color.Transparent,
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    ClassId           = Category,
                    WidthRequest      = 30,
                    HeightRequest     = 30,
                };
                var Line = new Button
                {
                    Margin            = 0,
                    BackgroundColor   = App.MC,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.Start,
                    ClassId           = Category,
                    HeightRequest     = 1,
                };

                var Comment = new Label
                {
                    Text = Category,
                    HorizontalTextAlignment = TextAlignment.Start,
                    VerticalTextAlignment   = TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.Start,
                    TextColor        = Color.Black,
                    FontSize         = 16,
                    WidthRequest     = 290,
                    Margin           = 20,
                    InputTransparent = true,
                };
                TagGrid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });

                TagGrid.Children.Add(EmptyAddedBox, 0, 6, TagRow, TagRow + 1);
                TagGrid.Children.Add(Line, 0, 6, TagRow, TagRow + 1);
                TagGrid.Children.Add(Box, 0, 6, TagRow, TagRow + 1);

                if (App.SideMenu.Categories.Contains(Category))
                {
                    Box.IsEnabled = false;
                    TagGrid.Children.Add(AddedBox, 0, 6, TagRow, TagRow + 1);
                    AddedBox.IsEnabled = false;
                }
                TagGrid.Children.Add(Comment, 0, 6, TagRow, TagRow + 1);
                TagRow++;
            }

            foreach (String Tag in Tags) //Display all the articles tags
            {
                var Box = new Button
                {
                    CornerRadius      = 10,
                    Margin            = 2,
                    BackgroundColor   = Color.Transparent,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    TextColor         = Color.Transparent,
                    ClassId           = Tag
                };
                Box.Clicked += TagButtonClicked;
                var EmptyAddedBox = new Image
                {
                    Source            = "Icon_Heart_red",
                    Margin            = 10,
                    BackgroundColor   = Color.Transparent,
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    ClassId           = Tag,
                    WidthRequest      = 30,
                    HeightRequest     = 30,
                };
                var Line = new Button
                {
                    Margin            = 0,
                    BackgroundColor   = App.MC,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.Start,
                    ClassId           = Tag,
                    HeightRequest     = 1,
                };

                var AddedBox = new Image
                {
                    Source            = "Icon_Heart_Full",
                    Margin            = 10,
                    BackgroundColor   = Color.Transparent,
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    ClassId           = Tag,
                    WidthRequest      = 30,
                    HeightRequest     = 30,
                };
                var Comment = new Label
                {
                    Text = Tag,
                    HorizontalTextAlignment = TextAlignment.Start,
                    VerticalTextAlignment   = TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.Start,
                    TextColor        = Color.Black,
                    FontSize         = 16,
                    WidthRequest     = 290,
                    Margin           = 20,
                    InputTransparent = true,
                };
                TagGrid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });

                TagGrid.Children.Add(EmptyAddedBox, 0, 6, TagRow, TagRow + 1);
                TagGrid.Children.Add(Line, 0, 6, TagRow, TagRow + 1);
                TagGrid.Children.Add(Box, 0, 6, TagRow, TagRow + 1);

                if (App.SideMenu.Tags.Contains(Tag))
                {
                    Box.IsEnabled = false;
                    TagGrid.Children.Add(AddedBox, 0, 6, TagRow, TagRow + 1);
                    AddedBox.IsEnabled = false;
                }
                TagGrid.Children.Add(Comment, 0, 6, TagRow, TagRow + 1);
                TagRow++;
            }


            ArticleGrid.Children.Add(Author, 1, 2, Row, Row + 1);
            ArticleGrid.Children.Add(Location, 2, 4, Row, Row + 1);
            ArticleGrid.Children.Add(BG, 0, 5, 0, Row + 2);
            ArticleGrid.Children.Add(BackGround, 0, 5, Row + 2, Row + 4);
            ArticleGrid.Children.Add(BackGroundReactionTimerFavorites, 0, 5, Row + 2, Row + 4);
            ArticleGrid.Children.Add(TimerIcon, 2, 3, Row + 2, Row + 4);
            ArticleGrid.Children.Add(TimerButton, 2, 3, Row + 2, Row + 4);
            TimerButton.TextColor = Color.White;
            ArticleGrid.Children.Add(FavIcon, 3, 4, Row + 2, Row + 4);

            ArticleGrid.Children.Add(ReactionImage, 1, 2, Row + 2, Row + 4);       //Reaction
            ArticleGrid.Children.Add(ReactionButton, 1, 2, Row + 2, Row + 4);      //Reaction
            ArticleGrid.Children.Add(ReactionsOthers1, 1, 2, Row + 1, Row + 2);    //Reaction
            ArticleGrid.Children.Add(ReactionsOthersText, 1, 2, Row + 1, Row + 2); //Reaction

            if (App.Online)
            {
                LoadComments();
            }

            ArticleGrid.Children.Add(TagGrid, 0, 5, Row + 4, Row + 5);
            TagGrid.BackgroundColor          = Color.White;
            CommentListView.InputTransparent = true;
            TagGrid.IsVisible = true;
        }