Ejemplo n.º 1
0
void VKSettingsPanel::OnResponseN(RequestId requestId, Tizen::Web::Json::JsonObject *object) {
	if (requestId == REQUEST_GET_MYSELF) {
		JsonArray* resp;

		JsonParseUtils::GetArray(object, L"response", resp);

		WebImageView *pWebImage;

		JsonObject* item;

		IJsonValue *itemValue;
		resp->GetAt(0, itemValue);
		item = static_cast<JsonObject *>(itemValue);

		String firstName, lastName, photoMax;

		JsonParseUtils::GetString(*item, L"first_name", firstName);
		JsonParseUtils::GetString(*item, L"last_name", lastName);
		JsonParseUtils::GetString(*item, L"photo_max", photoMax);

		AppLog("Avatar URL %ls", photoMax.GetPointer());

		pWebImage = new WebImageView();
		pWebImage->Construct(Tizen::Graphics::Rectangle(0, 0, 200, 200), photoMax);

		pAvatarPanel->AddControl(pWebImage);
		pAvatarPanel->RequestRedraw(true);

		pLabelName->SetText(firstName + L" " + lastName);
	}
}
void VKUMessagesListItemProvider::OnResponseN(RequestId requestId, JsonObject *object) {
	result r = E_SUCCESS;
	String cacheFile(VKUApp::GetInstance()->GetCacheDir() + "dialog" + Integer::ToString(_peerId) + ".json");
	JsonObject *response;
	JsonArray *items;

	AppLog("processing messages json");

	r = JsonParseUtils::GetObject(object, L"response", response);
	TryCatch(r == E_SUCCESS, , "failed get response from object");

	r = JsonParseUtils::GetArray(response, L"items", items);
	TryCatch(r == E_SUCCESS, , "failed get items from response");


	if(requestId == REQUEST_GET_NEW_MESSAGE) {

		if(_messagesJson == null) {
			AppLog("Assigned %d items", items->GetCount());
			_messagesJson = items->CloneN();
		} else {
			AppLog("added %d items", items->GetCount());
			for(int i = 0; i < items->GetCount(); i++) {
				IJsonValue *value;
				items->GetAt(i, value);
				_messagesJson->InsertAt(static_cast<JsonObject *>(value)->CloneN(), 0);
			}
		}

		_tableView->UpdateTableView();
		TryCatch(GetLastResult() == E_SUCCESS, r = GetLastResult() , "Failed pTableView->UpdateTableView");

		_tableView->RequestRedraw(true);
		TryCatch(GetLastResult() == E_SUCCESS, r = GetLastResult() , "Failed pTableView->RequestRedraw");

		r = _tableView->ScrollToItem(_tableView->GetItemCount() - 1);
		TryCatch(r == E_SUCCESS, , "Failed pTableView->ScrollToItem");

		JsonWriter::Compose(_messagesJson, cacheFile);
	} else if(requestId == REQUEST_UPDATE_HISTORY) {
ArrayList * VKUMessagesListItemProvider::GetMessageElementsN(const JsonObject *pMessageJson, int itemWidth) {
	AppLog("enter VKUMessagesListItemProvider::GetMessageElementsN");
	result r;

	// general
	ArrayList* pResultArray;

	// body stuff
	String messageText;
	MessageTextElement *pMessageTextElement;

	// attachs stuff
	IJsonValue *attachs;
	JsonArray * pAttachArray;
	int out;
	int emoji = 0;

	pResultArray = new ArrayList(SingleObjectDeleter);
	r = pResultArray->Construct(1);
	TryCatch(r == E_SUCCESS, , "pResultArray->Construct");
	JsonParseUtils::GetInteger(*pMessageJson, L"out", out);

	JsonObject * geoObject;
	r = JsonParseUtils::GetObject(pMessageJson, L"geo", geoObject);

	if (r == E_SUCCESS) {
		AppLog("Message has geo entry, receiving");
		MessageLocationElement * pLocationElement = new MessageLocationElement();
		pLocationElement->Construct(Rectangle(0, 0, 400, 400), geoObject);

		pResultArray->Add(pLocationElement);
	}

	r = JsonParseUtils::GetString(*pMessageJson, L"body", messageText);
	TryCatch(r == E_SUCCESS, , "JsonParseUtils::GetString body");

	JsonParseUtils::GetInteger(*pMessageJson, L"emoji", emoji);

	if (messageText.GetLength() != 0) {
		AppLog("Message has text entry, receiving");
		pMessageTextElement = new MessageTextElement();
		pMessageTextElement->Construct(Rectangle(0, 0, itemWidth-200, 10000));
		pMessageTextElement->SetText(messageText, emoji);

		pResultArray->Add(pMessageTextElement);
	}


	static const String attachConst(L"attachments");
	r = pMessageJson->GetValue(&attachConst, attachs);

	if (r == E_SUCCESS)
		pAttachArray = static_cast<JsonArray *>(attachs);

	for (int i=0; r == E_SUCCESS && i<pAttachArray->GetCount(); i++) {
		AppLog("Message has %d attachments, receiving %d", pAttachArray->GetCount(), i);

		IJsonValue *pAttachValue;
		JsonObject *pAttachObject;
		String attachType;

		MessageElement *pMessageElement;

		pAttachArray->GetAt(i, pAttachValue);

		pAttachObject = static_cast<JsonObject *>(pAttachValue);

		JsonParseUtils::GetString(*pAttachObject, L"type", attachType);

		if (attachType == L"photo") {
			AppLog("Message has photo, receiving");
			String imageUrl;

			IJsonValue *pPhotoValue;
			JsonObject *pPhotoObject;

			Rectangle thumbSize;

			int width = 0, height = 0;

			static const String photoConst(L"photo");

			pAttachObject->GetValue(&photoConst, pPhotoValue);
			pPhotoObject = static_cast<JsonObject *>(pPhotoValue);

			JsonParseUtils::GetString(*pPhotoObject, L"photo_604", imageUrl);
			JsonParseUtils::GetInteger(*pPhotoObject, L"width", width);
			JsonParseUtils::GetInteger(*pPhotoObject, L"height", height);

			if (width != 0 && height != 0) {
				thumbSize = ImageUtils::ScaleTo(320, Rectangle(0, 0, width, height));
			} else {
				thumbSize = Rectangle(0, 0, 320, 240);
			}

			MessagePhotoElement * pPhotoElement = new MessagePhotoElement();
			pPhotoElement->Construct(thumbSize, imageUrl);

			pMessageElement = static_cast<MessageElement *>(pPhotoElement);;

		} else if (attachType == L"video") {
			AppLog("Message has video, receiving");

//			IJsonValue *pVideoValue;
//			JsonObject *pVideoObject;
//
//			static const String videoConst(L"video");
//
//			pAttachObject->GetValue(&videoConst, pVideoValue);
//			pVideoObject = static_cast<JsonObject *>(pVideoValue);

			JsonObject *pVideoObject;
			JsonParseUtils::GetObject(pAttachObject, L"video", pVideoObject);

			MessageVideoElement *pVideoElement = new MessageVideoElement();
			pVideoElement->Construct(Rectangle(0, 0, 320, 240), pVideoObject);

			pMessageElement = static_cast<MessageElement *>(pVideoElement);

		} else if (attachType == L"audio") {
			AppLog("Message has audio, receiving");

			JsonObject *pAudioObject;
			JsonParseUtils::GetObject(pAttachObject, L"audio", pAudioObject);

			MessageAudioElement *pMessageAudioEleemnt = new MessageAudioElement();
			pMessageAudioEleemnt->Construct(Rectangle(0, 0, 520, 240), pAudioObject, out);

			pMessageElement = dynamic_cast<MessageElement *>(pMessageAudioEleemnt);

		} else if (attachType == L"doc") {
			AppLog("Message has doc, receiving");

			JsonObject *pDocObject;
			JsonParseUtils::GetObject(pAttachObject, L"doc", pDocObject);

			MessageDocElement * pDocElement = new MessageDocElement();
			pDocElement->Construct(Rectangle(0, 0, 520, 90), pDocObject, out);

			pMessageElement = static_cast<MessageElement * >(pDocElement);
		} else if (attachType == L"wall") {
			AppLog("Message has wall, receiving");

			JsonObject *pWallObject;
			JsonParseUtils::GetObject(pAttachObject, L"wall", pWallObject);

			MessageWallElement * pWallElement = new MessageWallElement();
			pWallElement->Construct(Rectangle(0, 0, 320, 240), pWallObject, out);

			pMessageElement = dynamic_cast<MessageElement *>(pWallElement);
		}

		pResultArray->Add(pMessageElement);
	}

	JsonArray *forwardedMessages;
	r = JsonParseUtils::GetArray(pMessageJson, L"fwd_messages", forwardedMessages);
	AppLog("Message has forwardedMessages?");
	for (int i=0; r == E_SUCCESS && i<forwardedMessages->GetCount(); i++) {
		AppLog("Message has forwardedMessages, receiving %d", i);

		JsonObject *fwdMessage;

		JsonParseUtils::GetObject(forwardedMessages, i, fwdMessage);

		MessageForwardedElement *pForwardedElement = new MessageForwardedElement();
		pForwardedElement->Construct(Rectangle(0, 0, 500, 40000), fwdMessage, out);

		MessageElement *pMessageElement;
		pMessageElement = static_cast<MessageForwardedElement *>(pForwardedElement);

		pResultArray->Add(pMessageElement);
	}

	AppLog("Message has done");

	return pResultArray;

CATCH:
	AppLogException("VKUMessagesListItemProvider::GetMessageElementsN is failed. %s", GetErrorMessage(r));
	return pResultArray;
}