예제 #1
0
        async void LoadList(int p = -1)
        {
            ImageSource getImage(string uri)
            {
                ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

                if (Convert.ToBoolean(localSettings.Values["IsNoPicsMode"]))
                {
                    if (Convert.ToBoolean(localSettings.Values["IsDarkMode"]))
                    {
                        return new BitmapImage(new Uri("ms-appx:/Assets/img_placeholder_night.png"))
                               {
                                   DecodePixelHeight = 150, DecodePixelWidth = 150
                               }
                    }
                    ;
                    else
                    {
                        return new BitmapImage(new Uri("ms-appx:/Assets/img_placeholder.png"))
                               {
                                   DecodePixelHeight = 150, DecodePixelWidth = 150
                               }
                    };
                }
                return(new BitmapImage(new Uri(uri)));
            }

            mainPage.ActiveProgressRing();
            if (p == 1)
            {
                string url = isFollowList ? $"/user/followList?uid={uid}&page={p}" : $"/user/fansList?uid={uid}&page={p}";
                string r   = await CoolApkSDK.GetCoolApkMessage(url);

                JArray array = JObject.Parse(r)["data"] as JArray;
                if (!(array is null) && array.Count > 0)
                {
                    firstItem = array.First["fuid"].ToString();
                    lastItem  = array.Last["fuid"].ToString();
                    if (infos.Count > 0)
                    {
                        var d = (from a in infos
                                 from b in array
                                 where a.Uid == b[isFollowList ? "fuid" : "uid"].ToString()
                                 select a).ToArray();

                        foreach (var item in d)
                        {
                            infos.Remove(item);
                        }
                    }
                    for (int i = 0; i < array.Count; i++)
                    {
                        JToken t = isFollowList ? array[i]["fUserInfo"] : array[i]["userInfo"];
                        infos.Insert(i, new UserInfo
                        {
                            Uid        = t["uid"].ToString(),
                            UserName   = t["username"].ToString(),
                            FansNum    = t["fans"].ToString(),
                            FollowNum  = t["follow"].ToString(),
                            Bio        = t["bio"].ToString(),
                            LoginTime  = Process.ConvertTime(t["logintime"].ToString()) + "活跃",
                            UserAvatar = getImage(t["userSmallAvatar"].ToString())
                        });
                    }
                }
            }
            else if (p == -1)
            {
                string url = isFollowList ? $"/user/followList?uid={uid}&page={++page}&firstItem={firstItem}&lastItem={lastItem}" : $"/user/fansList?uid={uid}&page={++page}&firstItem={firstItem}&lastItem={lastItem}";
                string r   = await CoolApkSDK.GetCoolApkMessage(url);

                JArray array = JObject.Parse(r)["data"] as JArray;
                if (!(array is null) && array.Count > 0)
                {
                    firstItem = array.Last["fuid"].ToString();
                    for (int i = 0; i < array.Count; i++)
                    {
                        JToken t = isFollowList ? array[i]["fUserInfo"] : array[i]["userInfo"];
                        infos.Add(new UserInfo
                        {
                            Uid        = t["uid"].ToString(),
                            UserName   = t["username"].ToString(),
                            FansNum    = t["fans"].ToString(),
                            FollowNum  = t["follow"].ToString(),
                            Bio        = t["bio"].ToString(),
                            LoginTime  = Process.ConvertTime(t["logintime"].ToString()) + "活跃",
                            UserAvatar = getImage(t["userSmallAvatar"].ToString())
                        });
                    }
                }
                else
                {
                    page--;
                }
            }
            mainPage.DeactiveProgressRing();
        }