@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;
    }
Esempio n. 2
0
  public void setUser(User user) {
    mUser = user;

    if (user.getRealName() == null) mFirst.setText(user.getName());
    else mFirst.setText(user.getRealName());

    List<String> seconds = new ArrayList<String>();

    if (user.getAge() != null) seconds.add(user.getAge());
    if (user.getGender() != null) seconds.add(user.getGender());
    if (user.getCountry() != null) seconds.add(user.getCountry());

    String second = "";
    for (String s : seconds) second = s + ", ";

    int playcount = Integer.parseInt(mUser.getPlaycount());
    NumberFormat format = NumberFormat.getNumberInstance();
    String count = format.format(playcount);
    String plays = count + " plays";
    if (mUser.getJoinDate() != null) plays += " since " + mUser.getJoinDate();
    mSecond.setText(second + plays);

    if (mUser.getImages().length > 0) {
      mAvatar.fetch(mUser.getImages()[0].getUrl());
    }
  }