コード例 #1
0
    private void OnMainPageLoaded(bool success, string text)
    {
        LibraryPageResponce libraryPageResponce = null;

        if (success && !string.IsNullOrEmpty(text))
        {
            try
            {
                libraryPageResponce = JsonUtility.FromJson <LibraryPageResponce>(text);
                FMLogger.vCore("resp: " + text);
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogError("ex: " + ex.Message);
                UnityEngine.Debug.LogError("failed to parse page responce");
                UnityEngine.Debug.LogError(text);
                libraryPageResponce = null;
            }
            if (libraryPageResponce == null || !libraryPageResponce.IsValid())
            {
                libraryPageResponce = null;
                FMLogger.vCore("resp not valid: " + text);
            }
        }
        else
        {
            FMLogger.vCore("lib req fail. 404 or resp empty");
        }
        this.libResponce = libraryPageResponce;
        if (this.mainPageCallback != null)
        {
            this.mainPageCallback(this.libResponce);
        }
        this.mainPageCallback = null;
    }
コード例 #2
0
    private void ParseMainPageContent(LibraryPageResponce responce)
    {
        List <PictureData> localPictures = DatabaseManager.GetLocalPictures();
        List <PictureData> list          = new List <PictureData>();

        for (int i = 0; i < responce.content.Count; i++)
        {
            WebPicData  webPic      = responce.content[i];
            PictureData pictureData = this.ParseWebPic(webPic, responce.paths, localPictures, false);
            if (pictureData != null)
            {
                list.Add(pictureData);
            }
        }
        this.orderedMainPage = list;
        this.featuredSection = new FeaturedInfo();
        if (responce.featured != null)
        {
            this.featuredSection.dailies       = new List <DailyPicInfo>();
            this.featuredSection.promoPics     = new List <PromoPicInfo>();
            this.featuredSection.externalLinks = new List <ExternalLinkInfo>();
            if (responce.featured.daily_items != null)
            {
                for (int j = 0; j < responce.featured.daily_items.Count; j++)
                {
                    FeaturedDailyResp tmp          = responce.featured.daily_items[j];
                    DailyPicInfo      dailyPicInfo = new DailyPicInfo();
                    dailyPicInfo.order    = tmp.order;
                    dailyPicInfo.id       = tmp.id;
                    dailyPicInfo.desc     = (tmp.description ?? string.Empty);
                    dailyPicInfo.day      = (tmp.day ?? string.Empty);
                    dailyPicInfo.month    = (tmp.month ?? string.Empty);
                    dailyPicInfo.btnLabel = (tmp.cta ?? string.Empty);
                    PictureData pictureData2 = this.orderedMainPage.Find((PictureData p) => p.Id == tmp.pic.id);
                    if (pictureData2 != null)
                    {
                        dailyPicInfo.picData = pictureData2;
                    }
                    else
                    {
                        dailyPicInfo.picData = this.ParseWebPic(tmp.pic, responce.paths, localPictures, false);
                    }
                    dailyPicInfo.picData.SetPicClass(PicClass.Daily);
                    this.featuredSection.dailies.Add(dailyPicInfo);
                }
            }
            if (responce.featured.editor_choice != null)
            {
                for (int k = 0; k < responce.featured.editor_choice.Count; k++)
                {
                    FeaturedEditorChoiceResp tmp          = responce.featured.editor_choice[k];
                    PromoPicInfo             promoPicInfo = new PromoPicInfo();
                    promoPicInfo.order    = tmp.order;
                    promoPicInfo.id       = tmp.id;
                    promoPicInfo.desc     = (tmp.description ?? string.Empty);
                    promoPicInfo.title    = (tmp.title ?? string.Empty);
                    promoPicInfo.btnLabel = (tmp.cta ?? string.Empty);
                    PictureData pictureData3 = this.orderedMainPage.Find((PictureData p) => p.Id == tmp.pic.id);
                    if (pictureData3 != null)
                    {
                        promoPicInfo.picData = pictureData3;
                    }
                    else
                    {
                        promoPicInfo.picData = this.ParseWebPic(tmp.pic, responce.paths, localPictures, false);
                    }
                    this.featuredSection.promoPics.Add(promoPicInfo);
                }
            }
            if (responce.featured.external_links != null)
            {
                for (int l = 0; l < responce.featured.external_links.Count; l++)
                {
                    FeaturedExternalLink featuredExternalLink = responce.featured.external_links[l];
                    ExternalLinkInfo     externalLinkInfo     = new ExternalLinkInfo();
                    externalLinkInfo.id           = featuredExternalLink.id;
                    externalLinkInfo.order        = featuredExternalLink.order;
                    externalLinkInfo.desc         = (featuredExternalLink.description ?? string.Empty);
                    externalLinkInfo.title        = (featuredExternalLink.title ?? string.Empty);
                    externalLinkInfo.btnLabel     = (featuredExternalLink.cta ?? string.Empty);
                    externalLinkInfo.targetUrl    = featuredExternalLink.target_url;
                    externalLinkInfo.targetScheme = (featuredExternalLink.target_scheme ?? string.Empty);
                    externalLinkInfo.imageData    = new ImageData(featuredExternalLink.paths, featuredExternalLink.img_url);
                    this.featuredSection.externalLinks.Add(externalLinkInfo);
                }
            }
        }
        this.featuredSection.OrderItems();
        this.newsTabInfo = new NewsInfo();
        if (responce.news != null)
        {
            this.newsTabInfo.promoPics     = new List <PromoPicInfo>();
            this.newsTabInfo.externalLinks = new List <ExternalLinkInfo>();
            if (responce.news.editor_choice != null)
            {
                for (int m = 0; m < responce.news.editor_choice.Count; m++)
                {
                    FeaturedEditorChoiceResp tmp           = responce.news.editor_choice[m];
                    PromoPicInfo             promoPicInfo2 = new PromoPicInfo();
                    promoPicInfo2.id       = tmp.id;
                    promoPicInfo2.order    = tmp.order;
                    promoPicInfo2.desc     = (tmp.description ?? string.Empty);
                    promoPicInfo2.title    = (tmp.title ?? string.Empty);
                    promoPicInfo2.btnLabel = (tmp.cta ?? string.Empty);
                    PictureData pictureData4 = this.orderedMainPage.Find((PictureData p) => p.Id == tmp.pic.id);
                    if (pictureData4 != null)
                    {
                        promoPicInfo2.picData = pictureData4;
                    }
                    else
                    {
                        promoPicInfo2.picData = this.ParseWebPic(tmp.pic, responce.paths, localPictures, false);
                    }
                    this.newsTabInfo.promoPics.Add(promoPicInfo2);
                }
            }
            if (responce.news.external_links != null)
            {
                for (int n = 0; n < responce.news.external_links.Count; n++)
                {
                    FeaturedExternalLink featuredExternalLink2 = responce.news.external_links[n];
                    ExternalLinkInfo     externalLinkInfo2     = new ExternalLinkInfo();
                    externalLinkInfo2.id           = featuredExternalLink2.id;
                    externalLinkInfo2.order        = featuredExternalLink2.order;
                    externalLinkInfo2.desc         = (featuredExternalLink2.description ?? string.Empty);
                    externalLinkInfo2.title        = (featuredExternalLink2.title ?? string.Empty);
                    externalLinkInfo2.btnLabel     = (featuredExternalLink2.cta ?? string.Empty);
                    externalLinkInfo2.targetUrl    = featuredExternalLink2.target_url;
                    externalLinkInfo2.targetScheme = (featuredExternalLink2.target_scheme ?? string.Empty);
                    externalLinkInfo2.imageData    = new ImageData(featuredExternalLink2.paths, featuredExternalLink2.img_url);
                    this.newsTabInfo.externalLinks.Add(externalLinkInfo2);
                }
            }
        }
        this.newsTabInfo.OrderItems();
    }