Example #1
0
        public async Task <List <RecommendItemModel> > GetRecommend()
        {
            try
            {
                var result = await recommendAPI.Recommend(last_idx).Request();

                if (result.status)
                {
                    var obj = await result.GetData <JObject>();

                    if (obj.code == 0)
                    {
                        var items = JsonConvert.DeserializeObject <List <RecommendItemModel> >(obj.data["items"].ToString());

                        for (int i = items.Count - 1; i >= 0; i--)
                        {
                            if (items[i].card_goto.Contains("ad_web") || items[i].card_goto.Contains("banner"))
                            {
                                items.Remove(items[i]);
                            }
                        }
                        last_idx = items.LastOrDefault()?.idx ?? "0";
                        return(items);
                    }
                    else
                    {
                        Utils.ShowMessageToast(obj.message);
                        return(new List <RecommendItemModel>());
                    }
                }
                else
                {
                    Utils.ShowMessageToast(result.message);
                    return(new List <RecommendItemModel>());
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("加载首页推荐信息失败", LogType.ERROR, ex);
                Utils.ShowMessageToast("加载首页推荐信息失败");
                return(new List <RecommendItemModel>());
            }
        }
Example #2
0
        public async Task GetRecommend(string idx = "0")
        {
            try
            {
                Loading = true;
                var result = await recommendAPI.Recommend(idx).Request();

                if (result.status)
                {
                    var obj = result.GetJObject();
                    if (obj["code"].ToInt32() == 0)
                    {
                        var items  = JsonConvert.DeserializeObject <ObservableCollection <RecommendItemModel> >(obj["data"]["items"].ToString());
                        var banner = items.FirstOrDefault(x => x.card_goto == "banner");
                        if (banner != null)
                        {
                            if (Banner == null || Banner.Count == 0)
                            {
                                Banner = banner.banner_item;
                            }
                            items.Remove(banner);
                        }
                        for (int i = items.Count - 1; i >= 0; i--)
                        {
                            if (items[i].card_goto.Contains("ad_web"))
                            {
                                items.Remove(items[i]);
                                continue;
                            }

                            var item = items[i];
                            if (item.three_point_v2 != null && item.three_point_v2.Count > 0 && item.card_goto == "av")
                            {
                                item.three_point_v2.Insert(1, new RecommendThreePointV2ItemModel()
                                {
                                    idx   = item.idx,
                                    url   = $"https://b23.tv/av{item.param}",
                                    title = "使用浏览器打开",
                                    type  = "browser"
                                });
                            }
                        }

                        if (Items == null)
                        {
                            Items = items;
                            //await GetRecommend(items.LastOrDefault().idx);
                        }
                        else
                        {
                            foreach (var item in items)
                            {
                                Items.Add(item);
                            }
                        }
                    }
                    else
                    {
                        Utils.ShowMessageToast(obj["message"].ToString());
                    }
                }
                else
                {
                    Utils.ShowMessageToast(result.message);
                }
            }
            catch (Exception ex)
            {
                var handel = HandelError <AnimeHomeModel>(ex);
                Utils.ShowMessageToast(handel.message);
            }
            finally
            {
                Loading = false;
            }
        }