Пример #1
0
  /**
   * Determine if the item given is already in cart. An item is in the cart if there appears to have
   * an item with the same name or item is a song and the album which the song belongs to is already
   * in the card, or the album about to be added already have a song added in the cart.
   *
   * @param item The item to be added to the cart.
   * @param cart The user's cart.
   * @return True if the item is already in the cart. False otherwise.
   */
  public LinkedList<Stock> itemIsInCart(String item, LinkedList<Stock> cart) {
    if (cart.size() == 0) {
      System.out.println("Cart is empty");
      return null;
    }
    LinkedList<Stock> duplicated = new LinkedList<Stock>();

    for (Stock s : cart) {
      // If the same song is found in cart.
      if (item.equalsIgnoreCase(s.getTitle())) duplicated.add(s);

      // Find in cart to see if the songs in this album
      // is already added.
      else if (s.getType() == StockType.ALBUM) {
        Album album = (Album) s;
        for (Song song : album.getSongs()) {
          if (song.getTitle().equalsIgnoreCase(item)) duplicated.add(s);
        }
      } else if (s.getType() == StockType.SONG) {
        Song song = (Song) s;
        if (getSongAlbum(song).getTitle().equalsIgnoreCase(item)) {
          System.out.println(item);
          duplicated.add(s);
        }
      }
    }
    return duplicated;
  }
Пример #2
0
  public void download(final Context context) {

    String album = "*";
    String title = "*";
    String artist = "*";
    if (this instanceof Song) {
      Song song = (Song) this;
      title = song.getName();
      album = song.getAlbum().getName();
      artist = song.getArtist().getName();
    } else if (this instanceof Album) {
      Album a = (Album) this;
      if (a.getArtist().getName().trim().equals("") == false) {
        artist = a.getArtist().getName();
      }
      album = a.getName();
    } else if (this instanceof Artist) {
      Artist a = (Artist) this;
      artist = a.getName();
    }
    SyncTask task = new SyncTask(context, true);
    task.execute(
        "download",
        new BasicNameValuePair("name", title),
        new BasicNameValuePair("album", album),
        new BasicNameValuePair("artist", artist));
  }
  private void writeCueFiles() {
    if (rippedDiscs.isEmpty() != true) {
      for (Album album : rippedDiscs) {
        parentWindow.setStatus("Writing cue sheet for: " + album.getDirectoryOnDisc().toString());

        try {
          sleep(1);
        } catch (InterruptedException ie) {
        }

        CueWriter cw = new CueWriter(album, options);
        if (options.isUseCustomOutputDirectory()) {
          cw.writeCue(options.getOutputFolder().getPath());
        } else {
          cw.writeCue();
        }
      }
    } else {
      parentWindow.setStatus("No music files found.");
      try {
        sleep(2000);
      } catch (InterruptedException ie) {
      }
    }
  }
  @Test
  public void testModifyAlbumRemovePhoto() throws Exception {
    // Setup
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
    photo.setUploadTime(new Date());
    createdAlbum.addToPhotos(photo);
    createdAlbum = repository.modify(createdAlbum);
    em.flush();

    // Execute
    createdAlbum.removeFromPhotos(photo);
    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    assertEquals(modifiedAlbum, actualAlbum);
    assertFalse(actualAlbum.getPhotos().contains(photo));
    assertNull(actualAlbum.getCoverPhoto());
  }
Пример #5
0
  private String jsonArtistes(Map<String, Artiste> artistes) {
    Map<String, Artiste> artistesTrie = new TreeMap<String, Artiste>(artistes);
    JSONObject jsonResultat = new JSONObject();
    JSONArray jsonArtistes = new JSONArray();
    for (String nome : artistesTrie.keySet()) {
      Artiste artiste = artistesTrie.get(nome);
      JSONObject jsonArtiste = new JSONObject();
      jsonArtiste.put("nom", nome);
      JSONArray jsonAlbums = new JSONArray();
      for (Integer annee : artiste.getAlbums().keySet()) {
        Album album = artiste.getAlbums().get(annee);
        JSONObject newAlbum = new JSONObject();
        newAlbum.put("id", album.getId());
        newAlbum.put("titre", album.getTitre());
        newAlbum.put("annee", album.getAnnee());
        newAlbum.put("qte", album.getQuantite());
        jsonAlbums.add(newAlbum);
      }
      jsonArtiste.accumulate("albums", jsonAlbums);
      jsonArtistes.add(jsonArtiste);
    }
    jsonResultat.accumulate("artistes", jsonArtistes);

    return jsonResultat.toString(2);
  }
Пример #6
0
  /**
   * Return sorted top albums based on the average of each album rating.
   *
   * @param bHideUnmounted if true, unmounted albums are not chosen
   * @param iNbBestofAlbums nb of items to return
   * @return top albums, can be less items than required according to nb of available albums
   */
  public List<Album> getBestOfAlbums(boolean bHideUnmounted, int iNbBestofAlbums) {
    // TODO: this code does not look at "bHideUnmounted" at all, so most of this
    // method and
    // the double copying is not necessary, or?

    // create a temporary table to remove unmounted albums
    // We consider an album as mounted if a least one track is mounted
    // This hashmap contains album-> album rates
    final Map<Album, Float> cacheRate =
        new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
    ReadOnlyIterator<Album> it = AlbumManager.getInstance().getAlbumsIterator();
    while (it.hasNext()) {
      Album album = it.next();
      cacheRate.put(album, (float) album.getRate());
    }
    // Now sort albums by rating
    List<Album> sortedAlbums = new ArrayList<Album>(cacheRate.keySet());
    Collections.sort(
        sortedAlbums,
        new Comparator<Album>() {
          public int compare(Album o1, Album o2) {
            // lowest first
            return (int) (cacheRate.get(o1) - cacheRate.get(o2));
          }
        });
    return getTopAlbums(sortedAlbums, iNbBestofAlbums);
  }
Пример #7
0
 /**
  * Get sorted list of albums associated with this item.
  *
  * @param item DOCUMENT_ME
  * @return a list of item, void list if no result
  */
 public synchronized List<Album> getAssociatedAlbums(Item item) {
   List<Album> out;
   // [Perf] If item is a track, just return its album
   if (item instanceof Track) {
     out = new ArrayList<Album>(1);
     out.add(((Track) item).getAlbum());
   } else {
     ReadOnlyIterator<Album> albums = getAlbumsIterator();
     // Use a set to avoid dups
     Set<Album> albumSet = new HashSet<Album>();
     while (albums.hasNext()) {
       Album album = albums.next();
       for (Track track : album.getTracksCache()) {
         if (item instanceof Artist && track.getArtist().equals(item)) {
           albumSet.add(album);
         } else if (item instanceof Genre && track.getGenre().equals(item)) {
           albumSet.add(album);
         }
         if (item instanceof Year && track.getYear().equals(item)) {
           albumSet.add(album);
         }
       }
     }
     out = new ArrayList<Album>(albumSet);
     Collections.sort(out);
   }
   return out;
 }
Пример #8
0
  /**
   * Change the item.
   *
   * @param old DOCUMENT_ME
   * @param sNewName DOCUMENT_ME
   * @return new album
   * @throws JajukException the jajuk exception
   */
  public Album changeAlbumName(Album old, String sNewName) throws JajukException {
    // check there is actually a change
    if (old.getName2().equals(sNewName)) {
      return old;
    }

    // check up front as later the state of the track is already changed
    boolean bQueueUpdateRequired = false;
    if (QueueModel.getPlayingFile() != null
        && QueueModel.getPlayingFile().getTrack().getAlbum().equals(old)) {
      bQueueUpdateRequired = true;
    }

    Album newItem = registerAlbum(sNewName, old.getDiscID());
    // re apply old properties from old item
    newItem.cloneProperties(old);

    // update tracks
    for (Track track : TrackManager.getInstance().getTracks()) {
      if (track.getAlbum().equals(old)) {
        TrackManager.getInstance().changeTrackAlbum(track, sNewName, null);
      }
    }

    // if current track album name is changed, notify it
    if (bQueueUpdateRequired) {
      ObservationManager.notify(new JajukEvent(JajukEvents.ALBUM_CHANGED));
    }

    // remove old item
    removeItem(old);

    return newItem;
  }
Пример #9
0
 /**
  * Find the album in which the song belongs to.
  *
  * @param song The song.
  * @return Return the album which the song belongs to. Or return null if no album is found.
  */
 public Album getSongAlbum(Song song) {
   for (Album album : musicDb) {
     if (album.getAlbumID().equalsIgnoreCase(song.getAlbumID())) {
       return album;
     }
   }
   return null;
 }
Пример #10
0
 /**
  * Given the title of the item, get the Stock object of the item.
  *
  * @param item The title of the item.
  * @return The Stock object of the item.
  */
 public Stock getItem(String item) {
   for (Album a : musicDb) {
     if (a.getTitle().equalsIgnoreCase(item)) return a;
     for (Song s : a.getSongs()) {
       if (s.getTitle().equalsIgnoreCase(item)) return s;
     }
   }
   return null;
 }
Пример #11
0
 /**
  * @param name
  * @return associated album (case insensitive) or null if no match
  */
 public Album getAlbumByName(String name) {
   Album out = null;
   for (Album album : getAlbums()) {
     if (album.getName().trim().toLowerCase().matches(name.trim().toLowerCase())) {
       out = album;
       break;
     }
   }
   return out;
 }
Пример #12
0
 /**
  * Check if a given song belongs to the given album.
  *
  * @param song The name of the song.
  * @param album The title of the album.
  * @return True if the song belongs to the album. False otherwise.
  */
 public boolean songBelongsToAlbum(String song, String album) {
   for (Album a : musicDb) {
     if (a.getTitle().equalsIgnoreCase(album)) {
       for (Song s : a.getSongs()) {
         if (s.getTitle().equalsIgnoreCase(song)) return true;
       }
     }
   }
   return false;
 }
Пример #13
0
 private Album getAlbumByTitle(String title, Artist artist) {
   Album album = (Album) albumCache.get(title);
   if (album == null) {
     album = new Album(getNextId());
     album.setTitle(title);
     albumCache.put(title, album);
     artist.addAlbum(album);
   }
   return album;
 }
Пример #14
0
      @Override
      public void onClick(View v) {
        // TODO: Check flag
        final Album album = mAlbums.get(getAdapterPosition());
        mCountPhotos = mImageUris.size();
        if (mSendPhoto) {
          mProgressDialog.show();
          for (Uri imageUri : mImageUris) {
            try {
              final Bitmap bitmap =
                  MediaStore.Images.Media.getBitmap(
                      SearchableActivity.this.getContentResolver(), imageUri);

              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);
              final byte[] data = stream.toByteArray();

              ParseFile file = new ParseFile("teste.jpg", data);

              file.saveInBackground(
                  new SaveCallback() {
                    public void done(ParseException e) {
                      // Handle success or failure here ...
                      mCountPhotos--;
                      if (mCountPhotos == 0) {
                        mProgressDialog.dismiss();
                      }
                    }
                  },
                  new ProgressCallback() {
                    public void done(Integer percentDone) {
                      // Update your progress spinner here. percentDone will be between 0 and 100.
                    }
                  });

              Photo photo = new Photo();
              photo.setImage(file);
              photo.setAlbum(album);
              photo.setAuthor(ParseUser.getCurrentUser());
              photo.saveInBackground();

            } catch (IOException e) {
              e.printStackTrace();
            }
            mSendPhoto = false;
          }

        } else {
          Intent intent = new Intent(SearchableActivity.this, AlbumDetailActivity.class);
          intent.putExtra(AlbumDetailActivity.ALBUM_ID_EXTRA, album.getObjectId());
          intent.putExtra(AlbumDetailActivity.ALBUM_NAME_EXTRA, album.getName());
          startActivity(intent);
        }
      }
Пример #15
0
 /**
  * Gets the album by name.
  *
  * @param name DOCUMENT_ME
  * @return associated album (case insensitive) or null if no match
  */
 public Album getAlbumByName(String name) {
   Album out = null;
   for (ReadOnlyIterator<Album> it = getAlbumsIterator(); it.hasNext(); ) {
     Album album = it.next();
     if (album.getName().equalsIgnoreCase(name)) {
       out = album;
       break;
     }
   }
   return out;
 }
Пример #16
0
  private List<Album> filter(List<Album> albums, String query) {
    query = query.toLowerCase();

    final List<Album> filteredAlbumsList = new ArrayList<>();
    for (Album album : albums) {
      final String text = album.getName().toLowerCase();
      if (text.contains(query)) {
        filteredAlbumsList.add(album);
      }
    }
    return filteredAlbumsList;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.activity_album_list, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.albumText);

    Album album = data.get(position);
    textView.setText(album.getAlbum_name());

    return rowView;
  }
Пример #18
0
  public void loadDataTrack(String path) {

    allTracks = new HashMap<Integer, Track>();
    List<String> data = loadData(path);
    for (String str : data) {
      Track track = new Track();
      String[] strArray = str.split("\\|");
      int trackId = Integer.parseInt(strArray[0]);
      int trackAlbum = -1; // -1 means none
      int trackArtist = -1;
      List<Integer> trackGenres = new LinkedList<Integer>();
      if (!strArray[1].equals("None")) {
        trackAlbum = Integer.parseInt(strArray[1]);
        if (allAlbums.containsKey(trackAlbum)) {
          Album album = allAlbums.get(trackAlbum);
          List<Integer> tracksInList = album.getTracks();
          tracksInList.add(trackId);
          album.setTracks(tracksInList);
          allAlbums.put(trackAlbum, album);
        }
      }
      if (!strArray[2].equals("None")) {
        trackArtist = Integer.parseInt(strArray[2]);
        if (allArtists.containsKey(trackArtist)) {
          Artist artist = allArtists.get(trackArtist);
          List<Integer> tracksInList = artist.getTracks();
          tracksInList.add(trackId);
          artist.setTracks(tracksInList);
          allArtists.put(trackArtist, artist);
        }
      }
      if (strArray.length > 3) {
        for (int i = 0; i < strArray.length - 3; i++) {
          int trackGenre = Integer.parseInt(strArray[i + 3]);
          trackGenres.add(trackGenre);
          if (allGenres.containsKey(trackGenre)) {
            Genre genre = allGenres.get(trackGenre);
            List<Integer> tracksInList = genre.getTracks();
            tracksInList.add(trackId);
            genre.setTracks(tracksInList);
            allGenres.put(trackGenre, genre);
          }
        }
      } else {
        trackGenres.add(-1);
      }
      track.setId(trackId);
      track.setAlbumId(trackAlbum);
      track.setArtistId(trackArtist);
      track.setGenreId(trackGenres);
      allTracks.put(trackId, track);
    }
  }
Пример #19
0
  /**
   * Search in database for the album with matching substring.
   *
   * @param searchString The substring in which the user typed in that is to be used in searching
   *     for the matching albums.
   * @return The list of albums with matching substring.
   */
  public LinkedList<Album> searchForAlbum(String searchString) {
    LinkedList<Album> results = new LinkedList<Album>();

    // Traverse the database and look for the album that contains
    // the search string.
    for (Album a : musicDb) {
      if (a.getTitle().contains(searchString)) {
        results.add(a);
      }
    }
    return results;
  }
  @Test
  public void testFindAllAlbumsByOwner() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    // Execute
    List<Album> foundAlbums = repository.findAllByOwner(user.getUserId());

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, createdAlbum.getAlbumId());
    assertEquals(1, foundAlbums.size());
    assertTrue(foundAlbums.contains(actualAlbum));
  }
Пример #21
0
 public synchronized void update(String title, String url) {
   album.setAlbumTitle(title);
   if (foreground) {
     browserController.updateBookmarks();
     browserController.updateInputBox(url);
   }
 }
Пример #22
0
 @Transient
 public Long getAlbumId() {
   if (albumId == null && album != null) {
     albumId = album.getId();
   }
   return albumId;
 }
  @Test
  public void testDeleteAlbum() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    em.persist(album);
    long albumId = album.getAlbumId();
    em.flush();

    // Execute
    repository.delete(album);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, albumId);
    assertNull(actualAlbum);
  }
Пример #24
0
  /**
   * Search for the list of songs that matches the searchString.
   *
   * @param searchString The searchString that is typed into the text box in the page.
   * @return The list of songs grouped into Hash Table for easy access.
   */
  public HashMap<Album, LinkedList<Song>> searchForSong(String searchString) {
    HashMap<Album, LinkedList<Song>> results = new HashMap<Album, LinkedList<Song>>();

    // Traverse the database, inside each album, looks for the song
    // that contains the search string.
    for (Album a : musicDb) {
      LinkedList<Song> songs = new LinkedList<Song>();
      for (Song s : a.getSongs()) {
        if (s.getTitle().contains(searchString)) {
          songs.add(s);
        }
      }
      results.put(a, songs);
    }

    return results;
  }
 @Override
 public Promise<Integer, Throwable, Void> getAlbumTrackCount(final Album album) {
   Deferred<Integer, Throwable, Void> deferred = new ADeferredObject<>();
   if (mAlbumTracks.get(album) != null) {
     return deferred.resolve(mAlbumTracks.get(album).size());
   }
   return deferred.reject(
       new Throwable("Couldn't find album " + album.getName() + " in collection"));
 }
Пример #26
0
 /**
  * Force to refresh the album max rating, it is not done soon as it is pretty CPU consumming and
  * we don't need a track by track rating precision.
  */
 public void refreshMaxRating() {
   // create a temporary table to remove unmounted albums
   // We consider an album as mounted if a least one track is mounted
   // This hashmap contains album-> album rates
   final Map<Album, Float> cacheRate =
       new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
   ReadOnlyIterator<Album> it = AlbumManager.getInstance().getAlbumsIterator();
   while (it.hasNext()) {
     Album album = it.next();
     cacheRate.put(album, (float) album.getRate());
   }
   // OK, now keep only the highest score
   for (Map.Entry<Album, Float> album : cacheRate.entrySet()) {
     long value = Math.round(album.getValue());
     if (value > maxRate) {
       maxRate = value;
     }
   }
 }
Пример #27
0
  /**
   * Adds metadata from the current track to a {@code MediaMetadata.Builder} object.
   *
   * @param metadata The constructed {@code MediaMetadata.Builder} object to add the current track
   *     metadata to.
   */
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public void getMediaMetadata(final MediaMetadata.Builder metadata) {
    final Album album = getAlbum();

    metadata
        .putLong(MediaMetadata.METADATA_KEY_DISC_NUMBER, (long) getDisc())
        .putLong(MediaMetadata.METADATA_KEY_DURATION, getTime())
        .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, (long) getTotalTracks())
        .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, (long) getTrack())
        .putLong(MediaMetadata.METADATA_KEY_YEAR, album.getDate())
        .putString(MediaMetadata.METADATA_KEY_ALBUM, album.getName())
        .putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName())
        .putString(MediaMetadata.METADATA_KEY_ARTIST, getArtistName())
        .putString(MediaMetadata.METADATA_KEY_COMPOSER, getComposerName())
        .putString(MediaMetadata.METADATA_KEY_DATE, Long.toString(getDate()))
        .putString(MediaMetadata.METADATA_KEY_TITLE, getTitle());

    putResponseObject(metadata, MediaMetadata.METADATA_KEY_GENRE, getGenres());
  }
Пример #28
0
  // pokazuje piosenki wybranego albumu
  private void showCurrentAlbum(Album album) {
    flowPane.getChildren().clear();

    Song tempSong = album.getSongs().get(0);
    // ok³adka albumu
    ImageView albumCover = new ImageView(tempSong.getAlbumCover());
    albumCover.imageProperty().bind(tempSong.albumCoverProperty());
    albumCover.setFitWidth(200);
    albumCover.setPreserveRatio(true);
    // tytu³ albumu
    Text albumTitle = new Text(tempSong.getAlbum());
    albumTitle.textProperty().bind(tempSong.albumProperty());
    albumTitle.setFont(new Font("Segoe UI Light", 20));
    albumTitle.setFill(Paint.valueOf("WHITE"));
    // VBox zawieraj¹cy ok³adkê i tytu³
    VBox albumData = new VBox(albumCover, albumTitle);
    flowPane.getChildren().addAll(albumData);

    loadSongs(album.getSongs());
  }
Пример #29
0
 /**
  * Change the item
  *
  * @param old
  * @param sNewName
  * @return new album
  */
 public Album changeAlbumName(Album old, String sNewName) throws JajukException {
   // check there is actually a change
   if (old.getName2().equals(sNewName)) {
     return old;
   }
   Album newItem = registerAlbum(sNewName);
   // re apply old properties from old item
   newItem.cloneProperties(old);
   // update tracks
   for (Track track : TrackManager.getInstance().getTracks()) {
     if (track.getAlbum().equals(old)) {
       TrackManager.getInstance().changeTrackAlbum(track, sNewName, null);
     }
   }
   // if current track album name is changed, notify it
   if (FIFO.getInstance().getCurrentFile() != null
       && FIFO.getInstance().getCurrentFile().getTrack().getAlbum().equals(old)) {
     ObservationManager.notify(new Event(EventSubject.EVENT_ALBUM_CHANGED));
   }
   return newItem;
 }
Пример #30
-1
  public void edit(final Context context) {

    String album = "*";
    String title = "*";
    String artist = "*";
    String editable = "";
    String typeName = "";
    if (this instanceof Song) {
      Song song = (Song) this;
      title = song.getName();
      album = song.getAlbum().getName();
      artist = song.getArtist().getName();
      editable = title;
      typeName = "track";
    } else if (this instanceof Album) {
      Album a = (Album) this;
      if (a.getArtist().getName().trim().equals("") == false) {
        artist = a.getArtist().getName();
      }
      album = a.getName();
      editable = album;
      typeName = "album";
    } else if (this instanceof Artist) {
      Artist a = (Artist) this;
      artist = a.getName();
      editable = artist;
      typeName = "artist";
    }
    showEditDialog(context, typeName, editable, title, album, artist);
  }