Esempio n. 1
0
        public async Task <LHYDAPI> PerformGetLHYDAPI(string itemcode)
        {
            Debug.WriteLine("Activate get LHYD");
            LHYDAPI Items = new LHYDAPI();

            Debug.WriteLine("mã hàng:" + itemcode);
            var uri = new Uri(string.Format(Constants.RestLHYDUrl, itemcode));

            try
            {
                Debug.WriteLine("link:" + uri);
                var response = await client.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    Debug.WriteLine(content);
                    Items = JsonConvert.DeserializeObject <LHYDAPI>(content);
                    return(Items);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
            throw new NotImplementedException();
        }
Esempio n. 2
0
        private async void LHYDF5(string itemcode)
        {
            lhydapi = await App.SvManager.GetLHYDAsync(itemcode);

            LHYD lhyd = lhydapi.data;

            //author.Text = "-" + lhyd.author + "-";
            try
            {
                if (lhyd.img != "")
                {
                    try
                    {
                        Debug.WriteLine("img");
                        byte[] proimageBytes = Convert.FromBase64String(lhyd.img);
                        var    inputbg       = ImageSource.FromStream(
                            () => new MemoryStream(proimageBytes));
                        bgimage.Source = await DependencyService.Get <IDraw>().Drawtext(inputbg, lhyd.content, "- " + lhyd.author + " - ");

                        Debug.WriteLine("chạy oke");
                    }
                    catch
                    {
                        Debug.WriteLine("lỗi draw text");
                        var inputbg = "bg_default";

                        bgimage.Source = await DependencyService.Get <IDraw>().Drawtext(inputbg, lhyd.content, "- " + lhyd.author + " - ");
                    }
                }
                else
                {
                    var inputbg = "bg_default";
                    Debug.WriteLine("ko có ảnh từ api");
                    bgimage.Source = await DependencyService.Get <IDraw>().Drawtext(inputbg, lhyd.content, "- " + lhyd.author + " - ");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Lỗi từ ban đầu:                 " + e);
                bgimage.Source = ImageSource.FromFile("bg_default");
            }
        }
Esempio n. 3
0
        private void SetWebLayout(string itemcode, int mode)
        {
            //1 là mode ezcheck cũ, 2 là lời hay ý đẹp
            NavigationPage.SetHasBackButton(this, true);
            NavigationPage.SetHasNavigationBar(this, true);
            StackLayout stackweb = new StackLayout();

            /*
             * ProgressBar probar = new ProgressBar()
             * {
             *  HorizontalOptions = LayoutOptions.FillAndExpand,
             *  IsVisible = false,
             *  Progress = 0.2,
             * };
             * resultweb.Navigating += (sender, e) =>
             * {
             *  probar.IsVisible = true;
             * };
             * resultweb.Navigated += (sender, e) =>
             * {
             *  probar.IsVisible = false;
             * };
             */
            var resultweb = new WebView
            {
                HeightRequest = App.Current.MainPage.Height,
                WidthRequest  = App.Current.MainPage.Width,
            };

            if (mode == 2)
            {
                this.Title = "Lời hay ý đẹp";
                lhydapi    = new LHYDAPI();
                bgimage    = new Image()
                {
                    WidthRequest    = App.Current.MainPage.Width,
                    HeightRequest   = App.Current.MainPage.Width + App.Current.MainPage.Width / 5 - 20,
                    Aspect          = Aspect.AspectFit,
                    Margin          = new Thickness(10, 10, 10, 0),
                    BackgroundColor = Color.FromHex("#f2f2f2")
                };

                /*author = new Label()
                 * {
                 *  WidthRequest = WidthRequest = App.Current.MainPage.Width,
                 *  //HeightRequest = 100,
                 *  HorizontalTextAlignment = TextAlignment.Center,
                 *  VerticalTextAlignment = TextAlignment.Center,
                 *
                 *  Margin = new Thickness(10, 10, 10, 0),
                 *  //BackgroundColor = Color.FromHex("#f2f2f2")
                 * };*/
                BoxView endBoxView = new BoxView
                {
                    Color         = Color.FromHex(Constants.ColorPrimary),
                    HeightRequest = Application.Current.MainPage.Height - Application.Current.MainPage.Width - 50,
                    WidthRequest  = Application.Current.MainPage.Width,
                    Margin        = new Thickness(0, 20, 0, 0),
                    //VerticalOptions = LayoutOptions.Center
                };
                ToolbarItems.Add(new ToolbarItem("Refresh", "ic_refresh", () =>
                {
                    LHYDF5(itemcode);
                }));
                try
                {
                    LHYDF5(itemcode);

                    ToolbarItems.Add(new ToolbarItem("Share", "ic_share", () =>
                    {
                        DependencyService.Get <IShare>().ShareAsync(bgimage.Source, "test");
                    })
                                     );
                    stackweb.Children.Add(bgimage);
                    //stackweb.Children.Add(author);
                    stackweb.Children.Add(endBoxView);
                }
                catch (Exception ex)
                {
                    if (ex.GetType().ToString() == "System.NotImplementedException")
                    {
                        CheckLoadingInit(itemcode);
                    }
                    Content = SetErrorPage();
                }
                //resultweb.Source = string.Format(Constants.WebLHYDUrl, itemcode);

                /*try {
                 *  var client = new HttpClient();
                 *  var shtml = await client.GetStringAsync("https://ezcheck.vn/loihayydep/B227690745826");
                 *  Debug.WriteLine(shtml);
                 * }
                 * catch(Exception e)
                 * {
                 *  Debug.WriteLine(e);
                 * }*/
            }
            else
            {
                resultweb.Source = string.Format(Constants.WebUrl, itemcode);
                stackweb.Children.Add(resultweb);
            }
            Content = stackweb;
        }