@Override protected List<Photoset> doInBackground(Void... arg0) { OAuth oAuth = authentication.getOAuth(); if (oAuth == null) return null; FlickrHelper.setOAuth(oAuth); List<Photoset> result = new ArrayList<Photoset>(); PhotosetsInterface intf = FlickrHelper.getFlickr().getPhotosetsInterface(); try { Collection<Photoset> photosets; int page = 1; final int perPage = 10; do { try { photosets = intf.getList(oAuth.getUser().getId(), perPage, page).getPhotosets(); } catch (FlickrException e) { if (e.getErrorCode().compareTo("1") == 0) // empty page break; throw e; } for (Photoset p : photosets) result.add(p); page += 1; } while (photosets.size() >= perPage); return result; } catch (IOException e) { Log.w(TAG, e); error = e; return null; } catch (FlickrException e) { Log.w(TAG, e); error = e; return null; } catch (JSONException e) { Log.w(TAG, e); error = e; return null; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user); authentication = Authentication.getInstance(getApplicationContext(), FlickrHelper.getFlickr()); button = (Button) findViewById(R.id.button_login); textView = (TextView) findViewById(R.id.text_login); ((Button) findViewById(R.id.button_templates)) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getApplicationContext(), TemplateActivity.class)); } }); ((Button) findViewById(R.id.button_get_photosets)) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { new GetPhotosetsTask().execute(); } }); photosetsAdapter = new Adapter(); ListView listView = (ListView) findViewById(R.id.listview_photosets); listView.setAdapter(photosetsAdapter); listView.setClickable(true); listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { showPhotoset(photosets.get(position)); } }); updateState(); }