//------------------------------------------------------------------------
void CPlaylistActivityTracker::DataDownloaded( CDownloadableResourcePtr inResource )
{
    //get the task type of the resource by finding it in our vector
    ERequestTaskType taskType = eRTT_MaxCount;
    for( int i = 0; i < eRTT_MaxCount; i++ )
    {
        if( m_downloadableResources[ i ] == inResource )
        {
            taskType = (ERequestTaskType)i;
            break;
        }
    }

    if( taskType == eRTT_RequestActivity )
    {
        bool dataRead = false;
        //parse xml
        int bufferSize = -1;
        char* buffer;
        inResource->GetRawData( &buffer, &bufferSize );

        //debug output data stream to log
        CryLog( "PlaylistActivity: Full processed Data %s", buffer );

        IXmlParser* parser = GetISystem()->GetXmlUtils()->CreateXmlParser();
        XmlNodeRef topNode = parser->ParseBuffer(buffer, bufferSize, false);
        if( topNode && stricmp( topNode->getTag(), "playlists" ) == 0 )
        {
            //Iterate over playlists
            const int numberOfPlaylistElements = topNode->getChildCount();
            int destPlaylistIdx = 0;	//separate index to write to in case there are non-playlist node
            for(int playlistIdx = 0; playlistIdx < numberOfPlaylistElements && destPlaylistIdx < MAX_PLAYLISTS; ++playlistIdx )
            {
                //get and check playlist node
                const XmlNodeRef playlistNode = topNode->getChild( playlistIdx );
                if( playlistNode && stricmp( playlistNode->getTag(), "playlist" ) == 0 )
                {
                    PlaylistActivity& currentPlaylist = m_activityData[ destPlaylistIdx ];

                    //copy name and Id into structure
                    const char* playlistName = NULL;
                    if( playlistNode->getAttr( "name", &playlistName ) )
                    {
                        cry_strcpy( currentPlaylist.name, playlistName );
                    }

                    int id = 0;
                    if( playlistNode->getAttr( "index", id ) )
                    {
                        currentPlaylist.id = id;
                    }

                    //clear totals
                    currentPlaylist.nPlayers = 0;
                    currentPlaylist.nGames = 0;

                    //Iterate over variants
                    const int numberOfVariantElements = playlistNode->getChildCount();
                    currentPlaylist.nVariants = 0; //use count as index to write to in case there are non-variant nodes
                    for(int variantIdx = 0; variantIdx < numberOfVariantElements && currentPlaylist.nVariants < MAX_VARIANTS; ++variantIdx )
                    {
                        //get and check variant node
                        const XmlNodeRef variantNode = playlistNode->getChild( variantIdx );
                        if( variantNode && stricmp( variantNode->getTag(), "variant" ) == 0 )
                        {
                            VariantActivity& currentVariant = currentPlaylist.variants[ currentPlaylist.nVariants ];

                            //copy data into structure
                            const char* variantName = NULL;
                            if( variantNode->getAttr( "name", &variantName ) )
                            {
                                cry_strcpy( currentVariant.name, variantName );
                            }

                            int variantId = 0;
                            if( variantNode->getAttr( "index", variantId ) )
                            {
                                currentVariant.id = variantId;
                            }

                            int count = 0;
                            if( variantNode->getAttr( "players", count ) )
                            {
                                currentVariant.nPlayers = count;
                                //increase total
                                currentPlaylist.nPlayers += count;
                            }

                            if( variantNode->getAttr( "games", count ) )
                            {
                                currentVariant.nGames = count;
                                //increase total
                                currentPlaylist.nGames += count;
                            }

                            currentPlaylist.nVariants++;

                            dataRead = true;
                        }
                    }

                    destPlaylistIdx++;
                }
            }//end loop
            m_nKnownPlaylists = destPlaylistIdx;
        }

        if( m_currentActivityCallback )
        {
            m_currentActivityCallback( dataRead, m_activityData, m_nKnownPlaylists );
        }

    }
    else
    {
        //other requests don't have a payload to deliver to us
    }

    ReleaseResourceReference( inResource );
}