private void fetchRecentStations() { LastFmServer server = AndroidLastFmServerFactory.getServer(); Session session = LastFMApplication.getInstance().session; // Is it worth it? if (session != null) { try { // Let me work it Station stations[] = server.getUserRecentStations(session.getName(), session.getKey()); if (stations != null && stations.length > 0) { // I put my thing down, flip it, and reverse it List<Station> list = Arrays.asList(stations); Collections.reverse(list); stations = (Station[]) list.toArray(); RecentStationsDao.getInstance().clearTable(); for (Station station : stations) { RecentStationsDao.getInstance() .appendRecentStation(station.getUrl(), station.getName()); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
@Override public Boolean doInBackground(Void... params) { boolean success = false; Session session = LastFMApplication.getInstance().session; // Check our subscriber status LastFmServer server = AndroidLastFmServerFactory.getServer(); try { fetchRecentStations(); User user = server.getUserInfo(null, session.getKey()); if (user != null) { String subscriber = user.getSubscriber(); SharedPreferences settings = getSharedPreferences(LastFm.PREFS, 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("lastfm_subscriber", subscriber); editor.commit(); session = new Session(session.getName(), session.getKey(), subscriber); LastFMApplication.getInstance().session = session; } } catch (WSError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { if (mUsername == null) { mUser = mServer.getUserInfo(null, session.getKey()); } else { mUser = mServer.getUserInfo(mUsername, null); tasteometer = mServer.tasteometerCompare(mUsername, session.getName(), 8); } success = true; } catch (Exception e) { e.printStackTrace(); } return success; }