public KbArticlesDetailsPage(KbArticles kbArticles)
        {
            this.kbArticles = kbArticles;
            InitializeComponent();
            BindingContext = new KbArticlesDetailsViewModel(kbArticles);

            var cancel = new ToolbarItem
            {
                Text    = "分享",
                Command = new Command(() =>
                {
                    DependencyService.Get <IShares>().Shares("http://kb.cnblogs.com/page/" + kbArticles.Id + "/", kbArticles.Title);
                })
            };

            ToolbarItems.Add(cancel);

            if (Device.Android == Device.RuntimePlatform)
            {
                cancel.Icon = "toolbar_share.png";
            }

            formsWebView.OnContentLoaded += delegate(object sender, EventArgs e)
            {
                RefreshKbArticles();
            };
        }
Example #2
0
        public KbArticlesSearchPage() : base()
        {
            InitializeComponent();
            BindingContext = new SearchViewModel(2);
            this.SearchsListView.ItemSelected += async delegate
            {
                var search = SearchsListView.SelectedItem as Search;
                if (search == null)
                {
                    return;
                }
                var articles = new KbArticles()
                {
                    Author    = search.UserName,
                    Body      = "",
                    Summary   = search.Content,
                    DiggCount = search.VoteTimes,
                    Id        = int.Parse(search.Id),
                    DateAdded = search.PublishTime,
                    Title     = search.Title.Replace("<strong>", "").Replace("</strong>", ""),
                    ViewCount = search.ViewTimes
                };

                var articlesDetails = new KbArticlesDetailsPage(articles);

                await NavigationService.PushAsync(Navigation, articlesDetails);

                this.SearchsListView.SelectedItem = null;
            };
        }
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.KbArticlesService.GetKbArticlesAsync(pageIndex, pageSize);

            if (result.Success)
            {
                var kbArticles = JsonConvert.DeserializeObject <List <KbArticles> >(result.Message.ToString());
                if (kbArticles.Count > 0)
                {
                    if (pageIndex == 1 && KbArticles.Count > 0)
                    {
                        KbArticles.Clear();
                    }
                    KbArticles.AddRange(kbArticles);
                    await SqliteUtil.Current.UpdateKbArticles(kbArticles);

                    pageIndex++;
                    LoadStatus  = LoadMoreStatus.StausDefault;
                    CanLoadMore = true;
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Crashes.TrackError(new Exception()
                {
                    Source = result.Message
                });
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.KbArticlesService.GetKbArticlesAsync(pageIndex);

            if (result.Success)
            {
                var kbArticles = JsonConvert.DeserializeObject <List <KbArticles> >(result.Message.ToString());
                if (kbArticles.Count > 0)
                {
                    if (pageIndex == 1 && KbArticles.Count > 0)
                    {
                        KbArticles.Clear();
                    }
                    KbArticles.AddRange(kbArticles);
                    pageIndex++;
                    LoadStatus  = LoadMoreStatus.StausDefault;
                    CanLoadMore = true;
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Log.SendLog("KbArticlesViewModel.GetKbArticlesAsync:" + result.Message);
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }
Example #5
0
        public KbArticlesDetailsPage(KbArticles kbArticles)
        {
            InitializeComponent();
            Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true);
            this.kbArticles = kbArticles;
            BindingContext  = new KbArticlesDetailsViewModel(kbArticles);

            if (Device.Android == Device.RuntimePlatform)
            {
                var cancel = new ToolbarItem
                {
                    Text    = "分享",
                    Command = new Command(() =>
                    {
                        DependencyService.Get <IShares>().Shares("http://kb.cnblogs.com/page/" + kbArticles.Id + "/", kbArticles.Title);
                    }),
                    Icon = "toolbar_share.png"
                };
                ToolbarItems.Add(cancel);
            }

            formsWebView.OnContentLoaded += delegate(object sender, EventArgs e)
            {
                RefreshKbArticles();
            };
        }
        internal static void Enter(Context context, int id, KbArticles kb)
        {
            string kbStr  = JsonConvert.SerializeObject(kb);
            Intent intent = new Intent(context, typeof(DetailKbArticlesActivity));

            intent.PutExtra("id", id);
            intent.PutExtra("kb", kbStr);
            context.StartActivity(intent);
        }
Example #7
0
 public KbArticlesDetailsViewModel(KbArticles articles)
 {
     this.articles     = articles;
     Title             = "知识库";
     KbArticlesDetails = new KbArticlesDetailsModel()
     {
         DiggDisplay = articles.DiggCount > 0 ? articles.DiggCount.ToString() : "推荐",
         ViewDisplay = articles.ViewCount > 0 ? articles.ViewCount.ToString() : "阅读"
     };
 }
 public KbArticlesDetailsViewModel(KbArticles articles)
 {
     this.articles     = articles;
     Title             = articles.Title;
     NextRefreshTime   = DateTime.Now.AddMinutes(15);
     KbArticlesDetails = new KbArticlesDetailsModel()
     {
         HasContent  = false,
         DiggDisplay = articles.DiggCount > 0 ? articles.DiggCount.ToString() : "推荐",
         ViewDisplay = articles.ViewCount > 0 ? articles.ViewCount.ToString() : "阅读",
         DateDisplay = "发布于 " + articles.DateDisplay
     };
 }
        public KbArticlesDetailsPage(KbArticles kbArticles)
        {
            InitializeComponent();
            Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true);
            this.kbArticles = kbArticles;
            BindingContext  = new KbArticlesDetailsViewModel(kbArticles);

            var bookmarks = new ToolbarItem {
                Text    = "收藏",
                Command = new Command(async() => {
                    if (UserTokenSettings.Current.HasExpiresIn())
                    {
                        MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                    }
                    else
                    {
                        var url = "http://kb.cnblogs.com/page/" + kbArticles.Id + "/";
                        await NavigationService.PushAsync(Navigation, new BookmarksEditPage(new Bookmarks()
                        {
                            Title = kbArticles.Title, LinkUrl = url, FromCNBlogs = true
                        }));
                    }
                }),
                Icon = "icon_bookmarks.png"
            };

            ToolbarItems.Add(bookmarks);

            if (Device.Android == Device.RuntimePlatform)
            {
                var cancel = new ToolbarItem
                {
                    Text    = "分享",
                    Command = new Command(() =>
                    {
                        DependencyService.Get <IShares>().Shares("http://kb.cnblogs.com/page/" + kbArticles.Id + "/", kbArticles.Title);
                    }),
                    Icon = "toolbar_share.png"
                };
                ToolbarItems.Add(cancel);
            }

            formsWebView.OnContentLoaded += delegate(object sender, EventArgs e)
            {
                RefreshKbArticles();
            };
        }
        async void  InitKbArticle()
        {
            string kbStr = Intent.GetStringExtra("kb");

            if (string.IsNullOrEmpty(kbStr))
            {
                kbArticles = await SQLiteUtil.SelectKbArticles(ID);
            }
            else
            {
                kbArticles = JsonConvert.DeserializeObject <KbArticles>(kbStr);
            }
            if (kbArticles != null)
            {
                OnRefresh();
                tv_view.Text = kbArticles.ViewCount.ToString();
                tv_ding.Text = kbArticles.Diggcount.ToString();
                SetToolBarTitle(kbArticles.Title);
            }
        }
Example #11
0
        async void initRecycler()
        {
            adapter = new BaseRecyclerViewAdapter <ZzkDocumentViewModel>(this, searchList, Resource.Layout.item_recyclerview_search, LoadMore);
            _recyclerView.SetAdapter(adapter);
            adapter.ItemClick += (position, tag) =>
            {
                var tempModel = searchList[position];
                tempModel.Title = tempModel.Title.Replace("<strong>", "").Replace("</strong>", "");
                switch (category)
                {
                case "Blog":
                    string  tempstr = tempModel.Uri.Replace("http://www.cnblogs.com/", "");
                    string  blogApp = tempstr.Substring(0, tempstr.IndexOf("/"));
                    Article article = new Article()
                    {
                        Id = int.Parse(tempModel.Id), Avatar = "", BlogApp = blogApp, Title = tempModel.Title, Author = tempModel.UserName, Url = tempModel.Uri, PostDate = tempModel.PublishTime, CommentCount = tempModel.CommentTimes, ViewCount = tempModel.ViewTimes, Diggcount = tempModel.VoteTimes
                    };
                    DetailBlogActivity.Enter(this, int.Parse(tag), article);
                    break;

                case "News":
                    NewsViewModel news = new NewsViewModel()
                    {
                        Id = int.Parse(tempModel.Id), Title = tempModel.Title, ViewCount = tempModel.ViewTimes, CommentCount = tempModel.CommentTimes, DiggCount = tempModel.VoteTimes, DateAdded = tempModel.PublishTime
                    };
                    DetailNewsActivity.Enter(this, int.Parse(tag), news);
                    break;

                case "Question":
                    QuestionActivity.Enter(this, int.Parse(tag), true);
                    break;

                case "Kb":
                    KbArticles kb = new KbArticles()
                    {
                        Id = int.Parse(tempModel.Id), Title = tempModel.Title, ViewCount = tempModel.ViewTimes, DateAdded = tempModel.PublishTime, Author = tempModel.UserName
                    };
                    DetailKbArticlesActivity.Enter(this, int.Parse(tag), kb);
                    break;

                default:
                    break;
                }
            };
            adapter.ItemLongClick += (tag, position) =>
            {
                AlertUtil.ToastShort(this, tag);
            };
            string read    = Resources.GetString(Resource.String.read);
            string comment = Resources.GetString(Resource.String.comment);
            string digg    = Resources.GetString(Resource.String.digg);

            adapter.OnConvertView += (holder, position) =>
            {
                var tempModel = searchList[position];
                if (tempModel.Id == null && !string.IsNullOrEmpty(tempModel.Uri))//问答id返回的是null,自己正则获取
                {
                    Regex regex = new Regex("\\d");
                    tempModel.Id = regex.Match(tempModel.Uri).Value;
                }
                //holder.SetText(Resource.Id.tv_dateAdded, tempModel.PublishTime.ToCommonString());
                holder.SetText(Resource.Id.tv_viewCount, tempModel.ViewTimes + " " + read);
                holder.SetText(Resource.Id.tv_commentCount, tempModel.CommentTimes + " " + comment);
                holder.SetText(Resource.Id.tv_diggCount, tempModel.VoteTimes + " " + digg);
                holder.SetText(Resource.Id.tv_url, tempModel.Uri);
                holder.SetText(Resource.Id.tv_author, tempModel.UserName);

                holder.GetView <LinearLayout>(Resource.Id.ly_item).Tag          = tempModel.Id.ToString();
                (holder.GetView <TextView>(Resource.Id.tv_title)).TextFormatted = Html.FromHtml(tempModel.Title.replaceStrongToFont());
                string tempstr = "<font color='#707070'>" + tempModel.PublishTime.ToString("yyyy年MM月dd日 HH:mm") + "</font>  " + tempModel.Content.replaceStrongToFont();
                (holder.GetView <TextView>(Resource.Id.tv_summary)).TextFormatted = Html.FromHtml(tempstr);
            };
        }
 public async void GetClientKbArticlesAsync()
 {
     KbArticles.AddRange(await SqliteUtil.Current.QueryKbArticles(pageSize));
 }
 public KbArticlesDetailsViewModel(KbArticles articles)
 {
     this.articles = articles;
     Title         = "知识库";
 }