private void showMenu() {
   String input = "";
   do {
     Iterator<Artist> iter = currentArtists.iterator();
     // display all current results with an associated index number
     for (int j = 1; j <= currentArtists.size(); j++) {
       Artist a = iter.next();
       System.out.println("[" + j + "] " + a.getName());
     }
     System.out.println("-");
     System.out.println("[L] List traveled artists");
     System.out.println("[q] Quit program");
     // prompt
     System.out.println(separator);
     System.out.println("Which artist do you want to check out?");
     System.out.print("Enter his/her index number or enter 'q' to exit: ");
     System.out.flush();
     ArtistNode anode = null;
     try {
       input = in.readLine();
       int neuerIndex = Integer.parseInt(input);
       // if the index exceeds the array's bounds, prompt again
       if (neuerIndex > currentArtists.size() || neuerIndex < 1)
         System.out.println("There is no such index! Please re-try your request, would you?");
       else {
         // fetch the selected artist - it will become the new center
         Artist a = (Artist) ((ArrayList<Artist>) currentArtists).get(neuerIndex - 1);
         anode = ui.retrieveArtistInformation(a.getName());
         displayArtistInformation(anode);
         currentArtists = ui.findArtistsByName(a.getName());
         System.out.println(separator);
       }
     } catch (UnknownHostException e) {
       System.out.println(
           "You don't seem to have established a working internet "
               + "connection going on right now. Please fix that and try again.");
       System.exit(1);
     } catch (IOException e) {
       e.printStackTrace();
     } catch (NumberFormatException e) {
       if (input.equals("L")) {
         listTraveledArtists();
         System.out.println(separator);
       } else if (input.equals("q")) break;
       else
         System.out.println(
             "I believe you screwed up the index input (your input: "
                 + input
                 + ")"
                 + "\n Would you mind doing it again, please?");
     } catch (NoSuchEntryException e) {
       System.out.println("There was an entry retrieval error! The code is " + e.getMessage());
     }
   } while (!input.equals("q"));
 }
Пример #2
0
 @DebugLog
 public Metadata lookupArtistInfo(final String artistName) {
   Call<Artist> call = mLastFM.getArtist(artistName);
   Response<Artist> response;
   try {
     response = call.execute();
   } catch (IOException e) {
     return null;
   }
   Artist artist = response.body();
   if (artist == null) {
     Timber.w("Failed to retrieve artist %s", artistName);
     return null;
   }
   Metadata.Builder bob = Metadata.builder();
   bob.putString(KEY_ARTIST_NAME, artist.getName());
   bob.putString(KEY_ARTIST_SUMMARY, artist.getWikiSummary());
   bob.putString(KEY_ARTIST_BIO, artist.getWikiText());
   Date lastChanged = artist.getWikiLastChanged();
   if (lastChanged != null) {
     bob.putLong(KEY_LAST_MODIFIED, lastChanged.getTime());
   }
   bob.putUri(KEY_ARTIST_URL_URI, Uri.parse(artist.getUrl()));
   bob.putString(KEY_ARTIST_MBID, artist.getMbid());
   return bob.build();
 }
Пример #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_artist_events);

    Artist artist = ActiveData.artist;

    if (MainActivity.wifi.isWifiEnabled()) new GetEventsTask().execute(artist.getName());
    else Toast.makeText(getApplicationContext(), R.string.wifi_off, Toast.LENGTH_LONG).show();
  }
Пример #4
0
 @Override
 public void onResume() {
   super.onResume();
   Artist artist = ActiveData.artist;
   new GetEventsTask().execute(artist.getName());
 }