/** Tests retrieval of Wikidata descriptions through enwiki. */ public class GetDescriptionsTaskTests extends ActivityUnitTestCase<TestDummyActivity> { private static final int TASK_COMPLETION_TIMEOUT = 200000; private static final Site SITE = Site.forLanguage("en"); public GetDescriptionsTaskTests() { super(TestDummyActivity.class); } public void testOneTitle() throws Throwable { getWikidataDescriptions(new PageTitle[] {new PageTitle("Test", SITE)}); } public void testThreeTitles() throws Throwable { getWikidataDescriptions( new PageTitle[] { new PageTitle("SAT", SITE), new PageTitle("Miller–Rabin primality test", SITE), new PageTitle("Radiocarbon dating", SITE) }); } void getWikidataDescriptions(final PageTitle[] ids) throws Throwable { final List<PageTitle> idList = new ArrayList<>(Arrays.asList(ids)); final CountDownLatch completionLatch = new CountDownLatch(1); runTestOnUiThread( new Runnable() { @Override public void run() { final WikipediaApp app = (WikipediaApp) getInstrumentation().getTargetContext().getApplicationContext(); new GetDescriptionsTask(app.getAPIForSite(SITE), SITE, idList) { @Override public void onFinish(Map<PageTitle, Void> descriptionsMap) { assertNotNull(descriptionsMap); assertEquals(descriptionsMap.size(), idList.size()); for (PageTitle title : idList) { assertNotNull(title.getDescription()); } completionLatch.countDown(); } }.execute(); } }); assertTrue(completionLatch.await(TASK_COMPLETION_TIMEOUT, TimeUnit.MILLISECONDS)); } }
public void setupToC(final Page page, Site site, boolean firstPage) { tocProgress.setVisibility(View.GONE); tocList.setVisibility(View.VISIBLE); headerView.setText(Html.fromHtml(page.getDisplayTitle())); headerView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { scrollToSection(page.getSections().get(0)); wasClicked = true; funnel.logClick(0, page.getTitle().getDisplayText()); hide(); } }); tocList.setAdapter(new ToCAdapter(page), site.getLanguageCode()); tocList.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Section section = (Section) parent.getAdapter().getItem(position); scrollToSection(section); wasClicked = true; funnel.logClick(position, section.getHeading()); hide(); } }); funnel = new ToCInteractionFunnel( WikipediaApp.getInstance(), site, page.getPageProperties().getPageId(), tocList.getAdapter().getCount()); if (!page.isMainPage() && !firstPage) { if (WikipediaApp.getInstance().getOnboardingStateMachine().isTocTutorialEnabled()) { showTocOnboarding(); } } }