List of usage examples for org.apache.commons.net.nntp NNTPClient listNewNewsgroups
public NewsgroupInfo[] listNewNewsgroups(NewGroupsOrNewsQuery query) throws IOException
From source file:me.lehrner.newsgroupsndy.presenter.tasks.UpdateGroupListAsyncTask.java
@Override protected Boolean doInBackground(Server... servers) { mServerId = servers[0].getId();//from w ww .ja v a 2 s .co m String hostName = servers[0].getServerUrl(); int lastVisitInt = servers[0].getLastVisit(); NewsgroupInfo[] newsgroupInfos; ArrayList<String> groupNames = new ArrayList<>(); try { NNTPClient nntpClient = new NNTPClient(); nntpClient.connect(hostName, 119); Log.d(LOG_TAG, "lastVisitInt: " + lastVisitInt); if (lastVisitInt != 0) { Calendar lastVisit = Calendar.getInstance(); lastVisit.setTimeInMillis(lastVisitInt * 1000L); NewGroupsOrNewsQuery query = new NewGroupsOrNewsQuery(lastVisit, false); newsgroupInfos = nntpClient.listNewNewsgroups(query); Log.d(LOG_TAG, "listNewNewsgroups"); } else { newsgroupInfos = nntpClient.listNewsgroups(); Log.d(LOG_TAG, "listNewsgroups"); } nntpClient.disconnect(); } catch (IOException e) { Log.d(LOG_TAG, "IOException"); GroupPresenter groupPresenter = mGroupPresenterWeakReference.get(); if (groupPresenter != null) { groupPresenter.updateNotSuccessful(); } return false; } if (newsgroupInfos == null) { Log.d(LOG_TAG, "newsgroupInfos is null"); return false; } for (NewsgroupInfo newsgroupInfo : newsgroupInfos) { groupNames.add(newsgroupInfo.getNewsgroup()); } return mGroupRepository.saveGroups(mServerId, groupNames); }