Exemple #1
0
        public void GetServiceDailySuccess(DailyModel daily)
        {
            if (swipeRefreshLayout.Refreshing)
            {
                swipeRefreshLayout.Refreshing = false;
            }
            if (daily != null && daily.id > 0)
            {
                this.daily     = daily;
                title          = daily.title;
                txtTitle.Text  = daily.title;
                txtAuthor.Text = daily.image_source;
                body.Settings.JavaScriptEnabled = true;
                body.Settings.DomStorageEnabled = true;
                var jsInterface = new WebViewJSInterface(this);
                body.SetWebViewClient(DailyWebViewClient.With(this));
                body.AddJavascriptInterface(jsInterface, "openlistner");
                body.LoadRenderedContent(daily.body.Replace("img-place-holder", "img-place-holder1"));
                jsInterface.CallFromPageReceived += delegate(object sender, WebViewJSInterface.CallFromPageReceivedEventArgs e)
                {
                    switch (e.Type)
                    {
                    case WebViewJSInterface.CallFromType.Image:
                        PhotoActivity.Start(this, e.Result.Split(','), e.Index);
                        break;

                    case WebViewJSInterface.CallFromType.Href:
                        Intent intent = new Intent();
                        intent.SetAction("android.intent.action.VIEW");
                        intent.SetData(Android.Net.Uri.Parse(e.Result));
                        intent.SetClassName("com.android.browser", "com.android.browser.BrowserActivity");
                        StartActivity(intent);
                        break;
                    }
                };
                if (daily.image != "")
                {
                    Picasso.With(this).Load(daily.image).Into(titleImage);
                }
                else
                {
                    appbar.LayoutParameters = new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MatchParent, toolbar.Height);
                    toolbarTitle.Text       = title;
                }
            }
        }
        public async void GetServiceArticleSuccess(ArticleModel article)
        {
            if (swipeRefreshLayout.Refreshing)
            {
                swipeRefreshLayout.Refreshing = false;
            }
            title          = article.Title;
            txtAuthor.Text = article.Author.Name;

            if (article.Author.IsOrg)
            {
                org.Visibility = ViewStates.Visible;
                org.SetImageResource(Resource.Drawable.identity);
            }
            else
            {
                if (article.Author.Badge != null)
                {
                    org.Visibility = ViewStates.Visible;
                    if (article.Author.Badge.Identity != null)
                    {
                        org.SetImageResource(Resource.Drawable.identity);
                    }
                    else if (article.Author.Badge.Best_answerer != null)
                    {
                        org.SetImageResource(Resource.Drawable.bestanswerer);
                    }
                }
                else
                {
                    org.Visibility = ViewStates.Gone;
                }
            }
            txtBio.Text = article.Author.Bio;
            if (this.article == null || this.article.Content != article.Content)
            {
                var content = "<h1>" + article.Title + "</h1>" + article.Content;

                articleContent.Settings.JavaScriptEnabled = true;
                articleContent.Settings.CacheMode         = CacheModes.CacheElseNetwork;
                var jsInterface = new WebViewJSInterface(this);
                articleContent.SetWebViewClient(DailyWebViewClient.With(this));
                articleContent.AddJavascriptInterface(jsInterface, "openlistner");
                articleContent.LoadRenderedContent(content);
                jsInterface.CallFromPageReceived += delegate(object sender, WebViewJSInterface.CallFromPageReceivedEventArgs e)
                {
                    switch (e.Type)
                    {
                    case WebViewJSInterface.CallFromType.Image:
                        PhotoActivity.Start(this, e.Result.Split(','), e.Index);
                        break;

                    case WebViewJSInterface.CallFromType.Href:
                        Intent intent = new Intent();
                        intent.SetAction("android.intent.action.VIEW");
                        intent.SetData(Android.Net.Uri.Parse(e.Result));
                        intent.SetClassName("com.android.browser", "com.android.browser.BrowserActivity");
                        StartActivity(intent);
                        break;
                    }
                };
            }
            txtTime.Text = "创建于:" + Convert.ToDateTime(article.PublishedTime).ToString("yyyy-MM-dd");

            if (article.LikesCount > 0)
            {
                txtGood.Text = article.LikesCount.ToString();
            }
            if (article.CommentsCount > 0)
            {
                txtComments.Text = article.CommentsCount.ToString();
                (txtComments.Parent as FrameLayout).Click += delegate
                {
                    ArticleCommentActivity.Start(this, slug);
                };
            }
            if (article.TitleImage != "")
            {
                Picasso.With(this)
                .Load(article.TitleImage)
                .Into(titleImage);
            }
            else
            {
                appbar.LayoutParameters = new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MatchParent, toolbar.Height);
                toolbarTitle.Text       = title;
            }
            var avatar = article.Author.Avatar.Template.Replace("{id}", article.Author.Avatar.Id);

            avatar = avatar.Replace("{size}", "l");
            await ImageService.Instance.LoadUrl(avatar)
            .Retry(3, 200)
            .DownSample(40, 40)
            .Transform(new CircleTransformation())
            .LoadingPlaceholder("ic_placeholder.png", ImageSource.ApplicationBundle)
            .ErrorPlaceholder("ic_placeholder.png", ImageSource.ApplicationBundle)
            .IntoAsync(imgAvatar);

            this.article = article;
        }