Exemple #1
0
        public void AddNews(int Argc)
        {
            List <NewsfeedTable> Rss = new List <NewsfeedTable>();

            if (Argc == 0)
            {
                Rss = App.database.GetNF(Loadnr);
            }
            else if (Argc == 1)
            {
                Down.IsVisible = false;
                int j   = 0;
                var RAL = App.database.GetHistory(App.LoggedinUser.ID);
                Console.WriteLine("History Gotten: " + RAL.Count());

                if (RAL != null)
                {
                    foreach (var RA in RAL)
                    {
                        RA.Image = RA.Image.Substring(4, RA.Image.Length - 4);
                        var NF = new NewsfeedTable
                        {
                            ID         = 0,
                            NewsScore  = 5,
                            Image      = RA.Image,
                            Article    = RA.Article,
                            Category   = "N/A",
                            Header     = RA.Header,
                            Ingress    = "",
                            DatePosted = DateTime.Now,
                            Plus       = 0
                        };
                        Rss.Add(NF);
                        j++;
                        Console.WriteLine("Artikel Inlagd");
                    }
                    CURR = j;
                }
            }
            else if (Argc == 2)
            {
                Down.IsVisible = false;
                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)
                    {
                        FA.Image = FA.Image.Substring(4, FA.Image.Length - 4);
                        var NF = new NewsfeedTable
                        {
                            ID         = 0,
                            NewsScore  = 5,
                            Image      = FA.Image,
                            Article    = FA.Article,
                            Category   = "N/A",
                            Header     = FA.Header,
                            Ingress    = "",
                            DatePosted = DateTime.Now,
                            Plus       = 0
                        };
                        Rss.Add(NF);
                        j++;
                        Console.WriteLine("Artikel Inlagd");
                    }
                    CURR = j;
                }
            }
            else
            {
                Rss = App.database.GetNF(Loadnr);
            }



            Console.WriteLine(Rss.Count);
            Console.WriteLine("Inladdning Klar");
            int i = 1;

            foreach (NewsfeedTable NF in Rss)
            {
                bool Exists = false;
                App.Online = true;
                foreach (var Article in ArticleList)
                {
                    if (Article.ID == NF.Article)
                    {
                        Exists = true;
                    }
                }
                //Console.WriteLine(ArticleList.Count);
                Console.WriteLine("Jämnförelse ned ArtikelLista klar");
                if (!Exists)
                {
                    var Box = new Article(NF, argc);

                    Console.WriteLine("ArtikelObjekt Skapat");
                    ArticleList.Add(Box);
                }
                i++;
                Device.BeginInvokeOnMainThread(() =>
                {
                    App.LS.LoadingText.Text = "Skapar Nyhetslistan. " + i + " Artiklar Skapade.";
                });
            }

            /*
             * ArticlePrintList.Clear();
             *
             * if(ArticleList.Count < 20)
             * {
             *  CURR = ArticleList.Count;
             * }
             *
             *
             * for(int j = PREV; j < CURR; j++)
             * {
             *  ArticlePrintList.Add(ArticleList[j]);
             * }*/
            if (First && App.Online)
            {
                Console.WriteLine("News Added, Creating Listview");
                PrintNews();
                Console.WriteLine("Listview Created");
            }
        }
Exemple #2
0
            public Article(NewsfeedTable NF, int argc)
            {
                ReactionNR = 1337;

                Tag       = NF.Category.Split(new[] { ", " }, StringSplitOptions.None)[0];
                ID        = NF.Article;
                Header    = NF.Header.Replace("*", "-").Replace("&quot;", "'");
                IMGSource = NF.Image;
                if (!NF.Ingress.Any())
                {
                    HasIngress = false;
                    Ingress    = NF.Ingress;
                }
                else
                {
                    Ingress = NF.Ingress;
                    var properties = App.Current.Properties;
                    if (properties.ContainsKey("showingress"))
                    {
                        HasIngress = (bool)properties["showingress"];
                    }
                    else
                    {
                        HasIngress = true;
                    }

                    Ingress = NF.Ingress;

                    int IL = 40;
                    int IH = 17;

                    if (Ingress.Length < IL)
                    {
                        INGHR = IH;
                    }
                    else if (Ingress.Length < IL * 2)
                    {
                        INGHR = IH * 2;
                    }
                    else if (Ingress.Length < IL * 3)
                    {
                        INGHR = IH * 3;
                    }

                    /*
                     * //If the ingress is more than X characters, then shorten it until it's not.
                     * while (Ingress.Length > 120)
                     * {
                     *  Ingress = Ingress.Remove(Ingress.Length - 1);
                     * }
                     * while (!Ingress.EndsWith(" "))
                     * {
                     *  Ingress = Ingress.Remove(Ingress.Length - 1);
                     * }
                     *
                     *
                     * /*string[] words = Ingress.Split(' ');
                     * string myLastWord = words[words.Length - 1];
                     * int wordIndex = Ingress.IndexOf(myLastWord);
                     * Ingress.Remove(wordIndex);
                     *
                     * if (Ingress.EndsWith(" "))
                     *  Ingress = Ingress.Remove(Ingress.Length - 1);
                     * if (Ingress.EndsWith(","))
                     *  Ingress = Ingress.Remove(Ingress.Length - 1);
                     * if (Ingress.EndsWith("!"))
                     *  Ingress = Ingress.Remove(Ingress.Length - 1);
                     * if (Ingress.EndsWith("."))
                     *  Ingress = Ingress.Remove(Ingress.Length - 1);
                     */
                    Ingress = "● " + Ingress + "...";

                    /*
                     * if (Ingress.Length < 80)
                     * {
                     *  HasIngress = false;
                     * }*/
                }


                DatePublished = NF.DatePosted;

                datePub = DatePublished.Day + "/" + DatePublished.Month + "/" + DatePublished.Year;

                DateLength = (datePub.Length * 7);

                Full          = true;
                CategoryBig   = true;
                CategorySmall = false;

                if (NF.Category == "")
                {
                }
                TagLength = (Tag.Length * 7);

                Plus = Convert.ToBoolean(NF.Plus);

                int BL = 100;
                int BH = 60;

                if (Header.Length < BL)
                {
                    HeaderLength = BH;
                }
                else if (Header.Length < BL * 2)
                {
                    HeaderLength = BH * 2;
                }
                else if (Header.Length < BL * 3)
                {
                    HeaderLength = BH * 3;
                }

                if (IMGSource.ToString() == Defaultimage)
                {
                    IMGSource     = "";
                    IHR           = 1;
                    CBWR          = 7;
                    CBHR          = HeaderLength;
                    BHR           = HeaderLength;
                    CBHO          = LayoutOptions.Start;
                    CBVO          = LayoutOptions.FillAndExpand;
                    Full          = false;
                    CategoryBig   = false;
                    CategorySmall = true;
                    INGHR         = 36;
                }
                else
                {
                    IHR   = 200;
                    BHR   = 200 + HeaderLength;
                    CBWR  = 200;
                    CBHR  = 7;
                    CBHO  = LayoutOptions.FillAndExpand;
                    CBVO  = LayoutOptions.Start;
                    INGHR = 54;
                }

                if (argc != 0)
                {
                    IsNormalfeed = false;
                    HasIngress   = false;
                    TagVisible   = false;
                }
                else
                {
                    IsNormalfeed = true;
                }

                ArticleReactions = NF.ArtikelReactions;
                ReactionSum      = NF.ReactionSum;

                var ReactionList = JsonConvert.DeserializeObject <List <ReactionTable> >(ReactionSum);

                foreach (ReactionTable Reaction in ReactionList)
                {
                    if (Reaction.User == App.LoggedinUser.ID)
                    {
                        ReactionSrc = "reactions_" + Reaction.Reaktion + ".png";
                        break;
                    }
                    else
                    {
                        ReactionSrc = "reactions_gray.png";
                    }
                }

                int MaxValue   = 0;
                int MostPicked = 0;

                for (int i = 0; i < 8; i++)
                {
                    int CurValue = 0;
                    foreach (ReactionTable Reaction in ReactionList)
                    {
                        if (Reaction.Reaktion == i)
                        {
                            CurValue++;
                        }
                    }
                    if (CurValue > MaxValue)
                    {
                        MaxValue   = CurValue;
                        MostPicked = i;
                    }
                }
                ReactionSrcOthers = "reactions_" + MostPicked + ".png";

                ReactionNR = MaxValue;

                Console.WriteLine("Artikel Klar");
            }
Exemple #3
0
            public Article(NewsfeedTable NF, int argc)
            {
                ReactionNR = 1337;

                Tag       = NF.Category.Split(new[] { ", " }, StringSplitOptions.None)[0];
                ID        = NF.Article;
                Header    = NF.Header.Replace("*", "-").Replace("&quot;", "'");
                IMGSource = NF.Image;
                if (!NF.Ingress.Any()) // If the ingress is empty, skip construction otherwise make a window whose size is based on the length of the Ingress.
                {
                    HasIngress = false;
                    Ingress    = NF.Ingress;
                }
                else
                {
                    Ingress = NF.Ingress;
                    var properties = App.Current.Properties;
                    if (properties.ContainsKey("showingress"))
                    {
                        HasIngress = (bool)properties["showingress"];
                    }
                    else
                    {
                        HasIngress = true;
                    }

                    Ingress = NF.Ingress;

                    int IL = 40;
                    int IH = 17;

                    if (Ingress.Length < IL)
                    {
                        INGHR = IH;
                    }
                    else if (Ingress.Length < IL * 2)
                    {
                        INGHR = IH * 2;
                    }
                    else if (Ingress.Length < IL * 3)
                    {
                        INGHR = IH * 3;
                    }

                    Ingress = "● " + Ingress + "...";
                }

                DatePublished = NF.DatePosted;

                datePub = DatePublished.Day + "/" + DatePublished.Month + "/" + DatePublished.Year;

                DateLength = (datePub.Length * 7);

                Full          = true;
                CategoryBig   = true;
                CategorySmall = false;

                if (NF.Category == "")
                {
                }
                TagLength = (Tag.Length * 7);

                Plus = Convert.ToBoolean(NF.Plus);

                int BL = 100;
                int BH = 60;

                if (Header.Length < BL)
                {
                    HeaderLength = BH;
                }
                else if (Header.Length < BL * 2)
                {
                    HeaderLength = BH * 2;
                }
                else if (Header.Length < BL * 3)
                {
                    HeaderLength = BH * 3;
                }
                if (IMGSource.ToString() == Defaultimage)
                {
                    IMGSource     = "";
                    IHR           = 1;
                    CBWR          = 7;
                    CBHR          = HeaderLength;
                    BHR           = HeaderLength;
                    CBHO          = LayoutOptions.Start;
                    CBVO          = LayoutOptions.FillAndExpand;
                    Full          = false;
                    CategoryBig   = false;
                    CategorySmall = true;
                    INGHR         = 36;
                }
                else
                {
                    IHR   = 200;
                    BHR   = 200 + HeaderLength;
                    CBWR  = 200;
                    CBHR  = 7;
                    CBHO  = LayoutOptions.FillAndExpand;
                    CBVO  = LayoutOptions.Start;
                    INGHR = 54;
                }

                if (argc != 0)
                {
                    IsNormalfeed = false;
                    HasIngress   = false;
                    TagVisible   = false;
                }
                else
                {
                    IsNormalfeed = true;
                }

                ArticleReactions = NF.ArtikelReactions;
                ReactionSum      = NF.ReactionSum;

                var ReactionList = JsonConvert.DeserializeObject <List <ReactionTable> >(ReactionSum);

                foreach (ReactionTable Reaction in ReactionList)
                {
                    if (Reaction.User == App.LoggedinUser.ID)
                    {
                        ReactionSrc = "reactions_" + Reaction.Reaktion + ".png";
                        break;
                    }
                    else
                    {
                        ReactionSrc = "reactions_gray.png";
                    }
                }

                int MaxValue   = 0;
                int MostPicked = 0;

                for (int i = 0; i < 8; i++)
                {
                    int CurValue = 0;
                    foreach (ReactionTable Reaction in ReactionList)
                    {
                        if (Reaction.Reaktion == i)
                        {
                            CurValue++;
                        }
                    }
                    if (CurValue > MaxValue)
                    {
                        MaxValue   = CurValue;
                        MostPicked = i;
                    }
                }
                ReactionSrcOthers = "reactions_" + MostPicked + ".png";

                ReactionNR = MaxValue;

                Console.WriteLine("Artikel Klar");
            }