예제 #1
0
void RequestList::downloadNextPhoto()
{
    if (mPhotoLoadIndex > 0)
    {
        mPhotoLoadIndex--;
        int index = mPhotoLoadIndex;
        EziFBIncomingRequest* incomingRequest = NULL;
        EziFacebookFriend *friendObject = NULL;
        
        incomingRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(index);
                
        friendObject = incomingRequest->getSender();
        
        unsigned int size = 200;
        
        if (PHOTO_SCALE <= 0.5 && PHOTO_SCALE > 0.25)
        {
            size = 100;
        }
        else if (PHOTO_SCALE < 0.25)
        {
            size = 50;
        }
        
        EziSocialObject::sharedObject()->getProfilePicForID(friendObject->getFBID(),
                                                            size, size, false);
    }
    else
    {
        this->unscheduleUpdate();
        ALL_DOWNLOAD_COMPLETE = true;
        this->hideLoadingAction();
    }
}
void internalRequestRecieveCallback(int responseCode,
                                    const char* requestID,
                                    const char* message,
                                    const char* senderID,
                                    const char* senderName,
                                    const char* receiverID,
                                    const char* data,
                                    const char* errorMessage)
{
    EziFacebookDelegate* tempFBDelegate;
    tempFBDelegate = EziSocialObject::sharedObject()->getFacebookDelegate();
    
    if (responseCode == EziSocialWrapperNS::RESPONSE_CODE::FB_CHALLENGE_RECEIVE ||
        responseCode == EziSocialWrapperNS::RESPONSE_CODE::FB_GIFT_RECEIVE ||
        responseCode == EziSocialWrapperNS::RESPONSE_CODE::FB_INVITE_RECEIVE)
    {
        // We can mark this request ID as complete in the List.
        //EziFBIncomingRequestManager::sharedManager()->requestComepleted(requestID);
        EziFBIncomingRequest* incomingRequest = EziFBIncomingRequestManager::sharedManager()->getIncomingRequest(requestID);
        
        switch (responseCode)
        {
            case EziSocialWrapperNS::RESPONSE_CODE::FB_CHALLENGE_RECEIVE:
                incomingRequest->setRequestType(EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE);
                break;
                
            case EziSocialWrapperNS::RESPONSE_CODE::FB_INVITE_RECEIVE:
                incomingRequest->setRequestType(EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE);
                break;
                
            case EziSocialWrapperNS::RESPONSE_CODE::FB_GIFT_RECEIVE:
                incomingRequest->setRequestType(EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT);
                break;
                
            default:
                break;
        }
        
        incomingRequest->setMessage(message);
        incomingRequest->setSender(senderID, senderName);
        incomingRequest->setReceiverID(receiverID);
        incomingRequest->setDataDictionary(getCustomizedDictionary(data));
        incomingRequest->setDataFetchedFromFacebook(true);
        incomingRequest->saveToUserDefaults();
        
        EziFBIncomingRequestManager::sharedManager()->processNextRequest();
    }
    
    if (tempFBDelegate)
    {
        tempFBDelegate->fbRecieveRequestCallback(responseCode,
                                                 message,
                                                 senderName,
                                                 getCustomizedDictionary(data));
    }
}
예제 #3
0
void RequestList::fbUserPhotoCallback(const char *userPhotoPath)
{
    int index = mPhotoLoadIndex;
    EziFBIncomingRequest* incomingRequest = NULL;
    EziFacebookFriend *friendObject = NULL;
    
    incomingRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(index);
        
    friendObject = incomingRequest->getSender();
    friendObject->setPhotoPath(userPhotoPath);
    
    mReadyForNextDownload = true;
}
EziFBIncomingRequest* EziFBIncomingRequest::create()
{
    EziFBIncomingRequest* fbRequest = new EziFBIncomingRequest();
    if (fbRequest)
    {
        fbRequest->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(fbRequest);
        return NULL;
    }
    
    return fbRequest;
}
// Useful to when you want to save the EziFBIncomingRequest Object in CCArray or CCDictionary.
CCObject* EziFBIncomingRequest::copyWithZone(CCZone *pZone)
{
    CCZone* pNewZone = NULL;
    EziFBIncomingRequest* pCopy = NULL;
    if(pZone && pZone->m_pCopyObject)
    {
        //in case of being called at sub class
        pCopy = (EziFBIncomingRequest*)(pZone->m_pCopyObject);
    }
    else
    {
        pCopy = new EziFBIncomingRequest();
        pNewZone = new CCZone(pCopy);
    }
    
    pCopy->setReceiverID(getReceiverID());
    pCopy->setSender(getSender());
    pCopy->setRequestID(getRequestID());
    pCopy->setMessage(getMessage());
    pCopy->setConsumed(isConsumed());
    pCopy->setDataDictionary(getDataDictionary());
    
    CC_SAFE_DELETE(pNewZone);
    return pCopy;
}
예제 #6
0
void RequestList::useItem(CCObject* pSender)
{
    if (pSender == NULL)
    {
        return;
    }
    
    CCMenuItemImage* sender = (CCMenuItemImage*)pSender;
    CCLOG("Call for useItem for tag = %d", sender->getTag());
    
    if (sender->getTag() > _fbIncomingRequestList->count())
    {
        return;
    }
    
    std::string messageToDisplay = "";
    
    EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(sender->getTag());
    
    if (fbRequest->isConsumed())
    {
        CCMessageBox("This item is already consumed.", "Consume Item Status");
        return;
    }
    
    
    EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType();
    
    const char* senderName      = fbRequest->getSender()->getName();
    const char* requestTypeChar = "";
    const char* message         = "";
    
    message = fbRequest->getMessage();
    
    CCDictionary* giftDictionary = fbRequest->getDataDictionary();
    
    switch (requestType)
    {
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE:
            requestTypeChar = "Invite";
            break;
            
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT:
            requestTypeChar = "Gift";
            break;
            
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE:
            requestTypeChar = "Challenge";
            break;
            
        default:
            requestTypeChar = "Unknown";
            break;
    }
    
    // Add the request Type
    messageToDisplay.append("Request Type = ").append(requestTypeChar).append("\n");
    
    // Add the sender Name
    messageToDisplay.append("Sender = ").append(senderName).append("\n");
    
    // Add the message.
    messageToDisplay.append("Message = ").append(message).append("\n");
    
    if (giftDictionary && giftDictionary->count()>0)
    {
        CCArray* allKeys = giftDictionary->allKeys();
        if (allKeys && allKeys->count() > 0)
        {
            messageToDisplay.append("Extra/Gift items sent:\n");
            for (int i=0; i<allKeys->count(); i++)
            {
                CCString* key   = (CCString*)allKeys->objectAtIndex(i);
                CCString* value = (CCString*)giftDictionary->objectForKey(key->getCString());
                messageToDisplay.append(key->getCString()).append(": ").append(value->getCString()).append("\n");
            }
        }
        
    }
    else
    {
        messageToDisplay.append("No Extra Items were sent by sender");
    }
    
    CCMessageBox(messageToDisplay.c_str(), "Item Consumed!!! :)))");
    
    EziFBIncomingRequestManager::sharedManager()->consumeItem(fbRequest);
    
    CCScene *pScene = CCScene::create();
	RequestList *pLayer = RequestList::create();
	pScene->addChild(pLayer);
	CCDirector::sharedDirector()->replaceScene(pScene);
    
}
예제 #7
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;
    
}
예제 #8
0
void RequestList::tableCellTouched(CCTableView *table, CCTableViewCell *cell)
{
    CCLOG("cell touched at index: %i", cell->getIdx());
    std::string messageToDisplay = "";
    
    EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(cell->getIdx());
    EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType();

    const char* senderName      = fbRequest->getSender()->getName();
    const char* requestTypeChar = "";
    const char* message         = "";
    
    message = fbRequest->getMessage();
    
    CCDictionary* giftDictionary = fbRequest->getDataDictionary();
    
    switch (requestType)
    {
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE:
            requestTypeChar = "Invite";
            break;
            
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT:
            requestTypeChar = "Gift";
            break;
            
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE:
            requestTypeChar = "Challenge";
            break;
            
        default:
            requestTypeChar = "Unknown";
            break;
    }
    
    // Add the request Type
    messageToDisplay.append("Request Type = ").append(requestTypeChar).append("\n");
    
    // Add the sender Name
    messageToDisplay.append("Sender = ").append(senderName).append("\n");
    
    // Add the message.
    messageToDisplay.append("Message = ").append(message).append("\n");
    
    if (giftDictionary && giftDictionary->count()>0)
    {
        CCArray* allKeys = giftDictionary->allKeys();
        if (allKeys && allKeys->count() > 0)
        {
            messageToDisplay.append("Extra/Gift items sent:\n");
            for (int i=0; i<allKeys->count(); i++)
            {
                CCString* key   = (CCString*)allKeys->objectAtIndex(i);
                CCString* value = (CCString*)giftDictionary->objectForKey(key->getCString());
                messageToDisplay.append(key->getCString()).append(": ").append(value->getCString()).append("\n");
            }
        }
        
    }
    else
    {
        messageToDisplay.append("No Extra Items were sent by sender");
    }
    
    CCMessageBox(messageToDisplay.c_str(), "Request Details");
}
EziFBIncomingRequest* EziFBIncomingRequest::createForRequestID(std::string requestID)
{
    EziFBIncomingRequest* fbRequest = EziFBIncomingRequest::create();
    
    if (fbRequest)
    {
        fbRequest->setRequestID(requestID);
        
        // Build the items from CCUserDefaults
        std::string key = FB_INCOMING_REQUEST_DATA_;
        key.append(requestID);
        
        std::string dataKey = DATA_DICTIONARY_;
        dataKey.append(requestID);
        
        std::string statusKey = REQUEST_CONSUMED_STATUS_;
        statusKey.append(requestID);
        
        std::string requestData = CCUserDefault::sharedUserDefault()->getStringForKey(key.c_str());
        std::string dictionaryString = CCUserDefault::sharedUserDefault()->getStringForKey(dataKey.c_str());
        bool toConsumed = CCUserDefault::sharedUserDefault()->getBoolForKey(statusKey.c_str());
        
        // Mark it as consumed or not.
        fbRequest->setConsumed(toConsumed);
        
        // We need to break Request Data String and Data Dictionary String
        
        std::vector< std::string > requestDataVector    = EziSocialObject::tokenizeStr(requestData.c_str(), ";");
        std::vector< std::string > dataDictionaryVector = EziSocialObject::tokenizeStr(dictionaryString.c_str(), ";");
        
        if (requestData.size()==0)
        {
            // Data is not fetched from the Facebook.
            fbRequest->setDataFetchedFromFacebook(false);
        }
        else
        {
            fbRequest->setDataFetchedFromFacebook(true);
        }
        
        // Save the Request Data
        for (int i=0; i<requestDataVector.size(); i += 2)
        {
            fbRequest->setData(requestDataVector[i], requestDataVector[i+1]);
        }
        
        // Build the Data Dictionary
        if (dataDictionaryVector.size()%2 == 0 && dataDictionaryVector.size() > 0) // It should be of even size.
        {
            CCDictionary *dataDictionary = CCDictionary::create();
            
            for (int j=0; j<dataDictionaryVector.size(); j += 2)
            {
                dataDictionary->setObject(CCString::create(dataDictionaryVector[j+1]), dataDictionaryVector[j]);
            }
            
            fbRequest->setDataDictionary(dataDictionary);
        }
    }
    
    return fbRequest;
}