Ejemplo n.º 1
0
  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();
      }
    }
  }
Ejemplo n.º 2
0
  private void SetupMyStations() {
    SharedPreferences settings = getSharedPreferences(LastFm.PREFS, 0);

    Session session = LastFMApplication.getInstance().session;
    mMyStationsAdapter = new LastFMStreamAdapter(this);
    if (isAuthenticatedUser) {
      mMyStationsAdapter.putStation(
          getString(R.string.profile_mylibrary),
          "lastfm://user/" + Uri.encode(mUsername) + "/personal");
      if (!settings.getBoolean("remove_loved", false) && session.getSubscriber().equals("1"))
        mMyStationsAdapter.putStation(
            getString(R.string.profile_myloved),
            "lastfm://user/" + Uri.encode(mUsername) + "/loved");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_myrecs),
          "lastfm://user/" + Uri.encode(mUsername) + "/recommended");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_mymix), "lastfm://user/" + Uri.encode(mUsername) + "/mix");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_myneighborhood),
          "lastfm://user/" + Uri.encode(mUsername) + "/neighbours");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_myfriends),
          "lastfm://user/" + Uri.encode(mUsername) + "/friends");
    } else {
      mMyStationsAdapter.putStation(
          getString(R.string.profile_userlibrary, mUsername),
          "lastfm://user/" + Uri.encode(mUsername) + "/personal");
      if (!settings.getBoolean("remove_loved", false) && session.getSubscriber().equals("1"))
        mMyStationsAdapter.putStation(
            getString(R.string.profile_userloved, mUsername),
            "lastfm://user/" + Uri.encode(mUsername) + "/loved");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_myrecs),
          "lastfm://user/" + Uri.encode(mUsername) + "/recommended");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_usermix, mUsername),
          "lastfm://user/" + Uri.encode(mUsername) + "/mix");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_userneighborhood, mUsername),
          "lastfm://user/" + Uri.encode(mUsername) + "/neighbours");
      mMyStationsAdapter.putStation(
          getString(R.string.profile_userfriends, mUsername),
          "lastfm://user/" + Uri.encode(mUsername) + "/friends");
    }

    mMyStationsAdapter.updateModel();
  }
Ejemplo n.º 3
0
    @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;
    }