void FriendListScene::fbUserPhotoCallback(const char *userPhotoPath, const char* fbID)
{
    if (_friendDictionary.size() == 0)
    {
        return;
    }
    
    EziFacebookFriend* myFriend = _friendDictionary.at(fbID);
    
    if (myFriend)
    {
        myFriend->saveData(userPhotoPath, "photo");        
        CCLOG("Downloaded photo for = %s", myFriend->getName().c_str());
    }
    else
    {
        CCLOG("Friend with ID = %s not found.", fbID);
    }
    
    _downloadCount++;
    if (_downloadCount == _friendList.size())
    {
        // this is the last we fetched. We can refresh the table view now.
        CCLOG("Download completed...");
        _tableView->reloadData();
    }
    
}
Example #2
0
CCTableViewCell* RequestList::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
    int index = idx;    
    EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(index);
    EziFacebookFriend* sender       = fbRequest->getSender();
    
    const char* senderName = sender->getName();
    
    // Create the fancy test.
    EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType();
    std::string messageToDisplay = "";
    
    switch (requestType)
    {
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE:
            messageToDisplay.append(senderName).append(" has sent invitation to you.");
            break;

        case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT:
            messageToDisplay.append(senderName).append(" has sent gift to you.");
            break;

        case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE:
            messageToDisplay.append(senderName).append(" has challenged to you.");
            break;
            
        default:
            messageToDisplay.append("Unknown message");
            break;
    }
    
    // Means users have already used this request.
    bool requestConsumed = fbRequest->isConsumed();
    
    CCSprite* profilePic            = NULL;
    ccColor4B bgColor = ccc4(20, 0, 40, 255);
    
    if (requestConsumed == false)
    {
        bgColor = ccc4(50, 50, 20, 255);
    }

    
    // Build the table cell.
    CCTableViewCell *cell = table->dequeueCell();
    
    if (cell == NULL)
    {
        cell = new CCTableViewCell();
        cell->autorelease();

                
        // Create the back layer of the cell.
        CCLayerColor* colorLayer = CCLayerColor::create(bgColor, SCREEN_WIDTH, CELL_HEIGHT);
        colorLayer->setTag(BACKGROUND_TAG);
        
        cell->addChild(colorLayer);
        
        // Get the sender profile picture path. Create it if path is available.
        if (sender != NULL && strcmp(sender->getPhotoPath(), "") != 0)
        {
            const char*  picPath = sender->getPhotoPath();
            profilePic = CCSprite::create(picPath);
        }
        else
        {
            profilePic = CCSprite::create(FB_DEFAULT_PHOTO);
        }

        // Add the profile pic to the cell row.
        profilePic->setAnchorPoint(ccp(0, 0.5));
        profilePic->setPosition(ccp(20, CELL_HEIGHT/2));
        cell->addChild(profilePic);
        profilePic->setTag(FRIEND_PHOTO_TAG);
        
        // Set the message.
        CCLabelTTF *messageLabel = CCLabelTTF::create(messageToDisplay.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE);
        messageLabel->setAnchorPoint(ccp(0, 0.5));
        messageLabel->setPosition(ccp(20 + 20 + profilePic->getContentSize().width, CELL_HEIGHT/2));
        messageLabel->setTag(REQUEST_MESSAGE_LABEL_TAG);
        messageLabel->setDimensions(CCSizeMake(SCREEN_WIDTH - (profilePic->getContentSize().width * 2) - 60, CELL_HEIGHT-5));
        messageLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
        cell->addChild(messageLabel);

        CCMenuItemImage* constumeItemButton = NULL;
        constumeItemButton = CCMenuItemImage::create("use.png", "use_pressed.png");
        

        constumeItemButton->setTag(idx);
        constumeItemButton->setTarget(this, menu_selector(RequestList::useItem));
        constumeItemButton->setScale(SCALE_FACTOR * 0.8);
        constumeItemButton->setTag(FRIEND_CONSUME_BUTTON_TAG);
        
        CCMenu* consumeMenu = CCMenu::create(constumeItemButton, NULL);
        consumeMenu->setTag(FRIEND_CONSUME_MENU_TAG);
        consumeMenu->setPosition(ccp(SCREEN_WIDTH - (constumeItemButton->getContentSize().width*SCALE_FACTOR*0.4),
                                       (CELL_HEIGHT - (constumeItemButton->getContentSize().height)*SCALE_FACTOR*0.4)));
        
        
        cell->addChild(consumeMenu);
        
        
    }
    else
    {
        // Refresh the cell data based upon idx.
        
        // 1. Refresh the profile picture.
        CCSprite* cellProfilePic = (CCSprite*)cell->getChildByTag(FRIEND_PHOTO_TAG);
        
        if (strcmp("", sender->getPhotoPath()) != 0 )
        {
            const char*  picPath = sender->getPhotoPath();
            profilePic = CCSprite::create(picPath);
            
        }
        else
        {
            profilePic = CCSprite::create(FB_DEFAULT_PHOTO);
        }
        
        cellProfilePic->setTexture(profilePic->getTexture());
        
        // Update the message Label.
        CCLabelTTF *messageLabel = (CCLabelTTF*)cell->getChildByTag(REQUEST_MESSAGE_LABEL_TAG);
        messageLabel->setString(messageToDisplay.c_str());
        
        CCMenu* consumeMenu = (CCMenu*)cell->getChildByTag(FRIEND_CONSUME_MENU_TAG);
        
        CCArray* children = consumeMenu->getChildren();
        
        if (children)
        {
            CCMenuItemImage* consumenButton = (CCMenuItemImage*)children->objectAtIndex(0);
            
            if (consumenButton)
            {
                consumenButton->setTag(index);
            }
            else
            {
                CCLOG("No Consume Button");
            }
            
        }
        
        CCLayerColor* bgLayer = (CCLayerColor*)cell->getChildByTag(BACKGROUND_TAG);
        bgLayer->setColor(ccc3(bgColor.r, bgColor.g, bgColor.b));
    }
    
    return cell;
    
}
Example #3
0
CCTableViewCell* FriendList::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
    EziFacebookFriend* friendDetails = (EziFacebookFriend*)mFriendList->objectAtIndex(idx);
    std::string friendID            = friendDetails->getFBID();
    std::string friendName          = friendDetails->getName();
    std::string installed           = "";
    std::string score               = "";
    CCSprite* profilePic            = NULL;
    
    // Set the score.
    long mylong = friendDetails->getScore();
    std::stringstream mystream;
    mystream << mylong;
    score = mystream.str();
    
    // Set the install status
    if (friendDetails->isInstalled())
    {
        installed = "Installed";
    }
    else
    {
        installed = "Not Installed";
    }
    
    
    CCTableViewCell *cell = table->dequeueCell();
    
    
    if (!cell) // Creation of Cell.
    {
        cell = new CCTableViewCell();
        cell->autorelease();
        
        CCLayerColor* colorLayer = CCLayerColor::create(ccc4(20, 0, 40, 255), SCREEN_WIDTH, CELL_HEIGHT);
        cell->addChild(colorLayer);
        
        CCSprite *sprite = NULL;
        
        if (strcmp(friendDetails->getPhotoPath(), "") != 0)
        {
            const char*  picPath = friendDetails->getPhotoPath();
            sprite = CCSprite::create(picPath);
        }
        else
        {
            sprite = CCSprite::create(FB_DEFAULT_PHOTO);
        }
        
        if (sprite == NULL)
        {
            CCLOG("Sprite is NULL");
        }
        
        sprite->setAnchorPoint(ccp(0, 0.5));
        sprite->setPosition(ccp(20, CELL_HEIGHT/2));
        cell->addChild(sprite);
        //sprite->setScale(0.9);
        sprite->setTag(FRIEND_PHOTO_TAG);
        
        // Friend Facebook ID
        CCLabelTTF *friendIDLabel = CCLabelTTF::create(friendID.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE);
        
        float gapY =  (CELL_HEIGHT - (friendIDLabel->getContentSize().height * 2)) / 3;
        
        if (sprite)
        {
            friendIDLabel->setPosition(ccp(sprite->getPositionX() + sprite->getContentSize().width + 20, CELL_HEIGHT - gapY));
        }
        
		friendIDLabel->setAnchorPoint(ccp(0, 1));
        friendIDLabel->setTag(FRIEND_ID_LABEL_TAG);
        cell->addChild(friendIDLabel);
        
        // Friend Facebook Name
        CCLabelTTF *friendNameLabel = CCLabelTTF::create(friendName.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE);
        friendNameLabel->setPosition(ccp(friendIDLabel->getPositionX(),
                                         friendIDLabel->getPositionY() - friendIDLabel->getContentSize().height - gapY));
        
		friendNameLabel->setAnchorPoint(ccp(0, 1));
        friendNameLabel->setTag(FRIEND_NAME_LABEL_TAG);
        cell->addChild(friendNameLabel);
        
        
        // High Score
        CCLabelTTF *scoreLabel = CCLabelTTF::create(score.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE);
        scoreLabel->setPosition(ccp(SCREEN_WIDTH - 20, friendIDLabel->getPositionY()));
        
        scoreLabel->setAnchorPoint(ccp(1, 1));
        scoreLabel->setTag(FRIEND_SCORE_LABEL_TAG);
        cell->addChild(scoreLabel);
        
        // Installed String
        CCLabelTTF *installedLabel = CCLabelTTF::create(installed.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE);
        installedLabel->setPosition(ccp(SCREEN_WIDTH - 20, friendNameLabel->getPositionY()));
        
        installedLabel->setAnchorPoint(ccp(1, 1));
        installedLabel->setTag(FRIEND_INSTALLED_LABEL_TAG);
        cell->addChild(installedLabel);
        
    }
    else
    {
        
        // Set the Friend ID
        CCLabelTTF *friendIDLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_ID_LABEL_TAG);
        friendIDLabel->setString(friendID.c_str());
        
        // Set the Friend Name
        CCLabelTTF *friendNameLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_NAME_LABEL_TAG);
        friendNameLabel->setString(friendName.c_str());
        
        
        CCLabelTTF *highScoreLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_SCORE_LABEL_TAG);
        if (highScoreLabel != NULL)
        {
            highScoreLabel->setString(score.c_str());
        }
        
        highScoreLabel->setVisible(mEnableHighScoreDisplay);
        
        
        CCLabelTTF *installedLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_INSTALLED_LABEL_TAG);
        if (installedLabel != NULL)
        {
            installedLabel->setString(installed.c_str());
        }
        installedLabel->setVisible(mEnableInstalledDisplay);
        
        
        CCSprite* cellProfilePic = (CCSprite*)cell->getChildByTag(FRIEND_PHOTO_TAG);
        
        if (strcmp("", friendDetails->getPhotoPath()) != 0 )
        {
            const char*  picPath = friendDetails->getPhotoPath();
            profilePic = CCSprite::create(picPath);
            
        }
        else
        {
            profilePic = CCSprite::create(FB_DEFAULT_PHOTO);
        }
        
        
        cellProfilePic->setTexture(profilePic->getTexture());
    }
    
    
    return cell;
}
TableViewCell* FriendListScene::tableCellAtIndex(TableView *table, ssize_t idx)
{
    int index = idx;
    EziFacebookFriend* myFriend = (EziFacebookFriend*)_friendList.at(index);
    std::string friendName = myFriend->getName();
    //const char* photoPath = myFriend->getPhotoPath().c_str();
    bool toRequestForPhoto = false;
    
    if (myFriend->getPhoto() == nullptr)
    {
        toRequestForPhoto = true;
        //EziSocialObject::sharedObject()->getProfilePicForID(this, myFriend->getFBID(), SCALED_VALUE(85.0f), SCALED_VALUE(85.0f), false);
    }
    
    // Build the table cell.
    TableViewCell *cell = table->cellAtIndex(idx);
    
    if (cell == NULL)
    {
        cell = new TableViewCell();
        cell->autorelease();
        
        LayerColor* colorLayer = LayerColor::create(Color4B(100, 100, 100, 200),
                                                        AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f),
                                                        SCALED_VALUE(124.0f));
        //cell->addChild(colorLayer);
        
        LayerColor* photoLayer = LayerColor::create(Color4B(255, 255, 255, 255),
                                                        SCALED_VALUE(100.0f),
                                                        SCALED_VALUE(100.0f));
        photoLayer->setPosition(SCALED_VALUE(40.0f), SCALED_VALUE(12.0f));
        cell->addChild(photoLayer);
        Sprite* userPhotoSprite = NULL;
        
        if (toRequestForPhoto)
        {
            userPhotoSprite = Sprite::create();
            userPhotoSprite->setContentSize(Size(SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)));
        }
        else
        {
            userPhotoSprite = myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this),
                                                 false,
                                                 SCALED_VALUE(85.0f),
                                                 SCALED_VALUE(85.0f));
            
            if (userPhotoSprite == nullptr) { userPhotoSprite = Sprite::create(); }
        }
        
        cell->addChild(userPhotoSprite);
        userPhotoSprite->setAnchorPoint(Point(0.0f, 0.0));
        userPhotoSprite->cocos2d::CCNode::setPosition(SCALED_VALUE(47.0f), SCALED_VALUE(18.0f));
        userPhotoSprite->setTag(TAG_PHOTO);
        
        auto message = LabelTTF::create(friendName.c_str(), "Arial", SCALED_VALUE(30.0f));
        message->setAnchorPoint(Point(0, 0.5));
        message->setPosition(Point(photoLayer->getContentSize().width + photoLayer->getPositionX() + SCALED_VALUE(20.0f),
                                 colorLayer->getContentSize().height/2));
        cell->addChild(message);
        message->setTag(TAG_MESSAGE);
        
        
        /*
        Sprite* consumedIcon = Sprite::createWithSpriteFrameName("green_tick");
        consumedIcon->setAnchorPoint(Point(1.0, 0.5));
        cell->addChild(consumedIcon);
        consumedIcon->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f),
                                      colorLayer->getContentSize().height/2));
        message->setTag(TAG_CONSUMED_ICON);
        
        MenuItemImage* useButton = MenuItemImage::create();
        useButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_prd"));
        useButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_nrl"));
        useButton->setAnchorPoint(Point(1.0, 0.5));
        useButton->setTarget(this, menu_selector(FriendListScene::useRequest));
        
        Menu* useMenu = Menu::create(useButton, NULL);
        cell->addChild(useMenu);
        useMenu->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f),
                                 colorLayer->getContentSize().height/2));
        
        useButton->setTag(index);
        useMenu->setTag(TAG_USE_MENU);
        */
        
    }
    else
    {
        Sprite* cellProfilePic = (Sprite*)cell->getChildByTag(TAG_PHOTO);
        
        if (toRequestForPhoto == false)
        {
            //cellProfilePic->setTexture(Sprite::create(myFriend->getPhotoPath())->getTexture());
            Sprite* tempSprite = myFriend->getPhoto();
            
            
            if (myFriend->getPhoto() != nullptr)
            {
                cellProfilePic->setTexture(tempSprite->getTexture());
            }
            else
            {
                myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this),
                                   false,
                                   SCALED_VALUE(85.0f),
                                   SCALED_VALUE(85.0f));    
            }
            
            
        }
        
        // Update the message Label.
        auto messageLabel = (LabelTTF*)cell->getChildByTag(TAG_MESSAGE);
        CCLOG("Friend Name = %s", friendName.c_str());
        
        if (messageLabel)
        {
            messageLabel->setString(friendName.c_str());    
        }
        
        
    }
    
    return cell;
}