void UsersPanel::BuildIndexForUser(JsonArray * friends) { /* String letter, prevLetter = L""; int currentGroup = 0; JsonArray * array = new JsonArray(); array->Construct(); for (int i=0; i<friends->GetCount(); i++) { JsonObject *user; JsonParseUtils::GetObject(friends, i, user); String name; JsonParseUtils::GetString(*user, L"first_name", name); name.SubString(0, 1, letter); if (letter != prevLetter) { _fastScrollIndex.Append(letter); _pCurrentModel->AddUserGroup(prevLetter, array); if (prevLetter.GetLength() > 0) { AppLog("Adding %ls to %d item", prevLetter.GetPointer(), currentGroup); _pLetterNav->Add(new String(prevLetter), new Integer(currentGroup)); currentGroup++; } prevLetter = letter; delete array; array = new JsonArray(); array->Construct(); } else { array->Add(user); } }*/ HashMap *letterMap = new HashMap(); letterMap->Construct(); for(int i = 0; i < friends->GetCount(); i++) { JsonObject *user; JsonParseUtils::GetObject(friends, i, user); String name; JsonParseUtils::GetString(*user, L"first_name", name); String letter; name.SubString(0, 1, letter); JsonArray *letterArray; if(!letterMap->ContainsKey(letter)) { letterArray = new JsonArray(); letterArray->Construct(); letterMap->Add(new String(letter), letterArray); } else { letterArray = static_cast<JsonArray*>(letterMap->GetValue(letter)); } letterArray->Add(user); } IList *letterList = letterMap->GetKeysN(); StringComparer comparer; letterList->Sort(comparer); for(int i = 0; i < letterList->GetCount(); i++) { String *letter = static_cast<String *>(letterList->GetAt(i)); _fastScrollIndex.Append(*letter); _pCurrentModel->AddUserGroup(*letter, static_cast<JsonArray *>(letterMap->GetValue(*letter))); _pLetterNav->Add(new String(*letter), new Integer(i)); } delete letterList; delete letterMap; }
void MainForm::OnParsingCompleted(ArrayList &feedData) { AppResource *pAppResource = Application::GetInstance()->GetAppResource(); if (feedData.GetCount() == 0) { // no service this day String emptyText; pAppResource->GetString("IDS_NOSERVICE", emptyText); __pListFood->SetTextOfEmptyList(emptyText); } else { IEnumerator *pEnum = feedData.GetEnumeratorN(); HashMap *pItem = null; int mensaIndex = -1; String *currentMensa = null; String currencySymbol; pAppResource->GetString("IDS_CURRENCY", currencySymbol); String soldOut; pAppResource->GetString("IDS_SOLDOUT", soldOut); // iterate over items (meals) in feed while (pEnum->MoveNext() == E_SUCCESS) { pItem = (HashMap *)pEnum->GetCurrent(); // check if mensa is already in the list (we assume the feed to be ordered) if (!currentMensa || !(static_cast<String *>(pItem->GetValue(*(new String("author")))))->Equals(*currentMensa, false)) { currentMensa = static_cast<String *>(pItem->GetValue(*(new String("author")))); mensaIndex++; // Create a main item of the ExpandableList CustomListItem* pMainItem = new CustomListItem(); pMainItem->Construct(100); pMainItem->SetItemFormat(*__pMainItemFormat); pMainItem->SetElement(TEXT_ID, *(new String(*currentMensa))); // Add the item to the ExpandableList __pListFood->AddItem(*pMainItem, mensaIndex); } String *title = static_cast<String *>(pItem->GetValue(*(new String("title")))); title->Trim(); String priceStudents; String priceStaff; int stringLength = title->GetLength(); // Create a sub item of the ExpandableList CustomListItem *pSubItem = new CustomListItem(); pSubItem->Construct(100); pSubItem->SetItemFormat(*__pSubItemFormat); // get prices if (title->EndsWith(L" EUR)")) { // parse price title->SubString(stringLength - 20, 5, priceStudents); priceStudents.Append(currencySymbol); title->SubString(stringLength - 9, 5, priceStaff); priceStaff.Append(currencySymbol); title->Remove(stringLength - 22, 22); pSubItem->SetElement(PRICESTUDENT_ID, priceStudents); pSubItem->SetElement(PRICESTAFF_ID, priceStaff); } else if (title->EndsWith(L"(ausverkauft)")) { // sold out title->Remove(stringLength - 14, 14); pSubItem->SetElement(REMARK_ID, soldOut); } pSubItem->SetElement(TEXT_ID, *title); // Add sub item to the ExpandableList __pListFood->AddSubItem(mensaIndex, *pSubItem); } // clean up delete pEnum; } __pListFood->RequestRedraw(); __pListFood->ScrollToTop(); StopLoadingAnimation(); }